From f804a35bb83d9ed301b67e142bb43240d8cb2e38 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Wed, 3 Jul 2013 21:49:29 +0200 Subject: [PATCH] option to strip requested prefix index in the list [[Special:PrefixIndex]] could be transcluded to generate a dynamic list of pages. Since all pages share the same prefix, it is not always wanted, specially when looking for subpages. Given articles named: - Project/Alix - Project/FixBug20281 - Project/S3cretPlan - Projects roadmap {{Special:PrefixIndex/Project}} yields: Project/Alix Project/FixBug20281 Project/S3cretPlan Projects roadmap Adding |stripprefix=1 get rid of the prefix: {{Special:PrefixIndex/Project|stripprefix=1}} /Alix /FixBug20281 /S3cretPlan s roadmap {{Special:PrefixIndex/Project/|stripprefix=1}} Alix FixBug20281 S3cretPlan The patch adds a checkbox to activate the prefix stripping. For the implementation, I have chosen a protected class property instead of adding parameters to various methods. That seems easier to handle. Change-Id: I96a0a08ea11a82016eb382abbeb2d54bfc2c4016 --- RELEASE-NOTES-1.22 | 4 ++++ includes/specials/SpecialPrefixindex.php | 21 ++++++++++++++++++++- languages/messages/MessagesEn.php | 1 + languages/messages/MessagesQqq.php | 1 + maintenance/language/messages.inc | 1 + 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index 9ba8f5b2b2..68e14dc7b1 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -154,6 +154,10 @@ production. * (bug 21912) Watchlist token implementation has been refactored and Special:ResetTokens was added to allow users to reset their tokens instead of presenting them in Preferences. +* Special:PrefixIndex now lets you strip the searched prefix from the displayed + titles. Given a list of articles named Bug1, Bug2, you can now transclude the + list of bug numbers using: {{Special:PrefixIndex/Bug|stripprefix=1}}. + The special page form received a new checkbox matching that option. === Bug fixes in 1.22 === * Disable Special:PasswordReset when $wgEnableEmail is false. Previously one diff --git a/includes/specials/SpecialPrefixindex.php b/includes/specials/SpecialPrefixindex.php index 1322d546fe..f2efd0f4a2 100644 --- a/includes/specials/SpecialPrefixindex.php +++ b/includes/specials/SpecialPrefixindex.php @@ -27,6 +27,13 @@ * @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; + // Inherit $maxPerPage function __construct() { @@ -53,6 +60,7 @@ class SpecialPrefixindex extends SpecialAllpages { $ns = $request->getIntOrNull( 'namespace' ); $namespace = (int)$ns; // if no namespace given, use 0 (NS_MAIN). $hideredirects = $request->getBool( 'hideredirects', false ); + $this->stripPrefix = $request->getBool( 'stripprefix', $this->stripPrefix ); $namespaces = $wgContLang->getNamespaces(); $out->setPageTitle( @@ -122,6 +130,12 @@ class SpecialPrefixindex extends SpecialAllpages { 'hideredirects', $hideredirects ) . ' ' . + Xml::checkLabel( + $this->msg( 'prefixindex-strip' )->text(), + 'stripprefix', + 'stripprefix', + $this->stripPrefix + ) . ' ' . Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . " "; @@ -191,13 +205,18 @@ class SpecialPrefixindex extends SpecialAllpages { if ( $res->numRows() > 0 ) { $out = Xml::openElement( 'table', array( 'id' => 'mw-prefixindex-list-table' ) ); + $prefixLength = strlen( $prefix ); while ( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) { $t = Title::makeTitle( $s->page_namespace, $s->page_title ); if ( $t ) { + $displayed = $t->getText(); + if ( $this->stripPrefix ) { + $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 ? '
' : '' ); diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index a26b7cf9c1..3bf18caaaf 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2745,6 +2745,7 @@ It now redirects to [[$2]].', 'mostrevisions-summary' => '', # do not translate or duplicate this message to other languages 'prefixindex' => 'All pages with prefix', 'prefixindex-namespace' => 'All pages with prefix ($1 namespace)', +'prefixindex-strip' => 'Strip prefix in list', 'prefixindex-summary' => '', # do not translate or duplicate this message to other languages 'shortpages' => 'Short pages', 'shortpages-summary' => '', # do not translate or duplicate this message to other languages diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index 272dd8a901..7772843961 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -4200,6 +4200,7 @@ $1 is a page title", 'prefixindex' => '{{doc-special|PrefixIndex}} When the user limits the list to a certain namespace, {{msg-mw|allinnamespace}} is used instead.', 'prefixindex-namespace' => 'The page title of [[Special:PrefixIndex]] limited to a specific namespace. Similar to {{msg-mw|allinnamespace}}. $1 is the name of the namespace', +'prefixindex-strip' => 'Label for a checkbox. If the checkbox is checked, the prefix searched will be removed from the title displayed in the list. Used in [[Special:PrefixIndex]].', 'shortpages' => '{{doc-special|ShortPages}}', 'longpages' => '{{doc-special|LongPages}}', 'deadendpages' => '{{doc-special|DeadendPages}}', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index c1af4aa89a..7adcdeb170 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1807,6 +1807,7 @@ $wgMessageStructure = array( 'prefixindex', 'prefixindex-namespace', 'prefixindex-summary', + 'prefixindex-strip', 'shortpages', 'shortpages-summary', 'longpages', -- 2.20.1