From eddedab1f4827518cf0d074c64b4beb8dc280b90 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Sat, 30 Jun 2007 09:23:05 +0000 Subject: [PATCH] Adding rvprop=lastid parameter to prop=revisions that lists revid of previous revision (bug 10297) --- RELEASE-NOTES | 1 + includes/api/ApiQueryRevisions.php | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 8657ddf9b6..0a681dae39 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -287,6 +287,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 10392) Include MediaWiki version details in version output * (bug 10411) Site language in meta=siteinfo * (bug 10391) action=help doesn't return help if format is fancy markup +* (bug 10297) include previous revision ID in prop=revisions == Maintenance script changes since 1.10 == diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index ea9e69917a..a6634d7a1b 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -41,7 +41,7 @@ class ApiQueryRevisions extends ApiQueryBase { parent :: __construct($query, $moduleName, 'rv'); } - private $fld_ids = false, $fld_flags = false, $fld_timestamp = false, + private $fld_ids = false, $fld_lastid = false, $fld_flags = false, $fld_timestamp = false, $fld_comment = false, $fld_user = false, $fld_content = false; public function execute() { @@ -78,10 +78,13 @@ class ApiQueryRevisions extends ApiQueryBase { $this->addFields('rev_page'); // Optional fields - $this->fld_ids = isset ($prop['ids']); + // lastid automatically sets ids and timestamp + // because it needs them internally + $this->fld_lastid = isset ($prop['lastid']); + $this->fld_ids = isset ($prop['ids']) || $this->fld_lastid); // $this->addFieldsIf('rev_text_id', $this->fld_ids); // should this be exposed? $this->fld_flags = $this->addFieldsIf('rev_minor_edit', isset ($prop['flags'])); - $this->fld_timestamp = $this->addFieldsIf('rev_timestamp', isset ($prop['timestamp'])); + $this->fld_timestamp = $this->addFieldsIf('rev_timestamp', isset ($prop['timestamp']) || $this->fld_lastid); $this->fld_comment = $this->addFieldsIf('rev_comment', isset ($prop['comment'])); if (isset ($prop['user'])) { @@ -180,6 +183,20 @@ class ApiQueryRevisions extends ApiQueryBase { $this->setContinueEnumParameter('startid', intval($row->rev_id)); break; } + $rowArr = $this->extractRowInfo($row); + + if($this->fld_lastid) { + $this->resetQueryParams(); + $this->addTables('revision'); + $this->addFields('rev_id'); + $this->addWhereFld('rev_page', $rowArr['pageid']); + $this->addWhere("rev_timestamp < '{$row->rev_timestamp}'"); + $this->addOption('LIMIT', 1); + $this->addOption('ORDER BY', 'rev_timestamp DESC'); + $res2 = $this->select(__METHOD__); + $row2 = $db->fetchObject($res2); + $rowArr['lastid'] = $row2->rev_id; + } $this->getResult()->addValue( array ( @@ -188,7 +205,7 @@ class ApiQueryRevisions extends ApiQueryBase { intval($row->rev_page), 'revisions'), null, - $this->extractRowInfo($row)); + $rowArr); } $db->freeResult($res); @@ -245,6 +262,7 @@ class ApiQueryRevisions extends ApiQueryBase { ApiBase :: PARAM_DFLT => 'ids|timestamp|flags|comment|user', ApiBase :: PARAM_TYPE => array ( 'ids', + 'lastid', 'flags', 'timestamp', 'user', -- 2.20.1