Move page tweaks:
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 25 Apr 2005 09:25:06 +0000 (09:25 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 25 Apr 2005 09:25:06 +0000 (09:25 +0000)
* Handle attempt to move over self with a particular error message.
* Handle attempt to move page to invalid namespace or interwiki with a
particular error message.
* Don't offer to delete the target page if it's a self-move or illegal move!

includes/SpecialMovepage.php
includes/Title.php
languages/Language.php

index 9f33992..68b8a11 100644 (file)
@@ -76,16 +76,16 @@ class MovePageForm {
                        # when the form is first opened.
                        $encNewTitle = $oldTitle;
                } else {
-                       $nt = Title::newFromURL( $this->newTitle );
-                       if ( $nt ) {
-                               // Check if it's valid
-                               if ( !$nt->isValidMoveTarget( $ot ) ) {
-                                       $err = 'articleexists';
+                       if( $err == '' ) {
+                               $nt = Title::newFromURL( $this->newTitle );
+                               if( $nt ) {
+                                       # If a title was supplied, probably from the move log revert
+                                       # link, check for validity. We can then show some diagnostic
+                                       # information and save a click.
+                                       $err = $ot->isValidMoveOperation( $nt );
                                }
-                               $encNewTitle = htmlspecialchars( $this->newTitle );
-                       } else {
-                               $encNewTitle = $oldTitle;
                        }
+                       $encNewTitle = htmlspecialchars( $this->newTitle );
                }
                $encReason = htmlspecialchars( $this->reason );
 
index fa5c9c6..4c3cef6 100644 (file)
@@ -901,7 +901,8 @@ class Title {
         * @access public
         */
        function isMovable() {
-               return Namespace::isMovable( $this->getNamespace() );
+               return Namespace::isMovable( $this->getNamespace() )
+                       && $this->getInterwiki() == '';
        }
        
        /**
@@ -1451,18 +1452,26 @@ class Title {
        }
        
        /**
-        * Move a title to a new location
+        * Check whether a given move operation would be valid.
+        * Returns true if ok, or a message key string for an error message
+        * if invalid. (Scarrrrry ugly interface this.)
         * @param Title &$nt the new title
         * @param bool $auth indicates whether $wgUser's permissions
         *      should be checked
         * @return mixed true on success, message name on failure
         * @access public
         */
-       function moveTo( &$nt, $auth = true, $reason = '' ) {
+       function isValidMoveOperation( &$nt, $auth = true, $reason = '' ) {
                global $wgUser;
                if( !$this or !$nt ) {
                        return 'badtitletext';
                }
+               if( $this->equals( $nt ) ) {
+                       return 'selfmove';
+               }
+               if( !$this->isMovable() || !$nt->isMovable() ) {
+                       return 'immobile_namespace';
+               }
 
                $fname = 'Title::move';
                $oldid = $this->getArticleID();
@@ -1471,13 +1480,9 @@ class Title {
                if ( strlen( $nt->getDBkey() ) < 1 ) {
                        return 'articleexists';
                }
-               if ( ( ! Namespace::isMovable( $this->getNamespace() ) ) ||
-                        ( '' == $this->getDBkey() ) ||
-                        ( '' != $this->getInterwiki() ) ||
+               if ( ( '' == $this->getDBkey() ) ||
                         ( !$oldid ) ||
-                    ( ! Namespace::isMovable( $nt->getNamespace() ) ) ||
-                        ( '' == $nt->getDBkey() ) ||
-                        ( '' != $nt->getInterwiki() ) ) {
+                    ( '' == $nt->getDBkey() ) ) {
                        return 'badarticleerror';
                }
 
@@ -1495,6 +1500,24 @@ class Title {
                        if ( ! $this->isValidMoveTarget( $nt ) ) {
                                return 'articleexists';
                        }
+               }
+               return true;
+       }
+       
+       /**
+        * Move a title to a new location
+        * @param Title &$nt the new title
+        * @param bool $auth indicates whether $wgUser's permissions
+        *      should be checked
+        * @return mixed true on success, message name on failure
+        * @access public
+        */
+       function moveTo( &$nt, $auth = true, $reason = '' ) {
+               $err = $this->isValidMoveOperation( $nt, $auth, $reason );
+               if( is_string( $err ) ) {
+                       return $err;
+               }
+               if( $nt->exists() ) {
                        $this->moveOverExistingRedirect( $nt, $reason );
                } else { # Target didn't exist, do normal move.
                        $this->moveToNewTitle( $nt, $newid, $reason );
@@ -1957,6 +1980,14 @@ class Title {
                        && $this->getNamespace() == $title->getNamespace()
                        && $this->getDbkey() == $title->getDbkey();
        }
+       
+       /**
+        * Check if page exists
+        * @return bool
+        */
+       function exists() {
+               return $this->getArticleId() != 0;
+       }
 
 }
 ?>
index 959c60f..cf2674f 100644 (file)
@@ -1612,6 +1612,8 @@ title. Please merge them manually.',
 
 The destination article "[[$1]]" already exists. Do you want to delete it to make way for the move?',
 'delete_and_move_reason' => 'Deleted to make way for move',
+'selfmove' => "Source and destination titles are the same; can't move a page over itself.",
+'immobile_namespace' => "Destination title is of a special type; cannot move pages into that namespace.",
 
 # Export