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() {
|
2015-08-08 00:08:33 +00:00
|
|
|
$this->useTransactionalTimeLimit();
|
|
|
|
|
|
2007-12-06 16:06:22 +00:00
|
|
|
$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'] ) {
|
2014-08-14 18:15:23 +00:00
|
|
|
$this->logFeatureUsage( 'action=delete&watch' );
|
2011-11-16 15:57:56 +00:00
|
|
|
$watch = 'watch';
|
|
|
|
|
} elseif ( $params['unwatch'] ) {
|
2014-08-14 18:15:23 +00:00
|
|
|
$this->logFeatureUsage( 'action=delete&unwatch' );
|
2011-11-16 15:57:56 +00:00
|
|
|
$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
|
2014-07-24 17:42:45 +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
|
2015-06-28 19:50:01 +00:00
|
|
|
return $page->doDeleteArticleReal( $reason, false, 0, true, $error, $user );
|
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'
|
|
|
|
|
),
|
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
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-01 20:12:50 +00:00
|
|
|
public function needsToken() {
|
2014-08-08 16:56:07 +00:00
|
|
|
return 'csrf';
|
2010-02-14 22:20:27 +00:00
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
|
2014-10-28 17:17:02 +00:00
|
|
|
protected function getExamplesMessages() {
|
2010-02-19 12:54:09 +00:00
|
|
|
return array(
|
2014-09-18 17:38:23 +00:00
|
|
|
'action=delete&title=Main%20Page&token=123ABC'
|
|
|
|
|
=> 'apihelp-delete-example-simple',
|
|
|
|
|
'action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move'
|
|
|
|
|
=> 'apihelp-delete-example-reason',
|
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
|
|
|
}
|