MediaWiki  1.27.3
SpecialPrefixindex.php
Go to the documentation of this file.
1 <?php
30 
35  protected $stripPrefix = false;
36 
37  protected $hideRedirects = false;
38 
39  // Inherit $maxPerPage
40 
41  function __construct() {
42  parent::__construct( 'Prefixindex' );
43  }
44 
49  function execute( $par ) {
51 
52  $this->setHeaders();
53  $this->outputHeader();
54 
55  $out = $this->getOutput();
56  $out->addModuleStyles( 'mediawiki.special' );
57 
58  # GET values
59  $request = $this->getRequest();
60  $from = $request->getVal( 'from', '' );
61  $prefix = $request->getVal( 'prefix', '' );
62  $ns = $request->getIntOrNull( 'namespace' );
63  $namespace = (int)$ns; // if no namespace given, use 0 (NS_MAIN).
64  $this->hideRedirects = $request->getBool( 'hideredirects', $this->hideRedirects );
65  $this->stripPrefix = $request->getBool( 'stripprefix', $this->stripPrefix );
66 
67  $namespaces = $wgContLang->getNamespaces();
68  $out->setPageTitle(
69  ( $namespace > 0 && array_key_exists( $namespace, $namespaces ) )
70  ? $this->msg( 'prefixindex-namespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
71  : $this->msg( 'prefixindex' )
72  );
73 
74  $showme = '';
75  if ( $par !== null ) {
76  $showme = $par;
77  } elseif ( $prefix != '' ) {
78  $showme = $prefix;
79  } elseif ( $from != '' && $ns === null ) {
80  // For back-compat with Special:Allpages
81  // Don't do this if namespace is passed, so paging works when doing NS views.
82  $showme = $from;
83  }
84 
85  // Bug 27864: if transcluded, show all pages instead of the form.
86  if ( $this->including() || $showme != '' || $ns !== null ) {
87  $this->showPrefixChunk( $namespace, $showme, $from );
88  } else {
89  $out->addHTML( $this->namespacePrefixForm( $namespace, null ) );
90  }
91  }
92 
99  protected function namespacePrefixForm( $namespace = NS_MAIN, $from = '' ) {
100  $out = Xml::openElement( 'div', [ 'class' => 'namespaceoptions' ] );
102  'form',
103  [ 'method' => 'get', 'action' => $this->getConfig()->get( 'Script' ) ]
104  );
105  $out .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
106  $out .= Xml::openElement( 'fieldset' );
107  $out .= Xml::element( 'legend', null, $this->msg( 'allpages' )->text() );
108  $out .= Xml::openElement( 'table', [ 'id' => 'nsselect', 'class' => 'allpages' ] );
109  $out .= "<tr>
110  <td class='mw-label'>" .
111  Xml::label( $this->msg( 'allpagesprefix' )->text(), 'nsfrom' ) .
112  "</td>
113  <td class='mw-input'>" .
114  Xml::input( 'prefix', 30, str_replace( '_', ' ', $from ), [ 'id' => 'nsfrom' ] ) .
115  "</td>
116  </tr>
117  <tr>
118  <td class='mw-label'>" .
119  Xml::label( $this->msg( 'namespace' )->text(), 'namespace' ) .
120  "</td>
121  <td class='mw-input'>" .
123  'selected' => $namespace,
124  ], [
125  'name' => 'namespace',
126  'id' => 'namespace',
127  'class' => 'namespaceselector',
128  ] ) .
130  $this->msg( 'allpages-hide-redirects' )->text(),
131  'hideredirects',
132  'hideredirects',
133  $this->hideRedirects
134  ) . ' ' .
136  $this->msg( 'prefixindex-strip' )->text(),
137  'stripprefix',
138  'stripprefix',
139  $this->stripPrefix
140  ) . ' ' .
141  Xml::submitButton( $this->msg( 'prefixindex-submit' )->text() ) .
142  "</td>
143  </tr>";
144  $out .= Xml::closeElement( 'table' );
145  $out .= Xml::closeElement( 'fieldset' );
146  $out .= Xml::closeElement( 'form' );
147  $out .= Xml::closeElement( 'div' );
148 
149  return $out;
150  }
151 
157  protected function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null ) {
159 
160  if ( $from === null ) {
161  $from = $prefix;
162  }
163 
164  $fromList = $this->getNamespaceKeyAndText( $namespace, $from );
165  $prefixList = $this->getNamespaceKeyAndText( $namespace, $prefix );
166  $namespaces = $wgContLang->getNamespaces();
167  $res = null;
168 
169  if ( !$prefixList || !$fromList ) {
170  $out = $this->msg( 'allpagesbadtitle' )->parseAsBlock();
171  } elseif ( !array_key_exists( $namespace, $namespaces ) ) {
172  // Show errormessage and reset to NS_MAIN
173  $out = $this->msg( 'allpages-bad-ns', $namespace )->parse();
174  $namespace = NS_MAIN;
175  } else {
176  list( $namespace, $prefixKey, $prefix ) = $prefixList;
177  list( /* $fromNS */, $fromKey, ) = $fromList;
178 
179  # ## @todo FIXME: Should complain if $fromNs != $namespace
180 
181  $dbr = wfGetDB( DB_SLAVE );
182 
183  $conds = [
184  'page_namespace' => $namespace,
185  'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
186  'page_title >= ' . $dbr->addQuotes( $fromKey ),
187  ];
188 
189  if ( $this->hideRedirects ) {
190  $conds['page_is_redirect'] = 0;
191  }
192 
193  $res = $dbr->select( 'page',
194  [ 'page_namespace', 'page_title', 'page_is_redirect' ],
195  $conds,
196  __METHOD__,
197  [
198  'ORDER BY' => 'page_title',
199  'LIMIT' => $this->maxPerPage + 1,
200  'USE INDEX' => 'name_title',
201  ]
202  );
203 
204  // @todo FIXME: Side link to previous
205 
206  $n = 0;
207  if ( $res->numRows() > 0 ) {
208  $out = Html::openElement( 'ul', [ 'class' => 'mw-prefixindex-list' ] );
209 
210  $prefixLength = strlen( $prefix );
211  while ( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
212  $t = Title::makeTitle( $s->page_namespace, $s->page_title );
213  if ( $t ) {
214  $displayed = $t->getText();
215  // Try not to generate unclickable links
216  if ( $this->stripPrefix && $prefixLength !== strlen( $displayed ) ) {
217  $displayed = substr( $displayed, $prefixLength );
218  }
219  $link = ( $s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
221  $t,
222  htmlspecialchars( $displayed ),
223  $s->page_is_redirect ? [ 'class' => 'mw-redirect' ] : []
224  ) .
225  ( $s->page_is_redirect ? '</div>' : '' );
226  } else {
227  $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
228  }
229 
230  $out .= "<li>$link</li>\n";
231  $n++;
232 
233  }
234  $out .= Html::closeElement( 'ul' );
235 
236  if ( $res->numRows() > 2 ) {
237  // Only apply CSS column styles if there's more than 2 entries.
238  // Otherwise rendering is broken as "mw-prefixindex-body"'s CSS column count is 3.
239  $out = Html::rawElement( 'div', [ 'class' => 'mw-prefixindex-body' ], $out );
240  }
241  } else {
242  $out = '';
243  }
244  }
245 
246  $output = $this->getOutput();
247 
248  if ( $this->including() ) {
249  // We don't show the nav-links and the form when included into other
250  // pages so let's just finish here.
251  $output->addHTML( $out );
252  return;
253  }
254 
255  $topOut = $this->namespacePrefixForm( $namespace, $prefix );
256 
257  if ( $res && ( $n == $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
258  $query = [
259  'from' => $s->page_title,
260  'prefix' => $prefix,
261  'hideredirects' => $this->hideRedirects,
262  'stripprefix' => $this->stripPrefix,
263  ];
264 
265  if ( $namespace || $prefix == '' ) {
266  // Keep the namespace even if it's 0 for empty prefixes.
267  // This tells us we're not just a holdover from old links.
268  $query['namespace'] = $namespace;
269  }
270 
271  $nextLink = Linker::linkKnown(
272  $this->getPageTitle(),
273  $this->msg( 'nextpage', str_replace( '_', ' ', $s->page_title ) )->escaped(),
274  [],
275  $query
276  );
277 
278  // Link shown at the top of the page below the form
279  $topOut .= Html::rawElement( 'div',
280  [ 'class' => 'mw-prefixindex-nav' ],
281  $nextLink
282  );
283 
284  // Link shown at the footer
285  $out .= "\n" . Html::element( 'hr' ) .
287  'div',
288  [ 'class' => 'mw-prefixindex-nav' ],
289  $nextLink
290  );
291 
292  }
293 
294  $output->addHTML( $topOut . $out );
295  }
296 
305  public function prefixSearchSubpages( $search, $limit, $offset ) {
306  return $this->prefixSearchString( $search, $limit, $offset );
307  }
308 
309  protected function getGroupName() {
310  return 'pages';
311  }
312 }
static closeElement($element)
Returns "".
Definition: Html.php:306
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
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
$stripPrefix
Whether to remove the searched prefix from the displayed link.
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:766
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:1422
static linkKnown($target, $html=null, $customAttribs=[], $query=[], $options=[ 'known', 'noclasses'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:264
const NS_MAIN
Definition: Defines.php:69
static element($element, $attribs=null, $contents= '', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:39
prefixSearchSubpages($search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
Definition: Html.php:210
Implements Special:Allpages.
static hidden($name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:759
static input($name, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML text input field.
Definition: Xml.php:275
getNamespaceKeyAndText($ns, $text)
msg()
Wrapper around wfMessage that sets the current context.
including($x=null)
Whether the special page is being evaluated via transclusion.
getOutput()
Get the OutputPage being used for this instance.
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
static submitButton($value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:460
static label($label, $id, $attribs=[])
Convenience function to build an HTML form label.
Definition: Xml.php:359
outputHeader($summaryMessageKey= '')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
the value to return A Title object or null for latest to be modified or replaced by the hook handler or if authentication is not possible after cache objects are set for highlighting & $link
Definition: hooks.txt:2585
static closeElement($element)
Shortcut to close an XML element.
Definition: Xml.php:118
execute($par)
Entry point : initialise variables and call subfunctions.
static openElement($element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:248
$res
Definition: database.txt:21
static openElement($element, $attribs=null)
This opens an XML element.
Definition: Xml.php:109
showPrefixChunk($namespace=NS_MAIN, $prefix, $from=null)
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
const DB_SLAVE
Definition: Defines.php:46
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
namespace and then decline to actually register it & $namespaces
Definition: hooks.txt:916
Implements Special:Prefixindex.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist 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:1008
$from
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
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2422
getConfig()
Shortcut to get main config object.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist 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 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:1008
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 local content language as $wgContLang
Definition: design.txt:56
static checkLabel($label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
Definition: Xml.php:420
getRequest()
Get the WebRequest being used for this instance.
prefixSearchString($search, $limit, $offset)
Perform a regular substring search for prefixSearchSubpages.
static element($element, $attribs=[], $contents= '')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:230
static & makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:524
namespacePrefixForm($namespace=NS_MAIN, $from= '')
HTML for the top form.
getPageTitle($subpage=false)
Get a self-referential title object.
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
Definition: Html.php:847