示例#1
0
 public function execute()
 {
     global $wgUser;
     $this->getMain()->requestWriteMode();
     $params = $this->extractRequestParams();
     $titleObj = NULL;
     if (!isset($params['title'])) {
         $this->dieUsageMsg(array('missingparam', 'title'));
     }
     if (!isset($params['token'])) {
         $this->dieUsageMsg(array('missingparam', 'token'));
     }
     if (!$wgUser->isAllowed('undelete')) {
         $this->dieUsageMsg(array('permdenied-undelete'));
     }
     if ($wgUser->isBlocked()) {
         $this->dieUsageMsg(array('blockedtext'));
     }
     if (!$wgUser->matchEditToken($params['token'])) {
         $this->dieUsageMsg(array('sessionfailure'));
     }
     $titleObj = Title::newFromText($params['title']);
     if (!$titleObj) {
         $this->dieUsageMsg(array('invalidtitle', $params['title']));
     }
     // Convert timestamps
     if (!isset($params['timestamps'])) {
         $params['timestamps'] = array();
     }
     if (!is_array($params['timestamps'])) {
         $params['timestamps'] = array($params['timestamps']);
     }
     foreach ($params['timestamps'] as $i => $ts) {
         $params['timestamps'][$i] = wfTimestamp(TS_MW, $ts);
     }
     $pa = new PageArchive($titleObj);
     $dbw = wfGetDB(DB_MASTER);
     $dbw->begin();
     $retval = $pa->undelete(isset($params['timestamps']) ? $params['timestamps'] : array(), $params['reason']);
     if (!is_array($retval)) {
         $this->dieUsageMsg(array('cannotundelete'));
     }
     if ($retval[1]) {
         wfRunHooks('FileUndeleteComplete', array($titleObj, array(), $wgUser, $params['reason']));
     }
     $info['title'] = $titleObj->getPrefixedText();
     $info['revisions'] = $retval[0];
     $info['fileversions'] = $retval[1];
     $info['reason'] = $retval[2];
     $this->getResult()->addValue(null, $this->getModuleName(), $info);
 }
示例#2
0
 public function execute()
 {
     global $wgUser;
     $user = $this->getOption('user', 'Command line script');
     $reason = $this->getOption('reason', '');
     $pageName = $this->getArg();
     $title = Title::newFromText($pageName);
     if (!$title) {
         $this->error("Invalid title", true);
     }
     $wgUser = User::newFromName($user);
     $archive = new PageArchive($title);
     $this->output("Undeleting " . $title->getPrefixedDBkey() . '...');
     $archive->undelete(array(), $reason);
     $this->output("done\n");
 }
示例#3
0
 /**
  * Restore the given (or all) text and video revisions for the page.
  * Once restored, the items will be removed from the archive tables.
  * The deletion log will be updated with an undeletion notice.
  *
  * @param $timestamps Array: pass an empty array to restore all revisions,
  *                           otherwise list the ones to undelete.
  * @param $comment String: reason for undeleting
  * @param $fileVersions Array
  * @param $unsuppress Boolean: false by default
  *
  * @return array(number of file revisions restored, number of video revisions restored, log message)
  *         on success, false on failure
  */
 function undelete($timestamps, $comment = '', $fileVersions = array(), $unsuppress = false)
 {
     // We currently restore only whole deleted videos, a restore link from
     // log could take us here...
     if ($this->title->exists()) {
         return;
     }
     $dbw = wfGetDB(DB_MASTER);
     $result = $dbw->select('oldvideo', '*', array('ov_name' => $this->title->getDBkey()), __METHOD__, array('ORDER BY' => 'ov_timestamp DESC'));
     $insertBatch = array();
     $insertCurrent = false;
     $archiveName = '';
     $first = true;
     foreach ($result as $row) {
         if ($first) {
             // this is our new current revision
             $insertCurrent = array('video_name' => $row->ov_name, 'video_url' => $row->ov_url, 'video_type' => $row->ov_type, 'video_user_id' => $row->ov_user_id, 'video_user_name' => $row->ov_user_name, 'video_timestamp' => $row->ov_timestamp);
         } else {
             // older revisions, they could be even elder current ones from ancient deletions
             $insertBatch = array('ov_name' => $row->ov_name, 'ov_archive_name' => $archiveName, 'ov_url' => $row->ov_url, 'ov_type' => $row->ov_type, 'ov_user_id' => $row->ov_user_id, 'ov_user_name' => $row->ov_user_name, 'ov_timestamp' => $row->ov_timestamp);
         }
         $first = false;
     }
     unset($result);
     if ($insertCurrent) {
         $dbw->insert('video', $insertCurrent, __METHOD__);
     }
     if ($insertBatch) {
         $dbw->insert('oldvideo', $insertBatch, __METHOD__);
     }
     // run parent version, because it uses a private function inside
     // files will not be touched anyway here, because it's not NS_FILE
     parent::undelete($timestamps, $comment, $fileVersions, $unsuppress);
     return array('', '', '');
 }
