From: Bryan Tong Minh Date: Tue, 13 May 2008 10:42:32 +0000 (+0000) Subject: ApiQueryRevisions now uses the Revision backend. This allows a more proper handling... X-Git-Tag: 1.31.0-rc.0~47673 X-Git-Url: https://git.cyclocoop.org/admin/?a=commitdiff_plain;h=c316a2d6d390e5489b66cf6584229db2e04b0e28;p=lhc%2Fweb%2Fwiklou.git ApiQueryRevisions now uses the Revision backend. This allows a more proper handling of rev_deleted. Also in case rev_size is filled on demand (bug 12188) there is only need to do this in one place. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 3e732d74f1..1b873ac262 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -333,6 +333,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 14022) Added usprop=registration and auprop=blockinfo * (bug 14021) Removed titles= support from list=backlinks (has been obsolete for ages) * (bug 13829) Expose parse tree via action=expandtemplates +* ApiQueryRevisions now uses the Revision backend === Languages updated in 1.13 === diff --git a/includes/Revision.php b/includes/Revision.php index f704846597..a6f9604099 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -258,6 +258,27 @@ class Revision { 'rev_parent_id' ); } + + /** + * Return the list of text fields that should be selected to read the + * revision text + */ + static function selectTextFields() { + return array( + 'old_text', + 'old_flags' + ); + } + /** + * Return the list of page fields that should be selected from page table + */ + static function selectPageFields() { + return array( + 'page_namespace', + 'page_title', + 'page_latest' + ); + } /** * @param object $row diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index c76c3803f4..4a97f6f2bd 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -70,34 +70,29 @@ class ApiQueryRevisions extends ApiQueryBase { $this->dieUsage('titles, pageids or a generator was used to supply multiple pages, but the limit, startid, endid, dirNewer, user, excludeuser, start and end parameters may only be used on a single page.', 'multpages'); $this->addTables('revision'); - $this->addWhere('rev_deleted=0'); + $this->addFields( Revision::selectFields() ); $prop = array_flip($prop); - // These field are needed regardless of the client requesting them - $this->addFields('rev_id'); - $this->addFields('rev_page'); - // Optional fields $this->fld_ids = isset ($prop['ids']); // $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_comment = $this->addFieldsIf('rev_comment', isset ($prop['comment'])); - $this->fld_size = $this->addFieldsIf('rev_len', isset ($prop['size'])); + $this->fld_flags = isset ($prop['flags']); + $this->fld_timestamp = isset ($prop['timestamp']); + $this->fld_comment = isset ($prop['comment']); + $this->fld_size = isset ($prop['size']); $this->tok_rollback = false; // Prevent PHP undefined property notice + // Uh... where if $token set? if(!is_null($token)) { $this->tok_rollback = $this->getTokenFlag($token, 'rollback'); } + $this->fld_user = isset ($prop['user']); - if (isset ($prop['user'])) { - $this->addFields('rev_user'); - $this->addFields('rev_user_text'); - $this->fld_user = true; + if ( $this->tok_rollback || ( $this->fld_content && $this->expandTemplates ) || $pageCount > 0) { + $this->addTables( 'page' ); + $this->addFields( Revision::selectPageFields() ); } - else if($this->tok_rollback) - $this->addFields('rev_user_text'); if (isset ($prop['content'])) { @@ -112,8 +107,7 @@ class ApiQueryRevisions extends ApiQueryBase { $this->addTables('text'); $this->addWhere('rev_text_id=old_id'); $this->addFields('old_id'); - $this->addFields('old_text'); - $this->addFields('old_flags'); + $this->addFields( Revision::selectTextFields() ); $this->fld_content = true; @@ -181,7 +175,6 @@ class ApiQueryRevisions extends ApiQueryBase { elseif ($pageCount > 0) { // When working in multi-page non-enumeration mode, // limit to the latest revision only - $this->addTables('page'); $this->addWhere('page_id=rev_page'); $this->addWhere('page_latest=rev_id'); $this->validateLimit('page_count', $pageCount, 1, $userMax, $botMax); @@ -211,14 +204,15 @@ class ApiQueryRevisions extends ApiQueryBase { break; } + $revision = new Revision( $row ); $this->getResult()->addValue( array ( 'query', 'pages', - intval($row->rev_page), + $revision->getPage(), 'revisions'), null, - $this->extractRowInfo($row)); + $this->extractRowInfo( $revision )); } $db->freeResult($res); @@ -234,55 +228,60 @@ class ApiQueryRevisions extends ApiQueryBase { } } - private function extractRowInfo($row) { + private function extractRowInfo( $revision ) { $vals = array (); if ($this->fld_ids) { - $vals['revid'] = intval($row->rev_id); + $vals['revid'] = $revision->getId(); // $vals['oldid'] = intval($row->rev_text_id); // todo: should this be exposed? } - if ($this->fld_flags && $row->rev_minor_edit) + if ($this->fld_flags && $revision->isMinor()) $vals['minor'] = ''; if ($this->fld_user) { - $vals['user'] = $row->rev_user_text; - if (!$row->rev_user) + $vals['user'] = $revision->getUserText(); + if (!$revision->getUser()) $vals['anon'] = ''; } if ($this->fld_timestamp) { - $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->rev_timestamp); + $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $revision->getTimestamp()); } - if ($this->fld_size && !is_null($row->rev_len)) { - $vals['size'] = intval($row->rev_len); + if ($this->fld_size && !is_null($revision->getSize())) { + $vals['size'] = $revision->getSize(); } - if ($this->fld_comment && !empty ($row->rev_comment)) { - $vals['comment'] = $row->rev_comment; + if ($this->fld_comment) { + $comment = $revision->getComment(); + if (!empty($comment)) + $vals['comment'] = $comment; } if($this->tok_rollback || ($this->fld_content && $this->expandTemplates)) - $title = Title::newFromID($row->rev_page); + $title = $revision->getTitle(); if($this->tok_rollback) { global $wgUser; - $vals['rollbacktoken'] = $wgUser->editToken(array($title->getPrefixedText(), $row->rev_user_text)); + $vals['rollbacktoken'] = $wgUser->editToken( array( + $title->getPrefixedText(), + $revision->getUserText(), + ) ); } if ($this->fld_content) { global $wgParser; - $text = Revision :: getRevisionText($row); + $text = $revision->getText(); # Expand templates after getting section content because # template-added sections don't count and Parser::preprocess() # will have less input if ($this->section !== false) { $text = $wgParser->getSection( $text, $this->section, false); if($text === false) - $this->dieUsage("There is no section {$this->section} in r{$row->rev_id}", 'nosuchsection'); + $this->dieUsage("There is no section {$this->section} in r".$revision->getId(), 'nosuchsection'); } if ($this->expandTemplates) { $text = $wgParser->preprocess( $text, $title, new ParserOptions() );