From 2b107e7ece7fec719eaf66ac20c846c3bb7e9293 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Sat, 1 Dec 2007 15:08:57 +0000 Subject: [PATCH] API: * Adding rollback tokens to prop=revisions * Fixing bug that broke prop=revisions multipage mode * Adding some comments on diff formatters --- RELEASE-NOTES | 1 + includes/api/ApiQueryRevisions.php | 36 +++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 2463b2a4ee..4b1ea7cb84 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -311,6 +311,7 @@ Full API documentation is available at http://www.mediawiki.org/wiki/API * Add apihighlimits permission, default for sysops and bots * Add limit=max to use maximal limit * Add action=parse to render parser output. Use it instead of action=render which is deprecated. +* Add rvtoken=rollback to prop=revisions === Languages updated in 1.12 === diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index 640fec77b2..246b5afb1e 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -45,14 +45,14 @@ class ApiQueryRevisions extends ApiQueryBase { $fld_comment = false, $fld_user = false, $fld_content = false; public function execute() { - $limit = $startid = $endid = $start = $end = $dir = $prop = $user = $excludeuser = $diffto = $difftoprev = $diffformat = null; + $limit = $startid = $endid = $start = $end = $dir = $prop = $user = $excludeuser = $diffto = $difftoprev = $diffformat = $token = null; extract($this->extractRequestParams()); // If any of those parameters are used, work in 'enumeration' mode. // Enum mode can only be used when exactly one page is provided. // Enumerating revisions on multiple pages make it extremely // difficult to manage continuations and require additional SQL indexes - $enumRevMode = (!is_null($user) || !is_null($excludeuser) || !is_null($limit) || !is_null($startid) || !is_null($endid) || $dir === 'newer' || !is_null($start) || !is_null($end) | !$difftoprev); + $enumRevMode = (!is_null($user) || !is_null($excludeuser) || !is_null($limit) || !is_null($startid) || !is_null($endid) || $dir === 'newer' || !is_null($start) || !is_null($end) | $difftoprev); $pageSet = $this->getPageSet(); @@ -85,10 +85,16 @@ class ApiQueryRevisions extends ApiQueryBase { $this->fld_timestamp = $this->addFieldsIf('rev_timestamp', isset ($prop['timestamp'])); $this->fld_comment = $this->addFieldsIf('rev_comment', isset ($prop['comment'])); $this->fld_size = $this->addFieldsIf('rev_len', isset ($prop['size'])); + if(!is_null($token)) + { + $this->tok_rollback = $this->getTokenFlag($token, 'rollback'); + } if($diffto || $difftoprev) switch($diffformat) { + // To add your own formatter, create a subclass of DiffFormatter + // in DifferenceEngine.php, then add it here case 'traditional': $this->formatter = new DiffFormatter; break; @@ -96,7 +102,8 @@ class ApiQueryRevisions extends ApiQueryBase { $this->formatter = new UnifiedDiffFormatter; break; case 'array': - $this->formatter = new ArrayDiffFormatter; + $this->formatter = new ArrayDiffFormatter; + break; } if($diffto) { @@ -125,6 +132,9 @@ class ApiQueryRevisions extends ApiQueryBase { $this->addFields('rev_user_text'); $this->fld_user = true; } + else if($this->tok_rollback) + $this->addFields('rev_user_text'); + if (isset ($prop['content']) || !is_null($diffto) || $difftoprev) { // For each page we will request, the user must have read rights for that page @@ -330,12 +340,19 @@ class ApiQueryRevisions extends ApiQueryBase { $vals['comment'] = $row->rev_comment; } + if($this->tok_rollback || ($this->fld_content && $this->expandTemplates)) + $title = Title::newFromID($row->rev_page); + + if($this->tok_rollback) { + $vals['rollbacktoken'] = $wgUser->editToken(array($title->getPrefixedText(), $row->rev_user_text)); + } + if ($this->fld_content || $this->diffto || $this->difftoprev) $text = Revision :: getRevisionText($row); if ($this->fld_content) { if ($this->expandTemplates) { global $wgParser; - $text = $wgParser->preprocess( $text, Title::newFromID($row->rev_page), new ParserOptions() ); + $text = $wgParser->preprocess( $text, $title, new ParserOptions() ); } ApiResult :: setContent($vals, $text); } @@ -420,8 +437,14 @@ class ApiQueryRevisions extends ApiQueryBase { 'unified', 'array', ), - ApiBase ::PARAM_DFLT => 'unified' - ) + ApiBase :: PARAM_DFLT => 'unified' + ), + 'token' => array( + ApiBase :: PARAM_TYPE => array( + 'rollback' + ), + ApiBase :: PARAM_ISMULTI => true + ), ); } @@ -440,6 +463,7 @@ class ApiQueryRevisions extends ApiQueryBase { 'diffto' => 'Revision number to compare all revisions with', 'difftoprev' => 'Diff each revision to the previous one (enum)', 'diffformat' => 'Format to use for diffs', + 'token' => 'Which tokens to obtain for each revision', ); } -- 2.20.1