From d3fecf5ac6b72f3229dce611add2e2871b82cbdf Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Tue, 10 Apr 2012 11:28:48 +0200 Subject: [PATCH] Added Linker::getInvalidTitleDescription() to display invalid title entries in various places. 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 | 25 +++++++++++++++++++++++++ includes/PageQueryPage.php | 8 ++++++-- languages/messages/MessagesEn.php | 2 ++ languages/messages/MessagesQqq.php | 7 +++++++ maintenance/language/messages.inc | 4 +++- 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index 918bebcd83..2d01d061f9 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -397,6 +397,31 @@ class Linker { return "{$prefix}{$html}{$inside}{$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 diff --git a/includes/PageQueryPage.php b/includes/PageQueryPage.php index dc5e971d1b..367f387e9e 100644 --- a/includes/PageQueryPage.php +++ b/includes/PageQueryPage.php @@ -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 ) ); } } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index bb080780fd..5c91d3cd2f 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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''", diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index e4f9ca7f25..a244fec2b0 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -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', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index d22449b8c3..b43be006a5 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -408,7 +408,9 @@ $wgMessageStructure = array( 'customjsprotected', 'ns-specialprotected', 'titleprotected', - 'filereadonlyerror' + 'filereadonlyerror', + 'invalidtitle-knownnamespace', + 'invalidtitle-unknownnamespace', ), 'virus' => array( 'virus-badscanner', -- 2.20.1