Merge "Make userWasLastToEdit reusable."
[lhc/web/wiklou.git] / includes / specials / SpecialMostinterwikis.php
1 <?php
2 /**
3 * Implements Special:Mostinterwikis
4 *
5 * Copyright © 2012 Umherirrender
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 Umherirrender
25 */
26
27 /**
28 * A special page that listed pages that have highest interwiki count
29 *
30 * @ingroup SpecialPage
31 */
32 class MostinterwikisPage extends QueryPage {
33
34 function __construct( $name = 'Mostinterwikis' ) {
35 parent::__construct( $name );
36 }
37
38 function isExpensive() { return true; }
39 function isSyndicated() { return false; }
40
41 function getQueryInfo() {
42 return array (
43 'tables' => array (
44 'langlinks',
45 'page'
46 ), 'fields' => array (
47 'namespace' => 'page_namespace',
48 'title' => 'page_title',
49 'value' => 'COUNT(*)'
50 ), 'conds' => array (
51 'page_namespace' => MWNamespace::getContentNamespaces()
52 ), 'options' => array (
53 'HAVING' => 'COUNT(*) > 1',
54 'GROUP BY' => array (
55 'page_namespace',
56 'page_title'
57 )
58 ), 'join_conds' => array (
59 'page' => array (
60 'LEFT JOIN',
61 'page_id = ll_from'
62 )
63 )
64 );
65 }
66
67 /**
68 * Pre-fill the link cache
69 *
70 * @param $db DatabaseBase
71 * @param $res
72 */
73 function preprocessResults( $db, $res ) {
74 # There's no point doing a batch check if we aren't caching results;
75 # the page must exist for it to have been pulled out of the table
76 if ( !$this->isCached() || !$res->numRows() ) {
77 return;
78 }
79
80 $batch = new LinkBatch;
81 foreach ( $res as $row ) {
82 $batch->add( $row->namespace, $row->title );
83 }
84 $batch->execute();
85
86 // Back to start for display
87 $res->seek( 0 );
88 }
89
90 /**
91 * @param $skin Skin
92 * @param $result
93 * @return string
94 */
95 function formatResult( $skin, $result ) {
96 $title = Title::makeTitleSafe( $result->namespace, $result->title );
97 if ( !$title ) {
98 return Html::element( 'span', array( 'class' => 'mw-invalidtitle' ),
99 Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
100 }
101
102 if ( $this->isCached() ) {
103 $link = Linker::link( $title );
104 } else {
105 $link = Linker::linkKnown( $title );
106 }
107
108 $count = $this->msg( 'ninterwikis' )->numParams( $result->value )->escaped();
109
110 return $this->getLanguage()->specialList( $link, $count );
111 }
112 }