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