MediaWiki  REL1_22
SpecialMostlinkedtemplates.php
Go to the documentation of this file.
00001 <?php
00031 class MostlinkedTemplatesPage extends QueryPage {
00032     function __construct( $name = 'Mostlinkedtemplates' ) {
00033         parent::__construct( $name );
00034     }
00035 
00041     public function isExpensive() {
00042         return true;
00043     }
00044 
00050     public function isSyndicated() {
00051         return false;
00052     }
00053 
00059     public function sortDescending() {
00060         return true;
00061     }
00062 
00063     public function getQueryInfo() {
00064         return array(
00065             'tables' => array( 'templatelinks' ),
00066             'fields' => array(
00067                 'namespace' => 'tl_namespace',
00068                 'title' => 'tl_title',
00069                 'value' => 'COUNT(*)'
00070             ),
00071             'conds' => array( 'tl_namespace' => NS_TEMPLATE ),
00072             'options' => array( 'GROUP BY' => array( 'tl_namespace', 'tl_title' ) )
00073         );
00074     }
00075 
00082     public function preprocessResults( $db, $res ) {
00083         if ( !$res->numRows() ) {
00084             return;
00085         }
00086 
00087         $batch = new LinkBatch();
00088         foreach ( $res as $row ) {
00089             $batch->add( $row->namespace, $row->title );
00090         }
00091         $batch->execute();
00092 
00093         $res->seek( 0 );
00094     }
00095 
00103     public function formatResult( $skin, $result ) {
00104         $title = Title::makeTitleSafe( $result->namespace, $result->title );
00105         if ( !$title ) {
00106             return Html::element(
00107                 'span',
00108                 array( 'class' => 'mw-invalidtitle' ),
00109                 Linker::getInvalidTitleDescription(
00110                     $this->getContext(),
00111                     $result->namespace,
00112                     $result->title
00113                 )
00114             );
00115         }
00116 
00117         return $this->getLanguage()->specialList(
00118             Linker::link( $title ),
00119             $this->makeWlhLink( $title, $result )
00120         );
00121     }
00122 
00130     private function makeWlhLink( $title, $result ) {
00131         $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
00132         $label = $this->msg( 'ntransclusions' )->numParams( $result->value )->escaped();
00133 
00134         return Linker::link( $wlh, $label );
00135     }
00136 
00137     protected function getGroupName() {
00138         return 'highuse';
00139     }
00140 }