Merge "Remove unnecesary else blocks"
[lhc/web/wiklou.git] / includes / MovePage.php
index 39dc642..2ad3158 100644 (file)
@@ -57,7 +57,7 @@ class MovePage {
                // Convert into a Status object
                if ( $errors ) {
                        foreach ( $errors as $error ) {
-                               call_user_func_array( [ $status, 'fatal' ], $error );
+                               $status->fatal( ...$error );
                        }
                }
 
@@ -280,13 +280,7 @@ class MovePage {
                        [ 'cl_from' => $pageid ],
                        __METHOD__
                );
-               if ( $this->newTitle->getNamespace() == NS_CATEGORY ) {
-                       $type = 'subcat';
-               } elseif ( $this->newTitle->getNamespace() == NS_FILE ) {
-                       $type = 'file';
-               } else {
-                       $type = 'page';
-               }
+               $type = MWNamespace::getCategoryLinkType( $this->newTitle->getNamespace() );
                foreach ( $prefixes as $prefixRow ) {
                        $prefix = $prefixRow->cl_sortkey_prefix;
                        $catTo = $prefixRow->cl_to;
@@ -310,7 +304,7 @@ class MovePage {
                        # Protect the redirect title as the title used to be...
                        $res = $dbw->select(
                                'page_restrictions',
-                               '*',
+                               [ 'pr_type', 'pr_level', 'pr_cascade', 'pr_user', 'pr_expiry' ],
                                [ 'pr_page' => $pageid ],
                                __METHOD__,
                                'FOR UPDATE'
@@ -415,7 +409,9 @@ class MovePage {
                        new AtomicSectionUpdate(
                                $dbw,
                                __METHOD__,
-                               function () use ( $params ) {
+                               // Hold onto $user to avoid HHVM bug where it no longer
+                               // becomes a reference (T118683)
+                               function () use ( $params, &$user ) {
                                        Hooks::run( 'TitleMoveComplete', $params );
                                }
                        )
@@ -442,7 +438,6 @@ class MovePage {
        private function moveToInternal( User $user, &$nt, $reason = '', $createRedirect = true,
                array $changeTags = []
        ) {
-               global $wgContLang;
                if ( $nt->exists() ) {
                        $moveOverRedirect = true;
                        $logType = 'move_redir';
@@ -520,8 +515,6 @@ class MovePage {
                if ( $reason ) {
                        $comment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason;
                }
-               # Truncate for whole multibyte characters.
-               $comment = $wgContLang->truncate( $comment, 255 );
 
                $dbw = wfGetDB( DB_MASTER );
 
@@ -530,15 +523,6 @@ class MovePage {
 
                $newpage = WikiPage::factory( $nt );
 
-               # Save a null revision in the page's history notifying of the move
-               $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true, $user );
-               if ( !is_object( $nullRevision ) ) {
-                       throw new MWException( 'No valid null revision produced in ' . __METHOD__ );
-               }
-
-               $nullRevId = $nullRevision->insertOn( $dbw );
-               $logEntry->setAssociatedRevId( $nullRevId );
-
                # Change the name of the target page:
                $dbw->update( 'page',
                        /* SET */ [
@@ -549,6 +533,15 @@ class MovePage {
                        __METHOD__
                );
 
+               # Save a null revision in the page's history notifying of the move
+               $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true, $user );
+               if ( !is_object( $nullRevision ) ) {
+                       throw new MWException( 'No valid null revision produced in ' . __METHOD__ );
+               }
+
+               $nullRevId = $nullRevision->insertOn( $dbw );
+               $logEntry->setAssociatedRevId( $nullRevId );
+
                if ( !$redirectContent ) {
                        // Clean up the old title *before* reset article id - T47348
                        WikiPage::onArticleDelete( $this->oldTitle );
@@ -600,7 +593,12 @@ class MovePage {
 
                                $redirectArticle->doEditUpdates( $redirectRevision, $user, [ 'created' => true ] );
 
-                               ChangeTags::addTags( $changeTags, null, $redirectRevId, null );
+                               // make a copy because of log entry below
+                               $redirectTags = $changeTags;
+                               if ( in_array( 'mw-new-redirect', ChangeTags::getSoftwareTags() ) ) {
+                                       $redirectTags[] = 'mw-new-redirect';
+                               }
+                               ChangeTags::addTags( $redirectTags, null, $redirectRevId, null );
                        }
                }