MediaWiki REL1_34
SpecialPagesWithProp.php
Go to the documentation of this file.
1<?php
31
35 private $propName = null;
36
40 private $existingPropNames = null;
41
45 private $ns;
46
50 private $reverse = false;
51
55 private $sortByValue = false;
56
57 function __construct( $name = 'PagesWithProp' ) {
58 parent::__construct( $name );
59 }
60
61 function isCacheable() {
62 return false;
63 }
64
65 public function execute( $par ) {
66 $this->setHeaders();
67 $this->outputHeader();
68 $this->getOutput()->addModuleStyles( 'mediawiki.special' );
69
70 $request = $this->getRequest();
71 $propname = $request->getVal( 'propname', $par );
72 $this->ns = $request->getIntOrNull( 'namespace' );
73 $this->reverse = $request->getBool( 'reverse' );
74 $this->sortByValue = $request->getBool( 'sortbyvalue' );
75
76 $propnames = $this->getExistingPropNames();
77
78 $form = HTMLForm::factory( 'ooui', [
79 'propname' => [
80 'type' => 'combobox',
81 'name' => 'propname',
82 'options' => $propnames,
83 'default' => $propname,
84 'label-message' => 'pageswithprop-prop',
85 'required' => true,
86 ],
87 'namespace' => [
88 'type' => 'namespaceselect',
89 'name' => 'namespace',
90 'label-message' => 'namespace',
91 'all' => '',
92 'default' => $this->ns,
93 ],
94 'reverse' => [
95 'type' => 'check',
96 'name' => 'reverse',
97 'default' => $this->reverse,
98 'label-message' => 'pageswithprop-reverse',
99 'required' => false,
100 ],
101 'sortbyvalue' => [
102 'type' => 'check',
103 'name' => 'sortbyvalue',
104 'default' => $this->sortByValue,
105 'label-message' => 'pageswithprop-sortbyvalue',
106 'required' => false,
107 ]
108 ], $this->getContext() );
109 $form->setMethod( 'get' );
110 $form->setSubmitCallback( [ $this, 'onSubmit' ] );
111 $form->setWrapperLegendMsg( 'pageswithprop-legend' );
112 $form->addHeaderText( $this->msg( 'pageswithprop-text' )->parseAsBlock() );
113 $form->setSubmitTextMsg( 'pageswithprop-submit' );
114
115 $form->prepareForm();
116 $form->displayForm( false );
117 if ( $propname !== '' && $propname !== null ) {
118 $form->trySubmit();
119 }
120 }
121
122 public function onSubmit( $data, $form ) {
123 $this->propName = $data['propname'];
124 parent::execute( $data['propname'] );
125 }
126
135 public function prefixSearchSubpages( $search, $limit, $offset ) {
136 $subpages = array_keys( $this->queryExistingProps( $limit, $offset ) );
137 // We've already limited and offsetted, set to N and 0 respectively.
138 return self::prefixSearchArray( $search, count( $subpages ), $subpages, 0 );
139 }
140
145 function isSyndicated() {
146 return false;
147 }
148
149 public function getQueryInfo() {
150 $query = [
151 'tables' => [ 'page_props', 'page' ],
152 'fields' => [
153 'page_id' => 'pp_page',
154 'page_namespace',
155 'page_title',
156 'page_len',
157 'page_is_redirect',
158 'page_latest',
159 'pp_value',
160 ],
161 'conds' => [
162 'pp_propname' => $this->propName,
163 ],
164 'join_conds' => [
165 'page' => [ 'JOIN', 'page_id = pp_page' ]
166 ],
167 'options' => []
168 ];
169
170 if ( $this->ns !== null ) {
171 $query['conds']['page_namespace'] = $this->ns;
172 }
173
174 return $query;
175 }
176
177 function getOrderFields() {
178 $sort = [ 'page_id' ];
179 if ( $this->sortByValue ) {
180 array_unshift( $sort, 'pp_sortkey' );
181 }
182 return $sort;
183 }
184
188 public function sortDescending() {
189 return !$this->reverse;
190 }
191
197 function formatResult( $skin, $result ) {
198 $title = Title::newFromRow( $result );
199 $ret = $this->getLinkRenderer()->makeKnownLink( $title );
200 if ( $result->pp_value !== '' ) {
201 // Do not show very long or binary values on the special page
202 $valueLength = strlen( $result->pp_value );
203 $isBinary = strpos( $result->pp_value, "\0" ) !== false;
204 $isTooLong = $valueLength > 1024;
205
206 if ( $isBinary || $isTooLong ) {
207 $message = $this
208 ->msg( $isBinary ? 'pageswithprop-prophidden-binary' : 'pageswithprop-prophidden-long' )
209 ->params( $this->getLanguage()->formatSize( $valueLength ) );
210
211 $propValue = Html::element( 'span', [ 'class' => 'prop-value-hidden' ], $message->text() );
212 } else {
213 $propValue = Html::element( 'span', [ 'class' => 'prop-value' ], $result->pp_value );
214 }
215
216 $ret .= $this->msg( 'colon-separator' )->escaped() . $propValue;
217 }
218
219 return $ret;
220 }
221
222 public function getExistingPropNames() {
223 if ( $this->existingPropNames === null ) {
224 $this->existingPropNames = $this->queryExistingProps();
225 }
227 }
228
229 protected function queryExistingProps( $limit = null, $offset = 0 ) {
230 $opts = [
231 'DISTINCT', 'ORDER BY' => 'pp_propname'
232 ];
233 if ( $limit ) {
234 $opts['LIMIT'] = $limit;
235 }
236 if ( $offset ) {
237 $opts['OFFSET'] = $offset;
238 }
239
240 $res = wfGetDB( DB_REPLICA )->select(
241 'page_props',
242 'pp_propname',
243 '',
244 __METHOD__,
245 $opts
246 );
247
248 $propnames = [];
249 foreach ( $res as $row ) {
250 $propnames[$row->pp_propname] = $row->pp_propname;
251 }
252
253 return $propnames;
254 }
255
256 protected function getGroupName() {
257 return 'pages';
258 }
259}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
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:36
int $offset
The offset and limit in use, as passed to the query() function.
Definition QueryPage.php:41
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
static prefixSearchArray( $search, $limit, array $subpages, $offset)
Helper function for implementations of prefixSearchSubpages() that filter the values in memory (as op...
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getRequest()
Get the WebRequest being used for this instance.
getLanguage()
Shortcut to get user's language.
Special:PagesWithProp to search the page_props table.
execute( $par)
This is the actual workhorse.
queryExistingProps( $limit=null, $offset=0)
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
isSyndicated()
Disable RSS/Atom feeds.
isCacheable()
Is the output of this query cacheable? Non-cacheable expensive pages will be disabled in miser mode a...
getOrderFields()
Subclasses return an array of fields to order by here.
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
__construct( $name='PagesWithProp')
$sort
const DB_REPLICA
Definition defines.php:25