# 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 );
* @access public
*/
function isMovable() {
- return Namespace::isMovable( $this->getNamespace() );
+ return Namespace::isMovable( $this->getNamespace() )
+ && $this->getInterwiki() == '';
}
/**
}
/**
- * 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();
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';
}
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 );
&& $this->getNamespace() == $title->getNamespace()
&& $this->getDbkey() == $title->getDbkey();
}
+
+ /**
+ * Check if page exists
+ * @return bool
+ */
+ function exists() {
+ return $this->getArticleId() != 0;
+ }
}
?>