3 * Copyright © 2015 Geoffrey Mon <geofbot@gmail.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * API Module to merge page histories
27 class ApiMergeHistory
extends ApiBase
{
29 public function execute() {
30 $this->useTransactionalTimeLimit();
32 $params = $this->extractRequestParams();
34 $this->requireOnlyOneParameter( $params, 'from', 'fromid' );
35 $this->requireOnlyOneParameter( $params, 'to', 'toid' );
37 // Get page objects (nonexistant pages get caught in MergeHistory::isValidMerge())
38 if ( isset( $params['from'] ) ) {
39 $fromTitle = Title
::newFromText( $params['from'] );
40 if ( !$fromTitle ||
$fromTitle->isExternal() ) {
41 $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['from'] ) ] );
43 } elseif ( isset( $params['fromid'] ) ) {
44 $fromTitle = Title
::newFromID( $params['fromid'] );
46 $this->dieWithError( [ 'apierror-nosuchpageid', $params['fromid'] ] );
50 if ( isset( $params['to'] ) ) {
51 $toTitle = Title
::newFromText( $params['to'] );
52 if ( !$toTitle ||
$toTitle->isExternal() ) {
53 $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['to'] ) ] );
55 } elseif ( isset( $params['toid'] ) ) {
56 $toTitle = Title
::newFromID( $params['toid'] );
58 $this->dieWithError( [ 'apierror-nosuchpageid', $params['toid'] ] );
62 $reason = $params['reason'];
63 $timestamp = $params['timestamp'];
66 $status = $this->merge( $fromTitle, $toTitle, $timestamp, $reason );
67 if ( !$status->isOK() ) {
68 $this->dieStatus( $status );
72 'from' => $fromTitle->getPrefixedText(),
73 'to' => $toTitle->getPrefixedText(),
74 'timestamp' => wfTimestamp( TS_ISO_8601
, $params['timestamp'] ),
75 'reason' => $params['reason']
77 $result = $this->getResult();
79 $result->addValue( null, $this->getModuleName(), $r );
85 * @param string $timestamp
86 * @param string $reason
89 protected function merge( Title
$from, Title
$to, $timestamp, $reason ) {
90 $mh = new MergeHistory( $from, $to, $timestamp );
92 return $mh->merge( $this->getUser(), $reason );
95 public function mustBePosted() {
99 public function isWriteMode() {
103 public function getAllowedParams() {
107 ApiBase
::PARAM_TYPE
=> 'integer'
111 ApiBase
::PARAM_TYPE
=> 'integer'
114 ApiBase
::PARAM_TYPE
=> 'timestamp'
120 public function needsToken() {
124 protected function getExamplesMessages() {
126 'action=mergehistory&from=Oldpage&to=Newpage&token=123ABC&' .
128 => 'apihelp-mergehistory-example-merge',
129 'action=mergehistory&from=Oldpage&to=Newpage&token=123ABC&' .
130 'reason=Reason×tamp=2015-12-31T04%3A37%3A41Z' // TODO
131 => 'apihelp-mergehistory-example-merge-timestamp',
135 public function getHelpUrls() {
136 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Mergehistory';