Merge "Http::getProxy() method to get proxy configuration"
[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 public function getQueryInfo() {
41 $tables = [ 'page' ];
42 $conds = [
43 'page_namespace' => MWNamespace::getContentNamespaces(),
44 'page_is_redirect' => 0
45 ];
46 $joinConds = [];
47 $options = [ 'USE INDEX' => [ 'page' => 'page_redirect_namespace_len' ] ];
48
49 // Allow extensions to modify the query
50 Hooks::run( 'ShortPagesQuery', [ &$tables, &$conds, &$joinConds, &$options ] );
51
52 return [
53 'tables' => $tables,
54 'fields' => [
55 'namespace' => 'page_namespace',
56 'title' => 'page_title',
57 'value' => 'page_len'
58 ],
59 'conds' => $conds,
60 'join_conds' => $joinConds,
61 'options' => $options
62 ];
63 }
64
65 function getOrderFields() {
66 return [ 'page_len' ];
67 }
68
69 /**
70 * @param IDatabase $db
71 * @param ResultWrapper $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 $res->seek( 0 );
87 }
88
89 function sortDescending() {
90 return false;
91 }
92
93 /**
94 * @param Skin $skin
95 * @param object $result Result row
96 * @return string
97 */
98 function formatResult( $skin, $result ) {
99 $dm = $this->getLanguage()->getDirMark();
100
101 $title = Title::makeTitleSafe( $result->namespace, $result->title );
102 if ( !$title ) {
103 return Html::element( 'span', [ 'class' => 'mw-invalidtitle' ],
104 Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
105 }
106
107 $hlink = Linker::linkKnown(
108 $title,
109 $this->msg( 'hist' )->escaped(),
110 [],
111 [ 'action' => 'history' ]
112 );
113 $hlinkInParentheses = $this->msg( 'parentheses' )->rawParams( $hlink )->escaped();
114
115 if ( $this->isCached() ) {
116 $plink = Linker::link( $title );
117 $exists = $title->exists();
118 } else {
119 $plink = Linker::linkKnown( $title );
120 $exists = true;
121 }
122
123 $size = $this->msg( 'nbytes' )->numParams( $result->value )->escaped();
124
125 return $exists
126 ? "${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]"
127 : "<del>${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]</del>";
128 }
129
130 protected function getGroupName() {
131 return 'maintenance';
132 }
133 }