Give a warning when people use $wgArticle. Add's a class that can be used to give...
authorBrian Wolff <bawolff@users.mediawiki.org>
Mon, 13 Feb 2012 00:19:06 +0000 (00:19 +0000)
committerBrian Wolff <bawolff@users.mediawiki.org>
Mon, 13 Feb 2012 00:19:06 +0000 (00:19 +0000)
See discussion on r111168.

Of course no one will see warning because trunk has $wgDeprecationReleaseLimit set to 1.17 by default
(<rant>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</rant>)

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
includes/DeprecatedGlobal.php [new file with mode: 0644]
includes/GlobalFunctions.php
includes/Wiki.php

index 856b3e5..90216c8 100644 (file)
@@ -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 (file)
index 0000000..6f3cdbd
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+/**
+ * Class to allow throwing wfDeprecated warnings
+ * when people use globals that we do not want them to.
+ * (For example like $wgArticle)
+ */
+
+class DeprecatedGlobal extends StubObject {
+        // The m's are to stay consistent with parent class.
+       protected $mRealValue, $mVersion;
+
+       function __construct( $name, $realValue, $version = false ) {
+               parent::__construct( $name );
+               $this->mRealValue = $realValue;
+               $this->mVersion = $version;
+       }
+
+       function _newObject() {
+               wfDeprecated( '$' . $this->mGlobal, $this->mVersion, false, 6 );
+               return $this->mRealValue;
+       }
+}
index dca4e14..0e31de5 100644 (file)
@@ -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 );
                }
        }
 }
index 04a6eb3..b20cb95 100644 (file)
@@ -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 ) ) {