21 private $mPageSet =
null;
34 parent::__construct( $mainModule, $moduleName );
35 $this->repoGroup = $repoGroup;
36 $this->tempFSFileFactory = $tempFSFileFactory;
37 $this->titleFactory = $titleFactory;
44 $rotation = $params[
'rotation'];
49 $pageSet = $this->getPageSet();
52 $result = $pageSet->getInvalidTitlesAndRevisions( [
53 'invalidTitles',
'special',
'missingIds',
'missingRevIds',
'interwikiTitles',
57 if ( $params[
'tags'] ) {
58 $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params[
'tags'], $this->
getAuthority() );
59 if ( !$ableToTag->isOK() ) {
64 foreach ( $pageSet->getPages() as $page ) {
65 $title = $this->titleFactory->newFromPageIdentity( $page );
67 $r[
'id'] = $title->getArticleID();
69 if ( !$title->exists() ) {
71 if ( $title->isKnown() ) {
76 $file = $this->repoGroup->findFile( $title, [
'latest' =>
true ] );
78 $r[
'result'] =
'Failure';
80 Status::newFatal(
'apierror-filedoesnotexist' )
85 $handler = $file->getHandler();
86 if ( !$handler || !$handler->canRotate() ) {
87 $r[
'result'] =
'Failure';
89 Status::newFatal(
'apierror-filetypecannotberotated' )
98 $srcPath = $file->getLocalRefPath();
99 if ( $srcPath ===
false ) {
100 $r[
'result'] =
'Failure';
102 Status::newFatal(
'apierror-filenopath' )
107 $ext = strtolower( pathinfo(
"$srcPath", PATHINFO_EXTENSION ) );
108 $tmpFile = $this->tempFSFileFactory->newTempFSFile(
'rotate_', $ext );
109 $dstPath = $tmpFile->getPath();
111 $err = $handler->rotate( $file, [
112 'srcPath' => $srcPath,
113 'dstPath' => $dstPath,
114 'rotation' => $rotation
117 $comment = $this->
msg(
119 )->numParams( $rotation )->inContentLanguage()->text();
121 $status = $file->upload(
129 $params[
'tags'] ?: []
131 if ( $status->isGood() ) {
132 $r[
'result'] =
'Success';
134 $r[
'result'] =
'Failure';
138 $r[
'result'] =
'Failure';
147 $apiResult->addValue(
null, $this->
getModuleName(), $result );
150 $continuationManager->setContinuationIntoResult( $apiResult );
157 private function getPageSet() {
160 return $this->mPageSet;
177 ParamValidator::PARAM_TYPE => [
'90',
'180',
'270' ],
178 ParamValidator::PARAM_REQUIRED => true
184 ParamValidator::PARAM_TYPE =>
'tags',
185 ParamValidator::PARAM_ISMULTI =>
true,
189 $result += $this->getPageSet()->getFinalParams( $flags );
203 'action=imagerotate&titles=File:Example.jpg&rotation=90&token=123ABC'
204 =>
'apihelp-imagerotate-example-simple',
205 'action=imagerotate&generator=categorymembers&gcmtitle=Category:Flip&gcmtype=file&' .
206 'rotation=180&token=123ABC'
207 =>
'apihelp-imagerotate-example-generator',
213 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Imagerotate';
218class_alias( ApiImageRotate::class,
'ApiImageRotate' );
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()