From d89deb84668a7883f3100db01ee6272149a3ddd6 Mon Sep 17 00:00:00 2001 From: withoutaname Date: Tue, 8 Jul 2014 01:00:11 -0700 Subject: [PATCH] Enforce some type hinting in Linker class Specifically for link(), linkText(), makeImageLink(), and makeBrokenImageLinkObj() functions Change-Id: I4c397de289ae51bc463b5ae7c2968703d1424368 --- RELEASE-NOTES-1.24 | 3 +++ includes/Linker.php | 21 ++++++++------------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/RELEASE-NOTES-1.24 b/RELEASE-NOTES-1.24 index 20aaad6111..3bef5a09e5 100644 --- a/RELEASE-NOTES-1.24 +++ b/RELEASE-NOTES-1.24 @@ -464,6 +464,9 @@ changes to languages because of Bugzilla reports. and "jquery" modules. In the past, this behavior was undefined, now it will throw an error. * Removed BagOStuff::replace(). (deprecated since 1.23) +* In Linker.php, link(), linkText() and makeBrokenImageLinkObj() now display + warnings if their first parameter is not a Title object. Also makeImageLink() + now requires a Parser as its first parameter. ==== Renamed classes ==== * CLDRPluralRuleConverter_Expression to CLDRPluralRuleConverterExpression diff --git a/includes/Linker.php b/includes/Linker.php index 012bc1ba64..be850d02fa 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -192,11 +192,11 @@ class Linker { public static function link( $target, $html = null, $customAttribs = array(), $query = array(), $options = array() ) { - wfProfileIn( __METHOD__ ); if ( !$target instanceof Title ) { - wfProfileOut( __METHOD__ ); + wfWarn( __METHOD__ . ': Requires $target to be a Title object.' ); return "$html"; } + wfProfileIn( __METHOD__ ); if ( is_string( $query ) ) { // some functions withing core using this still hand over query strings @@ -380,11 +380,10 @@ class Linker { * @return string */ private static function linkText( $target ) { - // We might be passed a non-Title by make*LinkObj(). Fail gracefully. if ( !$target instanceof Title ) { + wfWarn( __METHOD__ . ': Requires $target to be a Title object.' ); return ''; } - // If the target is just a fragment, with no title, we return the fragment // text. Otherwise, we return the title text itself. if ( $target->getPrefixedText() === '' && $target->hasFragment() ) { @@ -544,7 +543,7 @@ class Linker { * @since 1.20 * @return string HTML for an image, with links, wrappers, etc. */ - public static function makeImageLink( /*Parser*/ $parser, Title $title, + public static function makeImageLink( Parser $parser, Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "", $widthOption = null ) { @@ -637,13 +636,7 @@ class Linker { # If a thumbnail width has not been provided, it is set # to the default user option as specified in Language*.php if ( $fp['align'] == '' ) { - if ( $parser instanceof Parser ) { - $fp['align'] = $parser->getTargetLanguage()->alignEnd(); - } else { - # backwards compatibility, remove with makeImageLink2() - global $wgContLang; - $fp['align'] = $wgContLang->alignEnd(); - } + $fp['align'] = $parser->getTargetLanguage()->alignEnd(); } return $prefix . self::makeThumbLink2( $title, $file, $fp, $hp, $time, $query ) . $postfix; } @@ -932,10 +925,12 @@ class Linker { public static function makeBrokenImageLinkObj( $title, $label = '', $query = '', $unused1 = '', $unused2 = '', $time = false ) { - global $wgEnableUploads, $wgUploadMissingFileUrl, $wgUploadNavigationUrl; if ( !$title instanceof Title ) { + wfWarn( __METHOD__ . ': Requires $title to be a Title object.' ); return "" . htmlspecialchars( $label ); } + + global $wgEnableUploads, $wgUploadMissingFileUrl, $wgUploadNavigationUrl; wfProfileIn( __METHOD__ ); if ( $label == '' ) { $label = $title->getPrefixedText(); -- 2.20.1