MediaWiki  1.29.2
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 ) {
52 
53  $this->setHeaders();
54  $this->outputHeader();
55 
56  $out = $this->getOutput();
57  $out->addModuleStyles( 'mediawiki.special' );
58 
59  # GET values
60  $request = $this->getRequest();
61  $from = $request->getVal( 'from', '' );
62  $prefix = $request->getVal( 'prefix', '' );
63  $ns = $request->getIntOrNull( 'namespace' );
64  $namespace = (int)$ns; // if no namespace given, use 0 (NS_MAIN).
65  $this->hideRedirects = $request->getBool( 'hideredirects', $this->hideRedirects );
66  $this->stripPrefix = $request->getBool( 'stripprefix', $this->stripPrefix );
67 
68  $namespaces = $wgContLang->getNamespaces();
69  $out->setPageTitle(
70  ( $namespace > 0 && array_key_exists( $namespace, $namespaces ) )
71  ? $this->msg( 'prefixindex-namespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
72  : $this->msg( 'prefixindex' )
73  );
74 
75  $showme = '';
76  if ( $par !== null ) {
77  $showme = $par;
78  } elseif ( $prefix != '' ) {
79  $showme = $prefix;
80  } elseif ( $from != '' && $ns === null ) {
81  // For back-compat with Special:Allpages
82  // Don't do this if namespace is passed, so paging works when doing NS views.
83  $showme = $from;
84  }
85 
86  // T29864: if transcluded, show all pages instead of the form.
87  if ( $this->including() || $showme != '' || $ns !== null ) {
88  $this->showPrefixChunk( $namespace, $showme, $from );
89  } else {
90  $out->addHTML( $this->namespacePrefixForm( $namespace, null ) );
91  }
92  }
93 
100  protected function namespacePrefixForm( $namespace = NS_MAIN, $from = '' ) {
101  $out = Xml::openElement( 'div', [ 'class' => 'namespaceoptions' ] );
103  'form',
104  [ 'method' => 'get', 'action' => $this->getConfig()->get( 'Script' ) ]
105  );
106  $out .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
107  $out .= Xml::openElement( 'fieldset' );
108  $out .= Xml::element( 'legend', null, $this->msg( 'allpages' )->text() );
109  $out .= Xml::openElement( 'table', [ 'id' => 'nsselect', 'class' => 'allpages' ] );
110  $out .= "<tr>
111  <td class='mw-label'>" .
112  Xml::label( $this->msg( 'allpagesprefix' )->text(), 'nsfrom' ) .
113  "</td>
114  <td class='mw-input'>" .
115  Xml::input( 'prefix', 30, str_replace( '_', ' ', $from ), [ 'id' => 'nsfrom' ] ) .
116  "</td>
117  </tr>
118  <tr>
119  <td class='mw-label'>" .
120  Xml::label( $this->msg( 'namespace' )->text(), 'namespace' ) .
121  "</td>
122  <td class='mw-input'>" .
124  'selected' => $namespace,
125  ], [
126  'name' => 'namespace',
127  'id' => 'namespace',
128  'class' => 'namespaceselector',
129  ] ) .
131  $this->msg( 'allpages-hide-redirects' )->text(),
132  'hideredirects',
133  'hideredirects',
134  $this->hideRedirects
135  ) . ' ' .
137  $this->msg( 'prefixindex-strip' )->text(),
138  'stripprefix',
139  'stripprefix',
140  $this->stripPrefix
141  ) . ' ' .
142  Xml::submitButton( $this->msg( 'prefixindex-submit' )->text() ) .
143  "</td>
144  </tr>";
145  $out .= Xml::closeElement( 'table' );
146  $out .= Xml::closeElement( 'fieldset' );
147  $out .= Xml::closeElement( 'form' );
148  $out .= Xml::closeElement( 'div' );
149 
150  return $out;
151  }
152 
158  protected function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null ) {
160 
161  if ( $from === null ) {
162  $from = $prefix;
163  }
164 
165  $fromList = $this->getNamespaceKeyAndText( $namespace, $from );
166  $prefixList = $this->getNamespaceKeyAndText( $namespace, $prefix );
167  $namespaces = $wgContLang->getNamespaces();
168  $res = null;
169  $n = 0;
170  $nextRow = null;
171 
172  if ( !$prefixList || !$fromList ) {
173  $out = $this->msg( 'allpagesbadtitle' )->parseAsBlock();
174  } elseif ( !array_key_exists( $namespace, $namespaces ) ) {
175  // Show errormessage and reset to NS_MAIN
176  $out = $this->msg( 'allpages-bad-ns', $namespace )->parse();
177  $namespace = NS_MAIN;
178  } else {
179  list( $namespace, $prefixKey, $prefix ) = $prefixList;
180  list( /* $fromNS */, $fromKey, ) = $fromList;
181 
182  # ## @todo FIXME: Should complain if $fromNs != $namespace
183 
184  $dbr = wfGetDB( DB_REPLICA );
185 
186  $conds = [
187  'page_namespace' => $namespace,
188  'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
189  'page_title >= ' . $dbr->addQuotes( $fromKey ),
190  ];
191 
192  if ( $this->hideRedirects ) {
193  $conds['page_is_redirect'] = 0;
194  }
195 
196  $res = $dbr->select( 'page',
197  array_merge(
198  [ 'page_namespace', 'page_title' ],
200  ),
201  $conds,
202  __METHOD__,
203  [
204  'ORDER BY' => 'page_title',
205  'LIMIT' => $this->maxPerPage + 1,
206  'USE INDEX' => 'name_title',
207  ]
208  );
209 
210  // @todo FIXME: Side link to previous
211 
212  if ( $res->numRows() > 0 ) {
213  $out = Html::openElement( 'ul', [ 'class' => 'mw-prefixindex-list' ] );
214  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
215 
216  $prefixLength = strlen( $prefix );
217  foreach ( $res as $row ) {
218  if ( $n >= $this->maxPerPage ) {
219  $nextRow = $row;
220  break;
221  }
222  $title = Title::newFromRow( $row );
223  // Make sure it gets into LinkCache
224  $linkCache->addGoodLinkObjFromRow( $title, $row );
225  $displayed = $title->getText();
226  // Try not to generate unclickable links
227  if ( $this->stripPrefix && $prefixLength !== strlen( $displayed ) ) {
228  $displayed = substr( $displayed, $prefixLength );
229  }
230  $link = ( $title->isRedirect() ? '<div class="allpagesredirect">' : '' ) .
231  $this->getLinkRenderer()->makeKnownLink(
232  $title,
233  $displayed
234  ) .
235  ( $title->isRedirect() ? '</div>' : '' );
236 
237  $out .= "<li>$link</li>\n";
238  $n++;
239 
240  }
241  $out .= Html::closeElement( 'ul' );
242 
243  if ( $res->numRows() > 2 ) {
244  // Only apply CSS column styles if there's more than 2 entries.
245  // Otherwise rendering is broken as "mw-prefixindex-body"'s CSS column count is 3.
246  $out = Html::rawElement( 'div', [ 'class' => 'mw-prefixindex-body' ], $out );
247  }
248  } else {
249  $out = '';
250  }
251  }
252 
253  $output = $this->getOutput();
254 
255  if ( $this->including() ) {
256  // We don't show the nav-links and the form when included into other
257  // pages so let's just finish here.
258  $output->addHTML( $out );
259  return;
260  }
261 
262  $topOut = $this->namespacePrefixForm( $namespace, $prefix );
263 
264  if ( $res && ( $n == $this->maxPerPage ) && $nextRow ) {
265  $query = [
266  'from' => $nextRow->page_title,
267  'prefix' => $prefix,
268  'hideredirects' => $this->hideRedirects,
269  'stripprefix' => $this->stripPrefix,
270  ];
271 
272  if ( $namespace || $prefix == '' ) {
273  // Keep the namespace even if it's 0 for empty prefixes.
274  // This tells us we're not just a holdover from old links.
275  $query['namespace'] = $namespace;
276  }
277 
278  $nextLink = $this->getLinkRenderer()->makeKnownLink(
279  $this->getPageTitle(),
280  $this->msg( 'nextpage', str_replace( '_', ' ', $nextRow->page_title ) )->text(),
281  [],
282  $query
283  );
284 
285  // Link shown at the top of the page below the form
286  $topOut .= Html::rawElement( 'div',
287  [ 'class' => 'mw-prefixindex-nav' ],
288  $nextLink
289  );
290 
291  // Link shown at the footer
292  $out .= "\n" . Html::element( 'hr' ) .
294  'div',
295  [ 'class' => 'mw-prefixindex-nav' ],
296  $nextLink
297  );
298 
299  }
300 
301  $output->addHTML( $topOut . $out );
302  }
303 
312  public function prefixSearchSubpages( $search, $limit, $offset ) {
313  return $this->prefixSearchString( $search, $limit, $offset );
314  }
315 
316  protected function getGroupName() {
317  return 'pages';
318  }
319 }
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:628
$request
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2612
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:675
Xml\label
static label( $label, $id, $attribs=[])
Convenience function to build an HTML form label.
Definition: Xml.php:358
text
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
$namespaces
namespace and then decline to actually register it & $namespaces
Definition: hooks.txt:934
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$res
$res
Definition: database.txt:21
SpecialPrefixindex\showPrefixChunk
showPrefixChunk( $namespace=NS_MAIN, $prefix, $from=null)
Definition: SpecialPrefixindex.php:158
SpecialPrefixindex\execute
execute( $par)
Entry point : initialise variables and call subfunctions.
Definition: SpecialPrefixindex.php:50
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:109
LinkCache\getSelectFields
static getSelectFields()
Fields that LinkCache needs to select.
Definition: LinkCache.php:213
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
NS_MAIN
const NS_MAIN
Definition: Defines.php:62
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:309
$query
null for the 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:1572
SpecialPage\prefixSearchString
prefixSearchString( $search, $limit, $offset)
Perform a regular substring search for prefixSearchSubpages.
Definition: SpecialPage.php:448
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:714
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:453
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3060
SpecialPrefixindex\$stripPrefix
$stripPrefix
Whether to remove the searched prefix from the displayed link.
Definition: SpecialPrefixindex.php:36
$limit
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers please use GetContentModels hook to make them known to core if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive $limit
Definition: hooks.txt:1049
Xml\element
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:39
$output
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object & $output
Definition: hooks.txt:1049
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:484
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
SpecialPrefixindex\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialPrefixindex.php:316
list
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
Html\hidden
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:746
SpecialPrefixindex\namespacePrefixForm
namespacePrefixForm( $namespace=NS_MAIN, $from='')
HTML for the top form.
Definition: SpecialPrefixindex.php:100
SpecialPage\msg
msg()
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:746
Html\namespaceSelector
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
Definition: Html.php:834
SpecialAllPages\getNamespaceKeyAndText
getNamespaceKeyAndText( $ns, $text)
Definition: SpecialAllPages.php:348
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:665
SpecialPrefixindex\$hideRedirects
$hideRedirects
Definition: SpecialPrefixindex.php:38
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:856
SpecialPrefixindex\__construct
__construct()
Definition: SpecialPrefixindex.php:42
Xml\closeElement
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:118
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
SpecialAllPages
Implements Special:Allpages.
Definition: SpecialAllPages.php:30
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Html\openElement
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:251
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
$link
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:2929
SpecialPrefixindex\prefixSearchSubpages
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
Definition: SpecialPrefixindex.php:312
Xml\input
static input( $name, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML text input field.
Definition: Xml.php:274
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
SpecialPrefixindex
Implements Special:Prefixindex.
Definition: SpecialPrefixindex.php:30
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:583
SpecialPage\including
including( $x=null)
Whether the special page is being evaluated via transclusion.
Definition: SpecialPage.php:226
Xml\submitButton
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:459
Xml\checkLabel
static checkLabel( $label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
Definition: Xml.php:419
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
$out
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:783