MediaWiki  REL1_20
SpecialMostlinkedtemplates.php
Go to the documentation of this file.
00001 <?php
00031 class MostlinkedTemplatesPage extends QueryPage {
00032 
00033         function __construct( $name = 'Mostlinkedtemplates' ) {
00034                 parent::__construct( $name );
00035         }
00036 
00042         public function isExpensive() {
00043                 return true;
00044         }
00045 
00051         public function isSyndicated() {
00052                 return false;
00053         }
00054 
00060         public function sortDescending() {
00061                 return true;
00062         }
00063 
00064         public function getQueryInfo() {
00065                 return array (
00066                         'tables' => array ( 'templatelinks' ),
00067                         'fields' => array ( 'namespace' => 'tl_namespace',
00068                                         'title' => 'tl_title',
00069                                         'value' => 'COUNT(*)' ),
00070                         'conds' => array ( 'tl_namespace' => NS_TEMPLATE ),
00071                         'options' => array( 'GROUP BY' => array( 'tl_namespace', 'tl_title' ) )
00072                 );
00073         }
00074 
00081         public function preprocessResults( $db, $res ) {
00082                 if ( !$res->numRows() ) {
00083                         return;
00084                 }
00085 
00086                 $batch = new LinkBatch();
00087                 foreach ( $res as $row ) {
00088                         $batch->add( $row->namespace, $row->title );
00089                 }
00090                 $batch->execute();
00091 
00092                 $res->seek( 0 );
00093         }
00094 
00102         public function formatResult( $skin, $result ) {
00103                 $title = Title::makeTitleSafe( $result->namespace, $result->title );
00104                 if ( !$title ) {
00105                         return Html::element( 'span', array( 'class' => 'mw-invalidtitle' ),
00106                                 Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
00107                 }
00108 
00109                 return $this->getLanguage()->specialList(
00110                         Linker::link( $title ),
00111                         $this->makeWlhLink( $title, $result )
00112                 );
00113         }
00114 
00122         private function makeWlhLink( $title, $result ) {
00123                 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
00124                 $label = $this->msg( 'ntransclusions' )->numParams( $result->value )->escaped();
00125                 return Linker::link( $wlh, $label );
00126         }
00127 }
00128