Followup r82727, improve comments, cast return value to bool
[mediawiki.git] / includes / specials / SpecialMostlinkedtemplates.php
blob78f806f487eb0e26a30aca206ae3427ee56b8091
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 MostlinkedTemplatesPage extends QueryPage {
33 function __construct( $name = 'Mostlinkedtemplates' ) {
34 parent::__construct( $name );
37 /**
38 * Is this report expensive, i.e should it be cached?
40 * @return Boolean
42 public function isExpensive() {
43 return true;
46 /**
47 * Is there a feed available?
49 * @return Boolean
51 public function isSyndicated() {
52 return false;
55 /**
56 * Sort the results in descending order?
58 * @return Boolean
60 public function sortDescending() {
61 return true;
64 public function getQueryInfo() {
65 return array (
66 'tables' => array ( 'templatelinks' ),
67 'fields' => array ( 'tl_namespace AS namespace',
68 'tl_title AS title',
69 'COUNT(*) AS value' ),
70 'conds' => array ( 'tl_namespace' => NS_TEMPLATE ),
71 'options' => array( 'GROUP BY' => 'tl_title' )
75 /**
76 * Pre-cache page existence to speed up link generation
78 * @param $db Database connection
79 * @param $res ResultWrapper
81 public function preprocessResults( $db, $res ) {
82 $batch = new LinkBatch();
83 foreach ( $res as $row ) {
84 $batch->add( $row->namespace, $row->title );
86 $batch->execute();
87 if( $db->numRows( $res ) > 0 )
88 $db->dataSeek( $res, 0 );
91 /**
92 * Format a result row
94 * @param $skin Skin to use for UI elements
95 * @param $result Result row
96 * @return String
98 public function formatResult( $skin, $result ) {
99 $title = Title::makeTitle( $result->namespace, $result->title );
101 return wfSpecialList(
102 $skin->link( $title ),
103 $this->makeWlhLink( $title, $skin, $result )
108 * Make a "what links here" link for a given title
110 * @param $title Title to make the link for
111 * @param $skin Skin to use
112 * @param $result Result row
113 * @return String
115 private function makeWlhLink( $title, $skin, $result ) {
116 global $wgLang;
117 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' );
118 $label = wfMsgExt( 'ntransclusions', array( 'parsemag', 'escape' ),
119 $wgLang->formatNum( $result->value ) );
120 return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) );