Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / includes / specials / SpecialShortpages.php
blob7ec69e06f0611d2df4e203d8c92d26a7bbc92bc6
1 <?php
2 /**
3 * Implements Special:Shortpages
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.
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.
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
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * SpecialShortpages extends QueryPage. It is used to return the shortest
26 * pages in the database.
28 * @ingroup SpecialPage
30 class ShortPagesPage extends QueryPage {
32 function __construct( $name = 'Shortpages' ) {
33 parent::__construct( $name );
36 function isSyndicated() {
37 return false;
40 function getQueryInfo() {
41 return array(
42 'tables' => array( 'page' ),
43 'fields' => array(
44 'namespace' => 'page_namespace',
45 'title' => 'page_title',
46 'value' => 'page_len'
48 'conds' => array(
49 'page_namespace' => MWNamespace::getContentNamespaces(),
50 'page_is_redirect' => 0
52 'options' => array( 'USE INDEX' => 'page_redirect_namespace_len' )
56 function getOrderFields() {
57 return array( 'page_len' );
60 /**
61 * @param IDatabase $db
62 * @param ResultWrapper $res
64 function preprocessResults( $db, $res ) {
65 # There's no point doing a batch check if we aren't caching results;
66 # the page must exist for it to have been pulled out of the table
67 if ( !$this->isCached() || !$res->numRows() ) {
68 return;
71 $batch = new LinkBatch();
72 foreach ( $res as $row ) {
73 $batch->add( $row->namespace, $row->title );
75 $batch->execute();
77 $res->seek( 0 );
80 function sortDescending() {
81 return false;
84 /**
85 * @param Skin $skin
86 * @param object $result Result row
87 * @return string
89 function formatResult( $skin, $result ) {
90 $dm = $this->getLanguage()->getDirMark();
92 $title = Title::makeTitleSafe( $result->namespace, $result->title );
93 if ( !$title ) {
94 return Html::element( 'span', array( 'class' => 'mw-invalidtitle' ),
95 Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
98 $hlink = Linker::linkKnown(
99 $title,
100 $this->msg( 'hist' )->escaped(),
101 array(),
102 array( 'action' => 'history' )
104 $hlinkInParentheses = $this->msg( 'parentheses' )->rawParams( $hlink )->escaped();
106 if ( $this->isCached() ) {
107 $plink = Linker::link( $title );
108 $exists = $title->exists();
109 } else {
110 $plink = Linker::linkKnown( $title );
111 $exists = true;
114 $size = $this->msg( 'nbytes' )->numParams( $result->value )->escaped();
116 return $exists
117 ? "${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]"
118 : "<del>${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]</del>";
121 protected function getGroupName() {
122 return 'maintenance';