MediaWiki  1.23.2
SpecialPrefixindex.php
Go to the documentation of this file.
1 <?php
30 
35  protected $stripPrefix = false;
36 
37  protected $hideRedirects = false;
38 
39  // number of columns in output table
40  protected $columns = 3;
41 
42  // Inherit $maxPerPage
43 
44  function __construct() {
45  parent::__construct( 'Prefixindex' );
46  }
47 
52  function execute( $par ) {
54 
55  $this->setHeaders();
56  $this->outputHeader();
57 
58  $out = $this->getOutput();
59  $out->addModuleStyles( 'mediawiki.special' );
60 
61  # GET values
62  $request = $this->getRequest();
63  $from = $request->getVal( 'from', '' );
64  $prefix = $request->getVal( 'prefix', '' );
65  $ns = $request->getIntOrNull( 'namespace' );
66  $namespace = (int)$ns; // if no namespace given, use 0 (NS_MAIN).
67  $this->hideRedirects = $request->getBool( 'hideredirects', $this->hideRedirects );
68  $this->stripPrefix = $request->getBool( 'stripprefix', $this->stripPrefix );
69  $this->columns = $request->getInt( 'columns', $this->columns );
70 
71  $namespaces = $wgContLang->getNamespaces();
72  $out->setPageTitle(
73  ( $namespace > 0 && array_key_exists( $namespace, $namespaces ) )
74  ? $this->msg( 'prefixindex-namespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
75  : $this->msg( 'prefixindex' )
76  );
77 
78  $showme = '';
79  if ( isset( $par ) ) {
80  $showme = $par;
81  } elseif ( $prefix != '' ) {
82  $showme = $prefix;
83  } elseif ( $from != '' && $ns === null ) {
84  // For back-compat with Special:Allpages
85  // Don't do this if namespace is passed, so paging works when doing NS views.
86  $showme = $from;
87  }
88 
89  // Bug 27864: if transcluded, show all pages instead of the form.
90  if ( $this->including() || $showme != '' || $ns !== null ) {
91  $this->showPrefixChunk( $namespace, $showme, $from );
92  } else {
93  $out->addHTML( $this->namespacePrefixForm( $namespace, null ) );
94  }
95  }
96 
103  protected function namespacePrefixForm( $namespace = NS_MAIN, $from = '' ) {
104  global $wgScript;
105 
106  $out = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
107  $out .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
108  $out .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
109  $out .= Xml::openElement( 'fieldset' );
110  $out .= Xml::element( 'legend', null, $this->msg( 'allpages' )->text() );
111  $out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
112  $out .= "<tr>
113  <td class='mw-label'>" .
114  Xml::label( $this->msg( 'allpagesprefix' )->text(), 'nsfrom' ) .
115  "</td>
116  <td class='mw-input'>" .
117  Xml::input( 'prefix', 30, str_replace( '_', ' ', $from ), array( 'id' => 'nsfrom' ) ) .
118  "</td>
119  </tr>
120  <tr>
121  <td class='mw-label'>" .
122  Xml::label( $this->msg( 'namespace' )->text(), 'namespace' ) .
123  "</td>
124  <td class='mw-input'>" .
126  'selected' => $namespace,
127  ), array(
128  'name' => 'namespace',
129  'id' => 'namespace',
130  'class' => 'namespaceselector',
131  ) ) .
133  $this->msg( 'allpages-hide-redirects' )->text(),
134  'hideredirects',
135  'hideredirects',
136  $this->hideRedirects
137  ) . ' ' .
139  $this->msg( 'prefixindex-strip' )->text(),
140  'stripprefix',
141  'stripprefix',
142  $this->stripPrefix
143  ) . ' ' .
144  Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) .
145  "</td>
146  </tr>";
147  $out .= Xml::closeElement( 'table' );
148  $out .= Xml::closeElement( 'fieldset' );
149  $out .= Xml::closeElement( 'form' );
150  $out .= Xml::closeElement( 'div' );
151 
152  return $out;
153  }
154 
160  protected function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null ) {
162 
163  if ( $from === null ) {
164  $from = $prefix;
165  }
166 
167  $fromList = $this->getNamespaceKeyAndText( $namespace, $from );
168  $prefixList = $this->getNamespaceKeyAndText( $namespace, $prefix );
169  $namespaces = $wgContLang->getNamespaces();
170 
171  if ( !$prefixList || !$fromList ) {
172  $out = $this->msg( 'allpagesbadtitle' )->parseAsBlock();
173  } elseif ( !array_key_exists( $namespace, $namespaces ) ) {
174  // Show errormessage and reset to NS_MAIN
175  $out = $this->msg( 'allpages-bad-ns', $namespace )->parse();
176  $namespace = NS_MAIN;
177  } else {
178  list( $namespace, $prefixKey, $prefix ) = $prefixList;
179  list( /* $fromNS */, $fromKey, ) = $fromList;
180 
181  ### @todo FIXME: Should complain if $fromNs != $namespace
182 
183  $dbr = wfGetDB( DB_SLAVE );
184 
185  $conds = array(
186  'page_namespace' => $namespace,
187  'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
188  'page_title >= ' . $dbr->addQuotes( $fromKey ),
189  );
190 
191  if ( $this->hideRedirects ) {
192  $conds['page_is_redirect'] = 0;
193  }
194 
195  $res = $dbr->select( 'page',
196  array( 'page_namespace', 'page_title', 'page_is_redirect' ),
197  $conds,
198  __METHOD__,
199  array(
200  'ORDER BY' => 'page_title',
201  'LIMIT' => $this->maxPerPage + 1,
202  'USE INDEX' => 'name_title',
203  )
204  );
205 
206  ### @todo FIXME: Side link to previous
207 
208  $n = 0;
209  if ( $res->numRows() > 0 ) {
210  $out = Xml::openElement( 'table', array( 'class' => 'mw-prefixindex-list-table' ) );
211 
212  $prefixLength = strlen( $prefix );
213  while ( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
214  $t = Title::makeTitle( $s->page_namespace, $s->page_title );
215  if ( $t ) {
216  $displayed = $t->getText();
217  // Try not to generate unclickable links
218  if ( $this->stripPrefix && $prefixLength !== strlen( $displayed ) ) {
219  $displayed = substr( $displayed, $prefixLength );
220  }
221  $link = ( $s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
223  $t,
224  htmlspecialchars( $displayed ),
225  $s->page_is_redirect ? array( 'class' => 'mw-redirect' ) : array()
226  ) .
227  ( $s->page_is_redirect ? '</div>' : '' );
228  } else {
229  $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
230  }
231  if ( $n % $this->columns == 0 ) {
232  $out .= '<tr>';
233  }
234  $out .= "<td>$link</td>";
235  $n++;
236  if ( $n % $this->columns == 0 ) {
237  $out .= '</tr>';
238  }
239  }
240 
241  if ( $n % $this->columns != 0 ) {
242  $out .= '</tr>';
243  }
244 
245  $out .= Xml::closeElement( 'table' );
246  } else {
247  $out = '';
248  }
249  }
250 
251  $footer = '';
252  if ( $this->including() ) {
253  $out2 = '';
254  } else {
255  $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
256  $self = $this->getPageTitle();
257  $out2 = Xml::openElement( 'table', array( 'id' => 'mw-prefixindex-nav-table' ) ) .
258  '<tr>
259  <td>' .
260  $nsForm .
261  '</td>
262  <td id="mw-prefixindex-nav-form" class="mw-prefixindex-nav">';
263 
264  if ( isset( $res ) && $res && ( $n == $this->maxPerPage ) &&
265  ( $s = $res->fetchObject() )
266  ) {
267  $query = array(
268  'from' => $s->page_title,
269  'prefix' => $prefix,
270  'hideredirects' => $this->hideRedirects,
271  'stripprefix' => $this->stripPrefix,
272  'columns' => $this->columns,
273  );
274 
275  if ( $namespace || $prefix == '' ) {
276  // Keep the namespace even if it's 0 for empty prefixes.
277  // This tells us we're not just a holdover from old links.
278  $query['namespace'] = $namespace;
279  }
280 
281  $nextLink = Linker::linkKnown(
282  $self,
283  $this->msg( 'nextpage', str_replace( '_', ' ', $s->page_title ) )->escaped(),
284  array(),
285  $query
286  );
287 
288  $out2 .= $nextLink;
289 
290  $footer = "\n" . Html::element( 'hr' ) .
292  'div',
293  array( 'class' => 'mw-prefixindex-nav' ),
294  $nextLink
295  );
296  }
297  $out2 .= "</td></tr>" .
298  Xml::closeElement( 'table' );
299  }
300 
301  $this->getOutput()->addHTML( $out2 . $out . $footer );
302  }
303 
304  protected function getGroupName() {
305  return 'pages';
306  }
307 }
Xml\checkLabel
static checkLabel( $label, $name, $id, $checked=false, $attribs=array())
Convenience function to build an HTML checkbox with a label.
Definition: Xml.php:433
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:488
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:535
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3650
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
$n
$n
Definition: RandomTest.php:76
$from
$from
Definition: importImages.php:90
$s
$s
Definition: mergeMessageFileList.php:156
Html\hidden
static hidden( $name, $value, $attribs=array())
Convenience function to produce an input element with type=hidden.
Definition: Html.php:662
$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
SpecialPrefixindex\showPrefixChunk
showPrefixChunk( $namespace=NS_MAIN, $prefix, $from=null)
Definition: SpecialPrefixindex.php:160
SpecialPrefixindex\execute
execute( $par)
Entry point : initialise variables and call subfunctions.
Definition: SpecialPrefixindex.php:52
$link
set to $title object and return false for a match for latest after cache objects are set use the ContentHandler facility to handle CSS and JavaScript for highlighting & $link
Definition: hooks.txt:2149
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:109
Linker\linkKnown
static linkKnown( $target, $html=null, $customAttribs=array(), $query=array(), $options=array( 'known', 'noclasses'))
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:264
$dbr
$dbr
Definition: testCompression.php:48
NS_MAIN
const NS_MAIN
Definition: Defines.php:79
$out
$out
Definition: UtfNormalGenerate.php:167
Html\element
static element( $element, $attribs=array(), $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:148
SpecialPrefixindex\$stripPrefix
$stripPrefix
Whether to remove the searched prefix from the displayed link.
Definition: SpecialPrefixindex.php:35
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
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:352
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
SpecialPrefixindex\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialPrefixindex.php:304
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
SpecialPrefixindex\namespacePrefixForm
namespacePrefixForm( $namespace=NS_MAIN, $from='')
HTML for the top form.
Definition: SpecialPrefixindex.php:103
SpecialPage\msg
msg()
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:609
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:525
SpecialPrefixindex\$hideRedirects
$hideRedirects
Definition: SpecialPrefixindex.php:37
SpecialAllpages\getNamespaceKeyAndText
getNamespaceKeyAndText( $ns, $text)
Definition: SpecialAllpages.php:562
$self
$self
Definition: doMaintenance.php:54
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
SpecialPrefixindex\$columns
$columns
Definition: SpecialPrefixindex.php:40
$namespaces
namespace and then decline to actually register it & $namespaces
Definition: hooks.txt:815
SpecialPrefixindex\__construct
__construct()
Definition: SpecialPrefixindex.php:44
Xml\closeElement
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:118
Html\namespaceSelector
static namespaceSelector(array $params=array(), array $selectAttribs=array())
Build a drop-down box for selecting a namespace.
Definition: Html.php:707
Xml\submitButton
static submitButton( $value, $attribs=array())
Convenience function to build an HTML submit button.
Definition: Xml.php:463
$t
$t
Definition: testCompression.php:65
SpecialAllpages
Implements Special:Allpages.
Definition: SpecialAllpages.php:29
Xml\input
static input( $name, $size=false, $value=false, $attribs=array())
Convenience function to build an HTML text input field.
Definition: Xml.php:294
Html\rawElement
static rawElement( $element, $attribs=array(), $contents='')
Returns an HTML element in a string.
Definition: Html.php:124
Xml\label
static label( $label, $id, $attribs=array())
Convenience function to build an HTML form label.
Definition: Xml.php:374
$query
return true to allow those checks to and false if checking is done use this to change the tables headers temp or archived zone change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1105
SpecialPrefixindex
Implements Special:Prefixindex.
Definition: SpecialPrefixindex.php:29
$res
$res
Definition: database.txt:21
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:443
SpecialPage\including
including( $x=null)
Whether the special page is being evaluated via transclusion.
Definition: SpecialPage.php:207