MediaWiki
REL1_24
|
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 '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( 00106 'span', 00107 array( 'class' => 'mw-invalidtitle' ), 00108 Linker::getInvalidTitleDescription( 00109 $this->getContext(), 00110 $result->namespace, 00111 $result->title 00112 ) 00113 ); 00114 } 00115 00116 return $this->getLanguage()->specialList( 00117 Linker::link( $title ), 00118 $this->makeWlhLink( $title, $result ) 00119 ); 00120 } 00121 00129 private function makeWlhLink( $title, $result ) { 00130 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() ); 00131 $label = $this->msg( 'ntransclusions' )->numParams( $result->value )->escaped(); 00132 00133 return Linker::link( $wlh, $label ); 00134 } 00135 00136 protected function getGroupName() { 00137 return 'highuse'; 00138 } 00139 }