X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FMovePage.php;h=6d69eaa60baa65e8f34405cc22745fefadc55d53;hb=3167a7162ce4a61c4ddb84e1ccfadf1acfea5d41;hp=0f9374a7e3b5b186e647857402693fb399b9e244;hpb=bbe58340d3a9de8d21282a4732faa924192ffec6;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/MovePage.php b/includes/MovePage.php index 0f9374a7e3..6d69eaa60b 100644 --- a/includes/MovePage.php +++ b/includes/MovePage.php @@ -55,7 +55,7 @@ class MovePage { // Convert into a Status object if ( $errors ) { foreach ( $errors as $error ) { - call_user_func_array( array( $status, 'fatal' ), $error ); + call_user_func_array( [ $status, 'fatal' ], $error ); } } @@ -70,7 +70,7 @@ class MovePage { } Hooks::run( 'MovePageCheckPermissions', - array( $this->oldTitle, $this->newTitle, $user, $reason, $status ) + [ $this->oldTitle, $this->newTitle, $user, $reason, $status ] ); return $status; @@ -141,7 +141,7 @@ class MovePage { } // Hook for extensions to say a title can't be moved for technical reasons - Hooks::run( 'MovePageIsValidMove', array( $this->oldTitle, $this->newTitle, $status ) ); + Hooks::run( 'MovePageIsValidMove', [ $this->oldTitle, $this->newTitle, $status ] ); return $status; } @@ -228,7 +228,7 @@ class MovePage { public function move( User $user, $reason, $createRedirect ) { global $wgCategoryCollation; - Hooks::run( 'TitleMove', array( $this->oldTitle, $this->newTitle, $user ) ); + Hooks::run( 'TitleMove', [ $this->oldTitle, $this->newTitle, $user ] ); // If it is a file, move it first. // It is done before all other moving stuff is done because it's hard to revert. @@ -252,7 +252,7 @@ class MovePage { $protected = $this->oldTitle->isProtected(); // Do the actual move - $this->moveToInternal( $user, $this->newTitle, $reason, $createRedirect ); + $nullRevision = $this->moveToInternal( $user, $this->newTitle, $reason, $createRedirect ); // Refresh the sortkey for this row. Be careful to avoid resetting // cl_timestamp, which may disturb time-based lists on some sites. @@ -260,8 +260,8 @@ class MovePage { // from LinksUpdate::getCategoryInsertions() and friends. $prefixes = $dbw->select( 'categorylinks', - array( 'cl_sortkey_prefix', 'cl_to' ), - array( 'cl_from' => $pageid ), + [ 'cl_sortkey_prefix', 'cl_to' ], + [ 'cl_from' => $pageid ], __METHOD__ ); if ( $this->newTitle->getNamespace() == NS_CATEGORY ) { @@ -275,15 +275,15 @@ class MovePage { $prefix = $prefixRow->cl_sortkey_prefix; $catTo = $prefixRow->cl_to; $dbw->update( 'categorylinks', - array( + [ 'cl_sortkey' => Collation::singleton()->getSortKey( $this->newTitle->getCategorySortkey( $prefix ) ), 'cl_collation' => $wgCategoryCollation, 'cl_type' => $type, - 'cl_timestamp=cl_timestamp' ), - array( + 'cl_timestamp=cl_timestamp' ], + [ 'cl_from' => $pageid, - 'cl_to' => $catTo ), + 'cl_to' => $catTo ], __METHOD__ ); } @@ -293,17 +293,17 @@ class MovePage { if ( $protected ) { # Protect the redirect title as the title used to be... $dbw->insertSelect( 'page_restrictions', 'page_restrictions', - array( + [ 'pr_page' => $redirid, 'pr_type' => 'pr_type', 'pr_level' => 'pr_level', 'pr_cascade' => 'pr_cascade', 'pr_user' => 'pr_user', 'pr_expiry' => 'pr_expiry' - ), - array( 'pr_page' => $pageid ), + ], + [ 'pr_page' => $pageid ], __METHOD__, - array( 'IGNORE' ) + [ 'IGNORE' ] ); // Build comment for log @@ -320,10 +320,10 @@ class MovePage { $insertedPrIds = $dbw->select( 'page_restrictions', 'pr_id', - array( 'pr_page' => $redirid ), + [ 'pr_page' => $redirid ], __METHOD__ ); - $logRelationsValues = array(); + $logRelationsValues = []; foreach ( $insertedPrIds as $prid ) { $logRelationsValues[] = $prid->pr_id; } @@ -333,10 +333,10 @@ class MovePage { $logEntry->setTarget( $this->newTitle ); $logEntry->setComment( $comment ); $logEntry->setPerformer( $user ); - $logEntry->setParameters( array( + $logEntry->setParameters( [ '4::oldtitle' => $this->oldTitle->getPrefixedText(), - ) ); - $logEntry->setRelations( array( 'pr_id' => $logRelationsValues ) ); + ] ); + $logEntry->setRelations( [ 'pr_id' => $logRelationsValues ] ); $logId = $logEntry->insert(); $logEntry->publish( $logId ); } @@ -344,18 +344,18 @@ class MovePage { // Update *_from_namespace fields as needed if ( $this->oldTitle->getNamespace() != $this->newTitle->getNamespace() ) { $dbw->update( 'pagelinks', - array( 'pl_from_namespace' => $this->newTitle->getNamespace() ), - array( 'pl_from' => $pageid ), + [ 'pl_from_namespace' => $this->newTitle->getNamespace() ], + [ 'pl_from' => $pageid ], __METHOD__ ); $dbw->update( 'templatelinks', - array( 'tl_from_namespace' => $this->newTitle->getNamespace() ), - array( 'tl_from' => $pageid ), + [ 'tl_from_namespace' => $this->newTitle->getNamespace() ], + [ 'tl_from' => $pageid ], __METHOD__ ); $dbw->update( 'imagelinks', - array( 'il_from_namespace' => $this->newTitle->getNamespace() ), - array( 'il_from' => $pageid ), + [ 'il_from_namespace' => $this->newTitle->getNamespace() ], + [ 'il_from' => $pageid ], __METHOD__ ); } @@ -369,10 +369,26 @@ class MovePage { WatchedItem::duplicateEntries( $this->oldTitle, $this->newTitle ); } + Hooks::run( + 'TitleMoveCompleting', + [ $this->oldTitle, $this->newTitle, + $user, $pageid, $redirid, $reason, $nullRevision ] + ); + $dbw->endAtomic( __METHOD__ ); - $params = array( $this->oldTitle, $this->newTitle, $user, $pageid, $redirid, $reason ); - $dbw->onTransactionIdle( function () use ( $params ) { + $params = [ + &$this->oldTitle, + &$this->newTitle, + &$user, + $pageid, + $redirid, + $reason, + $nullRevision + ]; + $dbw->onTransactionIdle( function () use ( $params, $dbw ) { + // Keep each single hook handler atomic + $dbw->setFlag( DBO_TRX ); // flag is automatically reset by DB layer Hooks::run( 'TitleMoveComplete', $params ); } ); @@ -389,6 +405,7 @@ class MovePage { * @param string $reason The reason for the move * @param bool $createRedirect Whether to leave a redirect at the old title. Does not check * if the user has the suppressredirect right + * @return Revision the revision created by the move * @throws MWException */ private function moveToInternal( User $user, &$nt, $reason = '', $createRedirect = true ) { @@ -435,10 +452,10 @@ class MovePage { $logEntry->setPerformer( $user ); $logEntry->setTarget( $logTitle ); $logEntry->setComment( $reason ); - $logEntry->setParameters( array( + $logEntry->setParameters( [ '4::target' => $nt->getPrefixedText(), '5::noredir' => $redirectContent ? '0': '1', - ) ); + ] ); $formatter = LogFormatter::newFromEntry( $logEntry ); $formatter->setContext( RequestContext::newExtraneousContext( $this->oldTitle ) ); @@ -464,7 +481,7 @@ class MovePage { # by definition if we've got here it's rather uninteresting. # We have to remove it so that the next step doesn't trigger # a conflict on the unique namespace+title index... - $dbw->delete( 'page', array( 'page_id' => $newid ), __METHOD__ ); + $dbw->delete( 'page', [ 'page_id' => $newid ], __METHOD__ ); $newpage->doDeleteUpdates( $newid, $newcontent ); } @@ -479,11 +496,11 @@ class MovePage { # Change the name of the target page: $dbw->update( 'page', - /* SET */ array( + /* SET */ [ 'page_namespace' => $nt->getNamespace(), 'page_title' => $nt->getDBkey(), - ), - /* WHERE */ array( 'page_id' => $oldid ), + ], + /* WHERE */ [ 'page_id' => $oldid ], __METHOD__ ); @@ -499,17 +516,17 @@ class MovePage { $newpage->updateRevisionOn( $dbw, $nullRevision ); Hooks::run( 'NewRevisionFromEditComplete', - array( $newpage, $nullRevision, $nullRevision->getParentId(), $user ) ); + [ $newpage, $nullRevision, $nullRevision->getParentId(), $user ] ); $newpage->doEditUpdates( $nullRevision, $user, - array( 'changed' => false, 'moved' => true, 'oldcountable' => $oldcountable ) ); + [ 'changed' => false, 'moved' => true, 'oldcountable' => $oldcountable ] ); // If the default content model changes, we need to populate rev_content_model if ( $defaultContentModelChanging ) { $dbw->update( 'revision', - array( 'rev_content_model' => $contentModel ), - array( 'rev_page' => $nt->getArticleID(), 'rev_content_model IS NULL' ), + [ 'rev_content_model' => $contentModel ], + [ 'rev_page' => $nt->getArticleID(), 'rev_content_model IS NULL' ], __METHOD__ ); } @@ -525,25 +542,27 @@ class MovePage { $newid = $redirectArticle->insertOn( $dbw ); if ( $newid ) { // sanity $this->oldTitle->resetArticleID( $newid ); - $redirectRevision = new Revision( array( + $redirectRevision = new Revision( [ 'title' => $this->oldTitle, // for determining the default content model 'page' => $newid, 'user_text' => $user->getName(), 'user' => $user->getId(), 'comment' => $comment, - 'content' => $redirectContent ) ); + 'content' => $redirectContent ] ); $redirectRevision->insertOn( $dbw ); $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 ); Hooks::run( 'NewRevisionFromEditComplete', - array( $redirectArticle, $redirectRevision, false, $user ) ); + [ $redirectArticle, $redirectRevision, false, $user ] ); - $redirectArticle->doEditUpdates( $redirectRevision, $user, array( 'created' => true ) ); + $redirectArticle->doEditUpdates( $redirectRevision, $user, [ 'created' => true ] ); } } # Log the move $logid = $logEntry->insert(); $logEntry->publish( $logid ); + + return $nullRevision; } }