Merge "Drop index oi_name_archive_name on table oldimage"
[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\ResultWrapper;
29
30 /**
31 * A special page to show pages ordered by the number of pages linking to them.
32 *
33 * @ingroup SpecialPage
34 */
35 class MostlinkedPage extends QueryPage {
36 function __construct( $name = 'Mostlinked' ) {
37 parent::__construct( $name );
38 }
39
40 public function isExpensive() {
41 return true;
42 }
43
44 function isSyndicated() {
45 return false;
46 }
47
48 public function getQueryInfo() {
49 return [
50 'tables' => [ 'pagelinks', 'page' ],
51 'fields' => [
52 'namespace' => 'pl_namespace',
53 'title' => 'pl_title',
54 'value' => 'COUNT(*)',
55 'page_namespace'
56 ],
57 'options' => [
58 'HAVING' => 'COUNT(*) > 1',
59 'GROUP BY' => [
60 'pl_namespace', 'pl_title',
61 'page_namespace'
62 ]
63 ],
64 'join_conds' => [
65 'page' => [
66 'LEFT JOIN',
67 [
68 'page_namespace = pl_namespace',
69 'page_title = pl_title'
70 ]
71 ]
72 ]
73 ];
74 }
75
76 /**
77 * Pre-fill the link cache
78 *
79 * @param IDatabase $db
80 * @param ResultWrapper $res
81 */
82 function preprocessResults( $db, $res ) {
83 $this->executeLBFromResultWrapper( $res );
84 }
85
86 /**
87 * Make a link to "what links here" for the specified title
88 *
89 * @param Title $title Title being queried
90 * @param string $caption Text to display on the link
91 * @return string
92 */
93 function makeWlhLink( $title, $caption ) {
94 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
95
96 $linkRenderer = $this->getLinkRenderer();
97 return $linkRenderer->makeKnownLink( $wlh, $caption );
98 }
99
100 /**
101 * Make links to the page corresponding to the item,
102 * and the "what links here" page for it
103 *
104 * @param Skin $skin Skin to be used
105 * @param object $result Result row
106 * @return string
107 */
108 function formatResult( $skin, $result ) {
109 $title = Title::makeTitleSafe( $result->namespace, $result->title );
110 if ( !$title ) {
111 return Html::element(
112 'span',
113 [ 'class' => 'mw-invalidtitle' ],
114 Linker::getInvalidTitleDescription(
115 $this->getContext(),
116 $result->namespace,
117 $result->title )
118 );
119 }
120
121 $linkRenderer = $this->getLinkRenderer();
122 $link = $linkRenderer->makeLink( $title );
123 $wlh = $this->makeWlhLink(
124 $title,
125 $this->msg( 'nlinks' )->numParams( $result->value )->text()
126 );
127
128 return $this->getLanguage()->specialList( $link, $wlh );
129 }
130
131 protected function getGroupName() {
132 return 'highuse';
133 }
134 }