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
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
*/
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 ) );
}
}
'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''",
'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',
'customjsprotected',
'ns-specialprotected',
'titleprotected',
- 'filereadonlyerror'
+ 'filereadonlyerror',
+ 'invalidtitle-knownnamespace',
+ 'invalidtitle-unknownnamespace',
),
'virus' => array(
'virus-badscanner',