/**
  * @static
  * @param string $action
  * @param Article $article
  * @return bool
  * @throws UserBlockedError
  * @throws PermissionsError
  */
 static function onPowerDelete($action, $article)
 {
     global $wgOut, $wgUser, $wgRequest;
     if ($action !== 'powerdelete') {
         return true;
     }
     if (!$wgUser->isAllowed('delete') || !$wgUser->isAllowed('powerdelete')) {
         throw new PermissionsError('powerdelete');
     }
     if ($wgUser->isBlocked()) {
         throw new UserBlockedError($wgUser->mBlock);
     }
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         return false;
     }
     $reason = $wgRequest->getText('reason');
     $title = $article->getTitle();
     $file = $title->getNamespace() == NS_IMAGE ? wfLocalFile($title) : false;
     if ($file) {
         $oldimage = null;
         FileDeleteForm::doDelete($title, $file, $oldimage, $reason, false);
     } else {
         $article->doDelete($reason);
     }
     // this is stupid, but otherwise, WikiPage::doUpdateRestrictions complains about passing by reference
     $false = false;
     $article->doUpdateRestrictions(array('create' => 'sysop'), array('create' => 'infinity'), $false, $reason, $wgUser);
     return false;
 }
 /**
  * Helper function -- remove files and associated articles by Title
  *
  * @param Title $title Title to be removed
  *
  * @return bool
  */
 public function deleteFileByTitle($title)
 {
     if ($title->exists()) {
         $file = wfFindFile($title, array('ignoreRedirect' => true));
         $noOldArchive = "";
         // yes this really needs to be set this way
         $comment = "removing for test";
         $restrictDeletedVersions = false;
         $status = FileDeleteForm::doDelete($title, $file, $noOldArchive, $comment, $restrictDeletedVersions);
         if (!$status->isGood()) {
             return false;
         }
         $page = WikiPage::factory($title);
         $page->doDeleteArticle("removing for test");
         // see if it now doesn't exist; reload
         $title = Title::newFromText($title->getText(), NS_FILE);
     }
     return !($title && $title instanceof Title && $title->exists());
 }
Exemple #3
0
 protected function deleteFile($name)
 {
     $t = Title::newFromText($name, NS_FILE);
     $this->assertTrue($t->exists(), "File '{$name}' exists");
     if ($t->exists()) {
         $file = wfFindFile($name, array('ignoreRedirect' => true));
         $empty = "";
         FileDeleteForm::doDelete($t, $file, $empty, "none", true);
         $page = WikiPage::factory($t);
         $page->doDeleteArticle("testing");
     }
     $t = Title::newFromText($name, NS_FILE);
     $this->assertFalse($t->exists(), "File '{$name}' was deleted");
 }
 /**
  * Delete the file, or an earlier version of it
  */
 public function delete()
 {
     $file = $this->mPage->getFile();
     if (!$file->exists() || !$file->isLocal() || $file->getRedirected()) {
         // Standard article deletion
         parent::delete();
         return;
     }
     $deleter = new FileDeleteForm($file);
     $deleter->execute();
 }
Exemple #5
0
 /**
  * @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();
 }
Exemple #6
0
 /**
  * Delete the file, or an earlier version of it
  */
 public function delete()
 {
     global $wgUploadMaintenance;
     if ($wgUploadMaintenance && $this->mTitle && $this->mTitle->getNamespace() == NS_FILE) {
         global $wgOut;
         $wgOut->wrapWikiMsg("<div class='error'>\n\$1\n</div>\n", array('filedelete-maintenance'));
         return;
     }
     $this->loadFile();
     if (!$this->img->exists() || !$this->img->isLocal() || $this->img->getRedirected()) {
         // Standard article deletion
         parent::delete();
         return;
     }
     $deleter = new FileDeleteForm($this->img);
     $deleter->execute();
 }
