From: Florian Schmidt Date: Sat, 29 Oct 2016 20:46:17 +0000 (+0200) Subject: Move LinkBatch operations for QueryPage to a helper function X-Git-Tag: 1.31.0-rc.0~4999^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=88db9249f2e7fcbcb73ffacd7b49fefb9c09e624;p=lhc%2Fweb%2Fwiklou.git Move LinkBatch operations for QueryPage to a helper function This is easier to maintain as duplicated code everywhere. This change also adds LinkBatch operations to specialpages, that does not had it so far, but where it's useful. Change-Id: I4936ecfb2be3a7709d99570c0561ab0cc9cd754f --- diff --git a/includes/specialpage/PageQueryPage.php b/includes/specialpage/PageQueryPage.php index 97f004f243..3bb3f8515f 100644 --- a/includes/specialpage/PageQueryPage.php +++ b/includes/specialpage/PageQueryPage.php @@ -36,17 +36,7 @@ abstract class PageQueryPage extends QueryPage { * @param ResultWrapper $res */ public function preprocessResults( $db, $res ) { - if ( !$res->numRows() ) { - return; - } - - $batch = new LinkBatch(); - foreach ( $res as $row ) { - $batch->add( $row->namespace, $row->title ); - } - $batch->execute(); - - $res->seek( 0 ); + $this->executeLBFromResultWrapper( $res ); } /** diff --git a/includes/specialpage/QueryPage.php b/includes/specialpage/QueryPage.php index afbc5813a0..3592500055 100644 --- a/includes/specialpage/QueryPage.php +++ b/includes/specialpage/QueryPage.php @@ -825,4 +825,28 @@ abstract class QueryPage extends SpecialPage { function feedUrl() { return $this->getPageTitle()->getFullURL(); } + + /** + * Creates a new LinkBatch object, adds all pages from the passed ResultWrapper (MUST include + * title and optional the namespace field) and executes the batch. This operation will pre-cache + * LinkCache information like page existence and information for stub color and redirect hints. + * + * @param ResultWrapper $res The ResultWrapper object to process. Needs to include the title + * field and namespace field, if the $ns parameter isn't set. + * @param null $ns Use this namespace for the given titles in the ResultWrapper object, + * instead of the namespace value of $res. + */ + protected function executeLBFromResultWrapper( ResultWrapper $res, $ns = null ) { + if ( !$res->numRows() ) { + return; + } + + $batch = new LinkBatch; + foreach ( $res as $row ) { + $batch->add( $ns !== null ? $ns : $row->namespace, $row->title ); + } + $batch->execute(); + + $res->seek( 0 ); + } } diff --git a/includes/specialpage/WantedQueryPage.php b/includes/specialpage/WantedQueryPage.php index 1c19f3c756..39e3649b12 100644 --- a/includes/specialpage/WantedQueryPage.php +++ b/includes/specialpage/WantedQueryPage.php @@ -41,18 +41,7 @@ abstract class WantedQueryPage extends QueryPage { * @param ResultWrapper $res */ function preprocessResults( $db, $res ) { - if ( !$res->numRows() ) { - return; - } - - $batch = new LinkBatch; - foreach ( $res as $row ) { - $batch->add( $row->namespace, $row->title ); - } - $batch->execute(); - - // Back to start for display - $res->seek( 0 ); + $this->executeLBFromResultWrapper( $res ); } /** diff --git a/includes/specials/SpecialAncientpages.php b/includes/specials/SpecialAncientpages.php index 724435b04f..9ee1b75a06 100644 --- a/includes/specials/SpecialAncientpages.php +++ b/includes/specials/SpecialAncientpages.php @@ -64,6 +64,10 @@ class AncientPagesPage extends QueryPage { return false; } + public function preprocessResults( $db, $res ) { + $this->executeLBFromResultWrapper( $res ); + } + /** * @param Skin $skin * @param object $result Result row diff --git a/includes/specials/SpecialBrokenRedirects.php b/includes/specials/SpecialBrokenRedirects.php index b9b20511cf..17533968a0 100644 --- a/includes/specials/SpecialBrokenRedirects.php +++ b/includes/specials/SpecialBrokenRedirects.php @@ -171,18 +171,7 @@ class BrokenRedirectsPage extends QueryPage { * @param ResultWrapper $res */ function preprocessResults( $db, $res ) { - if ( !$res->numRows() ) { - return; - } - - $batch = new LinkBatch; - foreach ( $res as $row ) { - $batch->add( $row->namespace, $row->title ); - } - $batch->execute(); - - // Back to start for display - $res->seek( 0 ); + $this->executeLBFromResultWrapper( $res ); } protected function getGroupName() { diff --git a/includes/specials/SpecialLinkSearch.php b/includes/specials/SpecialLinkSearch.php index 307d6c3b59..a2fa8447ca 100644 --- a/includes/specials/SpecialLinkSearch.php +++ b/includes/specials/SpecialLinkSearch.php @@ -225,16 +225,7 @@ class LinkSearchPage extends QueryPage { * @param ResultWrapper $res */ function preprocessResults( $db, $res ) { - if ( $res->numRows() > 0 ) { - $linkBatch = new LinkBatch(); - - foreach ( $res as $row ) { - $linkBatch->add( $row->namespace, $row->title ); - } - - $res->seek( 0 ); - $linkBatch->execute(); - } + $this->executeLBFromResultWrapper( $res ); } /** diff --git a/includes/specials/SpecialListDuplicatedFiles.php b/includes/specials/SpecialListDuplicatedFiles.php index 49fa417c0e..dbe5c2fff0 100644 --- a/includes/specials/SpecialListDuplicatedFiles.php +++ b/includes/specials/SpecialListDuplicatedFiles.php @@ -75,16 +75,7 @@ class ListDuplicatedFilesPage extends QueryPage { * @param ResultWrapper $res */ function preprocessResults( $db, $res ) { - if ( $res->numRows() > 0 ) { - $linkBatch = new LinkBatch(); - - foreach ( $res as $row ) { - $linkBatch->add( $row->namespace, $row->title ); - } - - $res->seek( 0 ); - $linkBatch->execute(); - } + $this->executeLBFromResultWrapper( $res ); } /** diff --git a/includes/specials/SpecialMIMEsearch.php b/includes/specials/SpecialMIMEsearch.php index 6093f83947..1d02a4fd45 100644 --- a/includes/specials/SpecialMIMEsearch.php +++ b/includes/specials/SpecialMIMEsearch.php @@ -199,6 +199,10 @@ class MIMEsearchPage extends QueryPage { return in_array( $type, $types ); } + public function preprocessResults( $db, $res ) { + $this->executeLBFromResultWrapper( $res ); + } + protected function getGroupName() { return 'media'; } diff --git a/includes/specials/SpecialMediaStatistics.php b/includes/specials/SpecialMediaStatistics.php index ec877160cf..7683ad8beb 100644 --- a/includes/specials/SpecialMediaStatistics.php +++ b/includes/specials/SpecialMediaStatistics.php @@ -353,6 +353,7 @@ class MediaStatisticsPage extends QueryPage { * @param ResultWrapper $res */ public function preprocessResults( $dbr, $res ) { + $this->executeLBFromResultWrapper( $res ); $this->totalCount = $this->totalBytes = 0; foreach ( $res as $row ) { $mediaStats = $this->splitFakeTitle( $row->title ); diff --git a/includes/specials/SpecialMostcategories.php b/includes/specials/SpecialMostcategories.php index 06d21d568a..015701d877 100644 --- a/includes/specials/SpecialMostcategories.php +++ b/includes/specials/SpecialMostcategories.php @@ -69,19 +69,7 @@ class MostcategoriesPage extends QueryPage { * @param ResultWrapper $res */ function preprocessResults( $db, $res ) { - # There's no point doing a batch check if we aren't caching results; - # the page must exist for it to have been pulled out of the table - if ( !$this->isCached() || !$res->numRows() ) { - return; - } - - $batch = new LinkBatch(); - foreach ( $res as $row ) { - $batch->add( $row->namespace, $row->title ); - } - $batch->execute(); - - $res->seek( 0 ); + $this->executeLBFromResultWrapper( $res ); } /** diff --git a/includes/specials/SpecialMostinterwikis.php b/includes/specials/SpecialMostinterwikis.php index 8271d165b6..3e78352a50 100644 --- a/includes/specials/SpecialMostinterwikis.php +++ b/includes/specials/SpecialMostinterwikis.php @@ -75,20 +75,7 @@ class MostinterwikisPage extends QueryPage { * @param ResultWrapper $res */ function preprocessResults( $db, $res ) { - # There's no point doing a batch check if we aren't caching results; - # the page must exist for it to have been pulled out of the table - if ( !$this->isCached() || !$res->numRows() ) { - return; - } - - $batch = new LinkBatch; - foreach ( $res as $row ) { - $batch->add( $row->namespace, $row->title ); - } - $batch->execute(); - - // Back to start for display - $res->seek( 0 ); + $this->executeLBFromResultWrapper( $res ); } /** diff --git a/includes/specials/SpecialMostlinked.php b/includes/specials/SpecialMostlinked.php index 3663647129..01eb39e3f6 100644 --- a/includes/specials/SpecialMostlinked.php +++ b/includes/specials/SpecialMostlinked.php @@ -78,16 +78,7 @@ class MostlinkedPage extends QueryPage { * @param ResultWrapper $res */ function preprocessResults( $db, $res ) { - if ( $res->numRows() > 0 ) { - $linkBatch = new LinkBatch(); - - foreach ( $res as $row ) { - $linkBatch->add( $row->namespace, $row->title ); - } - - $res->seek( 0 ); - $linkBatch->execute(); - } + $this->executeLBFromResultWrapper( $res ); } /** diff --git a/includes/specials/SpecialMostlinkedcategories.php b/includes/specials/SpecialMostlinkedcategories.php index 3ead08ad41..41678cb34d 100644 --- a/includes/specials/SpecialMostlinkedcategories.php +++ b/includes/specials/SpecialMostlinkedcategories.php @@ -59,18 +59,7 @@ class MostlinkedCategoriesPage extends QueryPage { * @param ResultWrapper $res */ function preprocessResults( $db, $res ) { - if ( !$res->numRows() ) { - return; - } - - $batch = new LinkBatch; - foreach ( $res as $row ) { - $batch->add( NS_CATEGORY, $row->title ); - } - $batch->execute(); - - // Back to start for display - $res->seek( 0 ); + $this->executeLBFromResultWrapper( $res ); } /** diff --git a/includes/specials/SpecialMostlinkedtemplates.php b/includes/specials/SpecialMostlinkedtemplates.php index 950241f4fb..7fcb9d869c 100644 --- a/includes/specials/SpecialMostlinkedtemplates.php +++ b/includes/specials/SpecialMostlinkedtemplates.php @@ -79,17 +79,7 @@ class MostlinkedTemplatesPage extends QueryPage { * @param ResultWrapper $res */ public function preprocessResults( $db, $res ) { - if ( !$res->numRows() ) { - return; - } - - $batch = new LinkBatch(); - foreach ( $res as $row ) { - $batch->add( $row->namespace, $row->title ); - } - $batch->execute(); - - $res->seek( 0 ); + $this->executeLBFromResultWrapper( $res ); } /** diff --git a/includes/specials/SpecialShortpages.php b/includes/specials/SpecialShortpages.php index a76b511d0d..a78b082432 100644 --- a/includes/specials/SpecialShortpages.php +++ b/includes/specials/SpecialShortpages.php @@ -71,19 +71,7 @@ class ShortPagesPage extends QueryPage { * @param ResultWrapper $res */ function preprocessResults( $db, $res ) { - # There's no point doing a batch check if we aren't caching results; - # the page must exist for it to have been pulled out of the table - if ( !$this->isCached() || !$res->numRows() ) { - return; - } - - $batch = new LinkBatch(); - foreach ( $res as $row ) { - $batch->add( $row->namespace, $row->title ); - } - $batch->execute(); - - $res->seek( 0 ); + $this->executeLBFromResultWrapper( $res ); } function sortDescending() { diff --git a/includes/specials/SpecialUnusedcategories.php b/includes/specials/SpecialUnusedcategories.php index 45efaf3f13..88c0e2172f 100644 --- a/includes/specials/SpecialUnusedcategories.php +++ b/includes/specials/SpecialUnusedcategories.php @@ -76,4 +76,8 @@ class UnusedCategoriesPage extends QueryPage { protected function getGroupName() { return 'maintenance'; } + + public function preprocessResults( $db, $res ) { + $this->executeLBFromResultWrapper( $res ); + } }