r91452 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91451‎ | r91452 | r91453 >
Date:11:57, 5 July 2011
Author:mkroetzsch
Status:deferred
Tags:
Comment:
refactored label of DIWikiPage subobject identifier to avoid confusion with numeric subobjectid in SQLStore
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_WikiPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php
@@ -477,7 +477,7 @@
478478 if ( $description->getDataItem() instanceof SMWDIWikiPage ) {
479479 if ( $description->getComparator() == SMW_CMP_EQ ) {
480480 $query->type = SMW_SQL2_VALUE;
481 - $oid = $this->m_store->getSMWPageID( $description->getDataItem()->getDBkey(), $description->getDataItem()->getNamespace(), $description->getDataItem()->getInterwiki(), $description->getDataItem()->getSubobjectId() );
 481+ $oid = $this->m_store->getSMWPageID( $description->getDataItem()->getDBkey(), $description->getDataItem()->getNamespace(), $description->getDataItem()->getInterwiki(), $description->getDataItem()->getSubobjectName() );
482482 $query->joinfield = array( $oid );
483483 } else { // Join with smw_ids needed for other comparators (apply to title string).
484484 $query->jointable = 'smw_ids';
@@ -778,7 +778,7 @@
779779 if ( $i >= count( $keys ) ) break;
780780
781781 if ( $ftype == 'p' ) { // Special case: page id, resolve this in advance
782 - $oid = $this->getSMWPageID( $dataItem->getDBkey(), $dataItem->getNamespace(), $dataItem->getInterwiki(), $dataItem->getSubobjectId() );
 782+ $oid = $this->getSMWPageID( $dataItem->getDBkey(), $dataItem->getNamespace(), $dataItem->getInterwiki(), $dataItem->getSubobjectName() );
783783 $where .= ( $where ? ' AND ' : '' ) . "{$query->alias}.$fname=" . $this->m_dbs->addQuotes( $oid );
784784 break;
785785 } elseif ( $ftype != 'l' ) { // plain value, but not a text blob
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php
@@ -119,7 +119,7 @@
120120
121121 // *** Find out if this subject exists ***//
122122 $sortkey = '';
123 - $sid = $this->getSMWPageIDandSort( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectId(), $sortkey, true );
 123+ $sid = $this->getSMWPageIDandSort( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName(), $sortkey, true );
124124 if ( $sid == 0 ) { // no data, safe our time
125125 /// NOTE: we consider redirects for getting $sid, so $sid == 0 also means "no redirects"
126126 self::$in_getSemanticData--;
@@ -130,7 +130,7 @@
131131 // *** Prepare the cache ***//
132132 if ( !array_key_exists( $sid, $this->m_semdata ) ) { // new cache entry
133133 $this->m_semdata[$sid] = new SMWSqlStubSemanticData( $subject, false );
134 - if ( $subject->getSubobjectId() == '' ) { // no sortkey for subobjects
 134+ if ( $subject->getSubobjectName() == '' ) { // no sortkey for subobjects
135135 $this->m_semdata[$sid]->addPropertyStubValue( '_SKEY', array( $sortkey ) );
136136 }
137137 $this->m_sdstate[$sid] = array();
@@ -502,7 +502,7 @@
503503 if ( $i >= count( $dbkeys ) ) break;
504504
505505 if ( $typeid == 'p' ) { // Special case: page id, resolve this in advance
506 - $oid = $this->getSMWPageID( $value->getDBkey(), $value->getNamespace(), $value->getInterwiki(), $value->getSubobjectId() );
 506+ $oid = $this->getSMWPageID( $value->getDBkey(), $value->getNamespace(), $value->getInterwiki(), $value->getSubobjectName() );
507507 $where .= ( $where ? ' AND ' : '' ) . "t$tableindex.$fieldname=" . $db->addQuotes( $oid );
508508 break;
509509 } elseif ( $typeid != 'l' ) { // plain value, but not a text blob
@@ -538,7 +538,7 @@
539539 */
540540 public function getProperties( SMWDIWikiPage $subject, $requestoptions = null ) {
541541 wfProfileIn( "SMWSQLStore2::getProperties (SMW)" );
542 - $sid = $this->getSMWPageID( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectId() );
 542+ $sid = $this->getSMWPageID( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName() );
543543
544544 if ( $sid == 0 ) { // no id, no page, no properties
545545 wfProfileOut( "SMWSQLStore2::getProperties (SMW)" );
@@ -726,7 +726,7 @@
727727 }
728728
729729 // Always make an ID (pages without ID cannot be in query results, not even in fixed value queries!):
730 - $sid = $this->makeSMWPageID( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectId(), true, $sortkey );
 730+ $sid = $this->makeSMWPageID( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName(), true, $sortkey );
731731 $updates = array(); // collect data for bulk updates; format: tableid => updatearray
732732 $this->prepareDBUpdates( $updates, $data, $sid, $subject );
733733
@@ -799,8 +799,8 @@
800800 protected function prepareDBUpdates( &$updates, SMWSemanticData $data, $sid, SMWDIWikiPage $subject ) {
801801 if ( $sid == 0 ) {
802802 $sid = $this->makeSMWPageID( $subject->getDBkey(), $subject->getNamespace(),
803 - $subject->getInterwiki(), $subject->getSubobjectId(), true,
804 - str_replace( '_', ' ', $subject->getDBkey() ) . $subject->getSubobjectId() );
 803+ $subject->getInterwiki(), $subject->getSubobjectName(), true,
 804+ str_replace( '_', ' ', $subject->getDBkey() ) . $subject->getSubobjectName() );
805805 }
806806
807807 $proptables = self::getPropertyTables();
@@ -845,7 +845,7 @@
846846 $namespace = next( $dbkeys );
847847 $iw = next( $dbkeys );
848848 $sortkey = next( $dbkeys ); // not used; sortkeys are not set on writing objects
849 - $uvals[$fieldname] = $this->makeSMWPageID( $di->getDBkey(), $di->getNamespace(), $di->getInterwiki(), $di->getSubobjectId() );
 849+ $uvals[$fieldname] = $this->makeSMWPageID( $di->getDBkey(), $di->getNamespace(), $di->getInterwiki(), $di->getSubobjectName() );
850850 }
851851
852852 next( $dbkeys );
@@ -1898,9 +1898,9 @@
18991899 * the canonical alias ID for the given page. If no such ID exists, 0 is
19001900 * returned.
19011901 */
1902 - public function getSMWPageID( $title, $namespace, $iw, $subobjectId, $canonical = true ) {
 1902+ public function getSMWPageID( $title, $namespace, $iw, $subobjectName, $canonical = true ) {
19031903 $sort = '';
1904 - return $this->getSMWPageIDandSort( $title, $namespace, $iw, $subobjectId, $sort, $canonical );
 1904+ return $this->getSMWPageIDandSort( $title, $namespace, $iw, $subobjectName, $sort, $canonical );
19051905 }
19061906
19071907 /**
@@ -1910,13 +1910,13 @@
19111911 * @todo Centralise creation of id cache keys, and make sure non-local pages have only one key
19121912 * (no need to distinguish canonical/non-canonical in this case).
19131913 */
1914 - public function getSMWPageIDandSort( $title, $namespace, $iw, $subobjectId, &$sort, $canonical ) {
 1914+ public function getSMWPageIDandSort( $title, $namespace, $iw, $subobjectName, &$sort, $canonical ) {
19151915 global $smwgQEqualitySupport;
19161916
19171917 wfProfileIn( 'SMWSQLStore2::getSMWPageID (SMW)' );
19181918
1919 - $ckey = "$iw $namespace $title $subobjectId C";
1920 - $nkey = "$iw $namespace $title $subobjectId -";
 1919+ $ckey = "$iw $namespace $title $subobjectName C";
 1920+ $nkey = "$iw $namespace $title $subobjectName -";
19211921 $key = ( $canonical ? $ckey : $nkey );
19221922
19231923 if ( array_key_exists( $key, $this->m_ids ) ) {
@@ -1935,7 +1935,7 @@
19361936 $res = $db->select(
19371937 'smw_ids',
19381938 array( 'smw_id', 'smw_sortkey' ),
1939 - array( 'smw_title' => $title, 'smw_namespace' => $namespace, 'smw_iw' => $iw, 'smw_subobject' => $subobjectId ),
 1939+ array( 'smw_title' => $title, 'smw_namespace' => $namespace, 'smw_iw' => $iw, 'smw_subobject' => $subobjectName ),
19401940 'SMW::getSMWPageID', array( 'LIMIT' => 1 )
19411941 );
19421942 $row = $db->fetchObject( $res );
@@ -1951,7 +1951,7 @@
19521952 ' AND smw_namespace=' . $db->addQuotes( $namespace ) .
19531953 ' AND (smw_iw=' . $db->addQuotes( '' ) .
19541954 ' OR smw_iw=' . $db->addQuotes( SMW_SQL2_SMWREDIIW ) . ')' .
1955 - ' AND smw_subobject=' . $db->addQuotes( $subobjectId ),
 1955+ ' AND smw_subobject=' . $db->addQuotes( $subobjectName ),
19561956 'SMW::getSMWPageID', array( 'LIMIT' => 1 ) );
19571957 $row = $db->fetchObject( $res );
19581958
@@ -1961,7 +1961,7 @@
19621962
19631963 if ( ( $row->smw_iw == '' ) ) { // the id found is unique (canonical and non-canonical); fill cache also for the case *not* asked for
19641964 $this->m_ids[ $canonical ? $nkey : $ckey ] = $id; // (the other cache is filled below)
1965 - } elseif ( $canonical && ( $subobjectId == '' ) && ( $smwgQEqualitySupport != SMW_EQ_NONE ) ) { // check for redirect alias
 1965+ } elseif ( $canonical && ( $subobjectName == '' ) && ( $smwgQEqualitySupport != SMW_EQ_NONE ) ) { // check for redirect alias
19661966 if ( $namespace == SMW_NS_PROPERTY ) { // redirect properties only to properties
19671967 ///TODO: Shouldn't this condition be ensured during writing?
19681968 $res2 = $db->select( array( 'smw_redi2', 'smw_ids' ), 'o_id',
@@ -2001,11 +2001,11 @@
20022002 * the title is a redirect target (we do not want chains of redirects).
20032003 * But it is of no relevance if the title does not have an id yet.
20042004 */
2005 - protected function makeSMWPageID( $title, $namespace, $iw, $subobjectId, $canonical = true, $sortkey = '' ) {
 2005+ protected function makeSMWPageID( $title, $namespace, $iw, $subobjectName, $canonical = true, $sortkey = '' ) {
20062006 wfProfileIn( 'SMWSQLStore2::makeSMWPageID (SMW)' );
20072007
20082008 $oldsort = '';
2009 - $id = $this->getSMWPageIDandSort( $title, $namespace, $iw, $subobjectId, $oldsort, $canonical );
 2009+ $id = $this->getSMWPageIDandSort( $title, $namespace, $iw, $subobjectName, $oldsort, $canonical );
20102010
20112011 if ( $id == 0 ) {
20122012 $db = wfGetDB( DB_MASTER );
@@ -2018,19 +2018,19 @@
20192019 'smw_title' => $title,
20202020 'smw_namespace' => $namespace,
20212021 'smw_iw' => $iw,
2022 - 'smw_subobject' => $subobjectId,
 2022+ 'smw_subobject' => $subobjectName,
20232023 'smw_sortkey' => $sortkey
20242024 ),
20252025 'SMW::makeSMWPageID'
20262026 );
20272027
20282028 $id = $db->insertId();
2029 - $this->m_ids["$iw $namespace $title $subobjectId -"] = $id; // fill that cache, even if canonical was given
 2029+ $this->m_ids["$iw $namespace $title $subobjectName -"] = $id; // fill that cache, even if canonical was given
20302030
20312031 // This ID is also authorative for the canonical version.
20322032 // This is always the case: if $canonical===false and $id===0, then there is no redi-entry in
20332033 // smw_ids either, hence the object just did not exist at all.
2034 - $this->m_ids["$iw $namespace $title $subobjectId C"] = $id;
 2034+ $this->m_ids["$iw $namespace $title $subobjectName C"] = $id;
20352035 } elseif ( ( $sortkey != '' ) && ( $sortkey != $oldsort ) ) {
20362036 $db = wfGetDB( DB_MASTER );
20372037 $db->update( 'smw_ids', array( 'smw_sortkey' => $sortkey ), array( 'smw_id' => $id ), 'SMW::makeSMWPageID' );
@@ -2086,9 +2086,9 @@
20872087 * with iw being SMW_SQL2_SMWREDIIW. This information is used to determine
20882088 * whether the given ID is canonical or not.
20892089 */
2090 - public function cacheSMWPageID( $id, $title, $namespace, $iw, $subobjectId ) {
2091 - $ckey = "$iw $namespace $title $subobjectId C";
2092 - $nkey = "$iw $namespace $title $subobjectId -";
 2090+ public function cacheSMWPageID( $id, $title, $namespace, $iw, $subobjectName ) {
 2091+ $ckey = "$iw $namespace $title $subobjectName C";
 2092+ $nkey = "$iw $namespace $title $subobjectName -";
20932093
20942094 if ( count( $this->m_ids ) > 1500 ) { // prevent memory leak in very long PHP runs
20952095 $this->m_ids = array();
@@ -2226,7 +2226,7 @@
22272227 * @param $subject SMWDIWikiPage the data of which is deleted
22282228 */
22292229 protected function deleteSemanticData( SMWDIWikiPage $subject ) {
2230 - if ( $subject->getSubobjectId() != '' ) return; // not needed, and would mess up data
 2230+ if ( $subject->getSubobjectName() != '' ) return; // not needed, and would mess up data
22312231
22322232 $db = wfGetDB( DB_MASTER );
22332233
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_WikiPage.php
@@ -30,11 +30,11 @@
3131 */
3232 protected $m_interwiki;
3333 /**
34 - * Id for subobjects of pages, or empty string if the given object is
 34+ * Name for subobjects of pages, or empty string if the given object is
3535 * the page itself (not a subobject).
3636 * @var string
3737 */
38 - protected $m_subobjectid;
 38+ protected $m_subobjectname;
3939
4040 /**
4141 * Contructor. We do not bother with too much detailed validation here,
@@ -44,14 +44,14 @@
4545 * would be more work than it is worth, since callers will usually be
4646 * careful and since errors here do not have major consequences.
4747 */
48 - public function __construct( $dbkey, $namespace, $interwiki, $subobjectid = '' ) {
 48+ public function __construct( $dbkey, $namespace, $interwiki, $subobjectname = '' ) {
4949 if ( !is_numeric( $namespace ) ) {
5050 throw new SMWDataItemException( "Given namespace '$namespace' is not an integer." );
5151 }
5252 $this->m_dbkey = $dbkey;
5353 $this->m_namespace = (int)$namespace; // really make this an integer
5454 $this->m_interwiki = $interwiki;
55 - $this->m_subobjectid = $subobjectid;
 55+ $this->m_subobjectname = $subobjectname;
5656 }
5757
5858 public function getDIType() {
@@ -70,8 +70,8 @@
7171 return $this->m_interwiki;
7272 }
7373
74 - public function getSubobjectId() {
75 - return $this->m_subobjectid;
 74+ public function getSubobjectName() {
 75+ return $this->m_subobjectname;
7676 }
7777
7878 /**
@@ -104,10 +104,10 @@
105105 }
106106
107107 public function getSerialization() {
108 - if ( $this->m_subobjectid == '' ) {
 108+ if ( $this->m_subobjectname == '' ) {
109109 return strval( $this->m_dbkey . '#' . strval( $this->m_namespace ) . '#' . $this->m_interwiki );
110110 } else {
111 - return strval( $this->m_dbkey . '#' . strval( $this->m_namespace ) . '#' . $this->m_interwiki . '#' . $this->m_subobjectid );
 111+ return strval( $this->m_dbkey . '#' . strval( $this->m_namespace ) . '#' . $this->m_interwiki . '#' . $this->m_subobjectname );
112112 }
113113 }
114114