From 63601400e476c6cf43d985f3e7b9864681695ed4 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Fri, 18 Jan 2013 16:46:04 +0100 Subject: Update to MediaWiki 1.20.2 this update includes: * adjusted Arch Linux skin * updated FluxBBAuthPlugin * patch for https://bugzilla.wikimedia.org/show_bug.cgi?id=44024 --- includes/api/ApiDelete.php | 75 +++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 41 deletions(-) (limited to 'includes/api/ApiDelete.php') diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index cfaf6cc1..2d36f19a 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -4,7 +4,7 @@ * * Created on Jun 30, 2007 * - * Copyright © 2007 Roan Kattouw .@gmail.com + * Copyright © 2007 Roan Kattouw ".@gmail.com" * * 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 @@ -46,35 +46,24 @@ class ApiDelete extends ApiBase { public function execute() { $params = $this->extractRequestParams(); - $this->requireOnlyOneParameter( $params, 'title', 'pageid' ); - - if ( isset( $params['title'] ) ) { - $titleObj = Title::newFromText( $params['title'] ); - if ( !$titleObj ) { - $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); - } - } elseif ( isset( $params['pageid'] ) ) { - $titleObj = Title::newFromID( $params['pageid'] ); - if ( !$titleObj ) { - $this->dieUsageMsg( array( 'nosuchpageid', $params['pageid'] ) ); - } - } - if ( !$titleObj->exists() ) { + $pageObj = $this->getTitleOrPageId( $params, 'fromdbmaster' ); + if ( !$pageObj->exists() ) { $this->dieUsageMsg( 'notanarticle' ); } - $reason = ( isset( $params['reason'] ) ? $params['reason'] : null ); - $pageObj = WikiPage::factory( $titleObj ); + $titleObj = $pageObj->getTitle(); + $reason = $params['reason']; $user = $this->getUser(); if ( $titleObj->getNamespace() == NS_FILE ) { - $retval = self::deleteFile( $pageObj, $user, $params['token'], $params['oldimage'], $reason, false ); + $status = self::deleteFile( $pageObj, $user, $params['token'], $params['oldimage'], $reason, false ); } else { - $retval = self::delete( $pageObj, $user, $params['token'], $reason ); + $status = self::delete( $pageObj, $user, $params['token'], $reason ); } - if ( count( $retval ) ) { - $this->dieUsageMsg( reset( $retval ) ); // We don't care about multiple errors, just report one of them + if ( !$status->isGood() ) { + $errors = $status->getErrorsArray(); + $this->dieUsageMsg( $errors[0] ); // We don't care about multiple errors, just report one of them } // Deprecated parameters @@ -87,7 +76,11 @@ class ApiDelete extends ApiBase { } $this->setWatch( $watch, $titleObj, 'watchdeletion' ); - $r = array( 'title' => $titleObj->getPrefixedText(), 'reason' => $reason ); + $r = array( + 'title' => $titleObj->getPrefixedText(), + 'reason' => $reason, + 'logid' => $status->value + ); $this->getResult()->addValue( null, $this->getModuleName(), $r ); } @@ -109,7 +102,7 @@ class ApiDelete extends ApiBase { * @param $user User doing the action * @param $token String: delete token (same as edit token) * @param $reason String: reason for the deletion. Autogenerated if NULL - * @return Title::getUserPermissionsErrors()-like array + * @return Status */ public static function delete( Page $page, User $user, $token, &$reason = null ) { $title = $page->getTitle(); @@ -131,11 +124,7 @@ class ApiDelete extends ApiBase { $error = ''; // Luckily, Article.php provides a reusable delete function that does the hard work for us - if ( $page->doDeleteArticle( $reason, false, 0, true, $error ) ) { - return array(); - } else { - return array( array( 'cannotdelete', $title->getPrefixedText() ) ); - } + return $page->doDeleteArticleReal( $reason, false, 0, true, $error ); } /** @@ -145,7 +134,7 @@ class ApiDelete extends ApiBase { * @param $oldimage * @param $reason * @param $suppress bool - * @return \type|array|Title + * @return Status */ public static function deleteFile( Page $page, User $user, $token, $oldimage, &$reason = null, $suppress = false ) { $title = $page->getTitle(); @@ -167,19 +156,12 @@ class ApiDelete extends ApiBase { 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(); + return FileDeleteForm::doDelete( $title, $file, $oldimage, $reason, $suppress ); } public function mustBePosted() { @@ -196,7 +178,10 @@ class ApiDelete extends ApiBase { 'pageid' => array( ApiBase::PARAM_TYPE => 'integer' ), - 'token' => null, + 'token' => array( + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => true + ), 'reason' => null, 'watch' => array( ApiBase::PARAM_DFLT => false, @@ -233,16 +218,24 @@ class ApiDelete extends ApiBase { ); } + public function getResultProperties() { + return array( + '' => array( + 'title' => 'string', + 'reason' => 'string', + 'logid' => 'integer' + ) + ); + } + public function getDescription() { return 'Delete a page'; } public function getPossibleErrors() { return array_merge( parent::getPossibleErrors(), - $this->getRequireOnlyOneParameterErrorMessages( array( 'title', 'pageid' ) ), + $this->getTitleOrPageIdErrorMessage(), array( - array( 'invalidtitle', 'title' ), - array( 'nosuchpageid', 'pageid' ), array( 'notanarticle' ), array( 'hookaborted', 'error' ), array( 'delete-toobig', 'limit' ), -- cgit v1.2.3-54-g00ecf