MediaWiki REL1_40
SpecialShortPages.php
Go to the documentation of this file.
1<?php
32
40
42 private $namespaceInfo;
43
49 public function __construct(
50 NamespaceInfo $namespaceInfo,
51 ILoadBalancer $loadBalancer,
52 LinkBatchFactory $linkBatchFactory
53 ) {
54 parent::__construct( 'Shortpages' );
55 $this->namespaceInfo = $namespaceInfo;
56 $this->setDBLoadBalancer( $loadBalancer );
57 $this->setLinkBatchFactory( $linkBatchFactory );
58 }
59
60 public function isSyndicated() {
61 return false;
62 }
63
64 public function getQueryInfo() {
65 $config = $this->getConfig();
66 $tables = [ 'page' ];
67 $conds = [
68 'page_namespace' => array_diff(
69 $this->namespaceInfo->getContentNamespaces(),
70 $config->get( MainConfigNames::ShortPagesNamespaceExclusions )
71 ),
72 'page_is_redirect' => 0
73 ];
74 $joinConds = [];
75 $options = [ 'USE INDEX' => [ 'page' => 'page_redirect_namespace_len' ] ];
76
77 // Allow extensions to modify the query
78 $this->getHookRunner()->onShortPagesQuery( $tables, $conds, $joinConds, $options );
79
80 return [
81 'tables' => $tables,
82 'fields' => [
83 'namespace' => 'page_namespace',
84 'title' => 'page_title',
85 'value' => 'page_len'
86 ],
87 'conds' => $conds,
88 'join_conds' => $joinConds,
89 'options' => $options
90 ];
91 }
92
93 public function reallyDoQuery( $limit, $offset = false ) {
94 $fname = static::class . '::reallyDoQuery';
95 $dbr = $this->getRecacheDB();
96 $query = $this->getQueryInfo();
97 $order = $this->getOrderFields();
98
99 if ( $this->sortDescending() ) {
100 foreach ( $order as &$field ) {
101 $field .= ' DESC';
102 }
103 }
104
105 $tables = isset( $query['tables'] ) ? (array)$query['tables'] : [];
106 $fields = isset( $query['fields'] ) ? (array)$query['fields'] : [];
107 $conds = isset( $query['conds'] ) ? (array)$query['conds'] : [];
108 $options = isset( $query['options'] ) ? (array)$query['options'] : [];
109 $join_conds = isset( $query['join_conds'] ) ? (array)$query['join_conds'] : [];
110
111 if ( $limit !== false ) {
112 $options['LIMIT'] = intval( $limit );
113 }
114
115 if ( $offset !== false ) {
116 $options['OFFSET'] = intval( $offset );
117 }
118
119 $namespaces = $conds['page_namespace'];
120 if ( count( $namespaces ) === 1 ) {
121 $options['ORDER BY'] = $order;
122 $res = $dbr->select( $tables, $fields, $conds, $fname,
123 $options, $join_conds
124 );
125 } else {
126 unset( $conds['page_namespace'] );
127 $options['INNER ORDER BY'] = $order;
128 $options['ORDER BY'] = [ 'value' . ( $this->sortDescending() ? ' DESC' : '' ) ];
129 $sql = $dbr->unionConditionPermutations(
130 $tables,
131 $fields,
132 [ 'page_namespace' => $namespaces ],
133 $conds,
134 $fname,
135 $options,
136 $join_conds
137 );
138 $res = $dbr->query( $sql, $fname );
139 }
140
141 return $res;
142 }
143
144 protected function getOrderFields() {
145 return [ 'page_len' ];
146 }
147
152 public function preprocessResults( $db, $res ) {
154 }
155
156 protected function sortDescending() {
157 return false;
158 }
159
165 public function formatResult( $skin, $result ) {
166 $dm = $this->getLanguage()->getDirMark();
167
168 $title = Title::makeTitleSafe( $result->namespace, $result->title );
169 if ( !$title ) {
170 return Html::element( 'span', [ 'class' => 'mw-invalidtitle' ],
171 Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
172 }
173
174 $linkRenderer = $this->getLinkRenderer();
175 $hlink = $linkRenderer->makeKnownLink(
176 $title,
177 $this->msg( 'hist' )->text(),
178 [],
179 [ 'action' => 'history' ]
180 );
181 $hlinkInParentheses = $this->msg( 'parentheses' )->rawParams( $hlink )->escaped();
182
183 if ( $this->isCached() ) {
184 $plink = $linkRenderer->makeLink( $title );
185 $exists = $title->exists();
186 } else {
187 $plink = $linkRenderer->makeKnownLink( $title );
188 $exists = true;
189 }
190
191 $size = $this->msg( 'nbytes' )->numParams( $result->value )->escaped();
192
193 return $exists
194 ? "{$hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]"
195 : "<del>{$hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]</del>";
196 }
197
198 protected function getGroupName() {
199 return 'maintenance';
200 }
201}
This class is a collection of static functions that serve two purposes:
Definition Html.php:55
Some internal bits split of from Skin.php.
Definition Linker.php:67
A class containing constants representing the names of configuration variables.
Represents a title within MediaWiki.
Definition Title.php:82
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:45
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)
int $offset
The offset and limit in use, as passed to the query() function.
Definition QueryPage.php:50
isCached()
Whether or not the output of the page in question is retrieved from the database cache.
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
getRecacheDB()
Get a DB connection to be used for slow recache queries.
getContext()
Gets the context this SpecialPage is executed in.
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()
Sometimes we don't want to build rss / atom feeds.
__construct(NamespaceInfo $namespaceInfo, ILoadBalancer $loadBalancer, LinkBatchFactory $linkBatchFactory)
formatResult( $skin, $result)
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:36
This class is a delegate to ILBFactory for a given database cluster.
Result wrapper for grabbing data queried from an IDatabase object.