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