8 * Special page lists templates with a large number of
9 * transclusion links, i.e. "most used" templates
11 * @ingroup SpecialPage
12 * @author Rob Church <robchur@gmail.com>
14 class SpecialMostlinkedtemplates
extends QueryPage
{
21 public function getName() {
22 return 'Mostlinkedtemplates';
26 * Is this report expensive, i.e should it be cached?
30 public function isExpensive() {
35 * Is there a feed available?
39 public function isSyndicated() {
44 * Sort the results in descending order?
48 public function sortDescending() {
53 * Generate SQL for the report
57 public function getSql() {
58 $dbr = wfGetDB( DB_SLAVE
);
59 $templatelinks = $dbr->tableName( 'templatelinks' );
60 $name = $dbr->addQuotes( $this->getName() );
61 return "SELECT {$name} AS type,
62 " . NS_TEMPLATE
. " AS namespace,
66 WHERE tl_namespace = " . NS_TEMPLATE
. "
71 * Pre-cache page existence to speed up link generation
73 * @param $db Database connection
74 * @param $res ResultWrapper
76 public function preprocessResults( $db, $res ) {
77 $batch = new LinkBatch();
78 while( $row = $db->fetchObject( $res ) ) {
79 $batch->add( $row->namespace, $row->title
);
82 if( $db->numRows( $res ) > 0 )
83 $db->dataSeek( $res, 0 );
89 * @param $skin Skin to use for UI elements
90 * @param $result Result row
93 public function formatResult( $skin, $result ) {
94 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
97 $skin->link( $title ),
98 $this->makeWlhLink( $title, $skin, $result )
103 * Make a "what links here" link for a given title
105 * @param $title Title to make the link for
106 * @param $skin Skin to use
107 * @param $result Result row
110 private function makeWlhLink( $title, $skin, $result ) {
112 $wlh = SpecialPage
::getTitleFor( 'Whatlinkshere' );
113 $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
114 $wgLang->formatNum( $result->value
) );
115 return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) );
122 * @param $par Mixed: parameters passed to the page
124 function wfSpecialMostlinkedtemplates( $par = false ) {
125 list( $limit, $offset ) = wfCheckLimits();
126 $mlt = new SpecialMostlinkedtemplates();
127 $mlt->doQuery( $offset, $limit );