From: Brion Vibber Date: Mon, 25 Apr 2005 09:25:06 +0000 (+0000) Subject: Move page tweaks: X-Git-Tag: 1.5.0alpha1~146 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=5a4abfcfc38732c8367b6b0bbfce9a48b03ec1f9;p=lhc%2Fweb%2Fwiklou.git Move page tweaks: * 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! --- diff --git a/includes/SpecialMovepage.php b/includes/SpecialMovepage.php index 9f33992c03..68b8a115b8 100644 --- a/includes/SpecialMovepage.php +++ b/includes/SpecialMovepage.php @@ -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 ); diff --git a/includes/Title.php b/includes/Title.php index fa5c9c6783..4c3cef6fb6 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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; + } } ?> diff --git a/languages/Language.php b/languages/Language.php index 959c60f4af..cf2674fac1 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -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