示例#4
0
 public function execute()
 {
     $this->useTransactionalTimeLimit();
     $params = $this->extractRequestParams();
     $user = $this->getUser();
     if (!$user->isAllowed('undelete')) {
         $this->dieUsageMsg('permdenied-undelete');
     }
     if ($user->isBlocked()) {
         $this->dieBlocked($user->getBlock());
     }
     $titleObj = Title::newFromText($params['title']);
     if (!$titleObj || $titleObj->isExternal()) {
         $this->dieUsageMsg(['invalidtitle', $params['title']]);
     }
     // Check if user can add tags
     if (!is_null($params['tags'])) {
         $ableToTag = ChangeTags::canAddTagsAccompanyingChange($params['tags'], $user);
         if (!$ableToTag->isOK()) {
             $this->dieStatus($ableToTag);
         }
     }
     // Convert timestamps
     if (!isset($params['timestamps'])) {
         $params['timestamps'] = [];
     }
     if (!is_array($params['timestamps'])) {
         $params['timestamps'] = [$params['timestamps']];
     }
     foreach ($params['timestamps'] as $i => $ts) {
         $params['timestamps'][$i] = wfTimestamp(TS_MW, $ts);
     }
     $pa = new PageArchive($titleObj, $this->getConfig());
     $retval = $pa->undelete(isset($params['timestamps']) ? $params['timestamps'] : [], $params['reason'], $params['fileids'], false, $user, $params['tags']);
     if (!is_array($retval)) {
         $this->dieUsageMsg('cannotundelete');
     }
     if ($retval[1]) {
         Hooks::run('FileUndeleteComplete', [$titleObj, $params['fileids'], $this->getUser(), $params['reason']]);
     }
     $this->setWatch($params['watchlist'], $titleObj);
     $info['title'] = $titleObj->getPrefixedText();
     $info['revisions'] = intval($retval[0]);
     $info['fileversions'] = intval($retval[1]);
     $info['reason'] = $retval[2];
     $this->getResult()->addValue(null, $this->getModuleName(), $info);
 }
 public function execute()
 {
     global $wgUser;
     $params = $this->extractRequestParams();
     if (!$wgUser->isAllowed('undelete')) {
         $this->dieUsageMsg('permdenied-undelete');
     }
     if ($wgUser->isBlocked()) {
         $this->dieUsageMsg('blockedtext');
     }
     $titleObj = Title::newFromText($params['title']);
     if (!$titleObj) {
         $this->dieUsageMsg(array('invalidtitle', $params['title']));
     }
     // Convert timestamps
     if (!isset($params['timestamps'])) {
         $params['timestamps'] = array();
     }
     if (!is_array($params['timestamps'])) {
         $params['timestamps'] = array($params['timestamps']);
     }
     foreach ($params['timestamps'] as $i => $ts) {
         $params['timestamps'][$i] = wfTimestamp(TS_MW, $ts);
     }
     $pa = new PageArchive($titleObj);
     $retval = $pa->undelete(isset($params['timestamps']) ? $params['timestamps'] : array(), $params['reason']);
     if (!is_array($retval)) {
         $this->dieUsageMsg('cannotundelete');
     }
     if ($retval[1]) {
         wfRunHooks('FileUndeleteComplete', array($titleObj, array(), $wgUser, $params['reason']));
     }
     $this->setWatch($params['watchlist'], $titleObj);
     $info['title'] = $titleObj->getPrefixedText();
     $info['revisions'] = intval($retval[0]);
     $info['fileversions'] = intval($retval[1]);
     $info['reason'] = intval($retval[2]);
     $this->getResult()->addValue(null, $this->getModuleName(), $info);
 }
