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 MediaWiki\MediaWikiServices
;
25 use Wikimedia\Rdbms\IResultWrapper
;
26 use Wikimedia\Rdbms\IDatabase
;
29 * SpecialShortpages extends QueryPage. It is used to return the shortest
30 * pages in the database.
32 * @ingroup SpecialPage
34 class ShortPagesPage
extends QueryPage
{
36 function __construct( $name = 'Shortpages' ) {
37 parent
::__construct( $name );
40 function isSyndicated() {
44 public function getQueryInfo() {
45 $config = $this->getConfig();
46 $blacklist = $config->get( 'ShortPagesNamespaceBlacklist' );
49 'page_namespace' => array_diff(
50 MediaWikiServices
::getInstance()->getNamespaceInfo()->getContentNamespaces(),
53 'page_is_redirect' => 0
56 $options = [ 'USE INDEX' => [ 'page' => 'page_redirect_namespace_len' ] ];
58 // Allow extensions to modify the query
59 Hooks
::run( 'ShortPagesQuery', [ &$tables, &$conds, &$joinConds, &$options ] );
64 'namespace' => 'page_namespace',
65 'title' => 'page_title',
69 'join_conds' => $joinConds,
74 public function reallyDoQuery( $limit, $offset = false ) {
75 $fname = static::class . '::reallyDoQuery';
76 $dbr = $this->getRecacheDB();
77 $query = $this->getQueryInfo();
78 $order = $this->getOrderFields();
80 if ( $this->sortDescending() ) {
81 foreach ( $order as &$field ) {
86 $tables = isset( $query['tables'] ) ?
(array)$query['tables'] : [];
87 $fields = isset( $query['fields'] ) ?
(array)$query['fields'] : [];
88 $conds = isset( $query['conds'] ) ?
(array)$query['conds'] : [];
89 $options = isset( $query['options'] ) ?
(array)$query['options'] : [];
90 $join_conds = isset( $query['join_conds'] ) ?
(array)$query['join_conds'] : [];
92 if ( $limit !== false ) {
93 $options['LIMIT'] = intval( $limit );
96 if ( $offset !== false ) {
97 $options['OFFSET'] = intval( $offset );
100 $namespaces = $conds['page_namespace'];
101 if ( count( $namespaces ) === 1 ) {
102 $options['ORDER BY'] = $order;
103 $res = $dbr->select( $tables, $fields, $conds, $fname,
104 $options, $join_conds
107 unset( $conds['page_namespace'] );
108 $options['INNER ORDER BY'] = $order;
109 $options['ORDER BY'] = [ 'value' . ( $this->sortDescending() ?
' DESC' : '' ) ];
110 $sql = $dbr->unionConditionPermutations(
113 [ 'page_namespace' => $namespaces ],
119 $res = $dbr->query( $sql, $fname );
125 function getOrderFields() {
126 return [ 'page_len' ];
130 * @param IDatabase $db
131 * @param IResultWrapper $res
133 function preprocessResults( $db, $res ) {
134 $this->executeLBFromResultWrapper( $res );
137 function sortDescending() {
143 * @param object $result Result row
146 function formatResult( $skin, $result ) {
147 $dm = $this->getLanguage()->getDirMark();
149 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
151 return Html
::element( 'span', [ 'class' => 'mw-invalidtitle' ],
152 Linker
::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title
) );
155 $linkRenderer = $this->getLinkRenderer();
156 $hlink = $linkRenderer->makeKnownLink(
158 $this->msg( 'hist' )->text(),
160 [ 'action' => 'history' ]
162 $hlinkInParentheses = $this->msg( 'parentheses' )->rawParams( $hlink )->escaped();
164 if ( $this->isCached() ) {
165 $plink = $linkRenderer->makeLink( $title );
166 $exists = $title->exists();
168 $plink = $linkRenderer->makeKnownLink( $title );
172 $size = $this->msg( 'nbytes' )->numParams( $result->value
)->escaped();
175 ?
"${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]"
176 : "<del>${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]</del>";
179 protected function getGroupName() {
180 return 'maintenance';