MediaWiki  REL1_31
SpecialAllPages.php
Go to the documentation of this file.
1 <?php
31 
37  protected $maxPerPage = 345;
38 
44  protected $nsfromMsg = 'allpagesfrom';
45 
49  function __construct( $name = 'Allpages' ) {
50  parent::__construct( $name );
51  }
52 
58  function execute( $par ) {
59  $request = $this->getRequest();
60  $out = $this->getOutput();
61 
62  $this->setHeaders();
63  $this->outputHeader();
64  $out->allowClickjacking();
65 
66  # GET values
67  $from = $request->getVal( 'from', null );
68  $to = $request->getVal( 'to', null );
69  $namespace = $request->getInt( 'namespace' );
70 
71  $miserMode = (bool)$this->getConfig()->get( 'MiserMode' );
72 
73  // Redirects filter is disabled in MiserMode
74  $hideredirects = $request->getBool( 'hideredirects', false ) && !$miserMode;
75 
76  $namespaces = $this->getLanguage()->getNamespaces();
77 
78  $out->setPageTitle(
79  ( $namespace > 0 && array_key_exists( $namespace, $namespaces ) ) ?
80  $this->msg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) ) :
81  $this->msg( 'allarticles' )
82  );
83  $out->addModuleStyles( 'mediawiki.special' );
84 
85  if ( $par !== null ) {
86  $this->showChunk( $namespace, $par, $to, $hideredirects );
87  } elseif ( $from !== null && $to === null ) {
88  $this->showChunk( $namespace, $from, $to, $hideredirects );
89  } else {
90  $this->showToplevel( $namespace, $from, $to, $hideredirects );
91  }
92  }
93 
102  protected function outputHTMLForm( $namespace = NS_MAIN,
103  $from = '', $to = '', $hideRedirects = false
104  ) {
105  $miserMode = (bool)$this->getConfig()->get( 'MiserMode' );
106  $fields = [
107  'from' => [
108  'type' => 'text',
109  'name' => 'from',
110  'id' => 'nsfrom',
111  'size' => 30,
112  'label-message' => 'allpagesfrom',
113  'default' => str_replace( '_', ' ', $from ),
114  ],
115  'to' => [
116  'type' => 'text',
117  'name' => 'to',
118  'id' => 'nsto',
119  'size' => 30,
120  'label-message' => 'allpagesto',
121  'default' => str_replace( '_', ' ', $to ),
122  ],
123  'namespace' => [
124  'type' => 'namespaceselect',
125  'name' => 'namespace',
126  'id' => 'namespace',
127  'label-message' => 'namespace',
128  'all' => null,
129  'value' => $namespace,
130  ],
131  'hideredirects' => [
132  'type' => 'check',
133  'name' => 'hideredirects',
134  'id' => 'hidredirects',
135  'label-message' => 'allpages-hide-redirects',
136  'value' => $hideRedirects,
137  ],
138  ];
139 
140  if ( $miserMode ) {
141  unset( $fields['hideredirects'] );
142  }
143 
144  $form = HTMLForm::factory( 'table', $fields, $this->getContext() );
145  $form->setMethod( 'get' )
146  ->setWrapperLegendMsg( 'allpages' )
147  ->setSubmitTextMsg( 'allpagessubmit' )
148  ->prepareForm()
149  ->displayForm( false );
150  }
151 
158  function showToplevel( $namespace = NS_MAIN, $from = '', $to = '', $hideredirects = false ) {
159  $from = Title::makeTitleSafe( $namespace, $from );
160  $to = Title::makeTitleSafe( $namespace, $to );
161  $from = ( $from && $from->isLocal() ) ? $from->getDBkey() : null;
162  $to = ( $to && $to->isLocal() ) ? $to->getDBkey() : null;
163 
164  $this->showChunk( $namespace, $from, $to, $hideredirects );
165  }
166 
173  function showChunk( $namespace = NS_MAIN, $from = false, $to = false, $hideredirects = false ) {
174  $output = $this->getOutput();
175 
176  $fromList = $this->getNamespaceKeyAndText( $namespace, $from );
177  $toList = $this->getNamespaceKeyAndText( $namespace, $to );
178  $namespaces = $this->getContext()->getLanguage()->getNamespaces();
179  $n = 0;
180  $prevTitle = null;
181 
182  if ( !$fromList || !$toList ) {
183  $out = $this->msg( 'allpagesbadtitle' )->parseAsBlock();
184  } elseif ( !array_key_exists( $namespace, $namespaces ) ) {
185  // Show errormessage and reset to NS_MAIN
186  $out = $this->msg( 'allpages-bad-ns', $namespace )->parse();
187  $namespace = NS_MAIN;
188  } else {
189  list( $namespace, $fromKey, $from ) = $fromList;
190  list( , $toKey, $to ) = $toList;
191 
192  $dbr = wfGetDB( DB_REPLICA );
193  $filterConds = [ 'page_namespace' => $namespace ];
194  if ( $hideredirects ) {
195  $filterConds['page_is_redirect'] = 0;
196  }
197 
198  $conds = $filterConds;
199  $conds[] = 'page_title >= ' . $dbr->addQuotes( $fromKey );
200  if ( $toKey !== "" ) {
201  $conds[] = 'page_title <= ' . $dbr->addQuotes( $toKey );
202  }
203 
204  $res = $dbr->select( 'page',
205  [ 'page_namespace', 'page_title', 'page_is_redirect', 'page_id' ],
206  $conds,
207  __METHOD__,
208  [
209  'ORDER BY' => 'page_title',
210  'LIMIT' => $this->maxPerPage + 1,
211  'USE INDEX' => 'name_title',
212  ]
213  );
214 
215  $linkRenderer = $this->getLinkRenderer();
216  if ( $res->numRows() > 0 ) {
217  $out = Html::openElement( 'ul', [ 'class' => 'mw-allpages-chunk' ] );
218 
219  while ( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
220  $t = Title::newFromRow( $s );
221  if ( $t ) {
222  $out .= '<li' .
223  ( $s->page_is_redirect ? ' class="allpagesredirect"' : '' ) .
224  '>' .
225  $linkRenderer->makeLink( $t ) .
226  "</li>\n";
227  } else {
228  $out .= '<li>[[' . htmlspecialchars( $s->page_title ) . "]]</li>\n";
229  }
230  $n++;
231  }
232  $out .= Html::closeElement( 'ul' );
233 
234  if ( $res->numRows() > 2 ) {
235  // Only apply CSS column styles if there's more than 2 entries.
236  // Otherwise, rendering is broken as "mw-allpages-body"'s CSS column count is 3.
237  $out = Html::rawElement( 'div', [ 'class' => 'mw-allpages-body' ], $out );
238  }
239  } else {
240  $out = '';
241  }
242 
243  if ( $fromKey !== '' && !$this->including() ) {
244  # Get the first title from previous chunk
245  $prevConds = $filterConds;
246  $prevConds[] = 'page_title < ' . $dbr->addQuotes( $fromKey );
247  $prevKey = $dbr->selectField(
248  'page',
249  'page_title',
250  $prevConds,
251  __METHOD__,
252  [ 'ORDER BY' => 'page_title DESC', 'OFFSET' => $this->maxPerPage - 1 ]
253  );
254 
255  if ( $prevKey === false ) {
256  # The previous chunk is not complete, need to link to the very first title
257  # available in the database
258  $prevKey = $dbr->selectField(
259  'page',
260  'page_title',
261  $prevConds,
262  __METHOD__,
263  [ 'ORDER BY' => 'page_title' ]
264  );
265  }
266 
267  if ( $prevKey !== false ) {
268  $prevTitle = Title::makeTitle( $namespace, $prevKey );
269  }
270  }
271  }
272 
273  if ( $this->including() ) {
274  $output->addHTML( $out );
275  return;
276  }
277 
278  $navLinks = [];
279  $self = $this->getPageTitle();
280 
281  $linkRenderer = $this->getLinkRenderer();
282  // Generate a "previous page" link if needed
283  if ( $prevTitle ) {
284  $query = [ 'from' => $prevTitle->getText() ];
285 
286  if ( $namespace ) {
287  $query['namespace'] = $namespace;
288  }
289 
290  if ( $hideredirects ) {
291  $query['hideredirects'] = $hideredirects;
292  }
293 
294  $navLinks[] = $linkRenderer->makeKnownLink(
295  $self,
296  $this->msg( 'prevpage', $prevTitle->getText() )->text(),
297  [],
298  $query
299  );
300 
301  }
302 
303  // Generate a "next page" link if needed
304  if ( $n == $this->maxPerPage && $s = $res->fetchObject() ) {
305  # $s is the first link of the next chunk
306  $t = Title::makeTitle( $namespace, $s->page_title );
307  $query = [ 'from' => $t->getText() ];
308 
309  if ( $namespace ) {
310  $query['namespace'] = $namespace;
311  }
312 
313  if ( $hideredirects ) {
314  $query['hideredirects'] = $hideredirects;
315  }
316 
317  $navLinks[] = $linkRenderer->makeKnownLink(
318  $self,
319  $this->msg( 'nextpage', $t->getText() )->text(),
320  [],
321  $query
322  );
323  }
324 
325  $this->outputHTMLForm( $namespace, $from, $to, $hideredirects );
326 
327  if ( count( $navLinks ) ) {
328  // Add pagination links
329  $pagination = Html::rawElement( 'div',
330  [ 'class' => 'mw-allpages-nav' ],
331  $this->getLanguage()->pipeList( $navLinks )
332  );
333 
334  $output->addHTML( $pagination );
335  $out .= Html::element( 'hr' ) . $pagination; // Footer
336  }
337 
338  $output->addHTML( $out );
339  }
340 
346  protected function getNamespaceKeyAndText( $ns, $text ) {
347  if ( $text == '' ) {
348  # shortcut for common case
349  return [ $ns, '', '' ];
350  }
351 
352  $t = Title::makeTitleSafe( $ns, $text );
353  if ( $t && $t->isLocal() ) {
354  return [ $t->getNamespace(), $t->getDBkey(), $t->getText() ];
355  } elseif ( $t ) {
356  return null;
357  }
358 
359  # try again, in case the problem was an empty pagename
360  $text = preg_replace( '/(#|$)/', 'X$1', $text );
361  $t = Title::makeTitleSafe( $ns, $text );
362  if ( $t && $t->isLocal() ) {
363  return [ $t->getNamespace(), '', '' ];
364  } else {
365  return null;
366  }
367  }
368 
377  public function prefixSearchSubpages( $search, $limit, $offset ) {
378  return $this->prefixSearchString( $search, $limit, $offset );
379  }
380 
381  protected function getGroupName() {
382  return 'pages';
383  }
384 }
SpecialAllPages\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialAllPages.php:381
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:675
SpecialPage\msg
msg( $key)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:793
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:722
$output
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
Definition: hooks.txt:2255
SpecialAllPages\execute
execute( $par)
Entry point : initialise variables and call subfunctions.
Definition: SpecialAllPages.php:58
$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:864
SpecialAllPages\$maxPerPage
$maxPerPage
Maximum number of pages to show on single subpage.
Definition: SpecialAllPages.php:37
SpecialAllPages\showToplevel
showToplevel( $namespace=NS_MAIN, $from='', $to='', $hideredirects=false)
Definition: SpecialAllPages.php:158
$s
$s
Definition: mergeMessageFileList.php:187
IncludableSpecialPage
Shortcut to construct an includable special page.
Definition: IncludableSpecialPage.php:29
$res
$res
Definition: database.txt:21
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:752
SpecialAllPages\__construct
__construct( $name='Allpages')
Definition: SpecialAllPages.php:49
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:37
$dbr
$dbr
Definition: testCompression.php:50
NS_MAIN
const NS_MAIN
Definition: Defines.php:74
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:309
SpecialPage\prefixSearchString
prefixSearchString( $search, $limit, $offset)
Perform a regular substring search for prefixSearchSubpages.
Definition: SpecialPage.php:491
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:761
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:464
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2812
HTMLForm\factory
static factory( $displayFormat)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:279
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:527
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:534
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
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
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:695
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:562
SpecialAllPages\prefixSearchSubpages
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
Definition: SpecialAllPages.php:377
SpecialAllPages\outputHTMLForm
outputHTMLForm( $namespace=NS_MAIN, $from='', $to='', $hideRedirects=false)
Outputs the HTMLForm used on this page.
Definition: SpecialAllPages.php:102
SpecialAllPages\getNamespaceKeyAndText
getNamespaceKeyAndText( $ns, $text)
Definition: SpecialAllPages.php:346
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:712
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:907
$self
$self
Definition: doMaintenance.php:55
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
$namespaces
namespace and then decline to actually register it & $namespaces
Definition: hooks.txt:934
SpecialAllPages
Implements Special:Allpages.
Definition: SpecialAllPages.php:30
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
SpecialAllPages\showChunk
showChunk( $namespace=NS_MAIN, $from=false, $to=false, $hideredirects=false)
Definition: SpecialAllPages.php:173
$t
$t
Definition: testCompression.php:69
SpecialPage\$linkRenderer
MediaWiki Linker LinkRenderer null $linkRenderer
Definition: SpecialPage.php:66
$request
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:2806
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
$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:1620
SpecialAllPages\$nsfromMsg
$nsfromMsg
Determines, which message describes the input field 'nsfrom'.
Definition: SpecialAllPages.php:44
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:629
SpecialPage\including
including( $x=null)
Whether the special page is being evaluated via transclusion.
Definition: SpecialPage.php:226