(bug 26809) Uploading files with multiple extensions where one of the extensions...
[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() { return true; }
40 function isSyndicated() { return false; }
41
42 function getQueryInfo() {
43 return array (
44 'tables' => array ( 'pagelinks', 'page' ),
45 'fields' => array ( 'pl_namespace AS namespace',
46 'pl_title AS title',
47 'COUNT(*) AS value',
48 'page_namespace' ),
49 'options' => array ( 'HAVING' => 'COUNT(*) > 1',
50 'GROUP BY' => 'pl_namespace, pl_title, '.
51 'page_namespace' ),
52 'join_conds' => array ( 'page' => array ( 'LEFT JOIN',
53 array ( 'page_namespace = pl_namespace',
54 'page_title = pl_title' ) ) )
55 );
56 }
57
58 /**
59 * Pre-fill the link cache
60 */
61 function preprocessResults( $db, $res ) {
62 if( $db->numRows( $res ) > 0 ) {
63 $linkBatch = new LinkBatch();
64 foreach ( $res as $row ) {
65 $linkBatch->add( $row->namespace, $row->title );
66 }
67 $db->dataSeek( $res, 0 );
68 $linkBatch->execute();
69 }
70 }
71
72 /**
73 * Make a link to "what links here" for the specified title
74 *
75 * @param $title Title being queried
76 * @param $caption String: text to display on the link
77 * @param $skin Skin to use
78 * @return String
79 */
80 function makeWlhLink( &$title, $caption, &$skin ) {
81 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
82 return $skin->linkKnown( $wlh, $caption );
83 }
84
85 /**
86 * Make links to the page corresponding to the item, and the "what links here" page for it
87 *
88 * @param $skin Skin to be used
89 * @param $result Result row
90 * @return string
91 */
92 function formatResult( $skin, $result ) {
93 global $wgLang;
94 $title = Title::makeTitleSafe( $result->namespace, $result->title );
95 if ( !$title ) {
96 return '<!-- ' . htmlspecialchars( "Invalid title: [[$title]]" ) . ' -->';
97 }
98 $link = $skin->link( $title );
99 $wlh = $this->makeWlhLink( $title,
100 wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
101 $wgLang->formatNum( $result->value ) ), $skin );
102 return wfSpecialList( $link, $wlh );
103 }
104 }