示例#6
0
 public function execute()
 {
     $this->useTransactionalTimeLimit();
     $params = $this->extractRequestParams();
     if (!$this->getUser()->isAllowed('undelete')) {
         $this->dieUsageMsg('permdenied-undelete');
     }
     if ($this->getUser()->isBlocked()) {
         $this->dieUsage('You have been blocked from editing', 'blocked', 0, array('blockinfo' => ApiQueryUserInfo::getBlockInfo($this->getUser()->getBlock())));
     }
     $titleObj = Title::newFromText($params['title']);
     if (!$titleObj || $titleObj->isExternal()) {
         $this->dieUsageMsg(array('invalidtitle', $params['title']));
     }
     // Convert timestamps
     if (!isset($params['timestamps'])) {
         $params['timestamps'] = array();
     }
     if (!is_array($params['timestamps'])) {
         $params['timestamps'] = array($params['timestamps']);
     }
     foreach ($params['timestamps'] as $i => $ts) {
         $params['timestamps'][$i] = wfTimestamp(TS_MW, $ts);
     }
     $pa = new PageArchive($titleObj, $this->getConfig());
     $retval = $pa->undelete(isset($params['timestamps']) ? $params['timestamps'] : array(), $params['reason'], $params['fileids'], false, $this->getUser());
     if (!is_array($retval)) {
         $this->dieUsageMsg('cannotundelete');
     }
     if ($retval[1]) {
         Hooks::run('FileUndeleteComplete', array($titleObj, $params['fileids'], $this->getUser(), $params['reason']));
     }
     $this->setWatch($params['watchlist'], $titleObj);
     $info['title'] = $titleObj->getPrefixedText();
     $info['revisions'] = intval($retval[0]);
     $info['fileversions'] = intval($retval[1]);
     $info['reason'] = $retval[2];
     $this->getResult()->addValue(null, $this->getModuleName(), $info);
 }
示例#7
0
 public function execute()
 {
     global $wgUser;
     $user = $this->getOption('user', false);
     $reason = $this->getOption('reason', '');
     $pageName = $this->getArg();
     $title = Title::newFromText($pageName);
     if (!$title) {
         $this->error("Invalid title", true);
     }
     if ($user === false) {
         $wgUser = User::newSystemUser('Command line script', array('steal' => true));
     } else {
         $wgUser = User::newFromName($user);
     }
     if (!$wgUser) {
         $this->error("Invalid username", true);
     }
     $archive = new PageArchive($title, RequestContext::getMain()->getConfig());
     $this->output("Undeleting " . $title->getPrefixedDBkey() . '...');
     $archive->undelete(array(), $reason);
     $this->output("done\n");
 }
 /**
  * Hook
  *
  * @param Title $oTitle -- instance of Title class
  * @param Revision $revision    -- new revision
  * @param Integer  $old_page_id  -- old page ID
  *
  * @static
  * @access public
  *
  * @return boolean -- because it's a hook
  */
 public static function undeleteComments(&$oTitle, $revision, $old_page_id)
 {
     global $wgRC2UDPEnabled;
     wfProfileIn(__METHOD__);
     if ($oTitle instanceof Title) {
         $new_page_id = $oTitle->getArticleId();
         $listing = ArticleCommentList::newFromTitle($oTitle);
         $pagesToRecover = $listing->getRemovedCommentPages($oTitle);
         if (!empty($pagesToRecover) && is_array($pagesToRecover)) {
             $irc_backup = $wgRC2UDPEnabled;
             //backup
             $wgRC2UDPEnabled = false;
             //turn off
             foreach ($pagesToRecover as $page_id => $page_value) {
                 $oCommentTitle = Title::makeTitleSafe($page_value['nspace'], $page_value['title']);
                 if ($oCommentTitle instanceof Title) {
                     $archive = new PageArchive($oCommentTitle);
                     $ok = $archive->undelete('', wfMsg('article-comments-undeleted-comment', $new_page_id));
                     if (!is_array($ok)) {
                         Wikia::log(__METHOD__, 'error', "cannot restore comment {$page_value['title']} (id: {$page_id})");
                     }
                 }
             }
             $wgRC2UDPEnabled = $irc_backup;
             //restore to whatever it was
         }
     }
     wfProfileOut(__METHOD__);
     return true;
 }
