From 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Dec 2013 09:55:49 +0100 Subject: Update to MediaWiki 1.22.0 --- includes/specials/SpecialPrefixindex.php | 147 +++++++++++++++++++------------ 1 file changed, 89 insertions(+), 58 deletions(-) (limited to 'includes/specials/SpecialPrefixindex.php') diff --git a/includes/specials/SpecialPrefixindex.php b/includes/specials/SpecialPrefixindex.php index 6affa735..28d07ffc 100644 --- a/includes/specials/SpecialPrefixindex.php +++ b/includes/specials/SpecialPrefixindex.php @@ -27,6 +27,15 @@ * @ingroup SpecialPage */ class SpecialPrefixindex extends SpecialAllpages { + + /** + * Whether to remove the searched prefix from the displayed link. Useful + * for inclusion of a set of sub pages in a root page. + */ + protected $stripPrefix = false; + + protected $hideRedirects = false; + // Inherit $maxPerPage function __construct() { @@ -52,7 +61,8 @@ class SpecialPrefixindex extends SpecialAllpages { $prefix = $request->getVal( 'prefix', '' ); $ns = $request->getIntOrNull( 'namespace' ); $namespace = (int)$ns; // if no namespace given, use 0 (NS_MAIN). - $hideredirects = $request->getBool( 'hideredirects', false ); + $this->hideRedirects = $request->getBool( 'hideredirects', $this->hideRedirects ); + $this->stripPrefix = $request->getBool( 'stripprefix', $this->stripPrefix ); $namespaces = $wgContLang->getNamespaces(); $out->setPageTitle( @@ -62,11 +72,11 @@ class SpecialPrefixindex extends SpecialAllpages { ); $showme = ''; - if( isset( $par ) ) { + if ( isset( $par ) ) { $showme = $par; - } elseif( $prefix != '' ) { + } elseif ( $prefix != '' ) { $showme = $prefix; - } elseif( $from != '' && $ns === null ) { + } 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; @@ -74,9 +84,9 @@ class SpecialPrefixindex extends SpecialAllpages { // Bug 27864: if transcluded, show all pages instead of the form. if ( $this->including() || $showme != '' || $ns !== null ) { - $this->showPrefixChunk( $namespace, $showme, $from, $hideredirects ); + $this->showPrefixChunk( $namespace, $showme, $from ); } else { - $out->addHTML( $this->namespacePrefixForm( $namespace, null, $hideredirects ) ); + $out->addHTML( $this->namespacePrefixForm( $namespace, null ) ); } } @@ -84,10 +94,9 @@ class SpecialPrefixindex extends SpecialAllpages { * HTML for the top form * @param $namespace Integer: a namespace constant (default NS_MAIN). * @param string $from dbKey we are starting listing at. - * @param bool $hideredirects hide redirects (default FALSE) * @return string */ - function namespacePrefixForm( $namespace = NS_MAIN, $from = '', $hideredirects = false ) { + protected function namespacePrefixForm( $namespace = NS_MAIN, $from = '' ) { global $wgScript; $out = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) ); @@ -98,37 +107,44 @@ class SpecialPrefixindex extends SpecialAllpages { $out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) ); $out .= " " . - Xml::label( $this->msg( 'allpagesprefix' )->text(), 'nsfrom' ) . - " + Xml::label( $this->msg( 'allpagesprefix' )->text(), 'nsfrom' ) . + " " . - Xml::input( 'prefix', 30, str_replace( '_', ' ', $from ), array( 'id' => 'nsfrom' ) ) . - " + Xml::input( 'prefix', 30, str_replace( '_', ' ', $from ), array( 'id' => 'nsfrom' ) ) . + " - " . - Xml::label( $this->msg( 'namespace' )->text(), 'namespace' ) . - " + " . + Xml::label( $this->msg( 'namespace' )->text(), 'namespace' ) . + " " . - Html::namespaceSelector( array( - 'selected' => $namespace, - ), array( - 'name' => 'namespace', - 'id' => 'namespace', - 'class' => 'namespaceselector', - ) ) . - Xml::checkLabel( - $this->msg( 'allpages-hide-redirects' )->text(), - 'hideredirects', - 'hideredirects', - $hideredirects - ) . ' ' . - Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . - " + Html::namespaceSelector( array( + 'selected' => $namespace, + ), array( + 'name' => 'namespace', + 'id' => 'namespace', + 'class' => 'namespaceselector', + ) ) . + Xml::checkLabel( + $this->msg( 'allpages-hide-redirects' )->text(), + 'hideredirects', + 'hideredirects', + $this->hideRedirects + ) . ' ' . + Xml::checkLabel( + $this->msg( 'prefixindex-strip' )->text(), + 'stripprefix', + 'stripprefix', + $this->stripPrefix + ) . ' ' . + Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . + " "; $out .= Xml::closeElement( 'table' ); $out .= Xml::closeElement( 'fieldset' ); $out .= Xml::closeElement( 'form' ); $out .= Xml::closeElement( 'div' ); + return $out; } @@ -136,9 +152,8 @@ class SpecialPrefixindex extends SpecialAllpages { * @param $namespace Integer, default NS_MAIN * @param $prefix String * @param string $from list all pages from this name (default FALSE) - * @param bool $hideredirects hide redirects (default FALSE) */ - function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null, $hideredirects = false ) { + protected function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null ) { global $wgContLang; if ( $from === null ) { @@ -169,7 +184,7 @@ class SpecialPrefixindex extends SpecialAllpages { 'page_title >= ' . $dbr->addQuotes( $fromKey ), ); - if ( $hideredirects ) { + if ( $this->hideRedirects ) { $conds['page_is_redirect'] = 0; } @@ -178,8 +193,8 @@ class SpecialPrefixindex extends SpecialAllpages { $conds, __METHOD__, array( - 'ORDER BY' => 'page_title', - 'LIMIT' => $this->maxPerPage + 1, + 'ORDER BY' => 'page_title', + 'LIMIT' => $this->maxPerPage + 1, 'USE INDEX' => 'name_title', ) ); @@ -187,34 +202,42 @@ class SpecialPrefixindex extends SpecialAllpages { ### @todo FIXME: Side link to previous $n = 0; - if( $res->numRows() > 0 ) { + if ( $res->numRows() > 0 ) { $out = Xml::openElement( 'table', array( 'id' => 'mw-prefixindex-list-table' ) ); - while( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) { + $prefixLength = strlen( $prefix ); + while ( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) { $t = Title::makeTitle( $s->page_namespace, $s->page_title ); - if( $t ) { - $link = ($s->page_is_redirect ? '
' : '' ) . + 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 ? '
' : '' ) . Linker::linkKnown( $t, - htmlspecialchars( $t->getText() ), + htmlspecialchars( $displayed ), $s->page_is_redirect ? array( 'class' => 'mw-redirect' ) : array() ) . - ($s->page_is_redirect ? '
' : '' ); + ( $s->page_is_redirect ? '
' : '' ); } else { $link = '[[' . htmlspecialchars( $s->page_title ) . ']]'; } - if( $n % 3 == 0 ) { + if ( $n % 3 == 0 ) { $out .= ''; } $out .= "$link"; $n++; - if( $n % 3 == 0 ) { + if ( $n % 3 == 0 ) { $out .= ''; } } - if( ($n % 3) != 0 ) { + + if ( $n % 3 != 0 ) { $out .= ''; } + $out .= Xml::closeElement( 'table' ); } else { $out = ''; @@ -225,37 +248,45 @@ class SpecialPrefixindex extends SpecialAllpages { if ( $this->including() ) { $out2 = ''; } else { - $nsForm = $this->namespacePrefixForm( $namespace, $prefix, $hideredirects ); + $nsForm = $this->namespacePrefixForm( $namespace, $prefix ); $self = $this->getTitle(); $out2 = Xml::openElement( 'table', array( 'id' => 'mw-prefixindex-nav-table' ) ) . ' ' . - $nsForm . - ' - '; + $nsForm . + ' + '; - if( isset( $res ) && $res && ( $n == $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) { + if ( isset( $res ) && $res && ( $n == $this->maxPerPage ) && + ( $s = $res->fetchObject() ) + ) { $query = array( 'from' => $s->page_title, 'prefix' => $prefix, - 'hideredirects' => $hideredirects, + 'hideredirects' => $this->hideRedirects, ); - if( $namespace || $prefix == '' ) { + if ( $namespace || $prefix == '' ) { // Keep the namespace even if it's 0 for empty prefixes. // This tells us we're not just a holdover from old links. $query['namespace'] = $namespace; } + $nextLink = Linker::linkKnown( - $self, - $this->msg( 'nextpage', str_replace( '_', ' ', $s->page_title ) )->escaped(), - array(), - $query - ); + $self, + $this->msg( 'nextpage', str_replace( '_', ' ', $s->page_title ) )->escaped(), + array(), + $query + ); + $out2 .= $nextLink; - $footer = "\n" . Html::element( "hr" ) - . Html::rawElement( "div", array( "class" => "mw-prefixindex-nav" ), $nextLink ); + $footer = "\n" . Html::element( 'hr' ) . + Html::rawElement( + 'div', + array( 'class' => 'mw-prefixindex-nav' ), + $nextLink + ); } $out2 .= "" . Xml::closeElement( 'table' ); -- cgit v1.2.3-54-g00ecf