r87225 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87224‎ | r87225 | r87226 >
Date:21:56, 1 May 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
* (bug 27185) API: Add Special:ComparePages
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/api/ApiComparePages.php (added) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)
  • /trunk/phase3/includes/diff/DifferenceEngine.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/diff/DifferenceEngine.php
@@ -22,14 +22,14 @@
2323 /**#@+
2424 * @private
2525 */
26 - var $mOldid, $mNewid, $mTitle;
 26+ var $mOldid, $mNewid;
2727 var $mOldtitle, $mNewtitle, $mPagetitle;
2828 var $mOldtext, $mNewtext;
2929
3030 /**
3131 * @var Title
3232 */
33 - var $mOldPage, $mNewPage;
 33+ var $mOldPage, $mNewPage, $mTitle;
3434 var $mRcidMarkPatrolled;
3535
3636 /**
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
1125 + native
Added: svn:keywords
2126 + Id
Index: trunk/phase3/includes/api/ApiMain.php
@@ -64,6 +64,7 @@
6565 'help' => 'ApiHelp',
6666 'paraminfo' => 'ApiParamInfo',
6767 'rsd' => 'ApiRsd',
 68+ 'compare' => 'ApiComparePages',
6869
6970 // Write modules
7071 'purge' => 'ApiPurge',
Index: trunk/phase3/includes/AutoLoader.php
@@ -257,6 +257,7 @@
258258 # includes/api
259259 'ApiBase' => 'includes/api/ApiBase.php',
260260 'ApiBlock' => 'includes/api/ApiBlock.php',
 261+ 'ApiComparePages' => 'includes/api/ApiComparePages.php',
261262 'ApiDelete' => 'includes/api/ApiDelete.php',
262263 'ApiDisabled' => 'includes/api/ApiDisabled.php',
263264 'ApiEditPage' => 'includes/api/ApiEditPage.php',
Index: trunk/phase3/RELEASE-NOTES
@@ -370,6 +370,7 @@
371371 * Get a list of function hooks through meta=siteinfo
372372 * Get a list of all subscribed hooks, and those subscribers
373373 * (bug 28225) Allow hiding of user groups in list=allusers
 374+* (bug 27185) API: Add Special:ComparePages
374375
375376 === Languages updated in 1.18 ===
376377

Follow-up revisions

RevisionCommit summaryAuthorDate
r87242Followup r87225...reedy11:12, 2 May 2011

Comments

#Comment by Catrope (talk | contribs)   14:38, 2 May 2011
+		if ( isset( $params['fromtitle'] ) ) {
+			$vals['fromtitle'] = $params['fromtitle'];
+		}

Would be nice to unconditionally set $vars['fromtitle'] = $rev1->getTitle()->getPrefixedText() or something, so it's normalized and you get the title if you just specified a revid.

Status & tagging log