PHPSessionHandler: Implement SessionHandlerInterface
[mediawiki.git] / includes / api / ApiMergeHistory.php
blob8fa9d28ebf73f7f0788b734a4a57c33c238a1adf
1 <?php
2 /**
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
24 * @file
27 /**
28 * API Module to merge page histories
29 * @ingroup API
31 class ApiMergeHistory extends ApiBase {
33 public function execute() {
34 $this->useTransactionalTimeLimit();
36 $user = $this->getUser();
37 $params = $this->extractRequestParams();
39 $this->requireOnlyOneParameter( $params, 'from', 'fromid' );
40 $this->requireOnlyOneParameter( $params, 'to', 'toid' );
42 // Get page objects (nonexistant pages get caught in MergeHistory::isValidMerge())
43 if ( isset( $params['from'] ) ) {
44 $fromTitle = Title::newFromText( $params['from'] );
45 if ( !$fromTitle || $fromTitle->isExternal() ) {
46 $this->dieUsageMsg( array( 'invalidtitle', $params['from'] ) );
48 } elseif ( isset( $params['fromid'] ) ) {
49 $fromTitle = Title::newFromID( $params['fromid'] );
50 if ( !$fromTitle ) {
51 $this->dieUsageMsg( array( 'nosuchpageid', $params['fromid'] ) );
55 if ( isset( $params['to'] ) ) {
56 $toTitle = Title::newFromText( $params['to'] );
57 if ( !$toTitle || $toTitle->isExternal() ) {
58 $this->dieUsageMsg( array( 'invalidtitle', $params['to'] ) );
60 } elseif ( isset( $params['toid'] ) ) {
61 $toTitle = Title::newFromID( $params['toid'] );
62 if ( !$toTitle ) {
63 $this->dieUsageMsg( array( 'nosuchpageid', $params['toid'] ) );
67 $reason = $params['reason'];
68 $timestamp = $params['timestamp'];
70 // Merge!
71 $status = $this->merge( $fromTitle, $toTitle, $timestamp, $reason );
72 if ( !$status->isOK() ) {
73 $this->dieStatus( $status );
76 $r = array(
77 'from' => $fromTitle->getPrefixedText(),
78 'to' => $toTitle->getPrefixedText(),
79 'timestamp' => wfTimestamp( TS_ISO_8601, $params['timestamp'] ),
80 'reason' => $params['reason']
82 $result = $this->getResult();
84 $result->addValue( null, $this->getModuleName(), $r );
87 /**
88 * @param Title $from
89 * @param Title $to
90 * @param string $timestamp
91 * @param string $reason
92 * @return Status
94 protected function merge( Title $from, Title $to, $timestamp, $reason ) {
95 $mh = new MergeHistory( $from, $to, $timestamp );
97 return $mh->merge( $this->getUser(), $reason );
100 public function mustBePosted() {
101 return true;
104 public function isWriteMode() {
105 return true;
108 public function getAllowedParams() {
109 return array(
110 'from' => null,
111 'fromid' => array(
112 ApiBase::PARAM_TYPE => 'integer'
114 'to' => null,
115 'toid' => array(
116 ApiBase::PARAM_TYPE => 'integer'
118 'timestamp' => array(
119 ApiBase::PARAM_TYPE => 'timestamp'
121 'reason' => '',
125 public function needsToken() {
126 return 'csrf';
129 protected function getExamplesMessages() {
130 return array(
131 'action=mergehistory&from=Oldpage&to=Newpage&token=123ABC&' .
132 'reason=Reason'
133 => 'apihelp-mergehistory-example-merge',
134 'action=mergehistory&from=Oldpage&to=Newpage&token=123ABC&' .
135 'reason=Reason&timestamp=2015-12-31T04%3A37%3A41Z' // TODO
136 => 'apihelp-mergehistory-example-merge-timestamp',
140 public function getHelpUrls() {
141 return 'https://www.mediawiki.org/wiki/API:Mergehistory';