Allow partially blocked users to tag unrelated revisions
[lhc/web/wiklou.git] / includes / specials / SpecialMostlinked.php
1 <?php
2 /**
3 * Implements Special:Mostlinked
4 *
5 * Copyright © 2005 Ævar Arnfjörð Bjarmason, 2006 Rob Church
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
21 *
22 * @file
23 * @ingroup SpecialPage
24 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
25 * @author Rob Church <robchur@gmail.com>
26 */
27
28 use Wikimedia\Rdbms\IResultWrapper;
29 use Wikimedia\Rdbms\IDatabase;
30
31 /**
32 * A special page to show pages ordered by the number of pages linking to them.
33 *
34 * @ingroup SpecialPage
35 */
36 class MostlinkedPage extends QueryPage {
37 function __construct( $name = 'Mostlinked' ) {
38 parent::__construct( $name );
39 }
40
41 public function isExpensive() {
42 return true;
43 }
44
45 function isSyndicated() {
46 return false;
47 }
48
49 public function getQueryInfo() {
50 return [
51 'tables' => [ 'pagelinks', 'page' ],
52 'fields' => [
53 'namespace' => 'pl_namespace',
54 'title' => 'pl_title',
55 'value' => 'COUNT(*)',
56 'page_namespace'
57 ],
58 'options' => [
59 'HAVING' => 'COUNT(*) > 1',
60 'GROUP BY' => [
61 'pl_namespace', 'pl_title',
62 'page_namespace'
63 ]
64 ],
65 'join_conds' => [
66 'page' => [
67 'LEFT JOIN',
68 [
69 'page_namespace = pl_namespace',
70 'page_title = pl_title'
71 ]
72 ]
73 ]
74 ];
75 }
76
77 /**
78 * Pre-fill the link cache
79 *
80 * @param IDatabase $db
81 * @param IResultWrapper $res
82 */
83 function preprocessResults( $db, $res ) {
84 $this->executeLBFromResultWrapper( $res );
85 }
86
87 /**
88 * Make a link to "what links here" for the specified title
89 *
90 * @param Title $title Title being queried
91 * @param string $caption Text to display on the link
92 * @return string
93 */
94 function makeWlhLink( $title, $caption ) {
95 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
96
97 $linkRenderer = $this->getLinkRenderer();
98 return $linkRenderer->makeKnownLink( $wlh, $caption );
99 }
100
101 /**
102 * Make links to the page corresponding to the item,
103 * and the "what links here" page for it
104 *
105 * @param Skin $skin Skin to be used
106 * @param object $result Result row
107 * @return string
108 */
109 function formatResult( $skin, $result ) {
110 $title = Title::makeTitleSafe( $result->namespace, $result->title );
111 if ( !$title ) {
112 return Html::element(
113 'span',
114 [ 'class' => 'mw-invalidtitle' ],
115 Linker::getInvalidTitleDescription(
116 $this->getContext(),
117 $result->namespace,
118 $result->title )
119 );
120 }
121
122 $linkRenderer = $this->getLinkRenderer();
123 $link = $linkRenderer->makeLink( $title );
124 $wlh = $this->makeWlhLink(
125 $title,
126 $this->msg( 'nlinks' )->numParams( $result->value )->text()
127 );
128
129 return $this->getLanguage()->specialList( $link, $wlh );
130 }
131
132 protected function getGroupName() {
133 return 'highuse';
134 }
135 }