/** * Check whether a given move operation would be valid. * Returns true if ok, or a getUserPermissionsErrors()-like array otherwise * @param &$nt \type{Title} the new title * @param $auth \type{\bool} indicates whether $wgUser's permissions * should be checked * @param $reason \type{\string} is the log summary of the move, used for spam checking * @return \type{\mixed} True on success, getUserPermissionsErrors()-like array on failure */ public function isValidMoveOperation(&$nt, $auth = true, $reason = '') { global $wgUser; $errors = array(); if (!$nt) { // Normally we'd add this to $errors, but we'll get // lots of syntax errors if $nt is not an object return array(array('badtitletext')); } if ($this->equals($nt)) { $errors[] = array('selfmove'); } if (!$this->isMovable()) { $errors[] = array('immobile-source-namespace', $this->getNsText()); } if ($nt->getInterwiki() != '') { $errors[] = array('immobile-target-namespace-iw'); } if (!$nt->isMovable()) { $errors[] = array('immobile-target-namespace', $nt->getNsText()); } $oldid = $this->getArticleID(); $newid = $nt->getArticleID(); if (strlen($nt->getDBkey()) < 1) { $errors[] = array('articleexists'); } if ('' == $this->getDBkey() || !$oldid || '' == $nt->getDBkey()) { $errors[] = array('badarticleerror'); } // Image-specific checks if ($this->getNamespace() == NS_FILE) { $file = wfLocalFile($this); if ($file->exists()) { if ($nt->getNamespace() != NS_FILE) { $errors[] = array('imagenocrossnamespace'); } if ($nt->getText() != wfStripIllegalFilenameChars($nt->getText())) { $errors[] = array('imageinvalidfilename'); } if (!File::checkExtensionCompatibility($file, $nt->getDBKey())) { $errors[] = array('imagetypemismatch'); } } } if ($auth) { $errors = wfMergeErrorArrays($errors, $this->getUserPermissionsErrors('move', $wgUser), $this->getUserPermissionsErrors('edit', $wgUser), $nt->getUserPermissionsErrors('move-target', $wgUser), $nt->getUserPermissionsErrors('edit', $wgUser)); } $match = EditPage::matchSpamRegex($reason); if ($match !== false) { // This is kind of lame, won't display nice $errors[] = array('spamprotectiontext'); } $err = null; if (!wfRunHooks('AbortMove', array($this, $nt, $wgUser, &$err, $reason))) { $errors[] = array('hookaborted', $err); } # 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 (0 != $newid) { # Target exists; check for validity if (!$this->isValidMoveTarget($nt)) { $errors[] = array('articleexists'); } } else { $tp = $nt->getTitleProtection(); $right = $tp['pt_create_perm'] == 'sysop' ? 'protect' : $tp['pt_create_perm']; if ($tp and !$wgUser->isAllowed($right)) { $errors[] = array('cantmove-titleprotected'); } } if (empty($errors)) { return true; } return $errors; }