Added Linker::getInvalidTitleDescription() to display invalid title entries in variou...
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Tue, 10 Apr 2012 09:28:48 +0000 (11:28 +0200)
committerAlexandre Emsenhuber <ialex.wiki@gmail.com>
Mon, 7 May 2012 16:25:52 +0000 (18:25 +0200)
This method will use two new messages 'invalidtitle-knownnamespace' and 'invalidtitle-unknownnamespace' depending on the fact that the given namespace number exists or not.
I did put that method in Linker because I plan to use it in various places, notably in other QueryPage and Pager subclasses.

Change-Id: I13e7cdc2c0a8e86dc5e4b144b6012f3864d2ec06

includes/Linker.php
includes/PageQueryPage.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index 918bebc..2d01d06 100644 (file)
@@ -397,6 +397,31 @@ class Linker {
                return "<strong class=\"selflink\">{$prefix}{$html}{$inside}</strong>{$trail}";
        }
 
+       /**
+        * Get a message saying that an invalid title was encountered.
+        * This should be called after a method like Title::makeTitleSafe() returned
+        * a value indicating that the title object is invalid.
+        *
+        * @param $context IContextSource context to use to get the messages
+        * @param $namespace int Namespace number
+        * @param $title string Text of the title, without the namespace part
+        */
+       public static function getInvalidTitleDescription( IContextSource $context, $namespace, $title ) {
+               global $wgContLang;
+
+               // First we check whether the namespace exists or not.
+               if ( MWNamespace::exists( $namespace ) ) {
+                       if ( $namespace == NS_MAIN ) {
+                               $name = $context->msg( 'blanknamespace' )->text();
+                       } else {
+                               $name = $wgContLang->getFormattedNsText( $namespace );
+                       }
+                       return $context->msg( 'invalidtitle-knownnamespace', $namespace, $name, $title )->text();
+               } else {
+                       return $context->msg( 'invalidtitle-unknownnamespace', $namespace, $title )->text();
+               }
+       }
+
        /**
         * @param $title Title
         * @return Title
index dc5e971..367f387 100644 (file)
@@ -16,11 +16,15 @@ abstract class PageQueryPage extends QueryPage {
         */
        public function formatResult( $skin, $row ) {
                global $wgContLang;
+
                $title = Title::makeTitleSafe( $row->namespace, $row->title );
-               $text = $row->title;
+
                if ( $title instanceof Title ) {
                        $text = $wgContLang->convert( $title->getPrefixedText() );
+                       return Linker::linkKnown( $title, htmlspecialchars( $text ) );
+               } else {
+                       return Html::element( 'span', array( 'class' => 'mw-invalidtitle' ),
+                               Linker::getInvalidTitleDescription( $this->getContext(), $row->namespace, $row->title ) );
                }
-               return Linker::linkKnown( $title, htmlspecialchars( $text ) );
        }
 }
index bb08078..5c91d3c 100644 (file)
@@ -1039,6 +1039,8 @@ The reason given is "\'\'$2\'\'".',
 'filereadonlyerror'    => 'Unable to modify the file "$1" because the file repository "$2" is in read-only mode.
 
 The administrator who locked it offered this explanation: "$3".',
+'invalidtitle-knownnamespace'   => 'Invalid title with namespace "$2" and text "$3"',
+'invalidtitle-unknownnamespace' => 'Invalid title with unknown namespace number $1 and text "$2"',
 
 # Virus scanner
 'virus-badscanner'     => "Bad configuration: Unknown virus scanner: ''$1''",
index e4f9ca7..a244fec 100644 (file)
@@ -683,6 +683,13 @@ $1 is a filename, I think.',
 'editinginterface' => "A message shown when editing pages in the namespace MediaWiki:. In the [http://translatewiki.net/wiki/Main_Page?setlang=en URL], '''change \"setlang=en\" to your own language code.'''",
 'ns-specialprotected' => 'Error message displayed when trying to edit a page in the Special namespace',
 'titleprotected' => 'Use $1 for GENDER.',
+'invalidtitle-knownnamespace' => 'Displayed when an invalid title was encountered (generally in a list), but the namespace number is known to exist.
+* $1 is the namespace number
+* $2 is the namespace name in content language or {{msg-mw|blanknamespace}} for the main namespace
+* $3 is the part of the title after the namespace (e.g. SomeName for the page User:SomeName)',
+'invalidtitle-unknownnamespace' => 'Displayed when an invalid title was encountered (generally in a list) and the namespace number is unknown.
+* $1 is the namespace number
+* $2 is the part of the title after the namespace (e.g. SomeName for the page User:SomeName)',
 
 # Login and logout pages
 'logouttext' => 'Log out message',
index d22449b..b43be00 100644 (file)
@@ -408,7 +408,9 @@ $wgMessageStructure = array(
                'customjsprotected',
                'ns-specialprotected',
                'titleprotected',
-               'filereadonlyerror'
+               'filereadonlyerror',
+               'invalidtitle-knownnamespace',
+               'invalidtitle-unknownnamespace',
        ),
        'virus' => array(
                'virus-badscanner',