r75859 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75858‎ | r75859 | r75860 >
Date:17:12, 2 November 2010
Author:yaron
Status:deferred
Tags:
Comment:
Added handling for page moves - this was previously ignored by SIO, leading to "left behind" internal objects
Modified paths:
  • /trunk/extensions/SemanticInternalObjects/SemanticInternalObjects.php (modified) (history)
  • /trunk/extensions/SemanticInternalObjects/SemanticInternalObjects_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticInternalObjects/SemanticInternalObjects.php
@@ -25,6 +25,7 @@
2626 $wgHooks['ParserClearState'][] = 'SIOHandler::clearState';
2727 $wgHooks['SMWSQLStore2::updateDataAfter'][] = 'SIOHandler::updateData';
2828 $wgHooks['smwUpdatePropertySubjects'][] = 'SIOHandler::handleUpdatingOfInternalObjects';
 29+$wgHooks['TitleMoveComplete'][] = 'SIOHandler::handlePageMove';
2930 $wgHooks['smwRefreshDataJobs'][] = 'SIOHandler::handleRefreshingOfInternalObjects';
3031 $wgHooks['smwAddToRDFExport'][] = 'SIOSQLStore::createRDF';
3132
Index: trunk/extensions/SemanticInternalObjects/SemanticInternalObjects_body.php
@@ -111,7 +111,12 @@
112112
113113 $iw = '';
114114 $db = wfGetDB( DB_SLAVE );
115 - $res = $db->select( 'smw_ids', array( 'smw_id' ), 'smw_title LIKE ' . $db->addQuotes( $pageName . '#%' ) . ' AND ' . 'smw_namespace=' . $db->addQuotes( $namespace ) . ' AND smw_iw=' . $db->addQuotes( $iw ), 'SIO::getSMWPageObjectIDs', array() );
 115+ $res = $db->select(
 116+ 'smw_ids',
 117+ array( 'smw_id' ),
 118+ 'smw_title LIKE ' . $db->addQuotes( $pageName . '#%' ) . ' AND ' . 'smw_namespace=' . $db->addQuotes( $namespace ) . ' AND smw_iw=' . $db->addQuotes( $iw ),
 119+ 'SIO::getSMWPageObjectIDs'
 120+ );
116121 while ( $row = $db->fetchObject( $res ) ) {
117122 $ids[] = $row->smw_id;
118123 }
@@ -195,7 +200,12 @@
196201 // each one, and add it to the general array
197202 $iw = '';
198203 $db = wfGetDB( DB_SLAVE );
199 - $res = $db->select( 'smw_ids', array( 'smw_id', 'smw_namespace', 'smw_title' ), 'smw_title LIKE ' . $db->addQuotes( $pageName . '#%' ) . ' AND ' . 'smw_namespace=' . $db->addQuotes( $namespace ) . ' AND smw_iw=' . $db->addQuotes( $iw ), 'SIO::getSMWPageObjectIDs', array() );
 204+ $res = $db->select(
 205+ 'smw_ids',
 206+ array( 'smw_id', 'smw_namespace', 'smw_title' ),
 207+ 'smw_title LIKE ' . $db->addQuotes( $pageName . '#%' ) . ' AND ' . 'smw_namespace=' . $db->addQuotes( $namespace ) . ' AND smw_iw=' . $db->addQuotes( $iw ),
 208+ 'SIO::getSMWPageObjectIDs'
 209+ );
200210 while ( $row = $db->fetchObject( $res ) ) {
201211 $value = new SIOInternalObjectValue( $row->smw_title, $row->smw_namespace );
202212 $semdata = new SMWSemanticData( $value, false );
@@ -368,6 +378,45 @@
369379 }
370380
371381 /**
 382+ * Called after a page is moved - renames all the internal objects
 383+ * named "Old page#x" to "New page#x".
 384+ */
 385+ static public function handlePageMove( &$old_title, &$new_title, &$user, $page_id, $redir_id ) {
 386+ $oldPageName = $old_title->getDBkey();
 387+ $oldNamespace = $old_title->getNamespace();
 388+ $newPageName = $new_title->getDBkey();
 389+ $newNamespace = $new_title->getNamespace();
 390+ $iw = '';
 391+ $sioNames = array();
 392+ $db = wfGetDB( DB_SLAVE );
 393+ // Unfortunately, there's no foolproof way to do the replacement
 394+ // with a single SQL call, using regexps and wildcards -
 395+ // instead, we first get the set of all matching entries in
 396+ // the 'smw_ids' table, then call an explicit update on each
 397+ // one.
 398+ $res = $db->select(
 399+ 'smw_ids',
 400+ array( 'smw_title' ),
 401+ 'smw_title LIKE ' . $db->addQuotes( $oldPageName . '#%' ) . ' AND ' . 'smw_namespace=' . $db->addQuotes( $oldNamespace ) . ' AND smw_iw=' . $db->addQuotes( $iw ),
 402+ 'SIO::getTitlesForPageMove'
 403+ );
 404+ while ( $row = $db->fetchObject( $res ) ) {
 405+ $sioNames[] = $row->smw_title;
 406+ }
 407+ foreach ( $sioNames as $sioName ) {
 408+ // update the name, and possibly the namespace as well
 409+ $newSIOName = str_replace( $oldPageName, $newPageName, $sioName );
 410+ $db->update(
 411+ 'smw_ids',
 412+ array( 'smw_title' => $newSIOName, 'smw_namespace' => $newNamespace ),
 413+ array( 'smw_title' => $sioName, 'smw_namespace' => $oldNamespace ),
 414+ 'SIO::updateTitlesForPageMove'
 415+ );
 416+ }
 417+ return true;
 418+ }
 419+
 420+ /**
372421 * Takes a set of SMW "update jobs", and keeps only the unique, actual
373422 * titles among them - this is useful if there are any internal objects
374423 * among the group; a set of names like "Page name#1", "Page name#2"

Status & tagging log