From d5b26e049a031ec9fcfc06ed12ee0931094a8902 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Mon, 13 Feb 2012 00:19:06 +0000 Subject: [PATCH] Give a warning when people use $wgArticle. Add's a class that can be used to give warnings for other globals too. See discussion on r111168. Of course no one will see warning because trunk has $wgDeprecationReleaseLimit set to 1.17 by default (have I mentioned how I don't like that variable. People enable warnings to be *warned* about things. Making it so people won't get warned about things until a couple months after we've decided people should stop using function/interface/etc defeats the purpose of having warnings) p.s. Wasn't sure if this waranted something in the release notes, I don't think it does (It's just adding a warning) but wasn't sure. --- includes/AutoLoader.php | 1 + includes/DeprecatedGlobal.php | 22 ++++++++++++++++++++++ includes/GlobalFunctions.php | 9 +++++---- includes/Wiki.php | 2 +- 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 includes/DeprecatedGlobal.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 856b3e513e..90216c807e 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -53,6 +53,7 @@ $wgAutoloadLocalClasses = array( 'DBDataObject' => 'includes/DBDataObject.php', 'DeferrableUpdate' => 'includes/DeferredUpdates.php', 'DeferredUpdates' => 'includes/DeferredUpdates.php', + 'DeprecatedGlobal' => 'includes/DeprecatedGlobal.php', 'DerivativeRequest' => 'includes/WebRequest.php', 'DiffHistoryBlob' => 'includes/HistoryBlob.php', diff --git a/includes/DeprecatedGlobal.php b/includes/DeprecatedGlobal.php new file mode 100644 index 0000000000..6f3cdbd2f2 --- /dev/null +++ b/includes/DeprecatedGlobal.php @@ -0,0 +1,22 @@ +mRealValue = $realValue; + $this->mVersion = $version; + } + + function _newObject() { + wfDeprecated( '$' . $this->mGlobal, $this->mVersion, false, 6 ); + return $this->mRealValue; + } +} diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index dca4e141f9..0e31de51ac 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1002,12 +1002,13 @@ function wfLogDBError( $text ) { * Throws a warning that $function is deprecated * * @param $function String - * @param $version String|bool: Added in 1.19. + * @param $version String|bool: Version of MediaWiki that the function was deprecated in (Added in 1.19). * @param $component String|bool: Added in 1.19. + * @param $callerOffset integer: How far up the callstack is the original caller (Added in 1.20) * * @return null */ -function wfDeprecated( $function, $version = false, $component = false ) { +function wfDeprecated( $function, $version = false, $component = false, $callerOffset = 2 ) { static $functionsWarned = array(); MWDebug::deprecated( $function, $version, $component ); @@ -1032,9 +1033,9 @@ function wfDeprecated( $function, $version = false, $component = false ) { } $component = $component === false ? 'MediaWiki' : $component; - wfWarn( "Use of $function was deprecated in $component $version.", 2 ); + wfWarn( "Use of $function was deprecated in $component $version.", $callerOffset ); } else { - wfWarn( "Use of $function is deprecated.", 2 ); + wfWarn( "Use of $function is deprecated.", $callerOffset ); } } } diff --git a/includes/Wiki.php b/includes/Wiki.php index 04a6eb33e6..b20cb95837 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -272,7 +272,7 @@ class MediaWiki { * @deprecated since 1.18 */ global $wgArticle; - $wgArticle = $article; + $wgArticle = new DeprecatedGlobal( 'wgArticle', $article, '1.18' ); $this->performAction( $article ); } elseif ( is_string( $article ) ) { -- 2.20.1