Index: trunk/phase3/includes/diff/DifferenceEngine.php |
— | — | @@ -22,14 +22,14 @@ |
23 | 23 | /**#@+ |
24 | 24 | * @private |
25 | 25 | */ |
26 | | - var $mOldid, $mNewid, $mTitle; |
| 26 | + var $mOldid, $mNewid; |
27 | 27 | var $mOldtitle, $mNewtitle, $mPagetitle; |
28 | 28 | var $mOldtext, $mNewtext; |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @var Title |
32 | 32 | */ |
33 | | - var $mOldPage, $mNewPage; |
| 33 | + var $mOldPage, $mNewPage, $mTitle; |
34 | 34 | var $mRcidMarkPatrolled; |
35 | 35 | |
36 | 36 | /** |
Index: trunk/phase3/includes/api/ApiComparePages.php |
— | — | @@ -0,0 +1,123 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * |
| 5 | + * Created on May 1, 2011 |
| 6 | + * |
| 7 | + * Copyright © 2011 Sam Reed |
| 8 | + * |
| 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. |
| 13 | + * |
| 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. |
| 18 | + * |
| 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 |
| 23 | + * |
| 24 | + * @file |
| 25 | + */ |
| 26 | + |
| 27 | +class ApiComparePages extends ApiBase { |
| 28 | + |
| 29 | + public function __construct( $main, $action ) { |
| 30 | + parent::__construct( $main, $action ); |
| 31 | + } |
| 32 | + |
| 33 | + public function execute() { |
| 34 | + $params = $this->extractRequestParams(); |
| 35 | + |
| 36 | + $rev1 = $this->revisionOrTitle( $params['fromrev'], $params['fromtitle'] ); |
| 37 | + $rev2 = $this->revisionOrTitle( $params['torev'], $params['totitle'] ); |
| 38 | + |
| 39 | + $de = new DifferenceEngine( null, |
| 40 | + $rev1, |
| 41 | + $rev2, |
| 42 | + null, // rcid |
| 43 | + true, |
| 44 | + false ); |
| 45 | + |
| 46 | + $vals = array(); |
| 47 | + if ( isset( $params['fromtitle'] ) ) { |
| 48 | + $vals['fromtitle'] = $params['fromtitle']; |
| 49 | + } |
| 50 | + $vals['fromrevid'] = $rev1; |
| 51 | + if ( isset( $params['totitle'] ) ) { |
| 52 | + $vals['totitle'] = $params['totitle']; |
| 53 | + } |
| 54 | + $vals['torevid'] = $rev2; |
| 55 | + |
| 56 | + $difftext = $de->getDiffBody(); |
| 57 | + ApiResult::setContent( $vals, $difftext ); |
| 58 | + |
| 59 | + $this->getResult()->addValue( null, $this->getModuleName(), $vals ); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @param $revision int |
| 64 | + * @param $title string |
| 65 | + * @return int |
| 66 | + */ |
| 67 | + private function revisionOrTitle( $revision, $title ) { |
| 68 | + if( $revision ){ |
| 69 | + return $revision; |
| 70 | + } elseif( $title ) { |
| 71 | + $title = Title::newFromText( $title ); |
| 72 | + if( !$title ){ |
| 73 | + $this->dieUsageMsg( array( 'invalidtitle', $title ) ); |
| 74 | + } |
| 75 | + return $title->getLatestRevID(); |
| 76 | + } |
| 77 | + $this->dieUsage( 'inputneeded', 'A title or a revision number is needed for both the from and the to parameters' ); |
| 78 | + } |
| 79 | + |
| 80 | + public function getAllowedParams() { |
| 81 | + return array( |
| 82 | + 'fromtitle' => null, |
| 83 | + 'fromrev' => array( |
| 84 | + ApiBase::PARAM_TYPE => 'integer' |
| 85 | + ), |
| 86 | + 'totitle' => null, |
| 87 | + 'torev' => array( |
| 88 | + ApiBase::PARAM_TYPE => 'integer' |
| 89 | + ), |
| 90 | + ); |
| 91 | + } |
| 92 | + |
| 93 | + public function getParamDescription() { |
| 94 | + return array( |
| 95 | + 'title1' => 'First title to compare', |
| 96 | + 'rev1' => 'First revision to compare', |
| 97 | + 'title2' => 'Second title to compare', |
| 98 | + 'rev2' => 'Second revision to compare', |
| 99 | + ); |
| 100 | + } |
| 101 | + public function getDescription() { |
| 102 | + return array( |
| 103 | + 'Get the difference between 2 pages', |
| 104 | + 'You must pass a revision number or a page title for each part (1 and 2)' |
| 105 | + ); |
| 106 | + } |
| 107 | + |
| 108 | + public function getPossibleErrors() { |
| 109 | + return array_merge( parent::getPossibleErrors(), array( |
| 110 | + array( 'code' => 'inputneeded', 'info' => 'A title or a revision is needed' ), |
| 111 | + array( 'invalidtitle', 'title' ), |
| 112 | + ) ); |
| 113 | + } |
| 114 | + |
| 115 | + protected function getExamples() { |
| 116 | + return array( |
| 117 | + 'api.php?action=compare&rev1=1&rev2=2', |
| 118 | + ); |
| 119 | + } |
| 120 | + |
| 121 | + public function getVersion() { |
| 122 | + return __CLASS__ . ': $Id$'; |
| 123 | + } |
| 124 | +} |
Property changes on: trunk/phase3/includes/api/ApiComparePages.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 125 | + native |
Added: svn:keywords |
2 | 126 | + Id |
Index: trunk/phase3/includes/api/ApiMain.php |
— | — | @@ -64,6 +64,7 @@ |
65 | 65 | 'help' => 'ApiHelp', |
66 | 66 | 'paraminfo' => 'ApiParamInfo', |
67 | 67 | 'rsd' => 'ApiRsd', |
| 68 | + 'compare' => 'ApiComparePages', |
68 | 69 | |
69 | 70 | // Write modules |
70 | 71 | 'purge' => 'ApiPurge', |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -257,6 +257,7 @@ |
258 | 258 | # includes/api |
259 | 259 | 'ApiBase' => 'includes/api/ApiBase.php', |
260 | 260 | 'ApiBlock' => 'includes/api/ApiBlock.php', |
| 261 | + 'ApiComparePages' => 'includes/api/ApiComparePages.php', |
261 | 262 | 'ApiDelete' => 'includes/api/ApiDelete.php', |
262 | 263 | 'ApiDisabled' => 'includes/api/ApiDisabled.php', |
263 | 264 | 'ApiEditPage' => 'includes/api/ApiEditPage.php', |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -370,6 +370,7 @@ |
371 | 371 | * Get a list of function hooks through meta=siteinfo |
372 | 372 | * Get a list of all subscribed hooks, and those subscribers |
373 | 373 | * (bug 28225) Allow hiding of user groups in list=allusers |
| 374 | +* (bug 27185) API: Add Special:ComparePages |
374 | 375 | |
375 | 376 | === Languages updated in 1.18 === |
376 | 377 | |