2015-08-20 12:06:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class ApiQueryAllinfoboxes extends ApiQueryBase {
|
|
|
|
|
2015-08-20 13:14:23 +00:00
|
|
|
const CACHE_TTL = 86400;
|
2015-08-20 14:22:01 +00:00
|
|
|
const MCACHE_KEY = 'allinfoboxes-list';
|
2015-08-20 13:14:23 +00:00
|
|
|
|
2015-08-20 12:06:01 +00:00
|
|
|
public function execute() {
|
2018-08-05 11:06:26 +00:00
|
|
|
$db = $this->getDB();
|
|
|
|
$res = $this->getResult();
|
|
|
|
$cache = ObjectCache::getMainWANInstance();
|
2018-08-06 12:27:25 +00:00
|
|
|
$cachekey = $cache->makeKey( self::MCACHE_KEY );
|
2018-08-05 11:06:26 +00:00
|
|
|
|
|
|
|
$data = $cache->getWithSetCallback( $cachekey, self::CACHE_TTL, function () use ( $db ) {
|
|
|
|
$out = [];
|
|
|
|
|
2018-08-06 13:16:36 +00:00
|
|
|
$res = ( new AllinfoboxesQueryPage() )->doQuery();
|
2018-08-05 11:06:26 +00:00
|
|
|
while( $row = $res->fetchObject() ) {
|
|
|
|
$out[] = [
|
2018-08-06 13:16:36 +00:00
|
|
|
'pageid' => $row->value,
|
|
|
|
'title' => $row->title,
|
|
|
|
'label' => $this->createLabel( $row->title ),
|
|
|
|
'ns' => $row->namespace
|
2018-08-05 11:06:26 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $out;
|
2015-08-20 12:06:01 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
foreach ( $data as $id => $infobox ) {
|
2018-08-05 11:06:26 +00:00
|
|
|
$res->addValue( [ 'query', 'allinfoboxes' ], null, $infobox );
|
2015-08-20 12:06:01 +00:00
|
|
|
}
|
2018-08-05 11:06:26 +00:00
|
|
|
$res->addIndexedTagName( [ 'query', 'allinfoboxes' ], 'i' );
|
2015-08-20 12:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getVersion() {
|
|
|
|
return __CLASS__ . '$Id$';
|
|
|
|
}
|
2015-09-10 14:29:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @desc 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;
|
|
|
|
}
|
2015-08-20 12:06:01 +00:00
|
|
|
}
|