/** * @param $page WikiPage object to work on * @param $user User doing the action * @param $token * @param $oldimage * @param $reason * @param $suppress bool * @return \type|array|Title */ public static function deleteFile(Page $page, User $user, $token, $oldimage, &$reason = null, $suppress = false) { $title = $page->getTitle(); $errors = self::getPermissionsError($title, $user, $token); if (count($errors)) { return $errors; } $file = $page->getFile(); if (!$file->exists() || !$file->isLocal() || $file->getRedirected()) { return self::delete($page, $user, $token, $reason); } if ($oldimage) { if (!FileDeleteForm::isValidOldSpec($oldimage)) { return array(array('invalidoldimage')); } $oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName($title, $oldimage); if (!$oldfile->exists() || !$oldfile->isLocal() || $oldfile->getRedirected()) { return array(array('nodeleteablefile')); } } else { $oldfile = false; } if (is_null($reason)) { // Log and RC don't like null reasons $reason = ''; } $status = FileDeleteForm::doDelete($title, $file, $oldimage, $reason, $suppress); if (!$status->isGood()) { return array(array('cannotdelete', $title->getPrefixedText())); } return array(); }
/** * @param Page $page Object to work on * @param User $user User doing the action * @param string $oldimage Archive name * @param string $reason Reason for the deletion. Autogenerated if null. * @param bool $suppress Whether to mark all deleted versions as restricted * @return Status|array */ protected static function deleteFile(Page $page, User $user, $oldimage, &$reason = null, $suppress = false) { $title = $page->getTitle(); $file = $page->getFile(); if (!$file->exists() || !$file->isLocal() || $file->getRedirected()) { return self::delete($page, $user, $reason); } if ($oldimage) { if (!FileDeleteForm::isValidOldSpec($oldimage)) { return array(array('invalidoldimage')); } $oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName($title, $oldimage); if (!$oldfile->exists() || !$oldfile->isLocal() || $oldfile->getRedirected()) { return array(array('nodeleteablefile')); } } if (is_null($reason)) { // Log and RC don't like null reasons $reason = ''; } return FileDeleteForm::doDelete($title, $file, $oldimage, $reason, $suppress, $user); }
/** * @static * @param $token * @param $title * @param $oldimage * @param $reason * @param $suppress bool * @return \type|array|Title */ public static function deleteFile($token, &$title, $oldimage, &$reason = null, $suppress = false) { $errors = self::getPermissionsError($title, $token); if (count($errors)) { return $errors; } if ($oldimage && !FileDeleteForm::isValidOldSpec($oldimage)) { return array(array('invalidoldimage')); } $file = wfFindFile($title, array('ignoreRedirect' => true)); $oldfile = false; if ($oldimage) { $oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName($title, $oldimage); } if (!FileDeleteForm::haveDeletableFile($file, $oldfile, $oldimage)) { return self::delete(new Article($title), $token, $reason); } if (is_null($reason)) { // Log and RC don't like null reasons $reason = ''; } $status = FileDeleteForm::doDelete($title, $file, $oldimage, $reason, $suppress); if (!$status->isGood()) { return array(array('cannotdelete', $title->getPrefixedText())); } return array(); }