Merge "Use output/error maintenance functions"
[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 ( 'namespace' => 'page_namespace',
44 'title' => 'page_title',
45 'value' => 'page_len' ),
46 'conds' => array ( 'page_namespace' =>
47 MWNamespace::getContentNamespaces(),
48 'page_is_redirect' => 0 ),
49 'options' => array ( 'USE INDEX' => 'page_redirect_namespace_len' )
50 );
51 }
52
53 function getOrderFields() {
54 return array( 'page_len' );
55 }
56
57 /**
58 * @param $db DatabaseBase
59 * @param $res
60 * @return void
61 */
62 function preprocessResults( $db, $res ) {
63 # There's no point doing a batch check if we aren't caching results;
64 # the page must exist for it to have been pulled out of the table
65 if ( !$this->isCached() || !$res->numRows() ) {
66 return;
67 }
68
69 $batch = new LinkBatch();
70 foreach ( $res as $row ) {
71 $batch->add( $row->namespace, $row->title );
72 }
73 $batch->execute();
74
75 $res->seek( 0 );
76 }
77
78 function sortDescending() {
79 return false;
80 }
81
82 function formatResult( $skin, $result ) {
83 $dm = $this->getLanguage()->getDirMark();
84
85 $title = Title::makeTitleSafe( $result->namespace, $result->title );
86 if ( !$title ) {
87 return Html::element( 'span', array( 'class' => 'mw-invalidtitle' ),
88 Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
89 }
90
91 $hlink = Linker::linkKnown(
92 $title,
93 $this->msg( 'hist' )->escaped(),
94 array(),
95 array( 'action' => 'history' )
96 );
97 $hlinkInParentheses = $this->msg( 'parentheses' )->rawParams( $hlink )->escaped();
98
99 if ( $this->isCached() ) {
100 $plink = Linker::link( $title );
101 $exists = $title->exists();
102 } else {
103 $plink = Linker::linkKnown( $title );
104 $exists = true;
105 }
106
107 $size = $this->msg( 'nbytes' )->numParams( $result->value )->escaped();
108
109 return $exists
110 ? "${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]"
111 : "<del>${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]</del>";
112 }
113
114 protected function getGroupName() {
115 return 'maintenance';
116 }
117 }