From 4b99ac91bc5c509bdda6843ad00aff148820661f Mon Sep 17 00:00:00 2001 From: umherirrender Date: Sat, 8 Nov 2014 11:25:33 +0100 Subject: [PATCH] Refactor content fetch condition in ApiQueryRevisionsBase Use a member variable to make the ifs easier to maintain. Change-Id: I535740094708c563298a8b8d34027519d3900758 --- includes/api/ApiQueryAllDeletedRevisions.php | 2 +- includes/api/ApiQueryDeletedRevisions.php | 2 +- includes/api/ApiQueryRevisions.php | 2 +- includes/api/ApiQueryRevisionsBase.php | 9 ++++++--- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/includes/api/ApiQueryAllDeletedRevisions.php b/includes/api/ApiQueryAllDeletedRevisions.php index 0292e9a354..0b1accba41 100644 --- a/includes/api/ApiQueryAllDeletedRevisions.php +++ b/includes/api/ApiQueryAllDeletedRevisions.php @@ -109,7 +109,7 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase { $this->addWhereFld( 'ct_tag', $params['tag'] ); } - if ( $this->fld_content || !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) { + if ( $this->fetchContent ) { // Modern MediaWiki has the content for deleted revs in the 'text' // table using fields old_text and old_flags. But revisions deleted // pre-1.5 store the content in the 'archive' table directly using diff --git a/includes/api/ApiQueryDeletedRevisions.php b/includes/api/ApiQueryDeletedRevisions.php index 0271037cfb..26ae266843 100644 --- a/includes/api/ApiQueryDeletedRevisions.php +++ b/includes/api/ApiQueryDeletedRevisions.php @@ -94,7 +94,7 @@ class ApiQueryDeletedRevisions extends ApiQueryRevisionsBase { $this->addWhereFld( 'ct_tag', $params['tag'] ); } - if ( $this->fld_content || !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) { + if ( $this->fetchContent ) { // Modern MediaWiki has the content for deleted revs in the 'text' // table using fields old_text and old_flags. But revisions deleted // pre-1.5 store the content in the 'archive' table directly using diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index 2e980f3bcf..32355b91a9 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -167,7 +167,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { $this->addWhereFld( 'ct_tag', $params['tag'] ); } - if ( $this->fld_content || !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) { + if ( $this->fetchContent ) { // For each page we will request, the user must have read rights for that page $user = $this->getUser(); /** @var $title Title */ diff --git a/includes/api/ApiQueryRevisionsBase.php b/includes/api/ApiQueryRevisionsBase.php index 3879d7b566..4d75a20b77 100644 --- a/includes/api/ApiQueryRevisionsBase.php +++ b/includes/api/ApiQueryRevisionsBase.php @@ -32,7 +32,7 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase { protected $limit, $diffto, $difftotext, $expandTemplates, $generateXML, $section, - $parseContent, $contentFormat, $setParsedLimit = true; + $parseContent, $fetchContent, $contentFormat, $setParsedLimit = true; protected $fld_ids = false, $fld_flags = false, $fld_timestamp = false, $fld_size = false, $fld_sha1 = false, $fld_comment = false, @@ -111,8 +111,11 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase { $this->limit = $params['limit']; + $this->fetchContent = $this->fld_content || !is_null( $this->diffto ) + || !is_null( $this->difftotext ); + $smallLimit = false; - if ( $this->fld_content || !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) { + if ( $this->fetchContent ) { $smallLimit = true; $this->expandTemplates = $params['expandtemplates']; $this->generateXML = $params['generatexml']; @@ -249,7 +252,7 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase { $content = null; global $wgParser; - if ( $this->fld_content || !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) { + if ( $this->fetchContent ) { $content = $revision->getContent( Revision::FOR_THIS_USER, $this->getUser() ); // Expand templates after getting section content because // template-added sections don't count and Parser::preprocess() -- 2.20.1