28 private $mPageSet =
null;
34 private $tempFSFileFactory;
48 parent::__construct( $mainModule, $moduleName );
49 $this->repoGroup = $repoGroup;
50 $this->tempFSFileFactory = $tempFSFileFactory;
57 $rotation = $params[
'rotation'];
62 $pageSet = $this->getPageSet();
65 $result = $pageSet->getInvalidTitlesAndRevisions( [
66 'invalidTitles',
'special',
'missingIds',
'missingRevIds',
'interwikiTitles',
70 if ( $params[
'tags'] ) {
72 if ( !$ableToTag->isOK() ) {
77 foreach ( $pageSet->getTitles() as
$title ) {
79 $r[
'id'] =
$title->getArticleID();
80 ApiQueryBase::addTitleInfo( $r,
$title );
88 $file = $this->repoGroup->findFile(
$title, [
'latest' =>
true ] );
90 $r[
'result'] =
'Failure';
92 Status::newFatal(
'apierror-filedoesnotexist' )
97 $handler =
$file->getHandler();
98 if ( !$handler || !$handler->canRotate() ) {
99 $r[
'result'] =
'Failure';
101 Status::newFatal(
'apierror-filetypecannotberotated' )
110 $srcPath =
$file->getLocalRefPath();
111 if ( $srcPath ===
false ) {
112 $r[
'result'] =
'Failure';
114 Status::newFatal(
'apierror-filenopath' )
119 $ext = strtolower( pathinfo(
"$srcPath", PATHINFO_EXTENSION ) );
120 $tmpFile = $this->tempFSFileFactory->newTempFSFile(
'rotate_',
$ext );
121 $dstPath = $tmpFile->getPath();
123 $err = $handler->rotate(
$file, [
124 'srcPath' => $srcPath,
125 'dstPath' => $dstPath,
126 'rotation' => $rotation
129 $comment = $this->
msg(
131 )->numParams( $rotation )->inContentLanguage()->text();
133 $status =
$file->upload(
141 $params[
'tags'] ?: []
143 if ( $status->isGood() ) {
144 $r[
'result'] =
'Success';
146 $r[
'result'] =
'Failure';
150 $r[
'result'] =
'Failure';
152 Status::newFatal( ApiMessage::create( $err->getMsg() ) )
158 ApiResult::setIndexedTagName( $result,
'page' );
159 $apiResult->addValue(
null, $this->
getModuleName(), $result );
162 $continuationManager->setContinuationIntoResult( $apiResult );
169 private function getPageSet() {
172 return $this->mPageSet;
186 ParamValidator::PARAM_TYPE => [
'90',
'180',
'270' ],
187 ParamValidator::PARAM_REQUIRED =>
true
193 ParamValidator::PARAM_TYPE =>
'tags',
194 ParamValidator::PARAM_ISMULTI =>
true,
198 $result += $this->getPageSet()->getFinalParams( $flags );
210 'action=imagerotate&titles=File:Example.jpg&rotation=90&token=123ABC'
211 =>
'apihelp-imagerotate-example-simple',
212 'action=imagerotate&generator=categorymembers&gcmtitle=Category:Flip&gcmtype=file&' .
213 'rotation=180&token=123ABC'
214 =>
'apihelp-imagerotate-example-generator',
This abstract class implements many basic API functions, and is the base of all API classes.
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.
checkTitleUserPermissions( $pageIdentity, $actions, array $options=[])
Helper function for permission-denied errors.
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.
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)
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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
if(!is_readable( $file)) $ext