Debian Codegraph @

includes/specials/SpecialMostLinkedTemplates.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Specials;
22
23 use MediaWiki\Cache\LinkBatchFactory;
24 use MediaWiki\Html\Html;
25 use MediaWiki\Linker\Linker;
26 use MediaWiki\Linker\LinksMigration;
27 use MediaWiki\SpecialPage\QueryPage;
28 use MediaWiki\SpecialPage\SpecialPage;
29 use MediaWiki\Title\Title;
30 use Skin;
31 use stdClass;
32 use Wikimedia\Rdbms\IConnectionProvider;
33 use Wikimedia\Rdbms\IDatabase;
34 use Wikimedia\Rdbms\IResultWrapper;
35
36 /**
37 * List of templates with a large number of transclusion links,
38 * i.e. "most used" templates
39 *
40 * @ingroup SpecialPage
41 * @author Rob Church <[email protected]>
42 */
43 class SpecialMostLinkedTemplates extends QueryPage {
44
45 private LinksMigration $linksMigration;
46
47 /**
48 * @param IConnectionProvider $dbProvider
49 * @param LinkBatchFactory $linkBatchFactory
50 * @param LinksMigration $linksMigration
51 */
52 public function __construct(
53 IConnectionProvider $dbProvider,
54 LinkBatchFactory $linkBatchFactory,
55 LinksMigration $linksMigration
56 ) {
57 parent::__construct( 'Mostlinkedtemplates' );
58 $this->setDatabaseProvider( $dbProvider );
59 $this->setLinkBatchFactory( $linkBatchFactory );
60 $this->linksMigration = $linksMigration;
61 }
62
63 /**
64 * Is this report expensive, i.e should it be cached?
65 *
66 * @return bool
67 */
68 public function isExpensive() {
69 return true;
70 }
71
72 /**
73 * Is there a feed available?
74 *
75 * @return bool
76 */
77 public function isSyndicated() {
78 return false;
79 }
80
81 /**
82 * Sort the results in descending order?
83 *
84 * @return bool
85 */
86 public function sortDescending() {
87 return true;
88 }
89
90 public function getQueryInfo() {
91 $queryInfo = $this->linksMigration->getQueryInfo( 'templatelinks' );
92 [ $ns, $title ] = $this->linksMigration->getTitleFields( 'templatelinks' );
93 return [
94 'tables' => $queryInfo['tables'],
95 'fields' => [
96 'namespace' => $ns,
97 'title' => $title,
98 'value' => 'COUNT(*)'
99 ],
100 'options' => [ 'GROUP BY' => [ $ns, $title ] ],
101 'join_conds' => $queryInfo['joins']
102 ];
103 }
104
105 /**
106 * Pre-cache page existence to speed up link generation
107 *
108 * @param IDatabase $db
109 * @param IResultWrapper $res
110 */
111 public function preprocessResults( $db, $res ) {
112 $this->executeLBFromResultWrapper( $res );
113 }
114
115 /**
116 * Format a result row
117 *
118 * @param Skin $skin
119 * @param stdClass $result Result row
120 * @return string
121 */
122 public function formatResult( $skin, $result ) {
123 $title = Title::makeTitleSafe( $result->namespace, $result->title );
124 if ( !$title ) {
125 return Html::element(
126 'span',
127 [ 'class' => 'mw-invalidtitle' ],
128 Linker::getInvalidTitleDescription(
129 $this->getContext(),
130 $result->namespace,
131 $result->title
132 )
133 );
134 }
135
136 return $this->getLanguage()->specialList(
137 $this->getLinkRenderer()->makeLink( $title ),
138 $this->makeWlhLink( $title, $result )
139 );
140 }
141
142 /**
143 * Make a "what links here" link for a given title
144 *
145 * @param Title $title Title to make the link for
146 * @param stdClass $result Result row
147 * @return string
148 */
149 private function makeWlhLink( $title, $result ) {
150 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
151 $label = $this->msg( 'ntransclusions' )->numParams( $result->value )->text();
152
153 return $this->getLinkRenderer()->makeLink( $wlh, $label );
154 }
155
156 protected function getGroupName() {
157 return 'highuse';
158 }
159 }
160
161 /**
162 * Retain the old class name for backwards compatibility.
163 * @deprecated since 1.41
164 */
165 class_alias( SpecialMostLinkedTemplates::class, 'SpecialMostLinkedTemplates' );