| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
namespace MediaWiki\Api; |
| 24 |
|
| 25 |
use MediaWiki\Language\Language; |
| 26 |
use MediaWiki\Page\File\BadFileLookup; |
| 27 |
use RepoGroup; |
| 28 |
use UploadStashBadPathException; |
| 29 |
use UploadStashFileNotFoundException; |
| 30 |
use Wikimedia\ParamValidator\ParamValidator; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
class ApiQueryStashImageInfo extends ApiQueryImageInfo { |
| 38 |
|
| 39 |
private RepoGroup $repoGroup; |
| 40 |
|
| 41 |
public function __construct( |
| 42 |
ApiQuery $query, |
| 43 |
string $moduleName, |
| 44 |
RepoGroup $repoGroup, |
| 45 |
Language $contentLanguage, |
| 46 |
BadFileLookup $badFileLookup |
| 47 |
) { |
| 48 |
parent::__construct( |
| 49 |
$query, |
| 50 |
$moduleName, |
| 51 |
'sii', |
| 52 |
$repoGroup, |
| 53 |
$contentLanguage, |
| 54 |
$badFileLookup |
| 55 |
); |
| 56 |
$this->repoGroup = $repoGroup; |
| 57 |
} |
| 58 |
|
| 59 |
public function execute() { |
| 60 |
if ( !$this->getUser()->isRegistered() ) { |
| 61 |
$this->dieWithError( 'apierror-mustbeloggedin-uploadstash', 'notloggedin' ); |
| 62 |
} |
| 63 |
|
| 64 |
$params = $this->extractRequestParams(); |
| 65 |
$modulePrefix = $this->getModulePrefix(); |
| 66 |
|
| 67 |
$prop = array_fill_keys( $params['prop'], true ); |
| 68 |
|
| 69 |
$scale = $this->getScale( $params ); |
| 70 |
|
| 71 |
$result = $this->getResult(); |
| 72 |
|
| 73 |
$this->requireAtLeastOneParameter( $params, 'filekey', 'sessionkey' ); |
| 74 |
|
| 75 |
|
| 76 |
if ( !$params['filekey'] && $params['sessionkey'] ) { |
| 77 |
$params['filekey'] = $params['sessionkey']; |
| 78 |
} |
| 79 |
|
| 80 |
try { |
| 81 |
$stash = $this->repoGroup->getLocalRepo()->getUploadStash( $this->getUser() ); |
| 82 |
|
| 83 |
foreach ( $params['filekey'] as $filekey ) { |
| 84 |
$file = $stash->getFile( $filekey ); |
| 85 |
$finalThumbParam = $this->mergeThumbParams( $file, $scale, $params['urlparam'] ); |
| 86 |
$imageInfo = ApiQueryImageInfo::getInfo( $file, $prop, $result, $finalThumbParam ); |
| 87 |
$result->addValue( [ 'query', $this->getModuleName() ], null, $imageInfo ); |
| 88 |
$result->addIndexedTagName( [ 'query', $this->getModuleName() ], $modulePrefix ); |
| 89 |
} |
| 90 |
|
| 91 |
} catch ( UploadStashFileNotFoundException $e ) { |
| 92 |
$this->dieWithException( $e, [ 'wrap' => 'apierror-stashedfilenotfound' ] ); |
| 93 |
} catch ( UploadStashBadPathException $e ) { |
| 94 |
$this->dieWithException( $e, [ 'wrap' => 'apierror-stashpathinvalid' ] ); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
private const PROPERTY_FILTER = [ |
| 99 |
'user', 'userid', 'comment', 'parsedcomment', |
| 100 |
'mediatype', 'archivename', 'uploadwarning', |
| 101 |
]; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public static function getPropertyNames( $filter = null ) { |
| 110 |
return parent::getPropertyNames( $filter ?? self::PROPERTY_FILTER ); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
public static function getPropertyMessages( $filter = null ) { |
| 120 |
return parent::getPropertyMessages( $filter ?? self::PROPERTY_FILTER ); |
| 121 |
} |
| 122 |
|
| 123 |
public function getAllowedParams() { |
| 124 |
return [ |
| 125 |
'filekey' => [ |
| 126 |
ParamValidator::PARAM_ISMULTI => true, |
| 127 |
], |
| 128 |
'sessionkey' => [ |
| 129 |
ParamValidator::PARAM_ISMULTI => true, |
| 130 |
ParamValidator::PARAM_DEPRECATED => true, |
| 131 |
], |
| 132 |
'prop' => [ |
| 133 |
ParamValidator::PARAM_ISMULTI => true, |
| 134 |
ParamValidator::PARAM_DEFAULT => 'timestamp|url', |
| 135 |
ParamValidator::PARAM_TYPE => self::getPropertyNames(), |
| 136 |
ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-prop', |
| 137 |
ApiBase::PARAM_HELP_MSG_PER_VALUE => self::getPropertyMessages() |
| 138 |
], |
| 139 |
'urlwidth' => [ |
| 140 |
ParamValidator::PARAM_TYPE => 'integer', |
| 141 |
ParamValidator::PARAM_DEFAULT => -1, |
| 142 |
ApiBase::PARAM_HELP_MSG => [ |
| 143 |
'apihelp-query+imageinfo-param-urlwidth', |
| 144 |
ApiQueryImageInfo::TRANSFORM_LIMIT, |
| 145 |
], |
| 146 |
], |
| 147 |
'urlheight' => [ |
| 148 |
ParamValidator::PARAM_TYPE => 'integer', |
| 149 |
ParamValidator::PARAM_DEFAULT => -1, |
| 150 |
ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlheight', |
| 151 |
], |
| 152 |
'urlparam' => [ |
| 153 |
ParamValidator::PARAM_TYPE => 'string', |
| 154 |
ParamValidator::PARAM_DEFAULT => '', |
| 155 |
ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlparam', |
| 156 |
], |
| 157 |
]; |
| 158 |
} |
| 159 |
|
| 160 |
protected function getExamplesMessages() { |
| 161 |
return [ |
| 162 |
'action=query&prop=stashimageinfo&siifilekey=124sd34rsdf567' |
| 163 |
=> 'apihelp-query+stashimageinfo-example-simple', |
| 164 |
'action=query&prop=stashimageinfo&siifilekey=b34edoe3|bceffd4&' . |
| 165 |
'siiurlwidth=120&siiprop=url' |
| 166 |
=> 'apihelp-query+stashimageinfo-example-params', |
| 167 |
]; |
| 168 |
} |
| 169 |
|
| 170 |
public function getHelpUrls() { |
| 171 |
return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Stashimageinfo'; |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
class_alias( ApiQueryStashImageInfo::class, 'ApiQueryStashImageInfo' ); |