/** * @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); }
/** * Automatically review an revision and add a log entry in the review log. * * This is called during edit operations after the new revision is added * and the page tables updated, but before LinksUpdate is called. * * $auto is here for revisions checked off to be reviewed. Auto-review * triggers on edit, but we don't want those to count as just automatic. * This also makes it so the user's name shows up in the page history. * * If $flags is given, then they will be the review tags. If not, the one * from the stable version will be used or minimal tags if that's not possible. * If no appropriate tags can be found, then the review will abort. */ public static function autoReviewEdit(Page $article, $user, Revision $rev, array $flags = null, $auto = true) { wfProfileIn(__METHOD__); $title = $article->getTitle(); // convenience # Get current stable version ID (for logging) $oldSv = FlaggedRevision::newFromStable($title, FR_MASTER); $oldSvId = $oldSv ? $oldSv->getRevId() : 0; # Set the auto-review tags from the prior stable version. # Normally, this should already be done and given here... if (!is_array($flags)) { if ($oldSv) { # Use the last stable version if $flags not given if ($user->isAllowed('bot')) { $flags = $oldSv->getTags(); // no change for bot edits } else { # Account for perms/tags... $flags = self::getAutoReviewTags($user, $oldSv->getTags()); } } else { // new page? $flags = self::quickTags(FR_CHECKED); // use minimal level } if (!is_array($flags)) { wfProfileOut(__METHOD__); return false; // can't auto-review this revision } } # Get review property flags $propFlags = $auto ? array('auto') : array(); # Rev ID is not put into parser on edit, so do the same here. # Also, a second parse would be triggered otherwise. $editInfo = $article->prepareTextForEdit($rev->getText()); $poutput = $editInfo->output; // revision HTML output # If this is an image page, store corresponding file info $fileData = array('name' => null, 'timestamp' => null, 'sha1' => null); if ($title->getNamespace() == NS_FILE) { # We must use WikiFilePage process cache on upload or get bitten by slave lag $file = $article instanceof WikiFilePage || $article instanceof ImagePage ? $article->getFile() : wfFindFile($title, array('bypassCache' => true)); // skip cache; bug 31056 if (is_object($file) && $file->exists()) { $fileData['name'] = $title->getDBkey(); $fileData['timestamp'] = $file->getTimestamp(); $fileData['sha1'] = $file->getSha1(); } } # Our review entry $flaggedRevision = new FlaggedRevision(array('rev' => $rev, 'user_id' => $user->getId(), 'timestamp' => $rev->getTimestamp(), 'quality' => FlaggedRevs::getQualityTier($flags, 0), 'tags' => FlaggedRevision::flattenRevisionTags($flags), 'img_name' => $fileData['name'], 'img_timestamp' => $fileData['timestamp'], 'img_sha1' => $fileData['sha1'], 'templateVersions' => $poutput->getTemplateIds(), 'fileVersions' => $poutput->getFileSearchOptions(), 'flags' => implode(',', $propFlags))); $flaggedRevision->insert(); # Update the article review log FlaggedRevsLog::updateReviewLog($title, $flags, array(), '', $rev->getId(), $oldSvId, true, $auto); # Update page and tracking tables and clear cache FlaggedRevs::stableVersionUpdates($title); wfProfileOut(__METHOD__); return true; }