setHeaders(); $this->outputHeader(); $out = $this->getOutput(); $out->addModuleStyles( 'mediawiki.special' ); # GET values $request = $this->getRequest(); $from = $request->getVal( 'from', '' ); $prefix = $request->getVal( 'prefix', '' ); $ns = $request->getIntOrNull( 'namespace' ); $namespace = (int)$ns; // if no namespace given, use 0 (NS_MAIN). $this->hideRedirects = $request->getBool( 'hideredirects', $this->hideRedirects ); $this->stripPrefix = $request->getBool( 'stripprefix', $this->stripPrefix ); $namespaces = MediaWikiServices::getInstance()->getContentLanguage()->getNamespaces(); $out->setPageTitle( ( $namespace > 0 && array_key_exists( $namespace, $namespaces ) ) ? $this->msg( 'prefixindex-namespace', str_replace( '_', ' ', $namespaces[$namespace] ) ) : $this->msg( 'prefixindex' ) ); $showme = ''; if ( $par !== null ) { $showme = $par; } elseif ( $prefix != '' ) { $showme = $prefix; } elseif ( $from != '' && $ns === null ) { // For back-compat with Special:Allpages // Don't do this if namespace is passed, so paging works when doing NS views. $showme = $from; } // T29864: if transcluded, show all pages instead of the form. if ( $this->including() || $showme != '' || $ns !== null ) { $this->showPrefixChunk( $namespace, $showme, $from ); } else { $out->addHTML( $this->namespacePrefixForm( $namespace, null ) ); } } /** * HTML for the top form * @param int $namespace A namespace constant (default NS_MAIN). * @param string $from DbKey we are starting listing at. * @return string */ protected function namespacePrefixForm( $namespace = NS_MAIN, $from = '' ) { $formDescriptor = [ 'prefix' => [ 'label-message' => 'allpagesprefix', 'name' => 'prefix', 'id' => 'nsfrom', 'type' => 'text', 'size' => '30', 'default' => str_replace( '_', ' ', $from ), ], 'namespace' => [ 'type' => 'namespaceselect', 'name' => 'namespace', 'id' => 'namespace', 'label-message' => 'namespace', 'all' => null, 'default' => $namespace, ], 'hidedirects' => [ 'class' => 'HTMLCheckField', 'name' => 'hideredirects', 'label-message' => 'allpages-hide-redirects', ], 'stripprefix' => [ 'class' => 'HTMLCheckField', 'name' => 'stripprefix', 'label-message' => 'prefixindex-strip', ], ]; $context = new DerivativeContext( $this->getContext() ); $context->setTitle( $this->getPageTitle() ); // Remove subpage $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $context ); $htmlForm ->setMethod( 'get' ) ->setWrapperLegendMsg( 'prefixindex' ) ->setSubmitTextMsg( 'prefixindex-submit' ); return $htmlForm->prepareForm()->getHTML( false ); } /** * @param int $namespace * @param string $prefix * @param string|null $from List all pages from this name (default false) */ protected function showPrefixChunk( $namespace, $prefix, $from = null ) { if ( $from === null ) { $from = $prefix; } $fromList = $this->getNamespaceKeyAndText( $namespace, $from ); $prefixList = $this->getNamespaceKeyAndText( $namespace, $prefix ); $namespaces = MediaWikiServices::getInstance()->getContentLanguage()->getNamespaces(); $res = null; $n = 0; $nextRow = null; if ( !$prefixList || !$fromList ) { $out = $this->msg( 'allpagesbadtitle' )->parseAsBlock(); } elseif ( !array_key_exists( $namespace, $namespaces ) ) { // Show errormessage and reset to NS_MAIN $out = $this->msg( 'allpages-bad-ns', $namespace )->parse(); $namespace = NS_MAIN; } else { list( $namespace, $prefixKey, $prefix ) = $prefixList; list( /* $fromNS */, $fromKey, ) = $fromList; # ## @todo FIXME: Should complain if $fromNs != $namespace $dbr = wfGetDB( DB_REPLICA ); $conds = [ 'page_namespace' => $namespace, 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ), 'page_title >= ' . $dbr->addQuotes( $fromKey ), ]; if ( $this->hideRedirects ) { $conds['page_is_redirect'] = 0; } $res = $dbr->select( 'page', array_merge( [ 'page_namespace', 'page_title' ], LinkCache::getSelectFields() ), $conds, __METHOD__, [ 'ORDER BY' => 'page_title', 'LIMIT' => $this->maxPerPage + 1, 'USE INDEX' => 'name_title', ] ); // @todo FIXME: Side link to previous if ( $res->numRows() > 0 ) { $out = Html::openElement( 'ul', [ 'class' => 'mw-prefixindex-list' ] ); $linkCache = MediaWikiServices::getInstance()->getLinkCache(); $prefixLength = strlen( $prefix ); foreach ( $res as $row ) { if ( $n >= $this->maxPerPage ) { $nextRow = $row; break; } $title = Title::newFromRow( $row ); // Make sure it gets into LinkCache $linkCache->addGoodLinkObjFromRow( $title, $row ); $displayed = $title->getText(); // Try not to generate unclickable links if ( $this->stripPrefix && $prefixLength !== strlen( $displayed ) ) { $displayed = substr( $displayed, $prefixLength ); } $link = ( $title->isRedirect() ? '