From c8acd86afc1028801b38c6f9ede8c82c3c5cb3d0 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Fri, 21 Nov 2008 13:55:27 +0000 Subject: [PATCH] API: (bug 16408) Added DOM tree generation (rvgeneratexml) to prop=revisions. Looks kind of ugly in XML, but bots don't care about that, and people should use less crappy-looking formats anyway. --- RELEASE-NOTES | 1 + includes/api/ApiQueryRevisions.php | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index e9b6ee246f..d8dbd3d66b 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -450,6 +450,7 @@ The following extensions are migrated into MediaWiki 1.14: * (bug 12760) meta=userinfo&uiprop=ratelimits doesn't list group-specific rate limits * (bug 16398) meta=userinfo&uiprop=rights lists some rights twice in some cases +* (bug 16408) Added rvgeneratexml to prop=revisions === Languages updated in 1.14 === diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index db3b9e92d5..2689d7160b 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -74,7 +74,7 @@ class ApiQueryRevisions extends ApiQueryBase { } public function execute() { - $limit = $startid = $endid = $start = $end = $dir = $prop = $user = $excludeuser = $expandtemplates = $section = $token = null; + $limit = $startid = $endid = $start = $end = $dir = $prop = $user = $excludeuser = $expandtemplates = $generatexml = $section = $token = null; extract($this->extractRequestParams(false)); // If any of those parameters are used, work in 'enumeration' mode. @@ -115,7 +115,7 @@ class ApiQueryRevisions extends ApiQueryBase { $this->fld_user = isset ($prop['user']); $this->token = $token; - if ( !is_null($this->token) || ( $this->fld_content && $this->expandTemplates ) || $pageCount > 0) { + if ( !is_null($this->token) || $pageCount > 0) { $this->addFields( Revision::selectPageFields() ); } @@ -137,6 +137,7 @@ class ApiQueryRevisions extends ApiQueryBase { $this->fld_content = true; $this->expandTemplates = $expandtemplates; + $this->generateXML = $generatexml; if(isset($section)) $this->section = $section; else @@ -319,6 +320,17 @@ class ApiQueryRevisions extends ApiQueryBase { if($text === false) $this->dieUsage("There is no section {$this->section} in r".$revision->getId(), 'nosuchsection'); } + if ($this->generateXML) { + $wgParser->startExternalParse( $title, new ParserOptions(), OT_PREPROCESS ); + $dom = $wgParser->preprocessToDom( $text ); + if ( is_callable( array( $dom, 'saveXML' ) ) ) { + $xml = $dom->saveXML(); + } else { + $xml = $dom->__toString(); + } + $vals['parsetree'] = $xml; + + } if ($this->expandTemplates) { $text = $wgParser->preprocess( $text, $title, new ParserOptions() ); } @@ -373,8 +385,8 @@ class ApiQueryRevisions extends ApiQueryBase { 'excludeuser' => array( ApiBase :: PARAM_TYPE => 'user' ), - 'expandtemplates' => false, + 'generatexml' => false, 'section' => array( ApiBase :: PARAM_TYPE => 'integer' ), @@ -397,6 +409,7 @@ class ApiQueryRevisions extends ApiQueryBase { 'user' => 'only include revisions made by user', 'excludeuser' => 'exclude revisions made by user', 'expandtemplates' => 'expand templates in revision content', + 'generatexml' => 'generate XML parse tree for revision content', 'section' => 'only retrieve the content of this section', 'token' => 'Which tokens to obtain for each revision', ); -- 2.20.1