Explicitly declare ApiFormatXml::addXslt() protected
[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 $params = $this->extractRequestParams();
36 $modulePrefix = $this->getModulePrefix();
37
38 $prop = array_flip( $params['prop'] );
39
40 $scale = $this->getScale( $params );
41
42 $result = $this->getResult();
43
44 if ( !$params['filekey'] && !$params['sessionkey'] ) {
45 $this->dieUsage( "One of filekey or sessionkey must be supplied", 'nofilekey' );
46 }
47
48 // Alias sessionkey to filekey, but give an existing filekey precedence.
49 if ( !$params['filekey'] && $params['sessionkey'] ) {
50 $params['filekey'] = $params['sessionkey'];
51 }
52
53 try {
54 $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash( $this->getUser() );
55
56 foreach ( $params['filekey'] as $filekey ) {
57 $file = $stash->getFile( $filekey );
58 $finalThumbParam = $this->mergeThumbParams( $file, $scale, $params['urlparam'] );
59 $imageInfo = ApiQueryImageInfo::getInfo( $file, $prop, $result, $finalThumbParam );
60 $result->addValue( [ 'query', $this->getModuleName() ], null, $imageInfo );
61 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], $modulePrefix );
62 }
63 // @todo Update exception handling here to understand current getFile exceptions
64 } catch ( UploadStashFileNotFoundException $e ) {
65 $this->dieUsage( "File not found: " . $e->getMessage(), "invalidsessiondata" );
66 } catch ( UploadStashBadPathException $e ) {
67 $this->dieUsage( "Bad path: " . $e->getMessage(), "invalidsessiondata" );
68 }
69 }
70
71 private $propertyFilter = [
72 'user', 'userid', 'comment', 'parsedcomment',
73 'mediatype', 'archivename', 'uploadwarning',
74 ];
75
76 public function getAllowedParams() {
77 return [
78 'filekey' => [
79 ApiBase::PARAM_ISMULTI => true,
80 ],
81 'sessionkey' => [
82 ApiBase::PARAM_ISMULTI => true,
83 ApiBase::PARAM_DEPRECATED => true,
84 ],
85 'prop' => [
86 ApiBase::PARAM_ISMULTI => true,
87 ApiBase::PARAM_DFLT => 'timestamp|url',
88 ApiBase::PARAM_TYPE => self::getPropertyNames( $this->propertyFilter ),
89 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-prop',
90 ApiBase::PARAM_HELP_MSG_PER_VALUE => self::getPropertyMessages( $this->propertyFilter )
91 ],
92 'urlwidth' => [
93 ApiBase::PARAM_TYPE => 'integer',
94 ApiBase::PARAM_DFLT => -1,
95 ApiBase::PARAM_HELP_MSG => [
96 'apihelp-query+imageinfo-param-urlwidth',
97 ApiQueryImageInfo::TRANSFORM_LIMIT,
98 ],
99 ],
100 'urlheight' => [
101 ApiBase::PARAM_TYPE => 'integer',
102 ApiBase::PARAM_DFLT => -1,
103 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlheight',
104 ],
105 'urlparam' => [
106 ApiBase::PARAM_TYPE => 'string',
107 ApiBase::PARAM_DFLT => '',
108 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlparam',
109 ],
110 ];
111 }
112
113 protected function getExamplesMessages() {
114 return [
115 'action=query&prop=stashimageinfo&siifilekey=124sd34rsdf567'
116 => 'apihelp-query+stashimageinfo-example-simple',
117 'action=query&prop=stashimageinfo&siifilekey=b34edoe3|bceffd4&' .
118 'siiurlwidth=120&siiprop=url'
119 => 'apihelp-query+stashimageinfo-example-params',
120 ];
121 }
122
123 public function getHelpUrls() {
124 return 'https://www.mediawiki.org/wiki/API:Stashimageinfo';
125 }
126 }