2015-08-20 13:14:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class AllinfoboxesQueryPage extends PageQueryPage {
|
|
|
|
|
|
|
|
const ALL_INFOBOXES_TYPE = 'AllInfoboxes';
|
2015-09-16 10:14:21 +00:00
|
|
|
private static $subpagesBlacklist = [ 'doc', 'draft', 'test' ];
|
2015-08-20 13:14:23 +00:00
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
parent::__construct( self::ALL_INFOBOXES_TYPE );
|
|
|
|
}
|
|
|
|
|
2018-08-03 09:54:47 +00:00
|
|
|
function getGroupName() {
|
|
|
|
return 'pages';
|
|
|
|
}
|
|
|
|
|
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-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-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
|
|
|
|
*
|
|
|
|
* @param bool $limit Only for consistency
|
|
|
|
* @param bool $ignoreErrors Only for consistency
|
|
|
|
*
|
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-03 08:49:28 +00:00
|
|
|
* @see QueryPage::reallyDoQuery
|
|
|
|
*
|
2015-08-20 13:14:23 +00:00
|
|
|
* @param bool $limit Only for consistency
|
|
|
|
* @param bool $offset Only for consistency
|
|
|
|
*
|
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 = [];
|
|
|
|
|
|
|
|
while ( $row = $res->fetchObject() ) {
|
|
|
|
if($this->filterInfoboxes( $row )) {
|
|
|
|
$out[] = $row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new FakeResultWrapper($out);
|
2015-09-17 09:22:12 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 08:50:01 +00:00
|
|
|
public function addTitleToCache( Title $title ) {
|
|
|
|
if ( !$this->hasInfobox( $title ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2015-09-17 09:22:12 +00:00
|
|
|
|
2016-04-06 08:50:01 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2018-08-03 08:49:28 +00:00
|
|
|
$dbw->doAtomicSection(
|
|
|
|
__METHOD__,
|
|
|
|
function ( IDatabase $dbw, $fname ) use ( $title ) {
|
|
|
|
$dbw->insert( 'querycache', [
|
|
|
|
'qc_type' => $this->getName(),
|
|
|
|
'qc_namespace' => $title->getNamespace(),
|
|
|
|
'qc_title' => $title->getDBkey()
|
|
|
|
], $fname );
|
|
|
|
}
|
|
|
|
);
|
2015-09-09 13:28:22 +00:00
|
|
|
|
2017-07-12 12:21:06 +00:00
|
|
|
Hooks::run( 'AllInfoboxesQueryRecached' );
|
2016-04-06 08:50:01 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|