Remove Revision::getRevisionText from ApiQueryDeletedrevs
[lhc/web/wiklou.git] / includes / api / ApiQueryStashImageInfo.php
1 <?php
2 /**
3 * API for MediaWiki 1.16+
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 */
22
23 /**
24 * A query action to get image information from temporarily stashed files.
25 *
26 * @ingroup API
27 */
28 class ApiQueryStashImageInfo extends ApiQueryImageInfo {
29
30 public function __construct( ApiQuery $query, $moduleName ) {
31 parent::__construct( $query, $moduleName, 'sii' );
32 }
33
34 public function execute() {
35 if ( !$this->getUser()->isLoggedIn() ) {
36 $this->dieWithError( 'apierror-mustbeloggedin-uploadstash', 'notloggedin' );
37 }
38
39 $params = $this->extractRequestParams();
40 $modulePrefix = $this->getModulePrefix();
41
42 $prop = array_flip( $params['prop'] );
43
44 $scale = $this->getScale( $params );
45
46 $result = $this->getResult();
47
48 $this->requireAtLeastOneParameter( $params, 'filekey', 'sessionkey' );
49
50 // Alias sessionkey to filekey, but give an existing filekey precedence.
51 if ( !$params['filekey'] && $params['sessionkey'] ) {
52 $params['filekey'] = $params['sessionkey'];
53 }
54
55 try {
56 $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash( $this->getUser() );
57
58 foreach ( $params['filekey'] as $filekey ) {
59 $file = $stash->getFile( $filekey );
60 $finalThumbParam = $this->mergeThumbParams( $file, $scale, $params['urlparam'] );
61 $imageInfo = ApiQueryImageInfo::getInfo( $file, $prop, $result, $finalThumbParam );
62 $result->addValue( [ 'query', $this->getModuleName() ], null, $imageInfo );
63 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], $modulePrefix );
64 }
65 // @todo Update exception handling here to understand current getFile exceptions
66 } catch ( UploadStashFileNotFoundException $e ) {
67 $this->dieWithException( $e, [ 'wrap' => 'apierror-stashedfilenotfound' ] );
68 } catch ( UploadStashBadPathException $e ) {
69 $this->dieWithException( $e, [ 'wrap' => 'apierror-stashpathinvalid' ] );
70 }
71 }
72
73 private static $propertyFilter = [
74 'user', 'userid', 'comment', 'parsedcomment',
75 'mediatype', 'archivename', 'uploadwarning',
76 ];
77
78 /**
79 * Returns all possible parameters to siiprop
80 *
81 * @param array|null $filter List of properties to filter out
82 * @return array
83 */
84 public static function getPropertyNames( $filter = null ) {
85 if ( $filter === null ) {
86 $filter = self::$propertyFilter;
87 }
88 return parent::getPropertyNames( $filter );
89 }
90
91 /**
92 * Returns messages for all possible parameters to siiprop
93 *
94 * @param array|null $filter List of properties to filter out
95 * @return array
96 */
97 public static function getPropertyMessages( $filter = null ) {
98 if ( $filter === null ) {
99 $filter = self::$propertyFilter;
100 }
101 return parent::getPropertyMessages( $filter );
102 }
103
104 public function getAllowedParams() {
105 return [
106 'filekey' => [
107 ApiBase::PARAM_ISMULTI => true,
108 ],
109 'sessionkey' => [
110 ApiBase::PARAM_ISMULTI => true,
111 ApiBase::PARAM_DEPRECATED => true,
112 ],
113 'prop' => [
114 ApiBase::PARAM_ISMULTI => true,
115 ApiBase::PARAM_DFLT => 'timestamp|url',
116 ApiBase::PARAM_TYPE => self::getPropertyNames(),
117 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-prop',
118 ApiBase::PARAM_HELP_MSG_PER_VALUE => self::getPropertyMessages()
119 ],
120 'urlwidth' => [
121 ApiBase::PARAM_TYPE => 'integer',
122 ApiBase::PARAM_DFLT => -1,
123 ApiBase::PARAM_HELP_MSG => [
124 'apihelp-query+imageinfo-param-urlwidth',
125 ApiQueryImageInfo::TRANSFORM_LIMIT,
126 ],
127 ],
128 'urlheight' => [
129 ApiBase::PARAM_TYPE => 'integer',
130 ApiBase::PARAM_DFLT => -1,
131 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlheight',
132 ],
133 'urlparam' => [
134 ApiBase::PARAM_TYPE => 'string',
135 ApiBase::PARAM_DFLT => '',
136 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlparam',
137 ],
138 ];
139 }
140
141 protected function getExamplesMessages() {
142 return [
143 'action=query&prop=stashimageinfo&siifilekey=124sd34rsdf567'
144 => 'apihelp-query+stashimageinfo-example-simple',
145 'action=query&prop=stashimageinfo&siifilekey=b34edoe3|bceffd4&' .
146 'siiurlwidth=120&siiprop=url'
147 => 'apihelp-query+stashimageinfo-example-params',
148 ];
149 }
150
151 public function getHelpUrls() {
152 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Stashimageinfo';
153 }
154 }