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() {
|
2015-08-20 14:22:01 +00:00
|
|
|
$data = WikiaDataAccess::cache( wfMemcKey( self::MCACHE_KEY ), self::CACHE_TTL, function () {
|
2015-08-20 12:06:01 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2015-08-20 13:14:23 +00:00
|
|
|
|
|
|
|
return ( new WikiaSQL() )
|
|
|
|
->SELECT( 'qc_value', 'qc_namespace', 'qc_title' )
|
|
|
|
->FROM( 'querycache' )
|
|
|
|
->WHERE( 'qc_type' )->EQUAL_TO( AllinfoboxesQueryPage::ALL_INFOBOXES_TYPE )
|
2015-08-20 12:06:01 +00:00
|
|
|
->run( $dbr, function ( ResultWrapper $result ) {
|
|
|
|
$out = [ ];
|
|
|
|
while ( $row = $result->fetchRow() ) {
|
2015-08-20 13:14:23 +00:00
|
|
|
$out[] = [ 'pageid' => $row[ 'qc_value' ],
|
2015-09-10 14:29:46 +00:00
|
|
|
'title' => $row[ 'qc_title' ],
|
|
|
|
'label' => $this->createLabel( $row[ 'qc_title' ] ),
|
|
|
|
'ns' => $row[ 'qc_namespace' ] ];
|
2015-08-20 12:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $out;
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
foreach ( $data as $id => $infobox ) {
|
|
|
|
$this->getResult()->addValue( [ 'query', 'allinfoboxes' ], null, $infobox );
|
|
|
|
}
|
|
|
|
$this->getResult()->setIndexedTagName_internal( [ 'query', 'allinfoboxes' ], 'i' );
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|