From e65974bc4f63bbec0c3f592c600708e479a0f78c Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 18 Oct 2006 05:35:24 +0000 Subject: [PATCH] API * Optimized revision tag setting --- includes/api/ApiQueryRevisions.php | 12 +++++++----- includes/api/ApiResult.php | 14 +++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index 5fc52222a7..8e075bf557 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -224,12 +224,14 @@ class ApiQueryRevisions extends ApiQueryBase { } $db->freeResult($res); - // Ensure that all revisions are shown as '' elements + // Ensure that all revisions are shown as '' elements $result = $this->getResult(); - $data = & $result->getData(); - foreach ($data['query']['pages'] as & $page) { - if (is_array($page) && array_key_exists('revisions', $page)) { - $result->setIndexedTagName($page['revisions'], 'rev'); + if( $result->getIsRawMode()) { + $data = & $result->getData(); + foreach ($data['query']['pages'] as & $page) { + if (is_array($page) && array_key_exists('revisions', $page)) { + $result->setIndexedTagName($page['revisions'], 'rev'); + } } } } diff --git a/includes/api/ApiResult.php b/includes/api/ApiResult.php index 6bee415334..b56d7ac658 100644 --- a/includes/api/ApiResult.php +++ b/includes/api/ApiResult.php @@ -31,14 +31,14 @@ if (!defined('MEDIAWIKI')) { class ApiResult extends ApiBase { - private $mData, $mNeedsRaw; + private $mData, $mIsRawMode; /** * Constructor */ public function __construct($main) { parent :: __construct($main, 'result'); - $this->mNeedsRaw = false; + $this->mIsRawMode = false; $this->reset(); } @@ -51,10 +51,14 @@ class ApiResult extends ApiBase { * are needed by the formatter, for example in XML printing. */ public function setRawMode() { - $this->mNeedsRaw = true; + $this->mIsRawMode = true; + } + + public function getIsRawMode() { + return $this->mIsRawMode; } - function & getData() { + public function & getData() { return $this->mData; } @@ -108,7 +112,7 @@ class ApiResult extends ApiBase { */ public function setIndexedTagName(& $arr, $tag) { // In raw mode, add the '_element', otherwise just ignore - if (!$this->mNeedsRaw) + if (!$this->getIsRawMode()) return; if ($arr === null || $tag === null || !is_array($arr) || is_array($tag)) ApiBase :: dieDebug(__METHOD__, 'Bad parameter'); -- 2.20.1