Exemple #7
0
 /**
  * @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();
 }
Exemple #8
0
 static function deletePage($title, $sp = null)
 {
     $ret = null;
     $file = $title->getNamespace() == NS_IMAGE ? wfLocalFile($title) : false;
     if ($file) {
         $reason = wfMsg("blockandnuke-delete-file");
         $oldimage = null;
         // Must be passed by reference
         $ret = FileDeleteForm::doDelete($title, $file, $oldimage, $reason, false);
     } else {
         $reason = wfMsg("blockandnuke-delete-article");
         if ($title->isKnown()) {
             $article = new Article($title);
             $ret = $article->doDelete($reason);
             if ($ret && $sp) {
                 $sp->getOutput()->addHTML(wfMessage("blockandnuke-deleted-page", $title));
             }
         }
     }
     return $ret;
 }
Exemple #9
0
 /**
  * Delete the file, or an earlier version of it
  */
 public function delete()
 {
     if (!$this->img->exists() || !$this->img->isLocal()) {
         // Standard article deletion
         Article::delete();
         return;
     }
     $deleter = new FileDeleteForm($this->img);
     $deleter->execute();
 }
 function removeFilePermanently($fileName)
 {
     $deleteSuccess = false;
     try {
         $title = \Title::newFromText($fileName, NS_FILE);
         $file = \wfFindFile($title, array('ignoreRedirect' => true));
         $oldimage = null;
         // Leave it to null to delete all
         $reason = \wfMsg('attachmentRemovedPermanently');
         $suppress = false;
         // Do not hide revision log
         $status = \FileDeleteForm::doDelete($title, $file, $oldimage, $reason, $suppress);
         $deleteSuccess = $status->isGood() ? true : false;
     } catch (Exception $e) {
         $deleteSuccess = false;
     }
     return $deleteSuccess;
 }
Exemple #11
0
 function doDelete($pages, $reason)
 {
     foreach ($pages as $page) {
         $title = Title::newFromURL($page);
         $file = $title->getNamespace() == NS_IMAGE ? wfLocalFile($title) : false;
         if ($file) {
             $oldimage = null;
             // Must be passed by reference
             FileDeleteForm::doDelete($title, $file, $oldimage, $reason, false);
         } else {
             $article = new Article($title);
             $article->doDelete($reason);
         }
     }
 }
