MediaWiki REL1_39
SpecialShortPages.php
Go to the documentation of this file.
1<?php
29
37
39 private $namespaceInfo;
40
46 public function __construct(
47 NamespaceInfo $namespaceInfo,
48 ILoadBalancer $loadBalancer,
49 LinkBatchFactory $linkBatchFactory
50 ) {
51 parent::__construct( 'Shortpages' );
52 $this->namespaceInfo = $namespaceInfo;
53 $this->setDBLoadBalancer( $loadBalancer );
54 $this->setLinkBatchFactory( $linkBatchFactory );
55 }
56
57 public function isSyndicated() {
58 return false;
59 }
60
61 public function getQueryInfo() {
62 $config = $this->getConfig();
63 $tables = [ 'page' ];
64 $conds = [
65 'page_namespace' => array_diff(
66 $this->namespaceInfo->getContentNamespaces(),
67 $config->get( MainConfigNames::ShortPagesNamespaceExclusions )
68 ),
69 'page_is_redirect' => 0
70 ];
71 $joinConds = [];
72 $options = [ 'USE INDEX' => [ 'page' => 'page_redirect_namespace_len' ] ];
73
74 // Allow extensions to modify the query
75 $this->getHookRunner()->onShortPagesQuery( $tables, $conds, $joinConds, $options );
76
77 return [
78 'tables' => $tables,
79 'fields' => [
80 'namespace' => 'page_namespace',
81 'title' => 'page_title',
82 'value' => 'page_len'
83 ],
84 'conds' => $conds,
85 'join_conds' => $joinConds,
86 'options' => $options
87 ];
88 }
89
90 public function reallyDoQuery( $limit, $offset = false ) {
91 $fname = static::class . '::reallyDoQuery';
92 $dbr = $this->getRecacheDB();
93 $query = $this->getQueryInfo();
94 $order = $this->getOrderFields();
95
96 if ( $this->sortDescending() ) {
97 foreach ( $order as &$field ) {
98 $field .= ' DESC';
99 }
100 }
101
102 $tables = isset( $query['tables'] ) ? (array)$query['tables'] : [];
103 $fields = isset( $query['fields'] ) ? (array)$query['fields'] : [];
104 $conds = isset( $query['conds'] ) ? (array)$query['conds'] : [];
105 $options = isset( $query['options'] ) ? (array)$query['options'] : [];
106 $join_conds = isset( $query['join_conds'] ) ? (array)$query['join_conds'] : [];
107
108 if ( $limit !== false ) {
109 $options['LIMIT'] = intval( $limit );
110 }
111
112 if ( $offset !== false ) {
113 $options['OFFSET'] = intval( $offset );
114 }
115
116 $namespaces = $conds['page_namespace'];
117 if ( count( $namespaces ) === 1 ) {
118 $options['ORDER BY'] = $order;
119 $res = $dbr->select( $tables, $fields, $conds, $fname,
120 $options, $join_conds
121 );
122 } else {
123 unset( $conds['page_namespace'] );
124 $options['INNER ORDER BY'] = $order;
125 $options['ORDER BY'] = [ 'value' . ( $this->sortDescending() ? ' DESC' : '' ) ];
126 $sql = $dbr->unionConditionPermutations(
127 $tables,
128 $fields,
129 [ 'page_namespace' => $namespaces ],
130 $conds,
131 $fname,
132 $options,
133 $join_conds
134 );
135 $res = $dbr->query( $sql, $fname );
136 }
137
138 return $res;
139 }
140
141 protected function getOrderFields() {
142 return [ 'page_len' ];
143 }
144
149 public function preprocessResults( $db, $res ) {
151 }
152
153 protected function sortDescending() {
154 return false;
155 }
156
162 public function formatResult( $skin, $result ) {
163 $dm = $this->getLanguage()->getDirMark();
164
165 $title = Title::makeTitleSafe( $result->namespace, $result->title );
166 if ( !$title ) {
167 return Html::element( 'span', [ 'class' => 'mw-invalidtitle' ],
168 Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
169 }
170
171 $linkRenderer = $this->getLinkRenderer();
172 $hlink = $linkRenderer->makeKnownLink(
173 $title,
174 $this->msg( 'hist' )->text(),
175 [],
176 [ 'action' => 'history' ]
177 );
178 $hlinkInParentheses = $this->msg( 'parentheses' )->rawParams( $hlink )->escaped();
179
180 if ( $this->isCached() ) {
181 $plink = $linkRenderer->makeLink( $title );
182 $exists = $title->exists();
183 } else {
184 $plink = $linkRenderer->makeKnownLink( $title );
185 $exists = true;
186 }
187
188 $size = $this->msg( 'nbytes' )->numParams( $result->value )->escaped();
189
190 return $exists
191 ? "{$hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]"
192 : "<del>{$hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]</del>";
193 }
194
195 protected function getGroupName() {
196 return 'maintenance';
197 }
198}
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition Linker.php:189
A class containing constants representing the names of configuration variables.
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:42
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:47
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:39
Create and track the database connections and transactions for a given database cluster.
Result wrapper for grabbing data queried from an IDatabase object.