Part 1 of 2, moving ResourceLoader*Module classes to their own files - this commit...
[mediawiki.git] / includes / specials / SpecialMostlinkedtemplates.php
blob71df9044c5c4c780a0a90d45ff173f051d29f83a
1 <?php
2 /**
3 * Implements Special:Mostlinkedtemplates
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup SpecialPage
22 * @author Rob Church <robchur@gmail.com>
25 /**
26 * Special page lists templates with a large number of
27 * transclusion links, i.e. "most used" templates
29 * @ingroup SpecialPage
31 class SpecialMostlinkedtemplates extends QueryPage {
33 /**
34 * Name of the report
36 * @return String
38 public function getName() {
39 return 'Mostlinkedtemplates';
42 /**
43 * Is this report expensive, i.e should it be cached?
45 * @return Boolean
47 public function isExpensive() {
48 return true;
51 /**
52 * Is there a feed available?
54 * @return Boolean
56 public function isSyndicated() {
57 return false;
60 /**
61 * Sort the results in descending order?
63 * @return Boolean
65 public function sortDescending() {
66 return true;
69 /**
70 * Generate SQL for the report
72 * @return String
74 public function getSql() {
75 $dbr = wfGetDB( DB_SLAVE );
76 $templatelinks = $dbr->tableName( 'templatelinks' );
77 $name = $dbr->addQuotes( $this->getName() );
78 return "SELECT {$name} AS type,
79 " . NS_TEMPLATE . " AS namespace,
80 tl_title AS title,
81 COUNT(*) AS value
82 FROM {$templatelinks}
83 WHERE tl_namespace = " . NS_TEMPLATE . "
84 GROUP BY tl_title";
87 /**
88 * Pre-cache page existence to speed up link generation
90 * @param $db Database connection
91 * @param $res ResultWrapper
93 public function preprocessResults( $db, $res ) {
94 $batch = new LinkBatch();
95 foreach ( $res as $row ) {
96 $batch->add( $row->namespace, $row->title );
98 $batch->execute();
99 if( $db->numRows( $res ) > 0 )
100 $db->dataSeek( $res, 0 );
104 * Format a result row
106 * @param $skin Skin to use for UI elements
107 * @param $result Result row
108 * @return String
110 public function formatResult( $skin, $result ) {
111 $title = Title::makeTitleSafe( $result->namespace, $result->title );
113 return wfSpecialList(
114 $skin->link( $title ),
115 $this->makeWlhLink( $title, $skin, $result )
120 * Make a "what links here" link for a given title
122 * @param $title Title to make the link for
123 * @param $skin Skin to use
124 * @param $result Result row
125 * @return String
127 private function makeWlhLink( $title, $skin, $result ) {
128 global $wgLang;
129 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' );
130 $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
131 $wgLang->formatNum( $result->value ) );
132 return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) );
137 * Execution function
139 * @param $par Mixed: parameters passed to the page
141 function wfSpecialMostlinkedtemplates( $par = false ) {
142 list( $limit, $offset ) = wfCheckLimits();
143 $mlt = new SpecialMostlinkedtemplates();
144 $mlt->doQuery( $offset, $limit );