Nikerabbit has uploaded a new change for review.
https://gerrit.wikimedia.org/r/204505
Change subject: Cleanup linkfix
......................................................................
Cleanup linkfix
Mainly fixing the warning caused by passing null or false to
Title::newFromText.
While at it, update comments and make the code less nested.
Change-Id: Ib611203aee5fc8aea9b50ef1ad9b95592a7146f7
---
M TranslateHooks.php
1 file changed, 27 insertions(+), 19 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate
refs/changes/05/204505/1
diff --git a/TranslateHooks.php b/TranslateHooks.php
index ae8b883..41c2ab1 100644
--- a/TranslateHooks.php
+++ b/TranslateHooks.php
@@ -610,6 +610,9 @@
/**
* Make Special:MyLanguage links red if the target page doesn't exists.
* A bit hacky because the core code is not so flexible.
+ *
+ * Hook: LinkBegin
+ *
* @param $dummy
* @param Title $target
* @param string $html
@@ -617,31 +620,36 @@
* @param array $query
* @param array $options
* @param string|null $ret
- * @return bool
*/
public static function linkfix( $dummy, $target, &$html,
&$customAttribs,
&$query, &$options, &$ret
) {
- if ( $target->getNamespace() == NS_SPECIAL ) {
- list( $name, $subpage ) =
SpecialPageFactory::resolveAlias( $target->getDBkey() );
- if ( $name === 'MyLanguage' ) {
- $realTarget = Title::newFromText( $subpage );
- if ( !$realTarget || !$realTarget->exists() ) {
- $options[] = 'broken';
- $index = array_search( 'known',
$options, true );
- if ( $index !== false ) {
- unset( $options[$index] );
- }
-
- $index = array_search( 'noclasses',
$options, true );
- if ( $index !== false ) {
- unset( $options[$index] );
- }
- }
- }
+ if ( !$target->inNamespace( NS_SPECIAL ) ) {
+ return;
}
- return true;
+ list( $name, $subpage ) = SpecialPageFactory::resolveAlias(
$target->getDBkey() );
+ if ( $name !== 'MyLanguage' ) {
+ return;
+ }
+
+ if ( (string)$subpage === '' ) {
+ return;
+ }
+
+ $realTarget = Title::newFromText( $subpage );
+ if ( !$realTarget || !$realTarget->exists() ) {
+ $options[] = 'broken';
+ $index = array_search( 'known', $options, true );
+ if ( $index !== false ) {
+ unset( $options[$index] );
+ }
+
+ $index = array_search( 'noclasses', $options, true );
+ if ( $index !== false ) {
+ unset( $options[$index] );
+ }
+ }
}
public static function setupTranslateParserFunction( &$parser ) {
--
To view, visit https://gerrit.wikimedia.org/r/204505
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib611203aee5fc8aea9b50ef1ad9b95592a7146f7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits