51 private $loadBalancer;
54 private $searchEngineFactory;
64 parent::__construct(
'Allpages' );
66 $services = MediaWikiServices::getInstance();
67 $this->loadBalancer = $loadBalancer ?? $services->getDBLoadBalancer();
68 $this->searchEngineFactory = $searchEngineFactory ?? $services->getSearchEngineFactory();
82 $out->setPreventClickjacking(
false );
85 $from = $request->getVal(
'from',
null );
86 $to = $request->getVal(
'to',
null );
87 $namespace = $request->getInt(
'namespace' );
89 $miserMode = (bool)$this->
getConfig()->get( MainConfigNames::MiserMode );
92 $hideredirects = $request->getBool(
'hideredirects',
false ) && !$miserMode;
94 $namespaces = $this->
getLanguage()->getNamespaces();
97 ( $namespace > 0 && array_key_exists( $namespace, $namespaces ) ) ?
98 $this->
msg(
'allinnamespace', str_replace(
'_',
' ', $namespaces[$namespace] ) ) :
99 $this->
msg(
'allarticles' )
101 $out->addModuleStyles(
'mediawiki.special' );
103 if ( $par !==
null ) {
104 $this->showChunk( $namespace, $par, $to, $hideredirects );
105 } elseif ( $from !==
null && $to ===
null ) {
106 $this->showChunk( $namespace, $from, $to, $hideredirects );
108 $this->showToplevel( $namespace, $from, $to, $hideredirects );
121 $from =
'', $to =
'', $hideRedirects =
false
123 $miserMode = (bool)$this->
getConfig()->get( MainConfigNames::MiserMode );
130 'label-message' =>
'allpagesfrom',
131 'default' => str_replace(
'_',
' ', $from ),
138 'label-message' =>
'allpagesto',
139 'default' => str_replace(
'_',
' ', $to ),
142 'type' =>
'namespaceselect',
143 'name' =>
'namespace',
145 'label-message' =>
'namespace',
147 'default' => $namespace,
151 'name' =>
'hideredirects',
152 'id' =>
'hidredirects',
153 'label-message' =>
'allpages-hide-redirects',
154 'value' => $hideRedirects,
159 unset( $formDescriptor[
'hideredirects'] );
162 $htmlForm = HTMLForm::factory(
'ooui', $formDescriptor, $this->
getContext() );
166 ->setWrapperLegendMsg(
'allpages' )
167 ->setSubmitTextMsg(
'allpagessubmit' )
169 ->displayForm(
false );
178 private function showToplevel(
179 $namespace =
NS_MAIN, $from =
null, $to =
null, $hideredirects =
false
181 $from = $from ? Title::makeTitleSafe( $namespace, $from ) : null;
182 $to = $to ? Title::makeTitleSafe( $namespace, $to ) : null;
183 $from = ( $from && $from->isLocal() ) ? $from->getDBkey() :
null;
184 $to = ( $to && $to->isLocal() ) ? $to->getDBkey() :
null;
186 $this->showChunk( $namespace, $from, $to, $hideredirects );
195 private function showChunk(
196 $namespace =
NS_MAIN, $from =
null, $to =
null, $hideredirects =
false
202 $namespaces = $this->
getContext()->getLanguage()->getNamespaces();
206 if ( !$fromList || !$toList ) {
207 $out = $this->
msg(
'allpagesbadtitle' )->parseAsBlock();
208 } elseif ( !array_key_exists( $namespace, $namespaces ) ) {
210 $out = $this->
msg(
'allpages-bad-ns', $namespace )->parse();
213 list( $namespace, $fromKey, $from ) = $fromList;
214 list( , $toKey, $to ) = $toList;
216 $dbr = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
217 $filterConds = [
'page_namespace' => $namespace ];
218 if ( $hideredirects ) {
219 $filterConds[
'page_is_redirect'] = 0;
222 $conds = $filterConds;
223 $conds[] =
'page_title >= ' .
$dbr->addQuotes( $fromKey );
224 if ( $toKey !==
"" ) {
225 $conds[] =
'page_title <= ' .
$dbr->addQuotes( $toKey );
228 [
'page_namespace',
'page_title',
'page_is_redirect',
'page_id' ],
232 'ORDER BY' =>
'page_title',
233 'LIMIT' => $this->maxPerPage + 1,
234 'USE INDEX' =>
'page_name_title',
239 if (
$res->numRows() > 0 ) {
242 while ( ( $n < $this->maxPerPage ) && (
$s =
$res->fetchObject() ) ) {
246 (
$s->page_is_redirect ?
' class="allpagesredirect"' :
'' ) .
248 $linkRenderer->makeLink(
$t ) .
251 $out .=
'<li>[[' . htmlspecialchars(
$s->page_title ) .
"]]</li>\n";
257 if (
$res->numRows() > 2 ) {
266 if ( $fromKey !==
'' && !$this->
including() ) {
267 # Get the first title from previous chunk
268 $prevConds = $filterConds;
269 $prevConds[] =
'page_title < ' .
$dbr->addQuotes( $fromKey );
270 $prevKey =
$dbr->selectField(
275 [
'ORDER BY' =>
'page_title DESC',
'OFFSET' => $this->maxPerPage - 1 ]
278 if ( $prevKey ===
false ) {
279 # The previous chunk is not complete, need to link to the very first title
280 # available in the database
281 $prevKey =
$dbr->selectField(
286 [
'ORDER BY' =>
'page_title' ]
290 if ( $prevKey !==
false ) {
297 $output->addHTML( $out );
307 $query = [
'from' => $prevTitle->getText() ];
310 $query[
'namespace'] = $namespace;
313 if ( $hideredirects ) {
314 $query[
'hideredirects'] = $hideredirects;
317 $navLinks[] = $linkRenderer->makeKnownLink(
319 $this->
msg(
'prevpage', $prevTitle->getText() )->text(),
328 if ( $n == $this->maxPerPage &&
$s =
$res->fetchObject() ) {
329 # $s is the first link of the next chunk
331 $query = [
'from' =>
$t->getText() ];
334 $query[
'namespace'] = $namespace;
337 if ( $hideredirects ) {
338 $query[
'hideredirects'] = $hideredirects;
341 $navLinks[] = $linkRenderer->makeKnownLink(
343 $this->
msg(
'nextpage',
$t->getText() )->text(),
349 $this->
outputHTMLForm( $namespace, $from ??
'', $to ??
'', $hideredirects );
351 if ( count( $navLinks ) ) {
354 [
'class' =>
'mw-allpages-nav' ],
358 $output->addHTML( $pagination );
362 $output->addHTML( $out );
372 # shortcut for common case
373 return [ $ns,
'',
'' ];
376 $t = Title::makeTitleSafe( $ns, $text );
377 if (
$t &&
$t->isLocal() ) {
378 return [
$t->getNamespace(),
$t->getDBkey(),
$t->getText() ];
383 # try again, in case the problem was an empty pagename
384 $text = preg_replace(
'/(#|$)/',
'X$1', $text );
385 $t = Title::makeTitleSafe( $ns, $text );
386 if (
$t &&
$t->isLocal() ) {
387 return [
$t->getNamespace(),
'',
'' ];
402 return $this->
prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
static closeElement( $element)
Returns "</$element>".
Shortcut to construct an includable special page.
A class containing constants representing the names of configuration variables.
Factory class for SearchEngine.
Implements Special:Allpages.
int $maxPerPage
Maximum number of pages to show on single subpage.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
execute( $par)
Entry point : initialise variables and call subfunctions.
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
string $nsfromMsg
Determines, which message describes the input field 'nsfrom'.
__construct(ILoadBalancer $loadBalancer=null, SearchEngineFactory $searchEngineFactory=null)
outputHTMLForm( $namespace=NS_MAIN, $from='', $to='', $hideRedirects=false)
Outputs the HTMLForm used on this page.
getNamespaceKeyAndText( $ns, $text)
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
prefixSearchString( $search, $limit, $offset, SearchEngineFactory $searchEngineFactory=null)
Perform a regular substring search for prefixSearchSubpages.
getPageTitle( $subpage=false)
Get a self-referential title object.
getLanguage()
Shortcut to get user's language.
including( $x=null)
Whether the special page is being evaluated via transclusion.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
static newFromRow( $row)
Make a Title object from a DB row.
foreach( $mmfl['setupFiles'] as $fileName) if($queue) if(empty( $mmfl['quiet'])) $s