Removed more functions marked for removal in 1.19: wfParseCIDR(), wfRFC822Phrase...
[mediawiki.git] / includes / api / ApiComparePages.php
blob45ac060b4fef474030ff5635903311f85fad9700
1 <?php
2 /**
4 * Created on May 1, 2011
6 * Copyright © 2011 Sam Reed
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
23 * @file
26 class ApiComparePages extends ApiBase {
28 public function __construct( $main, $action ) {
29 parent::__construct( $main, $action );
32 public function execute() {
33 $params = $this->extractRequestParams();
35 $rev1 = $this->revisionOrTitle( $params['fromrev'], $params['fromtitle'] );
36 $rev2 = $this->revisionOrTitle( $params['torev'], $params['totitle'] );
38 $de = new DifferenceEngine( null,
39 $rev1,
40 $rev2,
41 null, // rcid
42 true,
43 false );
45 $vals = array();
46 if ( isset( $params['fromtitle'] ) ) {
47 $vals['fromtitle'] = $params['fromtitle'];
49 $vals['fromrevid'] = $rev1;
50 if ( isset( $params['totitle'] ) ) {
51 $vals['totitle'] = $params['totitle'];
53 $vals['torevid'] = $rev2;
55 $difftext = $de->getDiffBody();
56 ApiResult::setContent( $vals, $difftext );
58 $this->getResult()->addValue( null, $this->getModuleName(), $vals );
61 /**
62 * @param $revision int
63 * @param $title string
64 * @return int
66 private function revisionOrTitle( $revision, $title ) {
67 if( $revision ){
68 return $revision;
69 } elseif( $title ) {
70 $title = Title::newFromText( $title );
71 if( !$title ){
72 $this->dieUsageMsg( array( 'invalidtitle', $title ) );
74 return $title->getLatestRevID();
76 $this->dieUsage( 'inputneeded', 'A title or a revision number is needed for both the from and the to parameters' );
79 public function getAllowedParams() {
80 return array(
81 'fromtitle' => null,
82 'fromrev' => array(
83 ApiBase::PARAM_TYPE => 'integer'
85 'totitle' => null,
86 'torev' => array(
87 ApiBase::PARAM_TYPE => 'integer'
92 public function getParamDescription() {
93 return array(
94 'fromtitle' => 'First title to compare',
95 'fromrev' => 'First revision to compare',
96 'totitle' => 'Second title to compare',
97 'torev' => 'Second revision to compare',
100 public function getDescription() {
101 return array(
102 'Get the difference between 2 pages',
103 'You must pass a revision number or a page title for each part (1 and 2)'
107 public function getPossibleErrors() {
108 return array_merge( parent::getPossibleErrors(), array(
109 array( 'code' => 'inputneeded', 'info' => 'A title or a revision is needed' ),
110 array( 'invalidtitle', 'title' ),
111 ) );
114 protected function getExamples() {
115 return array(
116 'api.php?action=compare&rev1=1&rev2=2',
120 public function getVersion() {
121 return __CLASS__ . ': $Id$';