Index: trunk/extensions/SemanticInternalObjects/SemanticInternalObjects.php |
— | — | @@ -25,6 +25,7 @@ |
26 | 26 | $wgHooks['ParserClearState'][] = 'SIOHandler::clearState'; |
27 | 27 | $wgHooks['SMWSQLStore2::updateDataAfter'][] = 'SIOHandler::updateData'; |
28 | 28 | $wgHooks['smwUpdatePropertySubjects'][] = 'SIOHandler::handleUpdatingOfInternalObjects'; |
| 29 | +$wgHooks['TitleMoveComplete'][] = 'SIOHandler::handlePageMove'; |
29 | 30 | $wgHooks['smwRefreshDataJobs'][] = 'SIOHandler::handleRefreshingOfInternalObjects'; |
30 | 31 | $wgHooks['smwAddToRDFExport'][] = 'SIOSQLStore::createRDF'; |
31 | 32 | |
Index: trunk/extensions/SemanticInternalObjects/SemanticInternalObjects_body.php |
— | — | @@ -111,7 +111,12 @@ |
112 | 112 | |
113 | 113 | $iw = ''; |
114 | 114 | $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 | + ); |
116 | 121 | while ( $row = $db->fetchObject( $res ) ) { |
117 | 122 | $ids[] = $row->smw_id; |
118 | 123 | } |
— | — | @@ -195,7 +200,12 @@ |
196 | 201 | // each one, and add it to the general array |
197 | 202 | $iw = ''; |
198 | 203 | $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 | + ); |
200 | 210 | while ( $row = $db->fetchObject( $res ) ) { |
201 | 211 | $value = new SIOInternalObjectValue( $row->smw_title, $row->smw_namespace ); |
202 | 212 | $semdata = new SMWSemanticData( $value, false ); |
— | — | @@ -368,6 +378,45 @@ |
369 | 379 | } |
370 | 380 | |
371 | 381 | /** |
| 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 | + /** |
372 | 421 | * Takes a set of SMW "update jobs", and keeps only the unique, actual |
373 | 422 | * titles among them - this is useful if there are any internal objects |
374 | 423 | * among the group; a set of names like "Page name#1", "Page name#2" |