2007-12-06 16:06:22 +00:00
|
|
|
<?php
|
2010-02-19 12:54:09 +00:00
|
|
|
/**
|
2007-12-06 16:06:22 +00:00
|
|
|
* API for MediaWiki 1.8+
|
|
|
|
|
*
|
2010-08-07 19:59:42 +00:00
|
|
|
* Created on Jun 30, 2007
|
|
|
|
|
*
|
2010-02-19 12:54:09 +00:00
|
|
|
* Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
|
2007-12-06 16:06:22 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2010-06-21 13:13:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2007-12-06 16:06:22 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-07 19:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2007-12-06 16:06:22 +00:00
|
|
|
*/
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
2007-12-06 16:06:22 +00:00
|
|
|
// Eclipse helper - will be ignored in production
|
2010-02-19 12:54:09 +00:00
|
|
|
require_once( "ApiBase.php" );
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* API module that facilitates deleting pages. The API eqivalent of action=delete.
|
2008-01-12 07:08:17 +00:00
|
|
|
* Requires API write mode to be enabled.
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup API
|
2007-12-06 16:06:22 +00:00
|
|
|
*/
|
|
|
|
|
class ApiDelete extends ApiBase {
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
public function __construct( $main, $action ) {
|
2010-02-19 12:54:09 +00:00
|
|
|
parent::__construct( $main, $action );
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-01-12 07:08:17 +00:00
|
|
|
* Extracts the title, token, and reason from the request parameters and invokes
|
2008-04-14 07:45:50 +00:00
|
|
|
* the local delete() function with these as arguments. It does not make use of
|
|
|
|
|
* the delete function specified by Article.php. If the deletion succeeds, the
|
|
|
|
|
* details of the article deleted and the reason for deletion are added to the
|
2008-01-12 07:08:17 +00:00
|
|
|
* result object.
|
2007-12-06 16:06:22 +00:00
|
|
|
*/
|
|
|
|
|
public function execute() {
|
|
|
|
|
$params = $this->extractRequestParams();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->requireOnlyOneParameter( $params, 'title', 'pageid' );
|
2007-12-06 16:06:22 +00:00
|
|
|
|
2010-02-19 12:54:09 +00:00
|
|
|
if ( isset( $params['title'] ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$titleObj = Title::newFromText( $params['title'] );
|
2010-02-19 12:54:09 +00:00
|
|
|
if ( !$titleObj ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
|
2010-02-19 12:54:09 +00:00
|
|
|
}
|
|
|
|
|
} elseif ( isset( $params['pageid'] ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$titleObj = Title::newFromID( $params['pageid'] );
|
2010-02-19 12:54:09 +00:00
|
|
|
if ( !$titleObj ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'nosuchpageid', $params['pageid'] ) );
|
2010-02-19 12:54:09 +00:00
|
|
|
}
|
2008-10-07 14:57:59 +00:00
|
|
|
}
|
2010-02-19 12:54:09 +00:00
|
|
|
if ( !$titleObj->exists() ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'notanarticle' ) );
|
2010-02-19 12:54:09 +00:00
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$reason = ( isset( $params['reason'] ) ? $params['reason'] : null );
|
|
|
|
|
if ( $titleObj->getNamespace() == NS_FILE ) {
|
|
|
|
|
$retval = self::deleteFile( $params['token'], $titleObj, $params['oldimage'], $reason, false );
|
2010-02-19 12:54:09 +00:00
|
|
|
if ( count( $retval ) ) {
|
2010-01-23 22:26:40 +00:00
|
|
|
$this->dieUsageMsg( reset( $retval ) ); // We don't care about multiple errors, just report one of them
|
2010-02-19 12:54:09 +00:00
|
|
|
}
|
2008-05-19 21:30:03 +00:00
|
|
|
} else {
|
2010-01-11 15:55:52 +00:00
|
|
|
$articleObj = new Article( $titleObj );
|
|
|
|
|
$retval = self::delete( $articleObj, $params['token'], $reason );
|
2010-02-19 12:54:09 +00:00
|
|
|
|
|
|
|
|
if ( count( $retval ) ) {
|
2010-01-23 22:26:40 +00:00
|
|
|
$this->dieUsageMsg( reset( $retval ) ); // We don't care about multiple errors, just report one of them
|
2010-02-19 12:54:09 +00:00
|
|
|
}
|
2010-02-19 01:25:57 +00:00
|
|
|
|
2010-03-25 22:15:08 +00:00
|
|
|
// Deprecated parameters
|
2010-03-28 15:08:45 +00:00
|
|
|
if ( $params['watch'] ) {
|
2010-04-10 06:11:02 +00:00
|
|
|
$watch = 'watch';
|
2010-03-28 15:08:45 +00:00
|
|
|
} elseif ( $params['unwatch'] ) {
|
2010-04-10 06:11:02 +00:00
|
|
|
$watch = 'unwatch';
|
|
|
|
|
} else {
|
|
|
|
|
$watch = $params['watchlist'];
|
2010-02-19 12:54:09 +00:00
|
|
|
}
|
2010-04-14 12:17:39 +00:00
|
|
|
$this->setWatch( $watch, $titleObj, 'watchdeletion' );
|
2008-05-19 21:30:03 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$r = array( 'title' => $titleObj->getPrefixedText(), 'reason' => $reason );
|
|
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $r );
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
2008-01-12 07:08:17 +00:00
|
|
|
|
2010-10-03 20:29:44 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param &$title Title
|
|
|
|
|
* @param $token String
|
|
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
private static function getPermissionsError( &$title, $token ) {
|
2008-05-19 21:30:03 +00:00
|
|
|
global $wgUser;
|
2010-02-19 12:54:09 +00:00
|
|
|
|
2008-05-19 21:30:03 +00:00
|
|
|
// Check permissions
|
2010-01-11 15:55:52 +00:00
|
|
|
$errors = $title->getUserPermissionsErrors( 'delete', $wgUser );
|
2010-02-19 12:54:09 +00:00
|
|
|
if ( count( $errors ) > 0 ) {
|
|
|
|
|
return $errors;
|
|
|
|
|
}
|
2010-02-15 23:53:43 +00:00
|
|
|
|
2008-05-19 21:30:03 +00:00
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-12 07:08:17 +00:00
|
|
|
/**
|
|
|
|
|
* We have our own delete() function, since Article.php's implementation is split in two phases
|
|
|
|
|
*
|
2010-03-08 21:11:32 +00:00
|
|
|
* @param $article Article object to work on
|
|
|
|
|
* @param $token String: delete token (same as edit token)
|
|
|
|
|
* @param $reason String: reason for the deletion. Autogenerated if NULL
|
2008-01-18 14:34:14 +00:00
|
|
|
* @return Title::getUserPermissionsErrors()-like array
|
2008-01-12 07:08:17 +00:00
|
|
|
*/
|
2010-02-19 12:54:09 +00:00
|
|
|
public static function delete( &$article, $token, &$reason = null ) {
|
2008-05-24 20:44:49 +00:00
|
|
|
global $wgUser;
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $article->isBigDeletion() && !$wgUser->isAllowed( 'bigdelete' ) ) {
|
2009-06-05 19:17:45 +00:00
|
|
|
global $wgDeleteRevisionsLimit;
|
2010-01-11 15:55:52 +00:00
|
|
|
return array( array( 'delete-toobig', $wgDeleteRevisionsLimit ) );
|
2009-06-05 19:17:45 +00:00
|
|
|
}
|
2008-10-07 14:57:59 +00:00
|
|
|
$title = $article->getTitle();
|
2010-01-11 15:55:52 +00:00
|
|
|
$errors = self::getPermissionsError( $title, $token );
|
2010-02-19 12:54:09 +00:00
|
|
|
if ( count( $errors ) ) {
|
|
|
|
|
return $errors;
|
|
|
|
|
}
|
2008-01-12 07:08:17 +00:00
|
|
|
|
|
|
|
|
// Auto-generate a summary, if necessary
|
2010-02-19 12:54:09 +00:00
|
|
|
if ( is_null( $reason ) ) {
|
2010-01-23 22:52:40 +00:00
|
|
|
// Need to pass a throwaway variable because generateReason expects
|
|
|
|
|
// a reference
|
2008-05-26 10:14:58 +00:00
|
|
|
$hasHistory = false;
|
2010-01-11 15:55:52 +00:00
|
|
|
$reason = $article->generateReason( $hasHistory );
|
2010-02-19 12:54:09 +00:00
|
|
|
if ( $reason === false ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
return array( array( 'cannotdelete' ) );
|
2010-02-19 12:54:09 +00:00
|
|
|
}
|
2008-01-12 07:08:17 +00:00
|
|
|
}
|
2009-01-29 01:04:00 +00:00
|
|
|
|
|
|
|
|
$error = '';
|
2010-02-19 12:54:09 +00:00
|
|
|
if ( !wfRunHooks( 'ArticleDelete', array( &$article, &$wgUser, &$reason, $error ) ) ) {
|
2010-07-22 21:44:07 +00:00
|
|
|
return array( array( 'hookaborted', $error ) );
|
2010-02-19 12:54:09 +00:00
|
|
|
}
|
2008-01-12 07:08:17 +00:00
|
|
|
|
|
|
|
|
// Luckily, Article.php provides a reusable delete function that does the hard work for us
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $article->doDeleteArticle( $reason ) ) {
|
|
|
|
|
wfRunHooks( 'ArticleDeleteComplete', array( &$article, &$wgUser, $reason, $article->getId() ) );
|
2008-01-18 14:34:14 +00:00
|
|
|
return array();
|
2008-05-24 20:44:49 +00:00
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
return array( array( 'cannotdelete', $article->mTitle->getPrefixedText() ) );
|
2008-01-12 07:08:17 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-10-09 00:01:45 +00:00
|
|
|
/**
|
|
|
|
|
* @static
|
|
|
|
|
* @param $token
|
|
|
|
|
* @param $title
|
|
|
|
|
* @param $oldimage
|
|
|
|
|
* @param $reason
|
|
|
|
|
* @param $suppress bool
|
|
|
|
|
* @return \type|array|Title
|
|
|
|
|
*/
|
2010-02-19 12:54:09 +00:00
|
|
|
public static function deleteFile( $token, &$title, $oldimage, &$reason = null, $suppress = false ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$errors = self::getPermissionsError( $title, $token );
|
2010-02-19 12:54:09 +00:00
|
|
|
if ( count( $errors ) ) {
|
|
|
|
|
return $errors;
|
|
|
|
|
}
|
2008-05-19 21:30:03 +00:00
|
|
|
|
2010-02-19 12:54:09 +00:00
|
|
|
if ( $oldimage && !FileDeleteForm::isValidOldSpec( $oldimage ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
return array( array( 'invalidoldimage' ) );
|
2010-02-19 12:54:09 +00:00
|
|
|
}
|
2008-05-19 21:30:03 +00:00
|
|
|
|
2009-08-15 09:59:59 +00:00
|
|
|
$file = wfFindFile( $title, array( 'ignoreRedirect' => true ) );
|
2008-05-19 21:30:03 +00:00
|
|
|
$oldfile = false;
|
2010-02-19 12:54:09 +00:00
|
|
|
|
|
|
|
|
if ( $oldimage ) {
|
2008-05-19 21:30:03 +00:00
|
|
|
$oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $title, $oldimage );
|
2010-02-19 12:54:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !FileDeleteForm::haveDeletableFile( $file, $oldfile, $oldimage ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
return self::delete( new Article( $title ), $token, $reason );
|
2010-02-19 12:54:09 +00:00
|
|
|
}
|
|
|
|
|
if ( is_null( $reason ) ) { // Log and RC don't like null reasons
|
2008-12-13 21:07:18 +00:00
|
|
|
$reason = '';
|
2010-02-19 12:54:09 +00:00
|
|
|
}
|
2008-05-19 21:30:03 +00:00
|
|
|
$status = FileDeleteForm::doDelete( $title, $file, $oldimage, $reason, $suppress );
|
2010-02-19 12:54:09 +00:00
|
|
|
|
|
|
|
|
if ( !$status->isGood() ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
return array( array( 'cannotdelete', $title->getPrefixedText() ) );
|
2010-02-19 12:54:09 +00:00
|
|
|
}
|
|
|
|
|
|
2008-05-19 21:30:03 +00:00
|
|
|
return array();
|
|
|
|
|
}
|
2010-02-19 12:54:09 +00:00
|
|
|
|
2010-02-14 21:12:11 +00:00
|
|
|
public function mustBePosted() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2009-03-06 13:49:44 +00:00
|
|
|
public function isWriteMode() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getAllowedParams() {
|
2010-02-19 12:54:09 +00:00
|
|
|
return array(
|
2007-12-06 16:06:22 +00:00
|
|
|
'title' => null,
|
2008-10-07 14:57:59 +00:00
|
|
|
'pageid' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => 'integer'
|
|
|
|
|
),
|
2007-12-06 16:06:22 +00:00
|
|
|
'token' => null,
|
|
|
|
|
'reason' => null,
|
2010-03-25 22:15:08 +00:00
|
|
|
'watch' => array(
|
|
|
|
|
ApiBase::PARAM_DFLT => false,
|
|
|
|
|
ApiBase::PARAM_DEPRECATED => true,
|
|
|
|
|
),
|
|
|
|
|
'watchlist' => array(
|
|
|
|
|
ApiBase::PARAM_DFLT => 'preferences',
|
|
|
|
|
ApiBase::PARAM_TYPE => array(
|
|
|
|
|
'watch',
|
|
|
|
|
'unwatch',
|
|
|
|
|
'preferences',
|
|
|
|
|
'nochange'
|
|
|
|
|
),
|
|
|
|
|
),
|
2010-10-09 13:59:15 +00:00
|
|
|
'unwatch' => array(
|
|
|
|
|
ApiBase::PARAM_DFLT => false,
|
|
|
|
|
ApiBase::PARAM_DEPRECATED => true,
|
|
|
|
|
),
|
2010-10-13 23:11:40 +00:00
|
|
|
'oldimage' => null,
|
2007-12-06 16:06:22 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getParamDescription() {
|
2010-05-11 22:30:18 +00:00
|
|
|
$p = $this->getModulePrefix();
|
2010-02-19 12:54:09 +00:00
|
|
|
return array(
|
2010-05-11 22:30:18 +00:00
|
|
|
'title' => "Title of the page you want to delete. Cannot be used together with {$p}pageid",
|
|
|
|
|
'pageid' => "Page ID of the page you want to delete. Cannot be used together with {$p}title",
|
2007-12-06 16:06:22 +00:00
|
|
|
'token' => 'A delete token previously retrieved through prop=info',
|
2010-05-11 22:30:18 +00:00
|
|
|
'reason' => 'Reason for the deletion. If not set, an automatically generated reason will be used',
|
2008-03-02 19:00:50 +00:00
|
|
|
'watch' => 'Add the page to your watchlist',
|
2010-03-25 22:15:08 +00:00
|
|
|
'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
|
2008-05-19 21:30:03 +00:00
|
|
|
'unwatch' => 'Remove the page from your watchlist',
|
|
|
|
|
'oldimage' => 'The name of the old image to delete as provided by iiprop=archivename'
|
2007-12-06 16:06:22 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getDescription() {
|
2010-05-25 20:46:09 +00:00
|
|
|
return 'Delete a page';
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
2010-02-19 12:54:09 +00:00
|
|
|
|
2010-02-14 14:29:24 +00:00
|
|
|
public function getPossibleErrors() {
|
2010-02-13 00:28:27 +00:00
|
|
|
return array_merge( parent::getPossibleErrors(), array(
|
|
|
|
|
array( 'invalidtitle', 'title' ),
|
|
|
|
|
array( 'nosuchpageid', 'pageid' ),
|
|
|
|
|
array( 'notanarticle' ),
|
|
|
|
|
array( 'hookaborted', 'error' ),
|
2010-02-14 14:29:24 +00:00
|
|
|
) );
|
2010-02-13 00:28:27 +00:00
|
|
|
}
|
2010-02-19 12:54:09 +00:00
|
|
|
|
2010-10-01 20:12:50 +00:00
|
|
|
public function needsToken() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-15 23:53:43 +00:00
|
|
|
public function getTokenSalt() {
|
2010-02-16 21:59:16 +00:00
|
|
|
return '';
|
2010-02-14 22:20:27 +00:00
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
|
|
|
|
|
protected function getExamples() {
|
2010-02-19 12:54:09 +00:00
|
|
|
return array(
|
2007-12-06 16:06:22 +00:00
|
|
|
'api.php?action=delete&title=Main%20Page&token=123ABC',
|
|
|
|
|
'api.php?action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getVersion() {
|
2007-12-06 18:33:18 +00:00
|
|
|
return __CLASS__ . ': $Id$';
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
2010-02-13 00:28:27 +00:00
|
|
|
}
|