Type check the APC value in LoadBalancer::doWait()
[mediawiki.git] / includes / specials / SpecialMostlinkedtemplates.php
blobd10279163abe352f20ab2ae55bb1611543a1d5db
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 bool
41 public function isExpensive() {
42 return true;
45 /**
46 * Is there a feed available?
48 * @return bool
50 public function isSyndicated() {
51 return false;
54 /**
55 * Sort the results in descending order?
57 * @return bool
59 public function sortDescending() {
60 return true;
63 public function getQueryInfo() {
64 return [
65 'tables' => [ 'templatelinks' ],
66 'fields' => [
67 'namespace' => 'tl_namespace',
68 'title' => 'tl_title',
69 'value' => 'COUNT(*)'
71 'options' => [ 'GROUP BY' => [ 'tl_namespace', 'tl_title' ] ]
75 /**
76 * Pre-cache page existence to speed up link generation
78 * @param IDatabase $db
79 * @param ResultWrapper $res
81 public function preprocessResults( $db, $res ) {
82 $this->executeLBFromResultWrapper( $res );
85 /**
86 * Format a result row
88 * @param Skin $skin
89 * @param object $result Result row
90 * @return string
92 public function formatResult( $skin, $result ) {
93 $title = Title::makeTitleSafe( $result->namespace, $result->title );
94 if ( !$title ) {
95 return Html::element(
96 'span',
97 [ 'class' => 'mw-invalidtitle' ],
98 Linker::getInvalidTitleDescription(
99 $this->getContext(),
100 $result->namespace,
101 $result->title
106 return $this->getLanguage()->specialList(
107 $this->getLinkRenderer()->makeLink( $title ),
108 $this->makeWlhLink( $title, $result )
113 * Make a "what links here" link for a given title
115 * @param Title $title Title to make the link for
116 * @param object $result Result row
117 * @return string
119 private function makeWlhLink( $title, $result ) {
120 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
121 $label = $this->msg( 'ntransclusions' )->numParams( $result->value )->text();
123 return $this->getLinkRenderer()->makeLink( $wlh, $label );
126 protected function getGroupName() {
127 return 'highuse';