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