Bug 32673: Keep the username in the input field if not existing
[lhc/web/wiklou.git] / includes / specials / SpecialShortpages.php
1 <?php
2 /**
3 * Implements Special:Shortpages
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * SpecialShortpages extends QueryPage. It is used to return the shortest
26 * pages in the database.
27 *
28 * @ingroup SpecialPage
29 */
30 class ShortPagesPage extends QueryPage {
31
32 function __construct( $name = 'Shortpages' ) {
33 parent::__construct( $name );
34 }
35
36 function isSyndicated() {
37 return false;
38 }
39
40 function getQueryInfo() {
41 return array (
42 'tables' => array ( 'page' ),
43 'fields' => array ( 'page_namespace AS namespace',
44 'page_title AS title',
45 'page_len AS value' ),
46 'conds' => array ( 'page_namespace' => NS_MAIN,
47 'page_is_redirect' => 0 ),
48 'options' => array ( 'USE INDEX' => 'page_redirect_namespace_len' )
49 );
50 }
51
52 function getOrderFields() {
53 return array( 'page_len' );
54 }
55
56 /**
57 * @param $db DatabaseBase
58 * @param $res
59 * @return void
60 */
61 function preprocessResults( $db, $res ) {
62 # There's no point doing a batch check if we aren't caching results;
63 # the page must exist for it to have been pulled out of the table
64 if( $this->isCached() ) {
65 $batch = new LinkBatch();
66 foreach ( $res as $row ) {
67 $batch->add( $row->namespace, $row->title );
68 }
69 $batch->execute();
70 if ( $db->numRows( $res ) > 0 ) {
71 $db->dataSeek( $res, 0 );
72 }
73 }
74 }
75
76 function sortDescending() {
77 return false;
78 }
79
80 function formatResult( $skin, $result ) {
81 $dm = $this->getLanguage()->getDirMark();
82
83 $title = Title::makeTitle( $result->namespace, $result->title );
84 if ( !$title ) {
85 return '<!-- Invalid title ' . htmlspecialchars( "{$result->namespace}:{$result->title}" ). '-->';
86 }
87 $hlink = Linker::linkKnown(
88 $title,
89 wfMsgHtml( 'hist' ),
90 array(),
91 array( 'action' => 'history' )
92 );
93 $plink = $this->isCached()
94 ? Linker::link( $title )
95 : Linker::linkKnown( $title );
96 $size = $this->msg( 'nbytes' )->numParams( $result->value )->escaped();
97
98 return $title->exists()
99 ? "({$hlink}) {$dm}{$plink} {$dm}[{$size}]"
100 : "<del>({$hlink}) {$dm}{$plink} {$dm}[{$size}]</del>";
101 }
102 }