35 private $mPageSet =
null;
48 parent::__construct( $mainModule, $moduleName );
49 $this->repoGroup = $repoGroup;
50 $this->tempFSFileFactory = $tempFSFileFactory;
51 $this->titleFactory = $titleFactory;
58 $rotation =
$params[
'rotation'];
63 $pageSet = $this->getPageSet();
66 $result = $pageSet->getInvalidTitlesAndRevisions( [
67 'invalidTitles',
'special',
'missingIds',
'missingRevIds',
'interwikiTitles',
73 if ( !$ableToTag->isOK() ) {
78 foreach ( $pageSet->getPages() as $page ) {
79 $title = $this->titleFactory->newFromPageIdentity( $page );
81 $r[
'id'] = $title->getArticleID();
83 if ( !$title->exists() ) {
85 if ( $title->isKnown() ) {
90 $file = $this->repoGroup->findFile( $title, [
'latest' =>
true ] );
92 $r[
'result'] =
'Failure';
94 Status::newFatal(
'apierror-filedoesnotexist' )
99 $handler = $file->getHandler();
100 if ( !$handler || !$handler->canRotate() ) {
101 $r[
'result'] =
'Failure';
103 Status::newFatal(
'apierror-filetypecannotberotated' )
112 $srcPath = $file->getLocalRefPath();
113 if ( $srcPath ===
false ) {
114 $r[
'result'] =
'Failure';
116 Status::newFatal(
'apierror-filenopath' )
121 $ext = strtolower( pathinfo(
"$srcPath", PATHINFO_EXTENSION ) );
122 $tmpFile = $this->tempFSFileFactory->newTempFSFile(
'rotate_', $ext );
123 $dstPath = $tmpFile->getPath();
125 $err = $handler->rotate( $file, [
126 'srcPath' => $srcPath,
127 'dstPath' => $dstPath,
128 'rotation' => $rotation
131 $comment = $this->
msg(
133 )->numParams( $rotation )->inContentLanguage()->text();
135 $status = $file->upload(
145 if ( $status->isGood() ) {
146 $r[
'result'] =
'Success';
148 $r[
'result'] =
'Failure';
152 $r[
'result'] =
'Failure';
161 $apiResult->addValue(
null, $this->
getModuleName(), $result );
164 $continuationManager->setContinuationIntoResult( $apiResult );
171 private function getPageSet() {
174 return $this->mPageSet;
188 ParamValidator::PARAM_TYPE => [
'90',
'180',
'270' ],
189 ParamValidator::PARAM_REQUIRED => true
195 ParamValidator::PARAM_TYPE =>
'tags',
196 ParamValidator::PARAM_ISMULTI =>
true,
200 $result += $this->getPageSet()->getFinalParams( $flags );
212 'action=imagerotate&titles=File:Example.jpg&rotation=90&token=123ABC'
213 =>
'apihelp-imagerotate-example-simple',
214 'action=imagerotate&generator=categorymembers&gcmtitle=Category:Flip&gcmtype=file&' .
215 'rotation=180&token=123ABC'
216 =>
'apihelp-imagerotate-example-generator',
221 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Imagerotate';
226class_alias( ApiImageRotate::class,
'ApiImageRotate' );
array $params
The job parameters.
This is the main API class, used for both external and internal processing.
This class contains a list of pages that the client has requested.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Prioritized list of file repositories.