Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / api / ApiQueryStashImageInfo.php
blobb65ea3ffeba899690edc0b38d88601dda2422bac
1 <?php
2 /**
3 * API for MediaWiki 1.16+
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
23 namespace MediaWiki\Api;
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;
32 /**
33 * A query action to get image information from temporarily stashed files.
35 * @ingroup API
37 class ApiQueryStashImageInfo extends ApiQueryImageInfo {
39 private RepoGroup $repoGroup;
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
56 $this->repoGroup = $repoGroup;
59 public function execute() {
60 if ( !$this->getUser()->isRegistered() ) {
61 $this->dieWithError( 'apierror-mustbeloggedin-uploadstash', 'notloggedin' );
64 $params = $this->extractRequestParams();
65 $modulePrefix = $this->getModulePrefix();
67 $prop = array_fill_keys( $params['prop'], true );
69 $scale = $this->getScale( $params );
71 $result = $this->getResult();
73 $this->requireAtLeastOneParameter( $params, 'filekey', 'sessionkey' );
75 // Alias sessionkey to filekey, but give an existing filekey precedence.
76 if ( !$params['filekey'] && $params['sessionkey'] ) {
77 $params['filekey'] = $params['sessionkey'];
80 try {
81 $stash = $this->repoGroup->getLocalRepo()->getUploadStash( $this->getUser() );
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 );
90 // @todo Update exception handling here to understand current getFile exceptions
91 } catch ( UploadStashFileNotFoundException $e ) {
92 $this->dieWithException( $e, [ 'wrap' => 'apierror-stashedfilenotfound' ] );
93 } catch ( UploadStashBadPathException $e ) {
94 $this->dieWithException( $e, [ 'wrap' => 'apierror-stashpathinvalid' ] );
98 private const PROPERTY_FILTER = [
99 'user', 'userid', 'comment', 'parsedcomment',
100 'mediatype', 'archivename', 'uploadwarning',
104 * Returns all possible parameters to siiprop
106 * @param array|null $filter List of properties to filter out
107 * @return array
109 public static function getPropertyNames( $filter = null ) {
110 return parent::getPropertyNames( $filter ?? self::PROPERTY_FILTER );
114 * Returns messages for all possible parameters to siiprop
116 * @param array|null $filter List of properties to filter out
117 * @return array
119 public static function getPropertyMessages( $filter = null ) {
120 return parent::getPropertyMessages( $filter ?? self::PROPERTY_FILTER );
123 public function getAllowedParams() {
124 return [
125 'filekey' => [
126 ParamValidator::PARAM_ISMULTI => true,
128 'sessionkey' => [
129 ParamValidator::PARAM_ISMULTI => true,
130 ParamValidator::PARAM_DEPRECATED => true,
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()
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,
147 'urlheight' => [
148 ParamValidator::PARAM_TYPE => 'integer',
149 ParamValidator::PARAM_DEFAULT => -1,
150 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlheight',
152 'urlparam' => [
153 ParamValidator::PARAM_TYPE => 'string',
154 ParamValidator::PARAM_DEFAULT => '',
155 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlparam',
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',
170 public function getHelpUrls() {
171 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Stashimageinfo';
175 /** @deprecated class alias since 1.43 */
176 class_alias( ApiQueryStashImageInfo::class, 'ApiQueryStashImageInfo' );