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 return wfSpecialList(
00097 $skin->link( $title ),
00098 $this->makeWlhLink( $title, $skin, $result )
00099 );
00100 }
00101
00110 private function makeWlhLink( $title, $skin, $result ) {
00111 global $wgLang;
00112 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' );
00113 $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
00114 $wgLang->formatNum( $result->value ) );
00115 return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) );
00116 }
00117 }
00118
00124 function wfSpecialMostlinkedtemplates( $par = false ) {
00125 list( $limit, $offset ) = wfCheckLimits();
00126 $mlt = new SpecialMostlinkedtemplates();
00127 $mlt->doQuery( $offset, $limit );
00128 }