示例#9
0
 function undelete()
 {
     global $wgUploadMaintenance;
     if ($wgUploadMaintenance && $this->mTargetObj->getNamespace() == NS_FILE) {
         throw new ErrorPageError('undelete-error', 'filedelete-maintenance');
     }
     if (wfReadOnly()) {
         throw new ReadOnlyError();
     }
     # <Wikia> - use Phalanx to check recovered page title
     if (!wfRunHooks('CreatePageTitleCheck', array($this->mTargetObj, false))) {
         throw new ErrorPageError('undelete-error', 'spamprotectiontext');
     }
     # </Wikia>
     $out = $this->getOutput();
     $archive = new PageArchive($this->mTargetObj);
     wfRunHooks('UndeleteForm::undelete', array(&$archive, $this->mTargetObj));
     $ok = $archive->undelete($this->mTargetTimestamp, $this->mComment, $this->mFileVersions, $this->mUnsuppress);
     if (is_array($ok)) {
         if ($ok[1]) {
             // Undeleted file count
             wfRunHooks('FileUndeleteComplete', array($this->mTargetObj, $this->mFileVersions, $this->getUser(), $this->mComment));
         }
         $link = Linker::linkKnown($this->mTargetObj);
         $out->addHTML($this->msg('undeletedpage')->rawParams($link)->parse());
     } else {
         $out->setPageTitle($this->msg('undelete-error'));
         $out->addWikiMsg('cannotundelete');
         $out->addWikiMsg('undeleterevdel');
     }
     // Show file deletion warnings and errors
     $status = $archive->getFileStatus();
     if ($status && !$status->isGood()) {
         $out->addWikiText($status->getWikiText('undelete-error-short', 'undelete-error-long'));
     }
 }
示例#10
0
 function hideArchivedRevision($dbw, $timestamp)
 {
     $archive = new PageArchive($this->mTarget);
     $rev = $archive->getRevision($timestamp);
     if (!$rev) {
         $dbw->rollback();
         return 'hiderevision-error-missing';
     }
     $this->insertRevision($dbw, $this->mTarget, $rev);
     if ($dbw->affectedRows() != 1) {
         $dbw->rollback();
         return 'hiderevision-error-delete';
     }
     $dbw->delete('archive', array('ar_namespace' => $this->mTarget->getNamespace(), 'ar_title' => $this->mTarget->getDBkey(), 'ar_timestamp' => $timestamp), __METHOD__);
     $dbw->commit();
     return 'hiderevision-success';
 }
 /**
  * Undelete page (local file)
  * @param Title $title
  * @param boolean $removePremium
  * @return Status $status
  */
 public function undeletePage($title, $removePremium = false)
 {
     wfProfileIn(__METHOD__);
     // use Phalanx to check recovered page title
     if (!wfRunHooks('CreatePageTitleCheck', array($title, false))) {
         wfProfileOut(__METHOD__);
         return Status::newFatal(wfMessage('spamprotectiontext')->text());
     }
     $archive = new PageArchive($title);
     wfRunHooks('UndeleteForm::undelete', array(&$archive, $title));
     $time = '';
     $comment = '';
     $fileVersions = array();
     $unsuppress = false;
     $status = $archive->undelete($time, $comment, $fileVersions, $unsuppress);
     if (is_array($status)) {
         // Undeleted file count
         if ($status[1]) {
             // remove premium video from video_info table if swapping same video titles
             if ($removePremium) {
                 wfRunHooks('RemovePremiumVideo', array($title));
             }
             // clear file cache
             RepoGroup::singleton()->clearCache($title);
             wfRunHooks('FileUndeleteComplete', array($title, $fileVersions, $this->wg->User, $comment));
         }
         $status = Status::newGood();
     } else {
         $status = Status::newFatal(wfMessage('cannotundelete')->text());
     }
     wfProfileOut(__METHOD__);
     return $status;
 }
 function undelete()
 {
     global $wgOut, $wgUser;
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         return;
     }
     if (!is_null($this->mTargetObj)) {
         $archive = new PageArchive($this->mTargetObj);
         $ok = $archive->undelete($this->mTargetTimestamp, $this->mComment, $this->mFileVersions);
         if (is_array($ok)) {
             $skin = $wgUser->getSkin();
             $link = $skin->makeKnownLinkObj($this->mTargetObj);
             $wgOut->addHtml(wfMsgWikiHtml('undeletedpage', $link));
         } else {
             $wgOut->showFatalError(wfMsg("cannotundelete"));
         }
         // Show file deletion warnings and errors
         $status = $archive->getFileStatus();
         if ($status && !$status->isGood()) {
             $wgOut->addWikiText($status->getWikiText('undelete-error-short', 'undelete-error-long'));
         }
     } else {
         $wgOut->showFatalError(wfMsg("cannotundelete"));
     }
     return false;
 }
