MediaWiki REL1_32
SpecialPrefixindex.php
Go to the documentation of this file.
1<?php
24
31
36 protected $stripPrefix = false;
37
38 protected $hideRedirects = false;
39
40 // Inherit $maxPerPage
41
42 function __construct() {
43 parent::__construct( 'Prefixindex' );
44 }
45
50 function execute( $par ) {
51 $this->setHeaders();
52 $this->outputHeader();
53
54 $out = $this->getOutput();
55 $out->addModuleStyles( 'mediawiki.special' );
56
57 # GET values
58 $request = $this->getRequest();
59 $from = $request->getVal( 'from', '' );
60 $prefix = $request->getVal( 'prefix', '' );
61 $ns = $request->getIntOrNull( 'namespace' );
62 $namespace = (int)$ns; // if no namespace given, use 0 (NS_MAIN).
63 $this->hideRedirects = $request->getBool( 'hideredirects', $this->hideRedirects );
64 $this->stripPrefix = $request->getBool( 'stripprefix', $this->stripPrefix );
65
66 $namespaces = MediaWikiServices::getInstance()->getContentLanguage()->getNamespaces();
67 $out->setPageTitle(
68 ( $namespace > 0 && array_key_exists( $namespace, $namespaces ) )
69 ? $this->msg( 'prefixindex-namespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
70 : $this->msg( 'prefixindex' )
71 );
72
73 $showme = '';
74 if ( $par !== null ) {
75 $showme = $par;
76 } elseif ( $prefix != '' ) {
77 $showme = $prefix;
78 } elseif ( $from != '' && $ns === null ) {
79 // For back-compat with Special:Allpages
80 // Don't do this if namespace is passed, so paging works when doing NS views.
81 $showme = $from;
82 }
83
84 // T29864: if transcluded, show all pages instead of the form.
85 if ( $this->including() || $showme != '' || $ns !== null ) {
86 $this->showPrefixChunk( $namespace, $showme, $from );
87 } else {
88 $out->addHTML( $this->namespacePrefixForm( $namespace, null ) );
89 }
90 }
91
98 protected function namespacePrefixForm( $namespace = NS_MAIN, $from = '' ) {
100 'prefix' => [
101 'label-message' => 'allpagesprefix',
102 'name' => 'prefix',
103 'id' => 'nsfrom',
104 'type' => 'text',
105 'size' => '30',
106 'default' => str_replace( '_', ' ', $from ),
107 ],
108 'namespace' => [
109 'type' => 'namespaceselect',
110 'name' => 'namespace',
111 'id' => 'namespace',
112 'label-message' => 'namespace',
113 'all' => null,
114 'default' => $namespace,
115 ],
116 'hidedirects' => [
117 'class' => 'HTMLCheckField',
118 'name' => 'hideredirects',
119 'label-message' => 'allpages-hide-redirects',
120 ],
121 'stripprefix' => [
122 'class' => 'HTMLCheckField',
123 'name' => 'stripprefix',
124 'label-message' => 'prefixindex-strip',
125 ],
126 ];
127 $context = new DerivativeContext( $this->getContext() );
128 $context->setTitle( $this->getPageTitle() ); // Remove subpage
129 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $context );
130 $htmlForm
131 ->setMethod( 'get' )
132 ->setWrapperLegendMsg( 'prefixindex' )
133 ->setSubmitTextMsg( 'prefixindex-submit' );
134
135 return $htmlForm->prepareForm()->getHTML( false );
136 }
137
143 protected function showPrefixChunk( $namespace, $prefix, $from = null ) {
144 if ( $from === null ) {
145 $from = $prefix;
146 }
147
148 $fromList = $this->getNamespaceKeyAndText( $namespace, $from );
149 $prefixList = $this->getNamespaceKeyAndText( $namespace, $prefix );
150 $namespaces = MediaWikiServices::getInstance()->getContentLanguage()->getNamespaces();
151 $res = null;
152 $n = 0;
153 $nextRow = null;
154
155 if ( !$prefixList || !$fromList ) {
156 $out = $this->msg( 'allpagesbadtitle' )->parseAsBlock();
157 } elseif ( !array_key_exists( $namespace, $namespaces ) ) {
158 // Show errormessage and reset to NS_MAIN
159 $out = $this->msg( 'allpages-bad-ns', $namespace )->parse();
160 $namespace = NS_MAIN;
161 } else {
162 list( $namespace, $prefixKey, $prefix ) = $prefixList;
163 list( /* $fromNS */, $fromKey, ) = $fromList;
164
165 # ## @todo FIXME: Should complain if $fromNs != $namespace
166
168
169 $conds = [
170 'page_namespace' => $namespace,
171 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
172 'page_title >= ' . $dbr->addQuotes( $fromKey ),
173 ];
174
175 if ( $this->hideRedirects ) {
176 $conds['page_is_redirect'] = 0;
177 }
178
179 $res = $dbr->select( 'page',
180 array_merge(
181 [ 'page_namespace', 'page_title' ],
182 LinkCache::getSelectFields()
183 ),
184 $conds,
185 __METHOD__,
186 [
187 'ORDER BY' => 'page_title',
188 'LIMIT' => $this->maxPerPage + 1,
189 'USE INDEX' => 'name_title',
190 ]
191 );
192
193 // @todo FIXME: Side link to previous
194
195 if ( $res->numRows() > 0 ) {
196 $out = Html::openElement( 'ul', [ 'class' => 'mw-prefixindex-list' ] );
197 $linkCache = MediaWikiServices::getInstance()->getLinkCache();
198
199 $prefixLength = strlen( $prefix );
200 foreach ( $res as $row ) {
201 if ( $n >= $this->maxPerPage ) {
202 $nextRow = $row;
203 break;
204 }
205 $title = Title::newFromRow( $row );
206 // Make sure it gets into LinkCache
207 $linkCache->addGoodLinkObjFromRow( $title, $row );
208 $displayed = $title->getText();
209 // Try not to generate unclickable links
210 if ( $this->stripPrefix && $prefixLength !== strlen( $displayed ) ) {
211 $displayed = substr( $displayed, $prefixLength );
212 }
213 $link = ( $title->isRedirect() ? '<div class="allpagesredirect">' : '' ) .
214 $this->getLinkRenderer()->makeKnownLink(
215 $title,
216 $displayed
217 ) .
218 ( $title->isRedirect() ? '</div>' : '' );
219
220 $out .= "<li>$link</li>\n";
221 $n++;
222
223 }
224 $out .= Html::closeElement( 'ul' );
225
226 if ( $res->numRows() > 2 ) {
227 // Only apply CSS column styles if there's more than 2 entries.
228 // Otherwise rendering is broken as "mw-prefixindex-body"'s CSS column count is 3.
229 $out = Html::rawElement( 'div', [ 'class' => 'mw-prefixindex-body' ], $out );
230 }
231 } else {
232 $out = '';
233 }
234 }
235
236 $output = $this->getOutput();
237
238 if ( $this->including() ) {
239 // We don't show the nav-links and the form when included into other
240 // pages so let's just finish here.
241 $output->addHTML( $out );
242 return;
243 }
244
245 $topOut = $this->namespacePrefixForm( $namespace, $prefix );
246
247 if ( $res && ( $n == $this->maxPerPage ) && $nextRow ) {
248 $query = [
249 'from' => $nextRow->page_title,
250 'prefix' => $prefix,
251 'hideredirects' => $this->hideRedirects,
252 'stripprefix' => $this->stripPrefix,
253 ];
254
255 if ( $namespace || $prefix == '' ) {
256 // Keep the namespace even if it's 0 for empty prefixes.
257 // This tells us we're not just a holdover from old links.
258 $query['namespace'] = $namespace;
259 }
260
261 $nextLink = $this->getLinkRenderer()->makeKnownLink(
262 $this->getPageTitle(),
263 $this->msg( 'nextpage', str_replace( '_', ' ', $nextRow->page_title ) )->text(),
264 [],
265 $query
266 );
267
268 // Link shown at the top of the page below the form
269 $topOut .= Html::rawElement( 'div',
270 [ 'class' => 'mw-prefixindex-nav' ],
271 $nextLink
272 );
273
274 // Link shown at the footer
275 $out .= "\n" . Html::element( 'hr' ) .
276 Html::rawElement(
277 'div',
278 [ 'class' => 'mw-prefixindex-nav' ],
279 $nextLink
280 );
281
282 }
283
284 $output->addHTML( $topOut . $out );
285 }
286
295 public function prefixSearchSubpages( $search, $limit, $offset ) {
296 return $this->prefixSearchString( $search, $limit, $offset );
297 }
298
299 protected function getGroupName() {
300 return 'pages';
301 }
302}
within a display generated by the Derivative if and wherever such third party notices normally appear The contents of the NOTICE file are for informational purposes only and do not modify the License You may add Your own attribution notices within Derivative Works that You alongside or as an addendum to the NOTICE text from the provided that such additional attribution notices cannot be construed as modifying the License You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for or distribution of Your or for any such Derivative Works as a provided Your and distribution of the Work otherwise complies with the conditions stated in this License Submission of Contributions Unless You explicitly state any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this without any additional terms or conditions Notwithstanding the nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions Trademarks This License does not grant permission to use the trade service or product names of the except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file Disclaimer of Warranty Unless required by applicable law or agreed to in Licensor provides the WITHOUT WARRANTIES OR CONDITIONS OF ANY either express or including
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
An IContextSource implementation which will inherit context from another source but allow individual ...
MediaWikiServices is the service locator for the application scope of MediaWiki.
Implements Special:Allpages.
getNamespaceKeyAndText( $ns, $text)
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.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key)
Wrapper around wfMessage that sets the current context.
getRequest()
Get the WebRequest being used for this instance.
getPageTitle( $subpage=false)
Get a self-referential title object.
prefixSearchString( $search, $limit, $offset)
Perform a regular substring search for prefixSearchSubpages.
Implements Special:Prefixindex.
showPrefixChunk( $namespace, $prefix, $from=null)
namespacePrefixForm( $namespace=NS_MAIN, $from='')
HTML for the top form.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
$stripPrefix
Whether to remove the searched prefix from the displayed link.
execute( $par)
Entry point : initialise variables and call subfunctions.
$res
Definition database.txt:21
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2880
namespace and then decline to actually register it & $namespaces
Definition hooks.txt:964
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead & $formDescriptor
Definition hooks.txt:2208
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2885
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition hooks.txt:894
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition hooks.txt:3106
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition hooks.txt:1656
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2317
const NS_MAIN
Definition Defines.php:64
const DB_REPLICA
Definition defines.php:25