2015-08-20 13:14:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class AllinfoboxesQueryPage extends PageQueryPage {
|
|
|
|
|
|
|
|
const ALL_INFOBOXES_TYPE = 'AllInfoboxes';
|
2018-08-06 13:16:36 +00:00
|
|
|
private static $subpagesBlacklist = [];
|
2015-08-20 13:14:23 +00:00
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
parent::__construct( self::ALL_INFOBOXES_TYPE );
|
2018-08-06 13:16:36 +00:00
|
|
|
|
|
|
|
$blacklist = $this->getConfig( 'AllInfoboxesSubpagesBlacklist' );
|
2018-08-16 09:25:53 +00:00
|
|
|
if ( is_array( $blacklist ) ) {
|
2018-08-06 13:16:36 +00:00
|
|
|
self::$subpagesBlacklist = $blacklist;
|
|
|
|
}
|
2015-08-20 13:14:23 +00:00
|
|
|
}
|
|
|
|
|
2018-08-03 09:54:47 +00:00
|
|
|
function getGroupName() {
|
|
|
|
return 'pages';
|
2018-08-06 13:16:36 +00:00
|
|
|
}
|
2018-08-03 09:54:47 +00:00
|
|
|
|
2015-08-20 13:14:23 +00:00
|
|
|
public function sortDescending() {
|
2018-08-03 08:49:28 +00:00
|
|
|
return false;
|
2015-08-20 13:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isExpensive() {
|
|
|
|
return true;
|
|
|
|
}
|
2018-08-06 13:16:36 +00:00
|
|
|
|
|
|
|
public function isCached() {
|
|
|
|
return $this->isExpensive() && (
|
|
|
|
$this->getConfig()->get( 'MiserMode' ) ||
|
|
|
|
$this->getConfig()->get( 'AllInfoboxesMiserMode' )
|
|
|
|
);
|
|
|
|
}
|
2018-08-16 09:25:53 +00:00
|
|
|
|
2018-08-05 09:44:51 +00:00
|
|
|
public function getOrderFields() {
|
|
|
|
return [ 'title' ];
|
|
|
|
}
|
2015-08-20 13:14:23 +00:00
|
|
|
|
2018-08-05 09:44:51 +00:00
|
|
|
public function getCacheOrderFields() {
|
|
|
|
return $this->getOrderFields();
|
|
|
|
}
|
2018-08-16 09:25:53 +00:00
|
|
|
|
2018-08-03 08:49:28 +00:00
|
|
|
function getQueryInfo() {
|
|
|
|
return [
|
|
|
|
'tables' => [ 'page' ],
|
|
|
|
'fields' => [
|
|
|
|
'namespace' => 'page_namespace',
|
|
|
|
'title' => 'page_title',
|
2018-08-05 09:44:51 +00:00
|
|
|
'value' => 'page_id'
|
2018-08-03 08:49:28 +00:00
|
|
|
],
|
|
|
|
'conds' => [
|
|
|
|
'page_is_redirect' => 0,
|
|
|
|
'page_namespace' => NS_TEMPLATE
|
|
|
|
]
|
|
|
|
];
|
2015-08-20 13:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the querycache table
|
|
|
|
*
|
2018-08-06 13:16:36 +00:00
|
|
|
* @see QueryPage::recache
|
|
|
|
*
|
2015-08-20 13:14:23 +00:00
|
|
|
* @param bool $limit Only for consistency
|
2018-08-06 13:16:36 +00:00
|
|
|
* @param bool $ignoreErrors Whether to ignore database errors
|
2015-08-20 13:14:23 +00:00
|
|
|
*
|
2016-02-22 12:14:41 +00:00
|
|
|
* @return int number of rows updated
|
2015-08-20 13:14:23 +00:00
|
|
|
*/
|
|
|
|
public function recache( $limit = false, $ignoreErrors = true ) {
|
2018-08-03 08:49:28 +00:00
|
|
|
$res = parent::recache( false, $ignoreErrors );
|
2015-08-20 13:14:23 +00:00
|
|
|
|
2017-07-12 12:21:06 +00:00
|
|
|
Hooks::run( 'AllInfoboxesQueryRecached' );
|
2018-08-03 08:49:28 +00:00
|
|
|
return $res;
|
2015-08-20 13:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queries all templates and get only those with portable infoboxes
|
|
|
|
*
|
2018-08-16 09:25:53 +00:00
|
|
|
* @see QueryPage::reallyDoQuery
|
2018-08-03 08:49:28 +00:00
|
|
|
*
|
2018-08-06 13:16:36 +00:00
|
|
|
* @param int|bool $limit Numerical limit or false for no limit
|
|
|
|
* @param int|bool $offset Numerical offset or false for no limit
|
2015-08-20 13:14:23 +00:00
|
|
|
*
|
2018-08-03 08:49:28 +00:00
|
|
|
* @return ResultWrapper
|
2015-08-20 13:14:23 +00:00
|
|
|
*/
|
|
|
|
public function reallyDoQuery( $limit = false, $offset = false ) {
|
2018-08-03 08:49:28 +00:00
|
|
|
$res = parent::reallyDoQuery( false );
|
|
|
|
$out = [];
|
|
|
|
|
2018-08-06 13:16:36 +00:00
|
|
|
$maxResults = $this->getMaxResults();
|
|
|
|
if ( $limit == 0 ) {
|
|
|
|
$limit = $maxResults;
|
|
|
|
} else {
|
|
|
|
$limit = min( $limit, $maxResults );
|
|
|
|
}
|
|
|
|
|
|
|
|
while ( $limit >= 0 && $row = $res->fetchObject() ) {
|
2018-08-16 09:25:53 +00:00
|
|
|
if ( $this->filterInfoboxes( $row ) && $offset-- <= 0 ) {
|
2018-08-03 08:49:28 +00:00
|
|
|
$out[] = $row;
|
2018-08-06 13:16:36 +00:00
|
|
|
$limit--;
|
2018-08-16 09:25:53 +00:00
|
|
|
}
|
2018-08-03 08:49:28 +00:00
|
|
|
}
|
|
|
|
|
2018-08-06 13:16:36 +00:00
|
|
|
return new FakeResultWrapper( $out );
|
2015-09-17 09:22:12 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 09:54:04 +00:00
|
|
|
private function hasInfobox( Title $title ) {
|
2016-04-06 08:50:01 +00:00
|
|
|
// omit subages from blacklist
|
|
|
|
return !(
|
|
|
|
$title->isSubpage() &&
|
|
|
|
in_array( mb_strtolower( $title->getSubpageText() ), self::$subpagesBlacklist )
|
|
|
|
) &&
|
2016-04-06 09:54:04 +00:00
|
|
|
!empty( PortableInfoboxDataService::newFromTitle( $title )->getData() );
|
2016-04-06 08:50:01 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 09:54:04 +00:00
|
|
|
private function filterInfoboxes( $tmpl ) {
|
2018-08-05 09:44:51 +00:00
|
|
|
$title = Title::newFromID( $tmpl->value );
|
2016-04-06 08:50:01 +00:00
|
|
|
|
|
|
|
return $title &&
|
|
|
|
$title->exists() &&
|
|
|
|
$this->hasInfobox( $title );
|
2015-08-20 13:14:23 +00:00
|
|
|
}
|
|
|
|
}
|