Merge "deprecation: Remove DeprecationHelper::newArgumentWithDeprecation and change callers accordingly"
This commit is contained in:
commit
5e732f662c
6 changed files with 27 additions and 122 deletions
|
|
@ -137,48 +137,4 @@ trait DeprecationHelper {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is used to introduce new argument into function or __construct.
|
||||
* It returns provided $value if it's not null.
|
||||
* If $value is null it raises wfDeprecated exception with name of property and returns fallback.
|
||||
*
|
||||
*
|
||||
* * Example usage:
|
||||
* private $newVariable;
|
||||
* function __construct( $oldVariable, $newVariable ) {
|
||||
* ....
|
||||
* $this->newVariable = DeprecationHelper::newArgumentWithDeprecation(
|
||||
* __METHOD__,
|
||||
* "$newVariable",
|
||||
* $newVariable,
|
||||
* function() { return 0; } // Any way to evaluate default value for $newVariable
|
||||
* );
|
||||
* ....
|
||||
* }
|
||||
*
|
||||
* $foo = new Foo;
|
||||
* $foo->bar; // works but logs a warning
|
||||
*
|
||||
* @param string $method full class method
|
||||
* @param string $name new argument name
|
||||
* @param string $version version since argument was introduced
|
||||
* @param mixed|null $value
|
||||
* @param callable $fallback Closure of type (): mixed - it used if $value is null
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function newArgumentWithDeprecation(
|
||||
string $method,
|
||||
string $name,
|
||||
string $version,
|
||||
$value,
|
||||
callable $fallback
|
||||
) {
|
||||
if ( $value === null ) {
|
||||
wfDeprecated( $method . " without $name parameter", $version );
|
||||
return $fallback();
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ namespace MediaWiki\EditPage;
|
|||
|
||||
use Content;
|
||||
use ContentHandler;
|
||||
use DeprecationHelper;
|
||||
use Html;
|
||||
use IBufferingStatsdDataFactory;
|
||||
use MediaWiki\Content\IContentHandlerFactory;
|
||||
|
|
@ -107,15 +106,11 @@ class TextConflictHelper {
|
|||
$this->submitLabel = $submitLabel;
|
||||
$this->contentModel = $title->getContentModel();
|
||||
|
||||
$this->contentHandlerFactory = DeprecationHelper::newArgumentWithDeprecation(
|
||||
__METHOD__,
|
||||
'contentHandlerFactory',
|
||||
'1.35',
|
||||
$contentHandlerFactory,
|
||||
function () {
|
||||
return MediaWikiServices::getInstance()->getContentHandlerFactory();
|
||||
}
|
||||
);
|
||||
if ( !$contentHandlerFactory ) {
|
||||
wfDeprecated( __METHOD__ . ' without $contentHandlerFactory parameter', '1.35' );
|
||||
$contentHandlerFactory = MediaWikiServices::getInstance()->getContentHandlerFactory();
|
||||
}
|
||||
$this->contentHandlerFactory = $contentHandlerFactory;
|
||||
|
||||
$this->contentFormat = $this->contentHandlerFactory
|
||||
->getContentHandler( $this->contentModel )
|
||||
|
|
|
|||
|
|
@ -54,16 +54,14 @@ class LinkHolderArray {
|
|||
*/
|
||||
public function __construct( $parent, ILanguageConverter $languageConverter = null ) {
|
||||
$this->parent = $parent;
|
||||
$this->languageConverter = DeprecationHelper::newArgumentWithDeprecation(
|
||||
__METHOD__,
|
||||
'languageConverter',
|
||||
'1.35',
|
||||
$languageConverter,
|
||||
function () use ( $parent ) {
|
||||
return MediaWikiServices::getInstance()->getLanguageConverterFactory()
|
||||
->getLanguageConverter( $parent->getTargetLanguage() );
|
||||
}
|
||||
);
|
||||
|
||||
if ( !$languageConverter ) {
|
||||
wfDeprecated( __METHOD__ . ' without $languageConverter parameter', '1.35' );
|
||||
$languageConverter = MediaWikiServices::getInstance()
|
||||
->getLanguageConverterFactory()
|
||||
->getLanguageConverter( $parent->getTargetLanguage() );
|
||||
}
|
||||
$this->languageConverter = $languageConverter;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ namespace MediaWiki\Preferences;
|
|||
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use DeprecationHelper;
|
||||
use Exception;
|
||||
use Hooks;
|
||||
use Html;
|
||||
|
|
@ -153,16 +152,14 @@ class DefaultPreferencesFactory implements PreferencesFactory {
|
|||
$this->languageNameUtils = $languageNameUtils ??
|
||||
MediaWikiServices::getInstance()->getLanguageNameUtils();
|
||||
$this->logger = new NullLogger();
|
||||
$this->languageConverter = DeprecationHelper::newArgumentWithDeprecation(
|
||||
__METHOD__,
|
||||
'languageConverter',
|
||||
'1.35',
|
||||
$languageConverter,
|
||||
function () {
|
||||
return MediaWikiServices::getInstance()->getLanguageConverterFactory()
|
||||
->getLanguageConverter();
|
||||
}
|
||||
);
|
||||
|
||||
if ( !$languageConverter ) {
|
||||
wfDeprecated( __METHOD__ . ' without $languageConverter parameter', '1.35' );
|
||||
$languageConverter = MediaWikiServices::getInstance()
|
||||
->getLanguageConverterFactory()
|
||||
->getLanguageConverter();
|
||||
}
|
||||
$this->languageConverter = $languageConverter;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,15 +16,12 @@ class SpecialChangeContentModel extends FormSpecialPage {
|
|||
*/
|
||||
public function __construct( ?IContentHandlerFactory $contentHandlerFactory = null ) {
|
||||
parent::__construct( 'ChangeContentModel', 'editcontentmodel' );
|
||||
$this->contentHandlerFactory = DeprecationHelper::newArgumentWithDeprecation(
|
||||
__METHOD__,
|
||||
'contentHandlerFactory',
|
||||
'1.35',
|
||||
$contentHandlerFactory,
|
||||
function () {
|
||||
return MediaWikiServices::getInstance()->getContentHandlerFactory();
|
||||
}
|
||||
);
|
||||
|
||||
if ( !$contentHandlerFactory ) {
|
||||
wfDeprecated( __METHOD__ . ' without $contentHandlerFactory parameter', '1.35' );
|
||||
$contentHandlerFactory = MediaWikiServices::getInstance()->getContentHandlerFactory();
|
||||
}
|
||||
$this->contentHandlerFactory = $contentHandlerFactory;
|
||||
}
|
||||
|
||||
public function doesWrites() {
|
||||
|
|
|
|||
|
|
@ -171,42 +171,4 @@ class DeprecationHelperTest extends MediaWikiTestCase {
|
|||
[ null, Exception::class ]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers DeprecationHelper::newArgumentWithDeprecation
|
||||
*/
|
||||
public function testNewArgumentWithDeprecationRaisesExceptionIfNoValue() {
|
||||
MWDebug::clearLog();
|
||||
|
||||
$newArgument = DeprecationHelper::newArgumentWithDeprecation(
|
||||
__METHOD__,
|
||||
'NewArgument',
|
||||
'1.35',
|
||||
null,
|
||||
function () {
|
||||
return 0;
|
||||
}
|
||||
);
|
||||
|
||||
$wrapper = TestingAccessWrapper::newFromClass( MWDebug::class );
|
||||
$this->assertNotEmpty( $wrapper->deprecationWarnings );
|
||||
$this->assertSame( 0, $newArgument );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers DeprecationHelper::newArgumentWithDeprecation
|
||||
*/
|
||||
public function testNewArgumentWithDeprecationReturnsValue() {
|
||||
$newArgument = DeprecationHelper::newArgumentWithDeprecation(
|
||||
__METHOD__,
|
||||
'NewArgument',
|
||||
'1.35',
|
||||
0,
|
||||
function () {
|
||||
return 0;
|
||||
}
|
||||
);
|
||||
$this->assertSame( 0, $newArgument );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue