From b9893a38e1c4c2434561573201d15da58334773b Mon Sep 17 00:00:00 2001 From: mrbluesky Date: Wed, 28 Mar 2012 22:28:31 +0200 Subject: [PATCH] (bug 30963) Option to hide redirects in Allpages and Prefixindex Add an option to SpecialAllpages and SpecialPrefixindex to hide redirects. Change-Id: I335c54f31ef841dd0c2e51a2ec8b17f234308b0e --- RELEASE-NOTES-1.20 | 1 + includes/specials/SpecialAllpages.php | 71 +++++++++++++++++++----- includes/specials/SpecialPrefixindex.php | 52 +++++++++++------ languages/messages/MessagesEn.php | 1 + languages/messages/MessagesQqq.php | 1 + 5 files changed, 95 insertions(+), 31 deletions(-) diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index d300541ec2..6fa5ff4582 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -24,6 +24,7 @@ production. * (bug 23795) Add parser itself to ParserMakeImageParams hook. * Introduce a cryptographic random number generator source api for use when generating various tokens. +* (bug 30963) Option on Special:Prefixindex and Special:Allpages to not show redirects. === Bug fixes in 1.20 === * (bug 30245) Use the correct way to construct a log page title. diff --git a/includes/specials/SpecialAllpages.php b/includes/specials/SpecialAllpages.php index 619f23ddef..bf30dc83d3 100644 --- a/includes/specials/SpecialAllpages.php +++ b/includes/specials/SpecialAllpages.php @@ -30,24 +30,37 @@ class SpecialAllpages extends IncludableSpecialPage { /** * Maximum number of pages to show on single subpage. + * + * @var int $maxPerPage */ protected $maxPerPage = 345; /** * Maximum number of pages to show on single index subpage. + * + * @var int $maxLineCount */ protected $maxLineCount = 100; /** * Maximum number of chars to show for an entry. + * + * @var int $maxPageLength */ protected $maxPageLength = 70; /** * Determines, which message describes the input field 'nsfrom'. + * + * @var string $nsfromMsg */ protected $nsfromMsg = 'allpagesfrom'; + /** + * Constructor + * + * @param $name string: name of the special page, as seen in links and URLs (default: 'Allpages') + */ function __construct( $name = 'Allpages' ){ parent::__construct( $name ); } @@ -70,6 +83,7 @@ class SpecialAllpages extends IncludableSpecialPage { $from = $request->getVal( 'from', null ); $to = $request->getVal( 'to', null ); $namespace = $request->getInt( 'namespace' ); + $hideredirects = $request->getBool( 'hideredirects', false ); $namespaces = $wgContLang->getNamespaces(); @@ -81,11 +95,11 @@ class SpecialAllpages extends IncludableSpecialPage { $out->addModuleStyles( 'mediawiki.special' ); if( $par !== null ) { - $this->showChunk( $namespace, $par, $to ); + $this->showChunk( $namespace, $par, $to, $hideredirects ); } elseif( $from !== null && $to === null ) { - $this->showChunk( $namespace, $from, $to ); + $this->showChunk( $namespace, $from, $to, $hideredirects ); } else { - $this->showToplevel( $namespace, $from, $to ); + $this->showToplevel( $namespace, $from, $to, $hideredirects ); } } @@ -95,9 +109,10 @@ class SpecialAllpages extends IncludableSpecialPage { * @param $namespace Integer: a namespace constant (default NS_MAIN). * @param $from String: dbKey we are starting listing at. * @param $to String: dbKey we are ending listing at. + * @param $hideredirects Bool: dont show redirects (default FALSE) * @return string */ - function namespaceForm( $namespace = NS_MAIN, $from = '', $to = '' ) { + function namespaceForm( $namespace = NS_MAIN, $from = '', $to = '', $hideredirects = false ) { global $wgScript; $t = $this->getTitle(); @@ -132,6 +147,12 @@ class SpecialAllpages extends IncludableSpecialPage { array( 'selected' => $namespace ), array( 'name' => 'namespace', 'id' => 'namespace' ) ) . ' ' . + Xml::checkLabel( + wfMsg( 'allpages-hide-redirects' ), + 'hideredirects', + 'hideredirects', + $hideredirects + ) . ' ' . Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . " "; @@ -146,8 +167,9 @@ class SpecialAllpages extends IncludableSpecialPage { * @param $namespace Integer (default NS_MAIN) * @param $from String: list all pages from this name * @param $to String: list all pages to this name + * @param $hideredirects Bool: dont show redirects (default FALSE) */ - function showToplevel( $namespace = NS_MAIN, $from = '', $to = '' ) { + function showToplevel( $namespace = NS_MAIN, $from = '', $to = '', $hideredirects = false ) { $output = $this->getOutput(); # TODO: Either make this *much* faster or cache the title index points @@ -157,6 +179,10 @@ class SpecialAllpages extends IncludableSpecialPage { $out = ""; $where = array( 'page_namespace' => $namespace ); + if ( $hideredirects ) { + $where[ 'page_is_redirect' ] = 0; + } + $from = Title::makeTitleSafe( $namespace, $from ); $to = Title::makeTitleSafe( $namespace, $to ); $from = ( $from && $from->isLocal() ) ? $from->getDBkey() : null; @@ -225,9 +251,9 @@ class SpecialAllpages extends IncludableSpecialPage { // Instead, display the first section directly. if( count( $lines ) <= 2 ) { if( !empty($lines) ) { - $this->showChunk( $namespace, $from, $to ); + $this->showChunk( $namespace, $from, $to, $hideredirects ); } else { - $output->addHTML( $this->namespaceForm( $namespace, $from, $to ) ); + $output->addHTML( $this->namespaceForm( $namespace, $from, $to, $hideredirects ) ); } return; } @@ -237,10 +263,10 @@ class SpecialAllpages extends IncludableSpecialPage { while( count ( $lines ) > 0 ) { $inpoint = array_shift( $lines ); $outpoint = array_shift( $lines ); - $out .= $this->showline( $inpoint, $outpoint, $namespace ); + $out .= $this->showline( $inpoint, $outpoint, $namespace, $hideredirects ); } $out .= Xml::closeElement( 'table' ); - $nsForm = $this->namespaceForm( $namespace, $from, $to ); + $nsForm = $this->namespaceForm( $namespace, $from, $to, $hideredirects ); # Is there more? if( $this->including() ) { @@ -271,9 +297,10 @@ class SpecialAllpages extends IncludableSpecialPage { * @param $inpoint String: lower limit of pagenames * @param $outpoint String: upper limit of pagenames * @param $namespace Integer (Default NS_MAIN) + * @param $hideredirects Bool: dont show redirects (default FALSE) * @return string */ - function showline( $inpoint, $outpoint, $namespace = NS_MAIN ) { + function showline( $inpoint, $outpoint, $namespace = NS_MAIN, $hideredirects ) { global $wgContLang; $inpointf = htmlspecialchars( str_replace( '_', ' ', $inpoint ) ); $outpointf = htmlspecialchars( str_replace( '_', ' ', $outpoint ) ); @@ -282,8 +309,14 @@ class SpecialAllpages extends IncludableSpecialPage { $outpointf = $wgContLang->truncate( $outpointf, $this->maxPageLength ); $queryparams = $namespace ? "namespace=$namespace&" : ''; + + $queryhideredirects = array(); + if ($hideredirects) { + $queryhideredirects[ 'hideredirects' ] = 1; + } + $special = $this->getTitle(); - $link = htmlspecialchars( $special->getLocalUrl( $queryparams . 'from=' . urlencode($inpoint) . '&to=' . urlencode($outpoint) ) ); + $link = htmlspecialchars( $special->getLocalUrl( $queryparams . 'from=' . urlencode($inpoint) . '&to=' . urlencode($outpoint), $queryhideredirects ) ); $out = $this->msg( 'alphaindexline' )->rawParams( "$inpointf", @@ -296,8 +329,9 @@ class SpecialAllpages extends IncludableSpecialPage { * @param $namespace Integer (Default NS_MAIN) * @param $from String: list all pages from this name (default FALSE) * @param $to String: list all pages to this name (default FALSE) + * @param $hideredirects Bool: dont show redirects (default FALSE) */ - function showChunk( $namespace = NS_MAIN, $from = false, $to = false ) { + function showChunk( $namespace = NS_MAIN, $from = false, $to = false, $hideredirects = false ) { global $wgContLang; $output = $this->getOutput(); @@ -321,6 +355,11 @@ class SpecialAllpages extends IncludableSpecialPage { 'page_namespace' => $namespace, 'page_title >= ' . $dbr->addQuotes( $fromKey ) ); + + if ( $hideredirects ) { + $conds[ 'page_is_redirect' ] = 0; + } + if( $toKey !== "" ) { $conds[] = 'page_title <= ' . $dbr->addQuotes( $toKey ); } @@ -408,7 +447,7 @@ class SpecialAllpages extends IncludableSpecialPage { $self = $this->getTitle(); - $nsForm = $this->namespaceForm( $namespace, $from, $to ); + $nsForm = $this->namespaceForm( $namespace, $from, $to, $hideredirects ); $out2 = Xml::openElement( 'table', array( 'class' => 'mw-allpages-table-form' ) ). ' ' . @@ -424,6 +463,9 @@ class SpecialAllpages extends IncludableSpecialPage { if( $namespace ) $query['namespace'] = $namespace; + if( $hideredirects ) + $query['hideredirects'] = $hideredirects; + $prevLink = Linker::linkKnown( $self, $this->msg( 'prevpage', $pt )->escaped(), @@ -441,6 +483,9 @@ class SpecialAllpages extends IncludableSpecialPage { if( $namespace ) $query['namespace'] = $namespace; + if( $hideredirects ) + $query['hideredirects'] = $hideredirects; + $nextLink = Linker::linkKnown( $self, $this->msg( 'nextpage', $t->getText() )->escaped(), diff --git a/includes/specials/SpecialPrefixindex.php b/includes/specials/SpecialPrefixindex.php index 3202c00966..fca1748ec6 100644 --- a/includes/specials/SpecialPrefixindex.php +++ b/includes/specials/SpecialPrefixindex.php @@ -52,6 +52,7 @@ 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 ); $namespaces = $wgContLang->getNamespaces(); $out->setPageTitle( @@ -73,19 +74,20 @@ 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 ); + $this->showPrefixChunk( $namespace, $showme, $from, $hideredirects ); } else { - $out->addHTML( $this->namespacePrefixForm( $namespace, null ) ); + $out->addHTML( $this->namespacePrefixForm( $namespace, null, $hideredirects ) ); } } /** - * HTML for the top form - * @param $namespace Integer: a namespace constant (default NS_MAIN). - * @param $from String: dbKey we are starting listing at. + * HTML for the top form + * @param $namespace Integer: a namespace constant (default NS_MAIN). + * @param $from String: dbKey we are starting listing at. + * @param $hideredirects Bool: hide redirects (default FALSE) * @return string */ - function namespacePrefixForm( $namespace = NS_MAIN, $from = '' ) { + function namespacePrefixForm( $namespace = NS_MAIN, $from = '', $hideredirects = false ) { global $wgScript; $out = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) ); @@ -107,16 +109,22 @@ class SpecialPrefixindex extends SpecialAllpages { Xml::label( wfMsg( 'namespace' ), 'namespace' ) . " " . - Html::namespaceSelector( array( + Html::namespaceSelector( array( 'selected' => $namespace, ), array( 'name' => 'namespace', 'id' => 'namespace', 'class' => 'namespaceselector', - ) ) . - Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . + ) ) . + Xml::checkLabel( + wfMsg( 'allpages-hide-redirects' ), + 'hideredirects', + 'hideredirects', + $hideredirects + ) . ' ' . + Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . " - "; + "; $out .= Xml::closeElement( 'table' ); $out .= Xml::closeElement( 'fieldset' ); $out .= Xml::closeElement( 'form' ); @@ -128,8 +136,9 @@ class SpecialPrefixindex extends SpecialAllpages { * @param $namespace Integer, default NS_MAIN * @param $prefix String * @param $from String: list all pages from this name (default FALSE) + * @param $hideredirects Bool: hide redirects (default FALSE) */ - function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null ) { + function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null, $hideredirects = false ) { global $wgContLang; if ( $from === null ) { @@ -154,13 +163,19 @@ class SpecialPrefixindex extends SpecialAllpages { $dbr = wfGetDB( DB_SLAVE ); + $conds = array( + 'page_namespace' => $namespace, + 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ), + 'page_title >= ' . $dbr->addQuotes( $fromKey ), + ); + + if ( $hideredirects ) { + $conds['page_is_redirect'] = 0; + } + $res = $dbr->select( 'page', array( 'page_namespace', 'page_title', 'page_is_redirect' ), - array( - 'page_namespace' => $namespace, - 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ), - 'page_title >= ' . $dbr->addQuotes( $fromKey ), - ), + $conds, __METHOD__, array( 'ORDER BY' => 'page_title', @@ -209,7 +224,7 @@ class SpecialPrefixindex extends SpecialAllpages { if ( $this->including() ) { $out2 = ''; } else { - $nsForm = $this->namespacePrefixForm( $namespace, $prefix ); + $nsForm = $this->namespacePrefixForm( $namespace, $prefix, $hideredirects ); $self = $this->getTitle(); $out2 = Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) ) . ' @@ -221,7 +236,8 @@ class SpecialPrefixindex extends SpecialAllpages { if( isset( $res ) && $res && ( $n == $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) { $query = array( 'from' => $s->page_title, - 'prefix' => $prefix + 'prefix' => $prefix, + 'hideredirects' => $hideredirects, ); if( $namespace || ($prefix == '')) { diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 685b7a7e68..2f3cc1215a 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2664,6 +2664,7 @@ You can narrow down the view by selecting a log type, the username (case-sensiti 'allpagesbadtitle' => 'The given page title was invalid or had an inter-language or inter-wiki prefix. It may contain one or more characters which cannot be used in titles.', 'allpages-bad-ns' => '{{SITENAME}} does not have namespace "$1".', +'allpages-hide-redirects' => 'Hide redirects', # Special:Categories 'categories' => 'Categories', diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index edfe52e72d..0f57a4e505 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -2347,6 +2347,7 @@ The title is {{msg-mw|nopagetitle}}.', {{Identical|Go}}', 'allpagesprefix' => "Used for the label of the input box of [[Special:PrefixIndex]]. On this page you can either write 'Name of namespace:string from which to begin display in alphabetical order' in the top box, or you can choose a namespace in the bottom box and put 'string from which to begin display in alphabetical order' in the top box. The result will be the same.", +'allpages-hide-redirects' => 'Label for a checkbox. If the checkbox is checked redirects will not be shown in the list. Used in [[Special:PrefixIndex]] and [[Special:Allpages]].', # SpecialCachedPage 'cachedspecial-viewing-cached-ttl' => 'Message notifying they are viewing a cached page. $1 is a duration (ie "1 hour and 30 minutes")', -- 2.20.1