Merge "add basic print styles to CologneBlue"
[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
35 function __construct( $name = 'Mostlinked' ) {
36 parent::__construct( $name );
37 }
38
39 function isExpensive() {
40 return true;
41 }
42
43 function isSyndicated() {
44 return false;
45 }
46
47 function getQueryInfo() {
48 return array(
49 'tables' => array( 'pagelinks', 'page' ),
50 'fields' => array( 'namespace' => 'pl_namespace',
51 'title' => 'pl_title',
52 'value' => 'COUNT(*)',
53 'page_namespace' ),
54 'options' => array( 'HAVING' => 'COUNT(*) > 1',
55 'GROUP BY' => array( 'pl_namespace', 'pl_title',
56 'page_namespace' ) ),
57 'join_conds' => array( 'page' => array( 'LEFT JOIN',
58 array( 'page_namespace = pl_namespace',
59 'page_title = pl_title' ) ) )
60 );
61 }
62
63 /**
64 * Pre-fill the link cache
65 *
66 * @param DatabaseBase $db
67 * @param ResultWrapper $res
68 */
69 function preprocessResults( $db, $res ) {
70 if ( $res->numRows() > 0 ) {
71 $linkBatch = new LinkBatch();
72 foreach ( $res as $row ) {
73 $linkBatch->add( $row->namespace, $row->title );
74 }
75 $res->seek( 0 );
76 $linkBatch->execute();
77 }
78 }
79
80 /**
81 * Make a link to "what links here" for the specified title
82 *
83 * @param $title Title being queried
84 * @param string $caption text to display on the link
85 * @return String
86 */
87 function makeWlhLink( $title, $caption ) {
88 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
89 return Linker::linkKnown( $wlh, $caption );
90 }
91
92 /**
93 * Make links to the page corresponding to the item, and the "what links here" page for it
94 *
95 * @param Skin $skin Skin to be used
96 * @param object $result Result row
97 * @return string
98 */
99 function formatResult( $skin, $result ) {
100 $title = Title::makeTitleSafe( $result->namespace, $result->title );
101 if ( !$title ) {
102 return Html::element( 'span', array( 'class' => 'mw-invalidtitle' ),
103 Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
104 }
105 $link = Linker::link( $title );
106 $wlh = $this->makeWlhLink( $title,
107 $this->msg( 'nlinks' )->numParams( $result->value )->escaped() );
108 return $this->getLanguage()->specialList( $link, $wlh );
109 }
110
111 protected function getGroupName() {
112 return 'highuse';
113 }
114 }