api: Inject services into ApiImageRotate
Bug: T259960 Change-Id: I9c89ca3f504dd8a4950bf20ff72fac4fe5d5d6b1
This commit is contained in:
parent
d86e6e0426
commit
1b6d44d8d5
2 changed files with 33 additions and 7 deletions
|
|
@ -18,7 +18,7 @@
|
|||
* @file
|
||||
*/
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\FileBackend\FSFile\TempFSFileFactory;
|
||||
|
||||
/**
|
||||
* @ingroup API
|
||||
|
|
@ -26,6 +26,29 @@ use MediaWiki\MediaWikiServices;
|
|||
class ApiImageRotate extends ApiBase {
|
||||
private $mPageSet = null;
|
||||
|
||||
/** @var RepoGroup */
|
||||
private $repoGroup;
|
||||
|
||||
/** @var TempFSFileFactory */
|
||||
private $tempFSFileFactory;
|
||||
|
||||
/**
|
||||
* @param ApiMain $mainModule
|
||||
* @param string $moduleName
|
||||
* @param RepoGroup $repoGroup
|
||||
* @param TempFSFileFactory $tempFSFileFactory
|
||||
*/
|
||||
public function __construct(
|
||||
ApiMain $mainModule,
|
||||
$moduleName,
|
||||
RepoGroup $repoGroup,
|
||||
TempFSFileFactory $tempFSFileFactory
|
||||
) {
|
||||
parent::__construct( $mainModule, $moduleName );
|
||||
$this->repoGroup = $repoGroup;
|
||||
$this->tempFSFileFactory = $tempFSFileFactory;
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
$this->useTransactionalTimeLimit();
|
||||
|
||||
|
|
@ -61,9 +84,7 @@ class ApiImageRotate extends ApiBase {
|
|||
}
|
||||
}
|
||||
|
||||
$file = MediaWikiServices::getInstance()->getRepoGroup()->findFile(
|
||||
$title, [ 'latest' => true ]
|
||||
);
|
||||
$file = $this->repoGroup->findFile( $title, [ 'latest' => true ] );
|
||||
if ( !$file ) {
|
||||
$r['result'] = 'Failure';
|
||||
$r['errors'] = $this->getErrorFormatter()->arrayFromStatus(
|
||||
|
|
@ -95,8 +116,7 @@ class ApiImageRotate extends ApiBase {
|
|||
continue;
|
||||
}
|
||||
$ext = strtolower( pathinfo( "$srcPath", PATHINFO_EXTENSION ) );
|
||||
$tmpFile = MediaWikiServices::getInstance()->getTempFSFileFactory()
|
||||
->newTempFSFile( 'rotate_', $ext );
|
||||
$tmpFile = $this->tempFSFileFactory->newTempFSFile( 'rotate_', $ext );
|
||||
$dstPath = $tmpFile->getPath();
|
||||
// @phan-suppress-next-line PhanUndeclaredMethod
|
||||
$err = $handler->rotate( $file, [
|
||||
|
|
|
|||
|
|
@ -273,7 +273,13 @@ class ApiMain extends ApiBase {
|
|||
'UserOptionsManager',
|
||||
],
|
||||
],
|
||||
'imagerotate' => ApiImageRotate::class,
|
||||
'imagerotate' => [
|
||||
'class' => ApiImageRotate::class,
|
||||
'services' => [
|
||||
'RepoGroup',
|
||||
'TempFSFileFactory',
|
||||
]
|
||||
],
|
||||
'revisiondelete' => ApiRevisionDelete::class,
|
||||
'managetags' => ApiManageTags::class,
|
||||
'tag' => [
|
||||
|
|
|
|||
Loading…
Reference in a new issue