r111342 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111341‎ | r111342 | r111343 >
Date:00:19, 13 February 2012
Author:bawolff
Status:resolved (Comments)
Tags:
Comment:
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
(<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.
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/DeprecatedGlobal.php (added) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -1002,12 +1002,13 @@
10031003 * Throws a warning that $function is deprecated
10041004 *
10051005 * @param $function String
1006 - * @param $version String|bool: Added in 1.19.
 1006+ * @param $version String|bool: Version of MediaWiki that the function was deprecated in (Added in 1.19).
10071007 * @param $component String|bool: Added in 1.19.
 1008+ * @param $callerOffset integer: How far up the callstack is the original caller (Added in 1.20)
10081009 *
10091010 * @return null
10101011 */
1011 -function wfDeprecated( $function, $version = false, $component = false ) {
 1012+function wfDeprecated( $function, $version = false, $component = false, $callerOffset = 2 ) {
10121013 static $functionsWarned = array();
10131014
10141015 MWDebug::deprecated( $function, $version, $component );
@@ -1032,9 +1033,9 @@
10331034 }
10341035
10351036 $component = $component === false ? 'MediaWiki' : $component;
1036 - wfWarn( "Use of $function was deprecated in $component $version.", 2 );
 1037+ wfWarn( "Use of $function was deprecated in $component $version.", $callerOffset );
10371038 } else {
1038 - wfWarn( "Use of $function is deprecated.", 2 );
 1039+ wfWarn( "Use of $function is deprecated.", $callerOffset );
10391040 }
10401041 }
10411042 }
Index: trunk/phase3/includes/AutoLoader.php
@@ -53,6 +53,7 @@
5454 'DBDataObject' => 'includes/DBDataObject.php',
5555 'DeferrableUpdate' => 'includes/DeferredUpdates.php',
5656 'DeferredUpdates' => 'includes/DeferredUpdates.php',
 57+ 'DeprecatedGlobal' => 'includes/DeprecatedGlobal.php',
5758 'DerivativeRequest' => 'includes/WebRequest.php',
5859 'DiffHistoryBlob' => 'includes/HistoryBlob.php',
5960
Index: trunk/phase3/includes/Wiki.php
@@ -272,7 +272,7 @@
273273 * @deprecated since 1.18
274274 */
275275 global $wgArticle;
276 - $wgArticle = $article;
 276+ $wgArticle = new DeprecatedGlobal( 'wgArticle', $article, '1.18' );
277277
278278 $this->performAction( $article );
279279 } elseif ( is_string( $article ) ) {
Index: trunk/phase3/includes/DeprecatedGlobal.php
@@ -0,0 +1,22 @@
 2+<?php
 3+/**
 4+ * Class to allow throwing wfDeprecated warnings
 5+ * when people use globals that we do not want them to.
 6+ * (For example like $wgArticle)
 7+ */
 8+
 9+class DeprecatedGlobal extends StubObject {
 10+ // The m's are to stay consistent with parent class.
 11+ protected $mRealValue, $mVersion;
 12+
 13+ function __construct( $name, $realValue, $version = false ) {
 14+ parent::__construct( $name );
 15+ $this->mRealValue = $realValue;
 16+ $this->mVersion = $version;
 17+ }
 18+
 19+ function _newObject() {
 20+ wfDeprecated( '$' . $this->mGlobal, $this->mVersion, false, 6 );
 21+ return $this->mRealValue;
 22+ }
 23+}
Property changes on: trunk/phase3/includes/DeprecatedGlobal.php
___________________________________________________________________
Added: svn:eol-style
124 + native

Sign-offs

UserFlagDate
Nikerabbitinspected07:25, 13 February 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r111415follow-up r111342. Document the callerOffset paramter being used per CR.bawolff20:29, 13 February 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111168GOOD BYE $wgArticle!...ialex17:00, 10 February 2012

Comments

#Comment by Aaron Schulz (talk | contribs)   18:06, 13 February 2012

wfDeprecated( '$' . $this->mGlobal, $this->mVersion, false, 6 );

These needs a code comment to explain the 6. Interesting that there *is* a comment to explain the 'm' prefixes.

Status & tagging log