2007-12-06 16:06:22 +00:00
|
|
|
<?php
|
2010-02-19 12:54:09 +00:00
|
|
|
/**
|
2010-12-22 20:52:06 +00:00
|
|
|
*
|
2007-12-06 16:06:22 +00:00
|
|
|
*
|
2010-08-07 19:59:42 +00:00
|
|
|
* Created on Jun 30, 2007
|
|
|
|
|
*
|
2012-07-15 20:13:02 +00:00
|
|
|
* Copyright © 2007 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
|
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-10-20 18:50:33 +00:00
|
|
|
* API module that facilitates deleting pages. The API equivalent 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 {
|
|
|
|
|
/**
|
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
|
|
|
|
2012-04-28 13:45:37 +00:00
|
|
|
$pageObj = $this->getTitleOrPageId( $params, 'fromdbmaster' );
|
2012-04-07 21:47:06 +00:00
|
|
|
if ( !$pageObj->exists() ) {
|
|
|
|
|
$this->dieUsageMsg( 'notanarticle' );
|
2010-02-19 12:54:09 +00:00
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
|
2012-04-28 13:45:37 +00:00
|
|
|
$titleObj = $pageObj->getTitle();
|
2012-07-07 07:12:04 +00:00
|
|
|
$reason = $params['reason'];
|
2011-11-16 15:57:56 +00:00
|
|
|
$user = $this->getUser();
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $titleObj->getNamespace() == NS_FILE ) {
|
2013-11-16 19:09:17 +00:00
|
|
|
$status = self::deleteFile(
|
|
|
|
|
$pageObj,
|
|
|
|
|
$user,
|
|
|
|
|
$params['token'],
|
|
|
|
|
$params['oldimage'],
|
|
|
|
|
$reason,
|
|
|
|
|
false
|
|
|
|
|
);
|
2008-05-19 21:30:03 +00:00
|
|
|
} else {
|
2012-05-14 01:20:05 +00:00
|
|
|
$status = self::delete( $pageObj, $user, $params['token'], $reason );
|
2011-11-16 15:57:56 +00:00
|
|
|
}
|
2010-02-19 12:54:09 +00:00
|
|
|
|
2012-10-04 13:52:03 +00:00
|
|
|
if ( is_array( $status ) ) {
|
|
|
|
|
$this->dieUsageMsg( $status[0] );
|
|
|
|
|
}
|
2012-05-14 01:20:05 +00:00
|
|
|
if ( !$status->isGood() ) {
|
2013-06-13 17:56:29 +00:00
|
|
|
$this->dieStatus( $status );
|
2011-11-16 15:57:56 +00:00
|
|
|
}
|
2010-02-19 01:25:57 +00:00
|
|
|
|
2011-11-16 15:57:56 +00:00
|
|
|
// Deprecated parameters
|
|
|
|
|
if ( $params['watch'] ) {
|
|
|
|
|
$watch = 'watch';
|
|
|
|
|
} elseif ( $params['unwatch'] ) {
|
|
|
|
|
$watch = 'unwatch';
|
|
|
|
|
} else {
|
|
|
|
|
$watch = $params['watchlist'];
|
2008-05-19 21:30:03 +00:00
|
|
|
}
|
2011-11-16 15:57:56 +00:00
|
|
|
$this->setWatch( $watch, $titleObj, 'watchdeletion' );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2012-05-14 01:20:05 +00:00
|
|
|
$r = array(
|
|
|
|
|
'title' => $titleObj->getPrefixedText(),
|
|
|
|
|
'reason' => $reason,
|
|
|
|
|
'logid' => $status->value
|
|
|
|
|
);
|
2010-01-11 15:55:52 +00:00
|
|
|
$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
|
|
|
/**
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param Title $title
|
|
|
|
|
* @param User $user User doing the action
|
|
|
|
|
* @param string $token
|
2011-10-27 00:46:17 +00:00
|
|
|
* @return array
|
2010-10-03 20:29:44 +00:00
|
|
|
*/
|
2011-11-16 15:57:56 +00:00
|
|
|
private static function getPermissionsError( $title, $user, $token ) {
|
2008-05-19 21:30:03 +00:00
|
|
|
// Check permissions
|
2011-11-16 15:57:56 +00:00
|
|
|
return $title->getUserPermissionsErrors( 'delete', $user );
|
2008-05-19 21:30:03 +00:00
|
|
|
}
|
|
|
|
|
|
2008-01-12 07:08:17 +00:00
|
|
|
/**
|
|
|
|
|
* We have our own delete() function, since Article.php's implementation is split in two phases
|
|
|
|
|
*
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param Page|WikiPage $page Page or WikiPage object to work on
|
|
|
|
|
* @param User $user User doing the action
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $token delete token (same as edit token)
|
|
|
|
|
* @param string|null $reason reason for the deletion. Autogenerated if NULL
|
2012-10-04 13:52:03 +00:00
|
|
|
* @return Status|array
|
2008-01-12 07:08:17 +00:00
|
|
|
*/
|
2011-11-16 15:57:56 +00:00
|
|
|
public static function delete( Page $page, User $user, $token, &$reason = null ) {
|
|
|
|
|
$title = $page->getTitle();
|
|
|
|
|
$errors = self::getPermissionsError( $title, $user, $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 ) ) {
|
2011-04-13 23:36:27 +00:00
|
|
|
// Need to pass a throwaway variable because generateReason expects
|
|
|
|
|
// a reference
|
|
|
|
|
$hasHistory = false;
|
2012-10-10 18:13:40 +00:00
|
|
|
$reason = $page->getAutoDeleteReason( $hasHistory );
|
2010-02-19 12:54:09 +00:00
|
|
|
if ( $reason === false ) {
|
2011-11-16 15:57:56 +00:00
|
|
|
return array( array( 'cannotdelete', $title->getPrefixedText() ) );
|
2010-02-19 12:54:09 +00:00
|
|
|
}
|
2008-01-12 07:08:17 +00:00
|
|
|
}
|
2009-01-29 01:04:00 +00:00
|
|
|
|
2011-04-13 23:36:27 +00:00
|
|
|
$error = '';
|
2013-11-14 12:40:22 +00:00
|
|
|
|
2011-04-13 23:36:27 +00:00
|
|
|
// Luckily, Article.php provides a reusable delete function that does the hard work for us
|
2012-05-14 01:20:05 +00:00
|
|
|
return $page->doDeleteArticleReal( $reason, false, 0, true, $error );
|
2008-01-12 07:08:17 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-10-09 00:01:45 +00:00
|
|
|
/**
|
2013-11-17 19:04:13 +00:00
|
|
|
* @param Page $page Object to work on
|
|
|
|
|
* @param User $user User doing the action
|
|
|
|
|
* @param string $token Delete token (same as edit token)
|
|
|
|
|
* @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
|
2012-10-04 13:52:03 +00:00
|
|
|
* @return Status|array
|
2010-10-09 00:01:45 +00:00
|
|
|
*/
|
2013-11-16 19:09:17 +00:00
|
|
|
public static function deleteFile( Page $page, User $user, $token, $oldimage,
|
|
|
|
|
&$reason = null, $suppress = false
|
|
|
|
|
) {
|
2011-11-16 15:57:56 +00:00
|
|
|
$title = $page->getTitle();
|
|
|
|
|
$errors = self::getPermissionsError( $title, $user, $token );
|
2010-02-19 12:54:09 +00:00
|
|
|
if ( count( $errors ) ) {
|
|
|
|
|
return $errors;
|
|
|
|
|
}
|
2008-05-19 21:30:03 +00:00
|
|
|
|
2011-11-16 15:57:56 +00:00
|
|
|
$file = $page->getFile();
|
|
|
|
|
if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) {
|
|
|
|
|
return self::delete( $page, $user, $token, $reason );
|
2010-02-19 12:54:09 +00:00
|
|
|
}
|
2008-05-19 21:30:03 +00:00
|
|
|
|
2010-02-19 12:54:09 +00:00
|
|
|
if ( $oldimage ) {
|
2011-11-16 15:57:56 +00:00
|
|
|
if ( !FileDeleteForm::isValidOldSpec( $oldimage ) ) {
|
|
|
|
|
return array( array( 'invalidoldimage' ) );
|
|
|
|
|
}
|
2008-05-19 21:30:03 +00:00
|
|
|
$oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $title, $oldimage );
|
2011-11-16 15:57:56 +00:00
|
|
|
if ( !$oldfile->exists() || !$oldfile->isLocal() || $oldfile->getRedirected() ) {
|
|
|
|
|
return array( array( 'nodeleteablefile' ) );
|
|
|
|
|
}
|
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
|
|
|
}
|
2013-11-14 12:40:22 +00:00
|
|
|
|
2012-10-06 09:54:50 +00:00
|
|
|
return FileDeleteForm::doDelete( $title, $file, $oldimage, $reason, $suppress, $user );
|
2008-05-19 21:30:03 +00:00
|
|
|
}
|
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'
|
|
|
|
|
),
|
2012-07-18 17:24:38 +00:00
|
|
|
'token' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => 'string',
|
|
|
|
|
ApiBase::PARAM_REQUIRED => true
|
|
|
|
|
),
|
2007-12-06 16:06:22 +00:00
|
|
|
'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();
|
2013-11-14 12:40:22 +00:00
|
|
|
|
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',
|
2013-11-16 19:09:17 +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',
|
2013-11-16 19:09:17 +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
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
Added result properties to action=paraminfo
Added information about the properties of the results of API calls
to action=paraminfo, including information about "property groups":
what should the prop parameter be set to to get that property.
Uses the same format for types as parameters already do.
The output format of some modules doesn't fit this, so the result
properties for them weren't added, or only partially.
Partially implemented modules:
* expandtemplates:
parsetree is in its own tag
* protect, allusers, backlinks, deletedrevs, info, imageinfo,
logevents, querypage, recentchanges, revisions, searchinfo,
usercontribs, userinfo, users, watchlist, upload:
response with partially complex structure
Not implemented modules:
* feedcontributions, feedwatchlist, opensearch, rds:
non-standard reponse
* help:
error is normal response; not very useful for automated tools anyway
* paraminfo, parse, pageprops, siteinfo, userrights:
response with complex structure
Change-Id: Iff2a9bef79f994e73eef3062b4dd5461bff968ab
2012-05-02 15:00:30 +00:00
|
|
|
public function getResultProperties() {
|
|
|
|
|
return array(
|
|
|
|
|
'' => array(
|
|
|
|
|
'title' => 'string',
|
2012-07-07 13:29:14 +00:00
|
|
|
'reason' => 'string',
|
|
|
|
|
'logid' => 'integer'
|
Added result properties to action=paraminfo
Added information about the properties of the results of API calls
to action=paraminfo, including information about "property groups":
what should the prop parameter be set to to get that property.
Uses the same format for types as parameters already do.
The output format of some modules doesn't fit this, so the result
properties for them weren't added, or only partially.
Partially implemented modules:
* expandtemplates:
parsetree is in its own tag
* protect, allusers, backlinks, deletedrevs, info, imageinfo,
logevents, querypage, recentchanges, revisions, searchinfo,
usercontribs, userinfo, users, watchlist, upload:
response with partially complex structure
Not implemented modules:
* feedcontributions, feedwatchlist, opensearch, rds:
non-standard reponse
* help:
error is normal response; not very useful for automated tools anyway
* paraminfo, parse, pageprops, siteinfo, userrights:
response with complex structure
Change-Id: Iff2a9bef79f994e73eef3062b4dd5461bff968ab
2012-05-02 15:00:30 +00:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getDescription() {
|
2014-03-09 20:22:47 +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() {
|
2011-02-25 19:09:39 +00:00
|
|
|
return array_merge( parent::getPossibleErrors(),
|
2012-04-07 21:47:06 +00:00
|
|
|
$this->getTitleOrPageIdErrorMessage(),
|
2011-02-25 19:09:39 +00:00
|
|
|
array(
|
|
|
|
|
array( 'notanarticle' ),
|
|
|
|
|
array( 'hookaborted', 'error' ),
|
2011-11-16 15:57:56 +00:00
|
|
|
array( 'delete-toobig', 'limit' ),
|
|
|
|
|
array( 'cannotdelete', 'title' ),
|
|
|
|
|
array( 'invalidoldimage' ),
|
|
|
|
|
array( 'nodeleteablefile' ),
|
2011-02-25 19:09:39 +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
|
|
|
|
2011-08-17 22:24:21 +00:00
|
|
|
public function getExamples() {
|
2010-02-19 12:54:09 +00:00
|
|
|
return array(
|
2012-01-12 17:36:06 +00:00
|
|
|
'api.php?action=delete&title=Main%20Page&token=123ABC' => 'Delete the Main Page',
|
2013-11-16 19:09:17 +00:00
|
|
|
'api.php?action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move'
|
|
|
|
|
=> 'Delete the Main Page with the reason "Preparing for move"',
|
2007-12-06 16:06:22 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-17 16:38:24 +00:00
|
|
|
public function getHelpUrls() {
|
2011-11-28 15:43:11 +00:00
|
|
|
return 'https://www.mediawiki.org/wiki/API:Delete';
|
2011-07-17 16:38:24 +00:00
|
|
|
}
|
2011-03-23 21:54:59 +00:00
|
|
|
}
|