Add support for a second argument to wfDeprecated so we can start using it right away and let users limit what warnings they get if they need to, instead of delaying warnings for an entire release or more.

This commit is contained in:
Daniel Friesen 2011-09-15 02:10:44 +00:00
parent 3088982d20
commit 738e98cc56
2 changed files with 26 additions and 2 deletions

View file

@ -4039,6 +4039,13 @@ $wgShowHostnames = false;
*/
$wgDevelopmentWarnings = false;
/**
* Release limitation to wfDeprecated warnings, if set to a release number
* development warnings will not be generated for deprecations added in releases
* after the limit.
*/
$wgDeprecationReleaseLimit = false;
/** Only record profiling info for pages that took longer than this */
$wgProfileLimit = 0.0;

View file

@ -3335,13 +3335,30 @@ function wfGetNull() {
* Throws a warning that $function is deprecated
*
* @param $function String
* @param $version String
* @return null
*/
function wfDeprecated( $function ) {
function wfDeprecated( $function, $version=false ) {
static $functionsWarned = array();
if ( !isset( $functionsWarned[$function] ) ) {
$functionsWarned[$function] = true;
wfWarn( "Use of $function is deprecated.", 2 );
if ( $version ) {
global $wgDeprecationReleaseLimit;
if ( $wgDeprecationReleaseLimit ) {
# Strip -* off the end of $version so that branches can use the
# format #.##-branchname to avoid issues if the branch is merged into
# a version of MediaWiki later than what it was branched from
$comparableVersion = preg_replace( '/-.*$/', '', $version );
# If the comparableVersion is larger than our release limit then
# skip the warning message for the deprecation
if ( version_compare( $wgDeprecationReleaseLimit, $comparableVersion, '<' ) ) {
return;
}
}
wfWarn( "Use of $function was deprecated in $version.", 2 );
} else {
wfWarn( "Use of $function is deprecated.", 2 );
}
}
}