From ca32f08966f1b51fcb19460f0996bb0c4048e6fe Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 3 Dec 2011 13:29:22 +0100 Subject: Update to MediaWiki 1.18.0 * also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing --- includes/api/ApiComparePages.php | 130 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 includes/api/ApiComparePages.php (limited to 'includes/api/ApiComparePages.php') diff --git a/includes/api/ApiComparePages.php b/includes/api/ApiComparePages.php new file mode 100644 index 00000000..d43fa53f --- /dev/null +++ b/includes/api/ApiComparePages.php @@ -0,0 +1,130 @@ +extractRequestParams(); + + $rev1 = $this->revisionOrTitle( $params['fromrev'], $params['fromtitle'] ); + $rev2 = $this->revisionOrTitle( $params['torev'], $params['totitle'] ); + + $de = new DifferenceEngine( null, + $rev1, + $rev2, + null, // rcid + true, + false ); + + $vals = array(); + if ( isset( $params['fromtitle'] ) ) { + $vals['fromtitle'] = $params['fromtitle']; + } + $vals['fromrevid'] = $rev1; + if ( isset( $params['totitle'] ) ) { + $vals['totitle'] = $params['totitle']; + } + $vals['torevid'] = $rev2; + + $difftext = $de->getDiffBody(); + + if ( $difftext === false ) { + $this->dieUsage( 'The diff cannot be retrieved. ' . + 'Maybe one or both revisions do not exist or you do not have permission to view them.', 'baddiff' ); + } else { + ApiResult::setContent( $vals, $difftext ); + } + + $this->getResult()->addValue( null, $this->getModuleName(), $vals ); + } + + /** + * @param $revision int + * @param $titleText string + * @return int + */ + private function revisionOrTitle( $revision, $titleText ) { + if( $revision ){ + return $revision; + } elseif( $titleText ) { + $title = Title::newFromText( $titleText ); + if( !$title ){ + $this->dieUsageMsg( array( 'invalidtitle', $titleText ) ); + } + return $title->getLatestRevID(); + } + $this->dieUsage( 'inputneeded', 'A title or a revision number is needed for both the from and the to parameters' ); + } + + public function getAllowedParams() { + return array( + 'fromtitle' => null, + 'fromrev' => array( + ApiBase::PARAM_TYPE => 'integer' + ), + 'totitle' => null, + 'torev' => array( + ApiBase::PARAM_TYPE => 'integer' + ), + ); + } + + public function getParamDescription() { + return array( + 'fromtitle' => 'First title to compare', + 'fromrev' => 'First revision to compare', + 'totitle' => 'Second title to compare', + 'torev' => 'Second revision to compare', + ); + } + public function getDescription() { + return array( + 'Get the difference between 2 pages', + 'You must pass a revision number or a page title for each part (1 and 2)' + ); + } + + public function getPossibleErrors() { + return array_merge( parent::getPossibleErrors(), array( + array( 'code' => 'inputneeded', 'info' => 'A title or a revision is needed' ), + array( 'invalidtitle', 'title' ), + array( 'code' => 'baddiff', 'info' => 'The diff cannot be retrieved. Maybe one or both revisions do not exist or you do not have permission to view them.' ), + ) ); + } + + protected function getExamples() { + return array( + 'api.php?action=compare&fromrev=1&torev=2', + ); + } + + public function getVersion() { + return __CLASS__ . ': $Id: ApiComparePages.php 92400 2011-07-17 16:51:11Z reedy $'; + } +} -- cgit v1.2.3-54-g00ecf