示例#13
0
 function undelete()
 {
     global $wgOut, $wgUser;
     if (!is_null($this->mTargetObj)) {
         $archive = new PageArchive($this->mTargetObj);
         $ok = true;
         $ok = $archive->undelete($this->mTargetTimestamp, $this->mComment, $this->mFileVersions);
         if ($ok) {
             $skin =& $wgUser->getSkin();
             $link = $skin->makeKnownLinkObj($this->mTargetObj);
             $wgOut->addHtml(wfMsgWikiHtml('undeletedpage', $link));
             return true;
         }
     }
     $wgOut->showFatalError(wfMsg("cannotundelete"));
     return false;
 }
示例#14
0
 /**
  * @author ADi
  */
 public function restoreItems()
 {
     global $wgRC2UDPEnabled;
     wfProfileIn(__METHOD__);
     if ($this->mTitle instanceof Title) {
         $itemsToRecover = $this->_getRemovedItems();
         if (count($itemsToRecover) > 0) {
             $ircBackup = $wgRC2UDPEnabled;
             //backup
             $wgRC2UDPEnabled = false;
             //turn off
             foreach ($itemsToRecover as $pageId => $pageData) {
                 $itemTitle = Title::makeTitleSafe($pageData['nspace'], $pageData['title']);
                 if ($itemTitle instanceof Title) {
                     $archive = new PageArchive($itemTitle);
                     $result = $archive->undelete('', wfMsg('toplists-item-restored', $this->mTitle->getArticleId()));
                     if (!is_array($result)) {
                         Wikia::log(__METHOD__, 'error', "cannot restore list item: {$pageData['title']} (id: {$pageId})");
                     }
                 }
             }
             $wgRC2UDPEnabled = $ircBackup;
             //restore to whatever it was
         }
     }
     wfProfileOut(__METHOD__);
     return true;
 }
示例#15
0
 function undelete()
 {
     global $wgOut, $wgUser;
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         return;
     }
     if (!is_null($this->mTargetObj)) {
         $archive = new PageArchive($this->mTargetObj);
         $ok = $archive->undelete($this->mTargetTimestamp, $this->mComment, $this->mFileVersions, $this->mUnsuppress);
         if (is_array($ok)) {
             if ($ok[1]) {
                 // Undeleted file count
                 wfRunHooks('FileUndeleteComplete', array($this->mTargetObj, $this->mFileVersions, $wgUser, $this->mComment));
             }
             $skin = $wgUser->getSkin();
             $link = $skin->linkKnown($this->mTargetObj);
             $wgOut->addHTML(wfMsgWikiHtml('undeletedpage', $link));
         } else {
             $wgOut->showFatalError(wfMsg("cannotundelete"));
             $wgOut->addHTML('<p>' . wfMsgHtml("undeleterevdel") . '</p>');
         }
         // Show file deletion warnings and errors
         $status = $archive->getFileStatus();
         if ($status && !$status->isGood()) {
             $wgOut->addWikiText($status->getWikiText('undelete-error-short', 'undelete-error-long'));
         }
     } else {
         $wgOut->showFatalError(wfMsg("cannotundelete"));
     }
     return false;
 }
示例#16
0
<?php

$usage = <<<EOT
Undelete a page
Usage: php undelete.php [-u <user>] [-r <reason>] <pagename>

