4 * Special page lists templates with a large number of
5 * transclusion links, i.e. "most used" templates
7 * @addtogroup SpecialPage
8 * @author Rob Church <robchur@gmail.com>
10 class SpecialMostlinkedtemplates
extends QueryPage
{
17 public function getName() {
18 return 'Mostlinkedtemplates';
22 * Is this report expensive, i.e should it be cached?
26 public function isExpensive() {
31 * Is there a feed available?
35 public function isSyndicated() {
40 * Sort the results in descending order?
44 public function sortDescending() {
49 * Generate SQL for the report
53 public function getSql() {
54 $dbr = wfGetDB( DB_SLAVE
);
55 $templatelinks = $dbr->tableName( 'templatelinks' );
56 $name = $dbr->addQuotes( $this->getName() );
57 return "SELECT {$name} AS type,
58 " . NS_TEMPLATE
. " AS namespace,
62 WHERE tl_namespace = " . NS_TEMPLATE
. "
67 * Pre-cache page existence to speed up link generation
69 * @param Database $dbr Database connection
70 * @param int $res Result pointer
72 public function preprocessResults( $db, $res ) {
73 $batch = new LinkBatch();
74 while( $row = $db->fetchObject( $res ) ) {
75 $batch->add( $row->namespace, $row->title
);
78 if( $db->numRows( $res ) > 0 )
79 $db->dataSeek( $res, 0 );
85 * @param Skin $skin Skin to use for UI elements
86 * @param object $result Result row
89 public function formatResult( $skin, $result ) {
90 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
91 if( $title instanceof Title
) {
93 $skin->makeLinkObj( $title ),
94 $this->makeWlhLink( $title, $skin, $result )
97 $tsafe = htmlspecialchars( $result->title
);
98 return "Invalid title in result set; {$tsafe}";
103 * Make a "what links here" link for a given title
105 * @param Title $title Title to make the link for
106 * @param Skin $skin Skin to use
107 * @param object $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->makeKnownLinkObj( $wlh, $label, 'target=' . $title->getPrefixedUrl() );
122 * @param mixed $par Parameters passed to the page
124 function wfSpecialMostlinkedtemplates( $par = false ) {
125 list( $limit, $offset ) = wfCheckLimits();
126 $mlt = new SpecialMostlinkedtemplates();
127 $mlt->doQuery( $offset, $limit );