30 private $mPageSet =
null;
50 parent::__construct( $mainModule, $moduleName );
51 $this->repoGroup = $repoGroup;
52 $this->tempFSFileFactory = $tempFSFileFactory;
53 $this->titleFactory = $titleFactory;
60 $rotation =
$params[
'rotation'];
65 $pageSet = $this->getPageSet();
68 $result = $pageSet->getInvalidTitlesAndRevisions( [
69 'invalidTitles',
'special',
'missingIds',
'missingRevIds',
'interwikiTitles',
75 if ( !$ableToTag->isOK() ) {
80 foreach ( $pageSet->getPages() as $page ) {
81 $title = $this->titleFactory->newFromPageIdentity( $page );
83 $r[
'id'] = $title->getArticleID();
84 ApiQueryBase::addTitleInfo( $r, $title );
85 if ( !$title->exists() ) {
87 if ( $title->isKnown() ) {
92 $file = $this->repoGroup->findFile( $title, [
'latest' =>
true ] );
94 $r[
'result'] =
'Failure';
96 Status::newFatal(
'apierror-filedoesnotexist' )
101 $handler = $file->getHandler();
102 if ( !$handler || !$handler->canRotate() ) {
103 $r[
'result'] =
'Failure';
105 Status::newFatal(
'apierror-filetypecannotberotated' )
114 $srcPath = $file->getLocalRefPath();
115 if ( $srcPath ===
false ) {
116 $r[
'result'] =
'Failure';
118 Status::newFatal(
'apierror-filenopath' )
123 $ext = strtolower( pathinfo(
"$srcPath", PATHINFO_EXTENSION ) );
124 $tmpFile = $this->tempFSFileFactory->newTempFSFile(
'rotate_', $ext );
125 $dstPath = $tmpFile->getPath();
127 $err = $handler->rotate( $file, [
128 'srcPath' => $srcPath,
129 'dstPath' => $dstPath,
130 'rotation' => $rotation
133 $comment = $this->
msg(
135 )->numParams( $rotation )->inContentLanguage()->text();
137 $status = $file->upload(
147 if ( $status->isGood() ) {
148 $r[
'result'] =
'Success';
150 $r[
'result'] =
'Failure';
154 $r[
'result'] =
'Failure';
156 Status::newFatal( ApiMessage::create( $err->getMsg() ) )
162 ApiResult::setIndexedTagName( $result,
'page' );
163 $apiResult->addValue(
null, $this->
getModuleName(), $result );
166 $continuationManager->setContinuationIntoResult( $apiResult );
173 private function getPageSet() {
176 return $this->mPageSet;
190 ParamValidator::PARAM_TYPE => [
'90',
'180',
'270' ],
191 ParamValidator::PARAM_REQUIRED => true
197 ParamValidator::PARAM_TYPE =>
'tags',
198 ParamValidator::PARAM_ISMULTI =>
true,
202 $result += $this->getPageSet()->getFinalParams( $flags );
214 'action=imagerotate&titles=File:Example.jpg&rotation=90&token=123ABC'
215 =>
'apihelp-imagerotate-example-simple',
216 'action=imagerotate&generator=categorymembers&gcmtitle=Category:Flip&gcmtype=file&' .
217 'rotation=180&token=123ABC'
218 =>
'apihelp-imagerotate-example-generator',
223 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Imagerotate';
array $params
The job parameters.
This abstract class implements many basic API functions, and is the base of all API classes.
checkTitleUserPermissions(PageIdentity $pageIdentity, $actions, array $options=[])
Helper function for permission-denied errors.
setContinuationManager(ApiContinuationManager $manager=null)
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
getModuleName()
Get the name of the module being executed by this instance.
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
This manages continuation state.
mustBePosted()
Indicates whether this module must be called with a POST request.
isWriteMode()
Indicates whether this module requires write mode.
getAllowedParams( $flags=0)
getExamplesMessages()
Returns usage examples for this module.
getHelpUrls()
Return links to more detailed help pages about the module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
needsToken()
Returns the token type this module requires in order to execute.
__construct(ApiMain $mainModule, $moduleName, RepoGroup $repoGroup, TempFSFileFactory $tempFSFileFactory, TitleFactory $titleFactory)
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.