EOT;
$optionsWithArgs = array('u', 'r');
require_once 'commandLine.inc';
$user = '******';
$reason = '';
if (isset($options['u'])) {
    $user = $options['u'];
}
if (isset($options['r'])) {
    $reason = $options['r'];
}
$pageName = @$args[0];
$title = Title::newFromText($pageName);
if (!$title) {
    echo $usage;
    exit(1);
}
$wgUser = User::newFromName($user);
$archive = new PageArchive($title);
echo "Undeleting " . $title->getPrefixedDBkey() . '...';
$archive->undelete(array(), $reason);
echo "done\n";
 function undelete()
 {
     global $wgOut;
     if (!is_null($this->mTargetObj)) {
         $archive = new PageArchive($this->mTargetObj);
         if ($archive->undelete($this->mTargetTimestamp)) {
             $wgOut->addWikiText(wfMsg("undeletedtext", $this->mTarget));
             if (NS_IMAGE == $this->mTargetObj->getNamespace()) {
                 /* refresh image metadata cache */
                 new Image($this->mTargetObj);
             }
             return true;
         }
     }
     $wgOut->fatalError(wfMsg("cannotundelete"));
     return false;
 }
示例#18
0
 function undelete()
 {
     if ($this->getConfig()->get('UploadMaintenance') && $this->mTargetObj->getNamespace() == NS_FILE) {
         throw new ErrorPageError('undelete-error', 'filedelete-maintenance');
     }
     $this->checkReadOnly();
     $out = $this->getOutput();
     $archive = new PageArchive($this->mTargetObj, $this->getConfig());
     Hooks::run('UndeleteForm::undelete', array(&$archive, $this->mTargetObj));
     $ok = $archive->undelete($this->mTargetTimestamp, $this->mComment, $this->mFileVersions, $this->mUnsuppress, $this->getUser());
     if (is_array($ok)) {
         if ($ok[1]) {
             // Undeleted file count
             Hooks::run('FileUndeleteComplete', array($this->mTargetObj, $this->mFileVersions, $this->getUser(), $this->mComment));
         }
         $link = Linker::linkKnown($this->mTargetObj);
         $out->addHTML($this->msg('undeletedpage')->rawParams($link)->parse());
     } else {
         $out->setPageTitle($this->msg('undelete-error'));
     }
     // Show revision undeletion warnings and errors
     $status = $archive->getRevisionStatus();
     if ($status && !$status->isGood()) {
         $out->addWikiText('<div class="error">' . $status->getWikiText('cannotundelete', 'cannotundelete') . '</div>');
     }
     // Show file undeletion warnings and errors
     $status = $archive->getFileStatus();
     if ($status && !$status->isGood()) {
         $out->addWikiText('<div class="error">' . $status->getWikiText('undelete-error-short', 'undelete-error-long') . '</div>');
     }
 }
示例#19
0
 function undelete()
 {
     if (wfReadOnly()) {
         throw new ReadOnlyError();
     }
     if (!is_null($this->mTargetObj)) {
         $archive = new PageArchive($this->mTargetObj);
         wfRunHooks('UndeleteForm::undelete', array(&$archive, $this->mTargetObj));
         $ok = $archive->undelete($this->mTargetTimestamp, $this->mComment, $this->mFileVersions, $this->mUnsuppress);
         if (is_array($ok)) {
             if ($ok[1]) {
                 // Undeleted file count
                 wfRunHooks('FileUndeleteComplete', array($this->mTargetObj, $this->mFileVersions, $this->getUser(), $this->mComment));
             }
             $link = Linker::linkKnown($this->mTargetObj);
             $this->getOutput()->addHTML(wfMessage('undeletedpage')->rawParams($link)->parse());
         } else {
             $this->getOutput()->showFatalError(wfMsg('cannotundelete'));
             $this->getOutput()->addWikiMsg('undeleterevdel');
         }
         // Show file deletion warnings and errors
         $status = $archive->getFileStatus();
         if ($status && !$status->isGood()) {
             $this->getOutput()->addWikiText($status->getWikiText('undelete-error-short', 'undelete-error-long'));
         }
     } else {
         $this->getOutput()->showFatalError(wfMsg('cannotundelete'));
     }
     return false;
 }