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
21 * @ingroup SpecialPage
24 use Wikimedia\Rdbms\ResultWrapper
;
25 use Wikimedia\Rdbms\IDatabase
;
28 * SpecialShortpages extends QueryPage. It is used to return the shortest
29 * pages in the database.
31 * @ingroup SpecialPage
33 class ShortPagesPage
extends QueryPage
{
35 function __construct( $name = 'Shortpages' ) {
36 parent
::__construct( $name );
39 function isSyndicated() {
43 public function getQueryInfo() {
44 $config = $this->getConfig();
45 $blacklist = $config->get( 'ShortPagesNamespaceBlacklist' );
48 'page_namespace' => array_diff( MWNamespace
::getContentNamespaces(), $blacklist ),
49 'page_is_redirect' => 0
52 $options = [ 'USE INDEX' => [ 'page' => 'page_redirect_namespace_len' ] ];
54 // Allow extensions to modify the query
55 Hooks
::run( 'ShortPagesQuery', [ &$tables, &$conds, &$joinConds, &$options ] );
60 'namespace' => 'page_namespace',
61 'title' => 'page_title',
65 'join_conds' => $joinConds,
70 public function reallyDoQuery( $limit, $offset = false ) {
71 $fname = static::class . '::reallyDoQuery';
72 $dbr = $this->getRecacheDB();
73 $query = $this->getQueryInfo();
74 $order = $this->getOrderFields();
76 if ( $this->sortDescending() ) {
77 foreach ( $order as &$field ) {
82 $tables = isset( $query['tables'] ) ?
(array)$query['tables'] : [];
83 $fields = isset( $query['fields'] ) ?
(array)$query['fields'] : [];
84 $conds = isset( $query['conds'] ) ?
(array)$query['conds'] : [];
85 $options = isset( $query['options'] ) ?
(array)$query['options'] : [];
86 $join_conds = isset( $query['join_conds'] ) ?
(array)$query['join_conds'] : [];
88 if ( $limit !== false ) {
89 $options['LIMIT'] = intval( $limit );
92 if ( $offset !== false ) {
93 $options['OFFSET'] = intval( $offset );
96 $namespaces = $conds['page_namespace'];
97 if ( count( $namespaces ) === 1 ) {
98 $options['ORDER BY'] = $order;
99 $res = $dbr->select( $tables, $fields, $conds, $fname,
100 $options, $join_conds
103 unset( $conds['page_namespace'] );
104 $options['INNER ORDER BY'] = $order;
105 $options['ORDER BY'] = [ 'value' . ( $this->sortDescending() ?
' DESC' : '' ) ];
106 $sql = $dbr->unionConditionPermutations(
109 [ 'page_namespace' => $namespaces ],
115 $res = $dbr->query( $sql, $fname );
121 function getOrderFields() {
122 return [ 'page_len' ];
126 * @param IDatabase $db
127 * @param ResultWrapper $res
129 function preprocessResults( $db, $res ) {
130 $this->executeLBFromResultWrapper( $res );
133 function sortDescending() {
139 * @param object $result Result row
142 function formatResult( $skin, $result ) {
143 $dm = $this->getLanguage()->getDirMark();
145 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
147 return Html
::element( 'span', [ 'class' => 'mw-invalidtitle' ],
148 Linker
::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title
) );
151 $linkRenderer = $this->getLinkRenderer();
152 $hlink = $linkRenderer->makeKnownLink(
154 $this->msg( 'hist' )->text(),
156 [ 'action' => 'history' ]
158 $hlinkInParentheses = $this->msg( 'parentheses' )->rawParams( $hlink )->escaped();
160 if ( $this->isCached() ) {
161 $plink = $linkRenderer->makeLink( $title );
162 $exists = $title->exists();
164 $plink = $linkRenderer->makeKnownLink( $title );
168 $size = $this->msg( 'nbytes' )->numParams( $result->value
)->escaped();
171 ?
"${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]"
172 : "<del>${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]</del>";
175 protected function getGroupName() {
176 return 'maintenance';