Merge "Fix importation of weird file names in importTextFiles.php"
[lhc/web/wiklou.git] / includes / specials / SpecialPrefixindex.php
index 9891f86..5e3e430 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  * @ingroup SpecialPage
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * Implements Special:Prefixindex
@@ -165,6 +166,8 @@ class SpecialPrefixindex extends SpecialAllPages {
                $prefixList = $this->getNamespaceKeyAndText( $namespace, $prefix );
                $namespaces = $wgContLang->getNamespaces();
                $res = null;
+               $n = 0;
+               $nextRow = null;
 
                if ( !$prefixList || !$fromList ) {
                        $out = $this->msg( 'allpagesbadtitle' )->parseAsBlock();
@@ -178,7 +181,7 @@ class SpecialPrefixindex extends SpecialAllPages {
 
                        # ## @todo FIXME: Should complain if $fromNs != $namespace
 
-                       $dbr = wfGetDB( DB_SLAVE );
+                       $dbr = wfGetDB( DB_REPLICA );
 
                        $conds = [
                                'page_namespace' => $namespace,
@@ -191,7 +194,10 @@ class SpecialPrefixindex extends SpecialAllPages {
                        }
 
                        $res = $dbr->select( 'page',
-                               [ 'page_namespace', 'page_title', 'page_is_redirect' ],
+                               array_merge(
+                                       [ 'page_namespace', 'page_title' ],
+                                       LinkCache::getSelectFields()
+                               ),
                                $conds,
                                __METHOD__,
                                [
@@ -203,29 +209,30 @@ class SpecialPrefixindex extends SpecialAllPages {
 
                        // @todo FIXME: Side link to previous
 
-                       $n = 0;
                        if ( $res->numRows() > 0 ) {
                                $out = Html::openElement( 'ul', [ 'class' => 'mw-prefixindex-list' ] );
+                               $linkCache = MediaWikiServices::getInstance()->getLinkCache();
 
                                $prefixLength = strlen( $prefix );
-                               while ( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
-                                       $t = Title::makeTitle( $s->page_namespace, $s->page_title );
-                                       if ( $t ) {
-                                               $displayed = $t->getText();
-                                               // Try not to generate unclickable links
-                                               if ( $this->stripPrefix && $prefixLength !== strlen( $displayed ) ) {
-                                                       $displayed = substr( $displayed, $prefixLength );
-                                               }
-                                               $link = ( $s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
-                                                       Linker::linkKnown(
-                                                               $t,
-                                                               htmlspecialchars( $displayed ),
-                                                               $s->page_is_redirect ? [ 'class' => 'mw-redirect' ] : []
-                                                       ) .
-                                                       ( $s->page_is_redirect ? '</div>' : '' );
-                                       } else {
-                                               $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
+                               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() ? '<div class="allpagesredirect">' : '' ) .
+                                               Linker::linkKnown(
+                                                       $title,
+                                                       htmlspecialchars( $displayed )
+                                               ) .
+                                               ( $title->isRedirect() ? '</div>' : '' );
 
                                        $out .= "<li>$link</li>\n";
                                        $n++;
@@ -254,9 +261,9 @@ class SpecialPrefixindex extends SpecialAllPages {
 
                $topOut = $this->namespacePrefixForm( $namespace, $prefix );
 
-               if ( $res && ( $n == $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
+               if ( $res && ( $n == $this->maxPerPage ) && $nextRow ) {
                        $query = [
-                               'from' => $s->page_title,
+                               'from' => $nextRow->page_title,
                                'prefix' => $prefix,
                                'hideredirects' => $this->hideRedirects,
                                'stripprefix' => $this->stripPrefix,
@@ -270,7 +277,7 @@ class SpecialPrefixindex extends SpecialAllPages {
 
                        $nextLink = Linker::linkKnown(
                                $this->getPageTitle(),
-                               $this->msg( 'nextpage', str_replace( '_', ' ', $s->page_title ) )->escaped(),
+                               $this->msg( 'nextpage', str_replace( '_', ' ', $nextRow->page_title ) )->escaped(),
                                [],
                                $query
                        );