Merge "Add support for PHP7 random_bytes in favor of mcrypt_create_iv"
[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 use Wikimedia\Rdbms\ResultWrapper;
25
26 /**
27 * SpecialShortpages extends QueryPage. It is used to return the shortest
28 * pages in the database.
29 *
30 * @ingroup SpecialPage
31 */
32 class ShortPagesPage extends QueryPage {
33
34 function __construct( $name = 'Shortpages' ) {
35 parent::__construct( $name );
36 }
37
38 function isSyndicated() {
39 return false;
40 }
41
42 public function getQueryInfo() {
43 $tables = [ 'page' ];
44 $conds = [
45 'page_namespace' => MWNamespace::getContentNamespaces(),
46 'page_is_redirect' => 0
47 ];
48 $joinConds = [];
49 $options = [ 'USE INDEX' => [ 'page' => 'page_redirect_namespace_len' ] ];
50
51 // Allow extensions to modify the query
52 Hooks::run( 'ShortPagesQuery', [ &$tables, &$conds, &$joinConds, &$options ] );
53
54 return [
55 'tables' => $tables,
56 'fields' => [
57 'namespace' => 'page_namespace',
58 'title' => 'page_title',
59 'value' => 'page_len'
60 ],
61 'conds' => $conds,
62 'join_conds' => $joinConds,
63 'options' => $options
64 ];
65 }
66
67 function getOrderFields() {
68 return [ 'page_len' ];
69 }
70
71 /**
72 * @param IDatabase $db
73 * @param ResultWrapper $res
74 */
75 function preprocessResults( $db, $res ) {
76 $this->executeLBFromResultWrapper( $res );
77 }
78
79 function sortDescending() {
80 return false;
81 }
82
83 /**
84 * @param Skin $skin
85 * @param object $result Result row
86 * @return string
87 */
88 function formatResult( $skin, $result ) {
89 $dm = $this->getLanguage()->getDirMark();
90
91 $title = Title::makeTitleSafe( $result->namespace, $result->title );
92 if ( !$title ) {
93 return Html::element( 'span', [ 'class' => 'mw-invalidtitle' ],
94 Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
95 }
96
97 $linkRenderer = $this->getLinkRenderer();
98 $hlink = $linkRenderer->makeKnownLink(
99 $title,
100 $this->msg( 'hist' )->text(),
101 [],
102 [ 'action' => 'history' ]
103 );
104 $hlinkInParentheses = $this->msg( 'parentheses' )->rawParams( $hlink )->escaped();
105
106 if ( $this->isCached() ) {
107 $plink = $linkRenderer->makeLink( $title );
108 $exists = $title->exists();
109 } else {
110 $plink = $linkRenderer->makeKnownLink( $title );
111 $exists = true;
112 }
113
114 $size = $this->msg( 'nbytes' )->numParams( $result->value )->escaped();
115
116 return $exists
117 ? "${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]"
118 : "<del>${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]</del>";
119 }
120
121 protected function getGroupName() {
122 return 'maintenance';
123 }
124 }