Merge "Whitelist the <wbr> element."
[mediawiki.git] / includes / specials / SpecialMostlinkedtemplates.php
blobc90acb1f9a5776b2b46f8be75b8580a56d88f49d
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 {
32 function __construct( $name = 'Mostlinkedtemplates' ) {
33 parent::__construct( $name );
36 /**
37 * Is this report expensive, i.e should it be cached?
39 * @return Boolean
41 public function isExpensive() {
42 return true;
45 /**
46 * Is there a feed available?
48 * @return Boolean
50 public function isSyndicated() {
51 return false;
54 /**
55 * Sort the results in descending order?
57 * @return Boolean
59 public function sortDescending() {
60 return true;
63 public function getQueryInfo() {
64 return array(
65 'tables' => array( 'templatelinks' ),
66 'fields' => array(
67 'namespace' => 'tl_namespace',
68 'title' => 'tl_title',
69 'value' => 'COUNT(*)'
71 'conds' => array( 'tl_namespace' => NS_TEMPLATE ),
72 'options' => array( 'GROUP BY' => array( 'tl_namespace', 'tl_title' ) )
76 /**
77 * Pre-cache page existence to speed up link generation
79 * @param $db DatabaseBase connection
80 * @param ResultWrapper $res
82 public function preprocessResults( $db, $res ) {
83 if ( !$res->numRows() ) {
84 return;
87 $batch = new LinkBatch();
88 foreach ( $res as $row ) {
89 $batch->add( $row->namespace, $row->title );
91 $batch->execute();
93 $res->seek( 0 );
96 /**
97 * Format a result row
99 * @param Skin $skin
100 * @param object $result Result row
101 * @return string
103 public function formatResult( $skin, $result ) {
104 $title = Title::makeTitleSafe( $result->namespace, $result->title );
105 if ( !$title ) {
106 return Html::element(
107 'span',
108 array( 'class' => 'mw-invalidtitle' ),
109 Linker::getInvalidTitleDescription(
110 $this->getContext(),
111 $result->namespace,
112 $result->title
117 return $this->getLanguage()->specialList(
118 Linker::link( $title ),
119 $this->makeWlhLink( $title, $result )
124 * Make a "what links here" link for a given title
126 * @param Title $title Title to make the link for
127 * @param object $result Result row
128 * @return String
130 private function makeWlhLink( $title, $result ) {
131 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
132 $label = $this->msg( 'ntransclusions' )->numParams( $result->value )->escaped();
134 return Linker::link( $wlh, $label );
137 protected function getGroupName() {
138 return 'highuse';