Debian Codegraph @

includes/specials/SpecialMostLinked.php

raw symbols SCIP
1 <?php
2 /**
3 * Copyright © 2005 Ævar Arnfjörð Bjarmason, 2006 Rob Church
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 */
22
23 namespace MediaWiki\Specials;
24
25 use MediaWiki\Cache\LinkBatchFactory;
26 use MediaWiki\Html\Html;
27 use MediaWiki\Linker\Linker;
28 use MediaWiki\Linker\LinksMigration;
29 use MediaWiki\SpecialPage\QueryPage;
30 use MediaWiki\SpecialPage\SpecialPage;
31 use MediaWiki\Title\Title;
32 use Skin;
33 use stdClass;
34 use Wikimedia\Rdbms\IConnectionProvider;
35 use Wikimedia\Rdbms\IDatabase;
36 use Wikimedia\Rdbms\IResultWrapper;
37
38 /**
39 * List of pages ordered by the number of pages linking to them.
40 *
41 * @ingroup SpecialPage
42 * @author Ævar Arnfjörð Bjarmason <[email protected]om>
43 * @author Rob Church <[email protected]>
44 */
45 class SpecialMostLinked extends QueryPage {
46
47 private LinksMigration $linksMigration;
48
49 /**
50 * @param IConnectionProvider $dbProvider
51 * @param LinkBatchFactory $linkBatchFactory
52 * @param LinksMigration $linksMigration
53 */
54 public function __construct(
55 IConnectionProvider $dbProvider,
56 LinkBatchFactory $linkBatchFactory,
57 LinksMigration $linksMigration
58 ) {
59 parent::__construct( 'Mostlinked' );
60 $this->setDatabaseProvider( $dbProvider );
61 $this->setLinkBatchFactory( $linkBatchFactory );
62 $this->linksMigration = $linksMigration;
63 }
64
65 public function isExpensive() {
66 return true;
67 }
68
69 public function isSyndicated() {
70 return false;
71 }
72
73 public function getQueryInfo() {
74 [ $ns, $title ] = $this->linksMigration->getTitleFields( 'pagelinks' );
75 $queryInfo = $this->linksMigration->getQueryInfo( 'pagelinks' );
76 return [
77 'tables' => $queryInfo['tables'],
78 'fields' => [
79 'namespace' => $ns,
80 'title' => $title,
81 'value' => 'COUNT(*)'
82 ],
83 'options' => [
84 'HAVING' => 'COUNT(*) > 1',
85 'GROUP BY' => [ $ns, $title ],
86 ],
87 'join_conds' => $queryInfo['joins'],
88 ];
89 }
90
91 /**
92 * Pre-fill the link cache
93 *
94 * @param IDatabase $db
95 * @param IResultWrapper $res
96 */
97 public function preprocessResults( $db, $res ) {
98 $this->executeLBFromResultWrapper( $res );
99 }
100
101 /**
102 * Make a link to "what links here" for the specified title
103 *
104 * @param Title $title Title being queried
105 * @param string $caption Text to display on the link
106 * @return string
107 */
108 private function makeWlhLink( $title, $caption ) {
109 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
110
111 $linkRenderer = $this->getLinkRenderer();
112 return $linkRenderer->makeKnownLink( $wlh, $caption );
113 }
114
115 /**
116 * Make links to the page corresponding to the item,
117 * and the "what links here" page for it
118 *
119 * @param Skin $skin Skin to be used
120 * @param stdClass $result Result row
121 * @return string
122 */
123 public function formatResult( $skin, $result ) {
124 $title = Title::makeTitleSafe( $result->namespace, $result->title );
125 if ( !$title ) {
126 return Html::element(
127 'span',
128 [ 'class' => 'mw-invalidtitle' ],
129 Linker::getInvalidTitleDescription(
130 $this->getContext(),
131 $result->namespace,
132 $result->title )
133 );
134 }
135
136 $linkRenderer = $this->getLinkRenderer();
137 $link = $linkRenderer->makeLink( $title );
138 $wlh = $this->makeWlhLink(
139 $title,
140 $this->msg( 'nlinks' )->numParams( $result->value )->text()
141 );
142
143 return $this->getLanguage()->specialList( $link, $wlh );
144 }
145
146 protected function getGroupName() {
147 return 'highuse';
148 }
149 }
150
151 /**
152 * Retain the old class name for backwards compatibility.
153 * @deprecated since 1.41
154 */
155 class_alias( SpecialMostLinked::class, 'SpecialMostLinked' );