mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-24 08:14:29 +00:00
d0697bd473
ObjectCache::getMainWANInstance() has been removed under mediawiki 1.34+.
53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
<?php
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
class ApiQueryAllinfoboxes extends ApiQueryBase {
|
|
|
|
const CACHE_TTL = 86400;
|
|
const MCACHE_KEY = 'allinfoboxes-list';
|
|
|
|
public function execute() {
|
|
$db = $this->getDB();
|
|
$res = $this->getResult();
|
|
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
|
$cachekey = $cache->makeKey( self::MCACHE_KEY );
|
|
|
|
$data = $cache->getWithSetCallback( $cachekey, self::CACHE_TTL, function () use ( $db ) {
|
|
$out = [];
|
|
|
|
$res = ( new AllinfoboxesQueryPage() )->doQuery();
|
|
while ( $row = $res->fetchObject() ) {
|
|
$out[] = [
|
|
'pageid' => $row->value,
|
|
'title' => $row->title,
|
|
'label' => $this->createLabel( $row->title ),
|
|
'ns' => $row->namespace
|
|
];
|
|
}
|
|
|
|
return $out;
|
|
} );
|
|
|
|
foreach ( $data as $id => $infobox ) {
|
|
$res->addValue( [ 'query', 'allinfoboxes' ], null, $infobox );
|
|
}
|
|
$res->addIndexedTagName( [ 'query', 'allinfoboxes' ], 'i' );
|
|
}
|
|
|
|
/**
|
|
* As a infobox template label we want to return a nice, clean text, without e.g. '_' signs
|
|
* @param $text infobox template title
|
|
* @return string
|
|
*/
|
|
private function createLabel( $text ) {
|
|
$title = Title::newFromText( $text, NS_TEMPLATE );
|
|
|
|
if ( $title ) {
|
|
return $title->getText();
|
|
}
|
|
|
|
return $text;
|
|
}
|
|
}
|