5 * Created on Dec 29, 2015
7 * Copyright © 2015 Geoffrey Mon <geofbot@gmail.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
28 * API Module to merge page histories
31 class ApiMergeHistory
extends ApiBase
{
33 public function execute() {
34 $this->useTransactionalTimeLimit();
36 $params = $this->extractRequestParams();
38 $this->requireOnlyOneParameter( $params, 'from', 'fromid' );
39 $this->requireOnlyOneParameter( $params, 'to', 'toid' );
41 // Get page objects (nonexistant pages get caught in MergeHistory::isValidMerge())
42 if ( isset( $params['from'] ) ) {
43 $fromTitle = Title
::newFromText( $params['from'] );
44 if ( !$fromTitle ||
$fromTitle->isExternal() ) {
45 $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['from'] ) ] );
47 } elseif ( isset( $params['fromid'] ) ) {
48 $fromTitle = Title
::newFromID( $params['fromid'] );
50 $this->dieWithError( [ 'apierror-nosuchpageid', $params['fromid'] ] );
54 if ( isset( $params['to'] ) ) {
55 $toTitle = Title
::newFromText( $params['to'] );
56 if ( !$toTitle ||
$toTitle->isExternal() ) {
57 $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['to'] ) ] );
59 } elseif ( isset( $params['toid'] ) ) {
60 $toTitle = Title
::newFromID( $params['toid'] );
62 $this->dieWithError( [ 'apierror-nosuchpageid', $params['toid'] ] );
66 $reason = $params['reason'];
67 $timestamp = $params['timestamp'];
70 $status = $this->merge( $fromTitle, $toTitle, $timestamp, $reason );
71 if ( !$status->isOK() ) {
72 $this->dieStatus( $status );
76 'from' => $fromTitle->getPrefixedText(),
77 'to' => $toTitle->getPrefixedText(),
78 'timestamp' => wfTimestamp( TS_ISO_8601
, $params['timestamp'] ),
79 'reason' => $params['reason']
81 $result = $this->getResult();
83 $result->addValue( null, $this->getModuleName(), $r );
89 * @param string $timestamp
90 * @param string $reason
93 protected function merge( Title
$from, Title
$to, $timestamp, $reason ) {
94 $mh = new MergeHistory( $from, $to, $timestamp );
96 return $mh->merge( $this->getUser(), $reason );
99 public function mustBePosted() {
103 public function isWriteMode() {
107 public function getAllowedParams() {
111 ApiBase
::PARAM_TYPE
=> 'integer'
115 ApiBase
::PARAM_TYPE
=> 'integer'
118 ApiBase
::PARAM_TYPE
=> 'timestamp'
124 public function needsToken() {
128 protected function getExamplesMessages() {
130 'action=mergehistory&from=Oldpage&to=Newpage&token=123ABC&' .
132 => 'apihelp-mergehistory-example-merge',
133 'action=mergehistory&from=Oldpage&to=Newpage&token=123ABC&' .
134 'reason=Reason×tamp=2015-12-31T04%3A37%3A41Z' // TODO
135 => 'apihelp-mergehistory-example-merge-timestamp',
139 public function getHelpUrls() {
140 return 'https://www.mediawiki.org/wiki/API:Mergehistory';