Enforce some type hinting in Linker class
authorwithoutaname <drevitchi@gmail.com>
Tue, 8 Jul 2014 08:00:11 +0000 (01:00 -0700)
committerwithoutaname <drevitchi@gmail.com>
Tue, 16 Sep 2014 01:55:57 +0000 (18:55 -0700)
Specifically for link(), linkText(), makeImageLink(),
and makeBrokenImageLinkObj() functions

Change-Id: I4c397de289ae51bc463b5ae7c2968703d1424368

RELEASE-NOTES-1.24
includes/Linker.php

index 20aaad6..3bef5a0 100644 (file)
@@ -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
index 012bc1b..be850d0 100644 (file)
@@ -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 "<!-- ERROR -->$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 "<!-- ERROR -->" . htmlspecialchars( $label );
                }
+
+               global $wgEnableUploads, $wgUploadMissingFileUrl, $wgUploadNavigationUrl;
                wfProfileIn( __METHOD__ );
                if ( $label == '' ) {
                        $label = $title->getPrefixedText();