Exemple #12
0
    print "Skipping nonexistent page '" . $page->getPrefixedText() . "'\n";
    exit(1);
}
$wgTitle = $page;
// this cannot be NULL
print $page->getPrefixedText();
$dbw->begin();
$nspace = $page->getNamespace();
$success = 0;
$removed = 0;
if (in_array($nspace, array(NS_IMAGE, NS_FILE))) {
    $file = wfLocalFile($page);
    if ($file) {
        $oldimage = null;
        // Must be passed by reference
        $success = FileDeleteForm::doDelete($page, $file, $oldimage, $reason, $suppress)->isOK();
        $removed = 1;
    }
}
if ($removed == 0) {
    $page_id = $page->getArticleID();
    $art = new Article($page);
    $success = $art->doDeleteArticle($reason, $suppress);
}
$dbw->commit();
if ($success) {
    print "\n";
} else {
    print " FAILED\n";
}
if ($interval) {
 /**
  * Does the actual deletion of the pages.
  * 
  * @param array $pages The pages to delete
  * @param string $reason
  */
 protected function doDelete(array $pages, $reason)
 {
     global $wgOut;
     $res = array();
     foreach ($pages as $page) {
         $title = Title::newFromURL($page);
         $file = $title->getNamespace() == NS_FILE ? wfLocalFile($title) : false;
         if ($file) {
             $oldimage = null;
             // Must be passed by reference
             $ok = FileDeleteForm::doDelete($title, $file, $oldimage, $reason, false)->isOK();
         } else {
             $article = new Article($title, 0);
             $ok = $article->doDeleteArticle($reason);
         }
         if ($ok) {
             $res[] = wfMsgExt('nuke-deleted', array('parseinline'), $title->getPrefixedText());
         } else {
             $res[] = wfMsgExt('nuke-not-deleted', array('parseinline'), $title->getPrefixedText());
         }
     }
     $wgOut->addHTML("<ul>\n<li>" . implode("</li>\n<li>", $res) . "</li>\n</ul>\n");
 }
Exemple #14
0
 /**
  * Does the actual deletion of the pages.
  *
  * @param array $pages The pages to delete
  * @param string $reason
  */
 protected function doDelete(array $pages, $reason)
 {
     $res = array();
     foreach ($pages as $page) {
         $title = Title::newFromURL($page);
         $file = $title->getNamespace() == NS_FILE ? wfLocalFile($title) : false;
         $permission_errors = $title->getUserPermissionsErrors('delete', $this->getUser());
         if (count($permission_errors)) {
             throw new PermissionsError('delete', $permission_errors);
         }
         if ($file) {
             $oldimage = null;
             // Must be passed by reference
             $ok = FileDeleteForm::doDelete($title, $file, $oldimage, $reason, false)->isOK();
         } else {
             $article = new Article($title, 0);
             $ok = $article->doDeleteArticle($reason);
         }
         if ($ok) {
             $res[] = wfMsgExt('nuke-deleted', array('parseinline'), $title->getPrefixedText());
         } else {
             $res[] = wfMsgExt('nuke-not-deleted', array('parseinline'), $title->getPrefixedText());
         }
     }
     $this->getOutput()->addHTML("<ul>\n<li>" . implode("</li>\n<li>", $res) . "</li>\n</ul>\n");
     $this->getOutput()->addWikiMsg('nuke-delete-more');
 }
Exemple #15
0
	if( !$page->exists() ) {
		print "Skipping nonexistent page '" . $page->getPrefixedText () . "'\n";
		exit (1) ;
	}

	$wgTitle = $page; // this cannot be NULL

	print $page->getPrefixedText();
	$dbw->begin();
	$nspace = $page->getNamespace();
	$success = 0; $removed = 0;
	if ( in_array( $nspace, array(NS_IMAGE, NS_FILE) ) ) {
		$file = wfLocalFile( $page );
		if ( $file ) {
			$oldimage = null; // Must be passed by reference
			$success = FileDeleteForm::doDelete( $page, $file, $oldimage, $reason, false );
			$removed = 1;
		} 
	}
	if ( $removed == 0 ) {
		$page_id = $page->getArticleID();
		$art = new Article( $page );
		$success = $art->doDeleteArticle( $reason );
		if ( $success ) {
			wfRunHooks('ArticleDeleteComplete', array(&$art, &$wgUser, $reason, $page_id));
		}
	}
	$dbw->commit();

	if ( $success ) {
		print "\n";
Exemple #16
0
 /**
  * @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);
 }
 /**
  * Rollback edits and/or delete page creations by user
  *
  * @param $title String The page name to perform reverts on
  * @param $user String Username of user to revert
  * @param $time String Timestamp to revert edits since
  * @param $summary String Edit summary to give for reverts and deleted
  * @param $rollback Boolean Whether or not to perform rollbacks (default: true)
  * @param $delete Boolean Whether or not to perform deletions (default: true)
  * @param $markBot Boolean Whether or not to mark rollbacks as bot edits through
  *        the bot=1 URL parameter (default: false)
  * @return true on success, false on failure
  */
 private function rollbackTitle($title, $user, $time, $summary, $rollback = true, $delete = true, $markBot = false)
 {
     wfProfileIn(__METHOD__);
     // build article object and find article id
     $article = new Article($title);
     $pageId = $article->getID();
     // check if article exists
     if ($pageId <= 0) {
         wfProfileOut(__METHOD__);
         return false;
     }
     // fetch revisions from this article
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select('revision', array('rev_id', 'rev_user_text', 'rev_timestamp'), array('rev_page' => $pageId), __METHOD__, array('ORDER BY' => 'rev_id DESC'));
     // find the newest edit done by other user
     $revertRevId = false;
     while ($row = $dbr->fetchObject($res)) {
         if ($row->rev_user_text !== $user || $time !== '' && $row->rev_timestamp < $time) {
             $revertRevId = $row->rev_id;
             break;
         }
     }
     $dbr->freeResult($res);
     if ($revertRevId && $rollback) {
         // found an edit by other user - reverting
         $rev = Revision::newFromId($revertRevId);
         $text = $rev->getRawText();
         $flags = EDIT_UPDATE | EDIT_MINOR;
         if ($this->wg->User->isAllowed('bot') || $markBot) {
             $flags |= EDIT_FORCE_BOT;
         }
         $status = $article->doEdit($text, $summary, $flags);
         if ($status->isOK()) {
             wfProfileOut(__METHOD__);
             return true;
         } else {
             wfProfileOut(__METHOD__);
             return false;
         }
     } elseif (!$revertRevId && $delete) {
         // no edits by other users - deleting page
         $title = $article->getTitle();
         $file = $title->getNamespace() == NS_FILE ? wfLocalFile($title) : false;
         if ($file) {
             $oldimage = null;
             // Must be passed by reference
             $status = FileDeleteForm::doDelete($title, $file, $oldimage, $summary, false)->isOK();
         } else {
             $status = $article->doDeleteArticle($summary);
         }
         if ($status) {
             wfProfileOut(__METHOD__);
             return true;
         }
     }
     wfProfileOut(__METHOD__);
     return false;
 }