KSS: Make section headings links
[lhc/web/wiklou.git] / includes / MovePage.php
index 994be91..9891106 100644 (file)
@@ -64,24 +64,12 @@ class MovePage {
                        $status->fatal( 'spamprotectiontext' );
                }
 
-               # The move is allowed only if (1) the target doesn't exist, or
-               # (2) the target is a redirect to the source, and has no history
-               # (so we can undo bad moves right after they're done).
-
-               if ( $this->newTitle->getArticleID() ) { # Target exists; check for validity
-                       if ( !$this->isValidMoveTarget() ) {
-                               $status->fatal( 'articleexists' );
-                       }
-               } else {
-                       $tp = $this->newTitle->getTitleProtection();
-                       if ( $tp !== false ) {
-                               if ( !$user->isAllowed( $tp['permission'] ) ) {
-                                       $status->fatal( 'cantmove-titleprotected' );
-                               }
-                       }
+               $tp = $this->newTitle->getTitleProtection();
+               if ( $tp !== false && !$user->isAllowed( $tp['permission'] ) ) {
+                               $status->fatal( 'cantmove-titleprotected' );
                }
 
-               wfRunHooks( 'MovePageCheckPermissions',
+               Hooks::run( 'MovePageCheckPermissions',
                        array( $this->oldTitle, $this->newTitle, $user, $reason, $status )
                );
 
@@ -125,6 +113,13 @@ class MovePage {
                        $status->fatal( 'badarticleerror' );
                }
 
+               # The move is allowed only if (1) the target doesn't exist, or
+               # (2) the target is a redirect to the source, and has no history
+               # (so we can undo bad moves right after they're done).
+               if ( $this->newTitle->getArticleID() && !$this->isValidMoveTarget() ) {
+                       $status->fatal( 'articleexists' );
+               }
+
                // Content model checks
                if ( !$wgContentHandlerUseDB &&
                        $this->oldTitle->getContentModel() !== $this->newTitle->getContentModel() ) {
@@ -146,7 +141,7 @@ class MovePage {
                }
 
                // Hook for extensions to say a title can't be moved for technical reasons
-               wfRunHooks( 'MovePageIsValidMove', array( $this->oldTitle, $this->newTitle, $status ) );
+               Hooks::run( 'MovePageIsValidMove', array( $this->oldTitle, $this->newTitle, $status ) );
 
                return $status;
        }
@@ -159,6 +154,7 @@ class MovePage {
        protected function isValidFileMove() {
                $status = new Status();
                $file = wfLocalFile( $this->oldTitle );
+               $file->load( File::READ_LATEST );
                if ( $file->exists() ) {
                        if ( $this->newTitle->getText() != wfStripIllegalFilenameChars( $this->newTitle->getText() ) ) {
                                $status->fatal( 'imageinvalidfilename' );
@@ -186,6 +182,7 @@ class MovePage {
                # Is it an existing file?
                if ( $this->newTitle->inNamespace( NS_FILE ) ) {
                        $file = wfLocalFile( $this->newTitle );
+                       $file->load( File::READ_LATEST );
                        if ( $file->exists() ) {
                                wfDebug( __METHOD__ . ": file exists\n" );
                                return false;
@@ -231,13 +228,14 @@ class MovePage {
        public function move( User $user, $reason, $createRedirect ) {
                global $wgCategoryCollation;
 
-               wfRunHooks( 'TitleMove', array( $this->oldTitle, $this->newTitle, $user ) );
+               Hooks::run( 'TitleMove', array( $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.
                $dbw = wfGetDB( DB_MASTER );
                if ( $this->oldTitle->getNamespace() == NS_FILE ) {
                        $file = wfLocalFile( $this->oldTitle );
+                       $file->load( File::READ_LATEST );
                        if ( $file->exists() ) {
                                $status = $file->move( $this->newTitle );
                                if ( !$status->isOk() ) {
@@ -370,7 +368,10 @@ class MovePage {
 
                $dbw->commit( __METHOD__ );
 
-               wfRunHooks( 'TitleMoveComplete', array( &$this->oldTitle, &$this->newTitle, &$user, $pageid, $redirid, $reason ) );
+               Hooks::run(
+                       'TitleMoveComplete',
+                       array( &$this->oldTitle, &$this->newTitle, &$user, $pageid, $redirid, $reason )
+               );
                return Status::newGood();
        }
 
@@ -486,7 +487,7 @@ class MovePage {
 
                $newpage->updateRevisionOn( $dbw, $nullRevision );
 
-               wfRunHooks( 'NewRevisionFromEditComplete',
+               Hooks::run( 'NewRevisionFromEditComplete',
                        array( $newpage, $nullRevision, $nullRevision->getParentId(), $user ) );
 
                $newpage->doEditUpdates( $nullRevision, $user,
@@ -513,7 +514,7 @@ class MovePage {
                                $redirectRevision->insertOn( $dbw );
                                $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
 
-                               wfRunHooks( 'NewRevisionFromEditComplete',
+                               Hooks::run( 'NewRevisionFromEditComplete',
                                        array( $redirectArticle, $redirectRevision, false, $user ) );
 
                                $redirectArticle->doEditUpdates( $redirectRevision, $user, array( 'created' => true ) );