MediaWiki REL1_37
SpecialShortPages.php
Go to the documentation of this file.
1<?php
28
36
39
45 public function __construct(
49 ) {
50 parent::__construct( 'Shortpages' );
51 $this->namespaceInfo = $namespaceInfo;
52 $this->setDBLoadBalancer( $loadBalancer );
53 $this->setLinkBatchFactory( $linkBatchFactory );
54 }
55
56 public function isSyndicated() {
57 return false;
58 }
59
60 public function getQueryInfo() {
61 $config = $this->getConfig();
62 $tables = [ 'page' ];
63 $conds = [
64 'page_namespace' => array_diff(
65 $this->namespaceInfo->getContentNamespaces(),
66 $config->get( 'ShortPagesNamespaceExclusions' )
67 ),
68 'page_is_redirect' => 0
69 ];
70 $joinConds = [];
71 $options = [ 'USE INDEX' => [ 'page' => 'page_redirect_namespace_len' ] ];
72
73 // Allow extensions to modify the query
74 $this->getHookRunner()->onShortPagesQuery( $tables, $conds, $joinConds, $options );
75
76 return [
77 'tables' => $tables,
78 'fields' => [
79 'namespace' => 'page_namespace',
80 'title' => 'page_title',
81 'value' => 'page_len'
82 ],
83 'conds' => $conds,
84 'join_conds' => $joinConds,
85 'options' => $options
86 ];
87 }
88
89 public function reallyDoQuery( $limit, $offset = false ) {
90 $fname = static::class . '::reallyDoQuery';
91 $dbr = $this->getRecacheDB();
92 $query = $this->getQueryInfo();
93 $order = $this->getOrderFields();
94
95 if ( $this->sortDescending() ) {
96 foreach ( $order as &$field ) {
97 $field .= ' DESC';
98 }
99 }
100
101 $tables = isset( $query['tables'] ) ? (array)$query['tables'] : [];
102 $fields = isset( $query['fields'] ) ? (array)$query['fields'] : [];
103 $conds = isset( $query['conds'] ) ? (array)$query['conds'] : [];
104 $options = isset( $query['options'] ) ? (array)$query['options'] : [];
105 $join_conds = isset( $query['join_conds'] ) ? (array)$query['join_conds'] : [];
106
107 if ( $limit !== false ) {
108 $options['LIMIT'] = intval( $limit );
109 }
110
111 if ( $offset !== false ) {
112 $options['OFFSET'] = intval( $offset );
113 }
114
115 $namespaces = $conds['page_namespace'];
116 if ( count( $namespaces ) === 1 ) {
117 $options['ORDER BY'] = $order;
118 $res = $dbr->select( $tables, $fields, $conds, $fname,
119 $options, $join_conds
120 );
121 } else {
122 unset( $conds['page_namespace'] );
123 $options['INNER ORDER BY'] = $order;
124 $options['ORDER BY'] = [ 'value' . ( $this->sortDescending() ? ' DESC' : '' ) ];
125 $sql = $dbr->unionConditionPermutations(
126 $tables,
127 $fields,
128 [ 'page_namespace' => $namespaces ],
129 $conds,
130 $fname,
131 $options,
132 $join_conds
133 );
134 $res = $dbr->query( $sql, $fname );
135 }
136
137 return $res;
138 }
139
140 protected function getOrderFields() {
141 return [ 'page_len' ];
142 }
143
148 public function preprocessResults( $db, $res ) {
150 }
151
152 protected function sortDescending() {
153 return false;
154 }
155
161 public function formatResult( $skin, $result ) {
162 $dm = $this->getLanguage()->getDirMark();
163
164 $title = Title::makeTitleSafe( $result->namespace, $result->title );
165 if ( !$title ) {
166 return Html::element( 'span', [ 'class' => 'mw-invalidtitle' ],
167 Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
168 }
169
172 $title,
173 $this->msg( 'hist' )->text(),
174 [],
175 [ 'action' => 'history' ]
176 );
177 $hlinkInParentheses = $this->msg( 'parentheses' )->rawParams( $hlink )->escaped();
178
179 if ( $this->isCached() ) {
180 $plink = $linkRenderer->makeLink( $title );
181 $exists = $title->exists();
182 } else {
184 $exists = true;
185 }
186
187 $size = $this->msg( 'nbytes' )->numParams( $result->value )->escaped();
188
189 return $exists
190 ? "{$hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]"
191 : "<del>{$hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]</del>";
192 }
193
194 protected function getGroupName() {
195 return 'maintenance';
196 }
197}
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition Linker.php:185
makeKnownLink( $target, $text=null, array $extraAttribs=[], array $query=[])
makeLink( $target, $text=null, array $extraAttribs=[], array $query=[])
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
This is a class for doing query pages; since they're almost all the same, we factor out some of the f...
Definition QueryPage.php:41
executeLBFromResultWrapper(IResultWrapper $res, $ns=null)
Creates a new LinkBatch object, adds all pages from the passed result wrapper (MUST include title and...
setDBLoadBalancer(ILoadBalancer $loadBalancer)
LinkBatchFactory null $linkBatchFactory
Definition QueryPage.php:74
int $offset
The offset and limit in use, as passed to the query() function.
Definition QueryPage.php:46
isCached()
Whether or not the output of the page in question is retrieved from the database cache.
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
ILoadBalancer null $loadBalancer
Definition QueryPage.php:71
getRecacheDB()
Get a DB connection to be used for slow recache queries.
getContext()
Gets the context this SpecialPage is executed in.
LinkRenderer null $linkRenderer
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getLanguage()
Shortcut to get user's language.
SpecialShortpages extends QueryPage.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
reallyDoQuery( $limit, $offset=false)
Run the query and return the result.
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
preprocessResults( $db, $res)
sortDescending()
Override to sort by increasing values.
getOrderFields()
Subclasses return an array of fields to order by here.
isSyndicated()
Sometime we don't want to build rss / atom feeds.
__construct(NamespaceInfo $namespaceInfo, ILoadBalancer $loadBalancer, LinkBatchFactory $linkBatchFactory)
formatResult( $skin, $result)
NamespaceInfo $namespaceInfo
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
Database cluster connection, tracking, load balancing, and transaction manager interface.
Result wrapper for grabbing data queried from an IDatabase object.