00001 <?php 00014 class SpecialMostlinkedtemplates extends QueryPage { 00015 00021 public function getName() { 00022 return 'Mostlinkedtemplates'; 00023 } 00024 00030 public function isExpensive() { 00031 return true; 00032 } 00033 00039 public function isSyndicated() { 00040 return false; 00041 } 00042 00048 public function sortDescending() { 00049 return true; 00050 } 00051 00057 public function getSql() { 00058 $dbr = wfGetDB( DB_SLAVE ); 00059 $templatelinks = $dbr->tableName( 'templatelinks' ); 00060 $name = $dbr->addQuotes( $this->getName() ); 00061 return "SELECT {$name} AS type, 00062 " . NS_TEMPLATE . " AS namespace, 00063 tl_title AS title, 00064 COUNT(*) AS value 00065 FROM {$templatelinks} 00066 WHERE tl_namespace = " . NS_TEMPLATE . " 00067 GROUP BY tl_title"; 00068 } 00069 00076 public function preprocessResults( $db, $res ) { 00077 $batch = new LinkBatch(); 00078 while( $row = $db->fetchObject( $res ) ) { 00079 $batch->add( $row->namespace, $row->title ); 00080 } 00081 $batch->execute(); 00082 if( $db->numRows( $res ) > 0 ) 00083 $db->dataSeek( $res, 0 ); 00084 } 00085 00093 public function formatResult( $skin, $result ) { 00094 $title = Title::makeTitleSafe( $result->namespace, $result->title ); 00095 00096 $skin->link( $title ); 00097 return wfSpecialList( 00098 $skin->makeLinkObj( $title ), 00099 $this->makeWlhLink( $title, $skin, $result ) 00100 ); 00101 } 00102 00111 private function makeWlhLink( $title, $skin, $result ) { 00112 global $wgLang; 00113 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' ); 00114 $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ), 00115 $wgLang->formatNum( $result->value ) ); 00116 return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) ); 00117 } 00118 } 00119 00125 function wfSpecialMostlinkedtemplates( $par = false ) { 00126 list( $limit, $offset ) = wfCheckLimits(); 00127 $mlt = new SpecialMostlinkedtemplates(); 00128 $mlt->doQuery( $offset, $limit ); 00129 }