79 $out->addModuleStyles(
'mediawiki.special' );
83 $from = $request->getVal(
'from',
'' );
84 $prefix = $request->getVal(
'prefix',
'' );
85 $ns = $request->getIntOrNull(
'namespace' );
86 $namespace = (int)$ns;
87 $this->hideRedirects = $request->getBool(
'hideredirects', $this->hideRedirects );
88 $this->stripPrefix = $request->getBool(
'stripprefix', $this->stripPrefix );
91 $out->setPageTitleMsg(
92 ( $namespace > 0 && array_key_exists( $namespace, $namespaces ) )
93 ? $this->
msg(
'prefixindex-namespace' )->plaintextParams(
94 str_replace(
'_',
' ', $namespaces[$namespace] )
96 : $this->
msg(
'prefixindex' )
100 if ( $par !==
null ) {
102 } elseif ( $prefix !=
'' ) {
104 } elseif ( $from !=
'' && $ns ===
null ) {
111 if ( $this->
including() || $showme !=
'' || $ns !==
null ) {
127 'label-message' =>
'allpagesprefix',
132 'default' => str_replace(
'_',
' ', $from ),
135 'type' =>
'namespaceselect',
136 'name' =>
'namespace',
138 'label-message' =>
'namespace',
140 'default' => $namespace,
143 'class' => HTMLCheckField::class,
144 'name' =>
'hideredirects',
145 'label-message' =>
'allpages-hide-redirects',
148 'class' => HTMLCheckField::class,
149 'name' =>
'stripprefix',
150 'label-message' =>
'prefixindex-strip',
156 $htmlForm = HTMLForm::factory(
'ooui', $formDescriptor, $this->
getContext() )
159 ->setWrapperLegendMsg(
'prefixindex' )
160 ->setSubmitTextMsg(
'prefixindex-submit' );
162 return $htmlForm->prepareForm();
171 if ( $from ===
null ) {
175 $fromList = $this->getNamespaceKeyAndText( $namespace, $from );
176 $prefixList = $this->getNamespaceKeyAndText( $namespace, $prefix );
177 $namespaces = $this->getContentLanguage()->getNamespaces();
181 $preparedHtmlForm = $this->namespacePrefixForm( $namespace, $prefix );
183 if ( !$prefixList || !$fromList ) {
184 $out = $this->msg(
'allpagesbadtitle' )->parseAsBlock();
185 } elseif ( !array_key_exists( $namespace, $namespaces ) ) {
187 $out = $this->msg(
'allpages-bad-ns', $namespace )->parse();
190 [ $namespace, $prefixKey, $prefix ] = $prefixList;
191 [ , $fromKey, ] = $fromList;
193 # ## @todo FIXME: Should complain if $fromNs != $namespace
195 $dbr = $this->dbProvider->getReplicaDatabase();
196 $queryBuiler = $dbr->newSelectQueryBuilder()
197 ->select( LinkCache::getSelectFields() )
200 'page_namespace' => $namespace,
204 new LikeValue( $prefixKey, $dbr->anyString() )
206 $dbr->expr(
'page_title',
'>=', $fromKey ),
208 ->orderBy(
'page_title' )
209 ->limit( $this->maxPerPage + 1 )
210 ->useIndex(
'page_name_title' );
212 if ( $this->hideRedirects ) {
213 $queryBuiler->andWhere( [
'page_is_redirect' => 0 ] );
216 $this->getHookRunner()->onSpecialPrefixIndexQuery( $preparedHtmlForm->mFieldData, $queryBuiler );
218 $res = $queryBuiler->caller( __METHOD__ )->fetchResultSet();
222 if ( $res->numRows() > 0 ) {
223 $out = Html::openElement(
'ul', [
'class' =>
'mw-prefixindex-list' ] );
225 $prefixLength = strlen( $prefix );
226 foreach ( $res as $row ) {
227 if ( $n >= $this->maxPerPage ) {
231 $title = Title::newFromRow( $row );
233 $this->linkCache->addGoodLinkObjFromRow( $title, $row );
234 $displayed = $title->getText();
236 if ( $this->stripPrefix && $prefixLength !== strlen( $displayed ) ) {
237 $displayed = substr( $displayed, $prefixLength );
239 $link = ( $title->isRedirect() ?
'<div class="allpagesredirect">' :
'' ) .
240 $this->getLinkRenderer()->makeKnownLink(
244 ( $title->isRedirect() ?
'</div>' :
'' );
246 $out .=
"<li>$link</li>\n";
250 $out .= Html::closeElement(
'ul' );
252 if ( $res->numRows() > 2 ) {
255 $out = Html::rawElement(
'div', [
'class' =>
'mw-prefixindex-body' ], $out );
262 $output = $this->getOutput();
264 if ( $this->including() ) {
267 $output->addHTML( $out );
271 $topOut = $preparedHtmlForm->getHTML(
false );
273 if ( $res && ( $n == $this->maxPerPage ) && $nextRow ) {
275 'from' => $nextRow->page_title,
277 'hideredirects' => $this->hideRedirects,
278 'stripprefix' => $this->stripPrefix,
281 if ( $namespace || $prefix ==
'' ) {
284 $query[
'namespace'] = $namespace;
287 $nextLink = $this->getLinkRenderer()->makeKnownLink(
288 $this->getPageTitle(),
289 $this->msg(
'nextpage', str_replace(
'_',
' ', $nextRow->page_title ) )->text(),
295 $topOut .= Html::rawElement(
'div',
296 [
'class' =>
'mw-prefixindex-nav' ],
304 [
'class' =>
'mw-prefixindex-nav' ],
310 $output->addHTML( $topOut . $out );