option to strip requested prefix index in the list
authorAntoine Musso <hashar@free.fr>
Wed, 3 Jul 2013 19:49:29 +0000 (21:49 +0200)
committerAntoine Musso <hashar@free.fr>
Wed, 24 Jul 2013 20:41:04 +0000 (22:41 +0200)
[[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
includes/specials/SpecialPrefixindex.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index 9ba8f5b..68e14dc 100644 (file)
@@ -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
index 1322d54..f2efd0f 100644 (file)
  * @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() ) .
                        "</td>
                        </tr>";
@@ -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 ? '<div class="allpagesredirect">' : '' ) .
                                                        Linker::linkKnown(
                                                                $t,
-                                                               htmlspecialchars( $t->getText() ),
+                                                               htmlspecialchars( $displayed ),
                                                                $s->page_is_redirect ? array( 'class' => 'mw-redirect' ) : array()
                                                        ) .
                                                        ( $s->page_is_redirect ? '</div>' : '' );
index a26b7cf..3bf18ca 100644 (file)
@@ -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
index 272dd8a..7772843 100644 (file)
@@ -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}}',
index c1af4aa..7adcdeb 100644 (file)
@@ -1807,6 +1807,7 @@ $wgMessageStructure = array(
                'prefixindex',
                'prefixindex-namespace',
                'prefixindex-summary',
+               'prefixindex-strip',
                'shortpages',
                'shortpages-summary',
                'longpages',