Merge "Drop index oi_name_archive_name on table oldimage"
[lhc/web/wiklou.git] / includes / specials / SpecialMostlinkedtemplates.php
1 <?php
2 /**
3 * Implements Special:Mostlinkedtemplates
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 * @author Rob Church <robchur@gmail.com>
23 */
24
25 use Wikimedia\Rdbms\ResultWrapper;
26
27 /**
28 * Special page lists templates with a large number of
29 * transclusion links, i.e. "most used" templates
30 *
31 * @ingroup SpecialPage
32 */
33 class MostlinkedTemplatesPage extends QueryPage {
34 function __construct( $name = 'Mostlinkedtemplates' ) {
35 parent::__construct( $name );
36 }
37
38 /**
39 * Is this report expensive, i.e should it be cached?
40 *
41 * @return bool
42 */
43 public function isExpensive() {
44 return true;
45 }
46
47 /**
48 * Is there a feed available?
49 *
50 * @return bool
51 */
52 public function isSyndicated() {
53 return false;
54 }
55
56 /**
57 * Sort the results in descending order?
58 *
59 * @return bool
60 */
61 public function sortDescending() {
62 return true;
63 }
64
65 public function getQueryInfo() {
66 return [
67 'tables' => [ 'templatelinks' ],
68 'fields' => [
69 'namespace' => 'tl_namespace',
70 'title' => 'tl_title',
71 'value' => 'COUNT(*)'
72 ],
73 'options' => [ 'GROUP BY' => [ 'tl_namespace', 'tl_title' ] ]
74 ];
75 }
76
77 /**
78 * Pre-cache page existence to speed up link generation
79 *
80 * @param IDatabase $db
81 * @param ResultWrapper $res
82 */
83 public function preprocessResults( $db, $res ) {
84 $this->executeLBFromResultWrapper( $res );
85 }
86
87 /**
88 * Format a result row
89 *
90 * @param Skin $skin
91 * @param object $result Result row
92 * @return string
93 */
94 public function formatResult( $skin, $result ) {
95 $title = Title::makeTitleSafe( $result->namespace, $result->title );
96 if ( !$title ) {
97 return Html::element(
98 'span',
99 [ 'class' => 'mw-invalidtitle' ],
100 Linker::getInvalidTitleDescription(
101 $this->getContext(),
102 $result->namespace,
103 $result->title
104 )
105 );
106 }
107
108 return $this->getLanguage()->specialList(
109 $this->getLinkRenderer()->makeLink( $title ),
110 $this->makeWlhLink( $title, $result )
111 );
112 }
113
114 /**
115 * Make a "what links here" link for a given title
116 *
117 * @param Title $title Title to make the link for
118 * @param object $result Result row
119 * @return string
120 */
121 private function makeWlhLink( $title, $result ) {
122 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
123 $label = $this->msg( 'ntransclusions' )->numParams( $result->value )->text();
124
125 return $this->getLinkRenderer()->makeLink( $wlh, $label );
126 }
127
128 protected function getGroupName() {
129 return 'highuse';
130 }
131 }