61 $out->addModuleStyles(
'mediawiki.special' );
65 $from = $request->getVal(
'from',
'' );
66 $prefix = $request->getVal(
'prefix',
'' );
67 $ns = $request->getIntOrNull(
'namespace' );
68 $namespace = (int)$ns;
69 $this->hideRedirects = $request->getBool(
'hideredirects', $this->hideRedirects );
70 $this->stripPrefix = $request->getBool(
'stripprefix', $this->stripPrefix );
73 $out->setPageTitleMsg(
74 ( $namespace > 0 && array_key_exists( $namespace, $namespaces ) )
75 ? $this->
msg(
'prefixindex-namespace' )->plaintextParams(
76 str_replace(
'_',
' ', $namespaces[$namespace] )
78 : $this->
msg(
'prefixindex' )
82 if ( $par !==
null ) {
84 } elseif ( $prefix !=
'' ) {
86 } elseif ( $from !=
'' && $ns ===
null ) {
93 if ( $this->
including() || $showme !=
'' || $ns !==
null ) {
155 $fromList = $this->getNamespaceKeyAndText( $namespace, $from );
156 $prefixList = $this->getNamespaceKeyAndText( $namespace, $prefix );
157 $namespaces = $this->getContentLanguage()->getNamespaces();
161 $preparedHtmlForm = $this->namespacePrefixForm( $namespace, $prefix );
163 if ( !$prefixList || !$fromList ) {
164 $out = $this->msg(
'allpagesbadtitle' )->parseAsBlock();
165 } elseif ( !array_key_exists( $namespace, $namespaces ) ) {
167 $out = $this->msg(
'allpages-bad-ns', $namespace )->parse();
170 [ $namespace, $prefixKey, $prefix ] = $prefixList;
171 [ , $fromKey, ] = $fromList;
173 # ## @todo FIXME: Should complain if $fromNs != $namespace
175 $dbr = $this->dbProvider->getReplicaDatabase();
176 $queryBuiler = $dbr->newSelectQueryBuilder()
177 ->select( LinkCache::getSelectFields() )
180 'page_namespace' => $namespace,
184 new LikeValue( $prefixKey, $dbr->anyString() )
186 $dbr->expr(
'page_title',
'>=', $fromKey ),
188 ->orderBy(
'page_title' )
189 ->limit( $this->maxPerPage + 1 )
190 ->useIndex(
'page_name_title' );
192 if ( $this->hideRedirects ) {
193 $queryBuiler->andWhere( [
'page_is_redirect' => 0 ] );
196 $this->getHookRunner()->onSpecialPrefixIndexQuery( $preparedHtmlForm->mFieldData, $queryBuiler );
198 $res = $queryBuiler->caller( __METHOD__ )->fetchResultSet();
202 if ( $res->numRows() > 0 ) {
203 $out = Html::openElement(
'ul', [
'class' =>
'mw-prefixindex-list' ] );
205 $prefixLength = strlen( $prefix );
206 foreach ( $res as $row ) {
207 if ( $n >= $this->maxPerPage ) {
211 $title = Title::newFromRow( $row );
213 $this->linkCache->addGoodLinkObjFromRow( $title, $row );
214 $displayed = $title->getText();
216 if ( $this->stripPrefix && $prefixLength !== strlen( $displayed ) ) {
217 $displayed = substr( $displayed, $prefixLength );
219 $link = ( $title->isRedirect() ?
'<div class="allpagesredirect">' :
'' ) .
220 $this->getLinkRenderer()->makeKnownLink(
224 ( $title->isRedirect() ?
'</div>' :
'' );
226 $out .=
"<li>$link</li>\n";
230 $out .= Html::closeElement(
'ul' );
232 if ( $res->numRows() > 2 ) {
235 $out = Html::rawElement(
'div', [
'class' =>
'mw-prefixindex-body' ], $out );
242 $output = $this->getOutput();
244 if ( $this->including() ) {
247 $output->addHTML( $out );
251 $topOut = $preparedHtmlForm->getHTML(
false );
253 if ( $res && ( $n == $this->maxPerPage ) && $nextRow ) {
255 'from' => $nextRow->page_title,
257 'hideredirects' => $this->hideRedirects,
258 'stripprefix' => $this->stripPrefix,
261 if ( $namespace || $prefix ==
'' ) {
264 $query[
'namespace'] = $namespace;
267 $nextLink = $this->getLinkRenderer()->makeKnownLink(
268 $this->getPageTitle(),
269 $this->msg(
'nextpage', str_replace(
'_',
' ', $nextRow->page_title ) )->text(),
275 $topOut .= Html::rawElement(
'div',
276 [
'class' =>
'mw-prefixindex-nav' ],
284 [
'class' =>
'mw-prefixindex-nav' ],
290 $output->addHTML( $topOut . $out );