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