Example #1
0
 /**
  * Sanity checks for when a file is being moved
  *
  * @return Status
  */
 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');
         }
         if (!File::checkExtensionCompatibility($file, $this->newTitle->getDBkey())) {
             $status->fatal('imagetypemismatch');
         }
     }
     if (!$this->newTitle->inNamespace(NS_FILE)) {
         $status->fatal('imagenocrossnamespace');
     }
     return $status;
 }
Example #2
0
 /**
  * Check if the requested move target is a valid file move target
  * @param Title $nt Target title
  * @return array List of errors
  */
 protected function validateFileMoveOperation($nt)
 {
     global $wgUser;
     $errors = array();
     // wfFindFile( $nt ) / wfLocalFile( $nt ) is not allowed until below
     $file = wfLocalFile($this);
     if ($file->exists()) {
         if ($nt->getText() != wfStripIllegalFilenameChars($nt->getText())) {
             $errors[] = array('imageinvalidfilename');
         }
         if (!File::checkExtensionCompatibility($file, $nt->getDBkey())) {
             $errors[] = array('imagetypemismatch');
         }
     }
     if ($nt->getNamespace() != NS_FILE) {
         $errors[] = array('imagenocrossnamespace');
         // From here we want to do checks on a file object, so if we can't
         // create one, we must return.
         return $errors;
     }
     // wfFindFile( $nt ) / wfLocalFile( $nt ) is allowed below here
     $destFile = wfLocalFile($nt);
     if (!$wgUser->isAllowed('reupload-shared') && !$destFile->exists() && wfFindFile($nt)) {
         $errors[] = array('file-exists-sharedrepo');
     }
     return $errors;
 }
Example #3
0
 /**
  * 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) {
         if ($nt->getNamespace() != NS_FILE) {
             $errors[] = array('imagenocrossnamespace');
         }
         $file = wfLocalFile($this);
         if ($file->exists()) {
             if ($nt->getText() != wfStripIllegalFilenameChars($nt->getText())) {
                 $errors[] = array('imageinvalidfilename');
             }
             if (!File::checkExtensionCompatibility($file, $nt->getDBkey())) {
                 $errors[] = array('imagetypemismatch');
             }
         }
         $destfile = wfLocalFile($nt);
         if (!$wgUser->isAllowed('reupload-shared') && !$destfile->exists() && wfFindFile($nt)) {
             $errors[] = array('file-exists-sharedrepo');
         }
     }
     if ($nt->getNamespace() == NS_FILE && $this->getNamespace() != NS_FILE) {
         $errors[] = array('nonfile-cannot-move-to-file');
     }
     if ($auth) {
         $errors = wfMergeErrorArrays($errors, $this->getUserPermissionsErrors('move', $wgUser), $this->getUserPermissionsErrors('edit', $wgUser), $nt->getUserPermissionsErrors('move-target', $wgUser), $nt->getUserPermissionsErrors('edit', $wgUser));
     }
     $match = EditPage::matchSummarySpamRegex($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;
 }