Merge "Typo fix"
[mediawiki.git] / includes / api / ApiQueryStashImageInfo.php
blob6899375ac61b35feac18838475cb86c88a30a526
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 /**
24 * A query action to get image information from temporarily stashed files.
26 * @ingroup API
28 class ApiQueryStashImageInfo extends ApiQueryImageInfo {
30 public function __construct( $query, $moduleName ) {
31 parent::__construct( $query, $moduleName, 'sii' );
34 public function execute() {
35 $params = $this->extractRequestParams();
36 $modulePrefix = $this->getModulePrefix();
38 $prop = array_flip( $params['prop'] );
40 $scale = $this->getScale( $params );
42 $result = $this->getResult();
44 if ( !$params['filekey'] && !$params['sessionkey'] ) {
45 $this->dieUsage( "One of filekey or sessionkey must be supplied", 'nofilekey' );
48 // Alias sessionkey to filekey, but give an existing filekey precedence.
49 if ( !$params['filekey'] && $params['sessionkey'] ) {
50 $params['filekey'] = $params['sessionkey'];
53 try {
54 $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash();
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( array( 'query', $this->getModuleName() ), null, $imageInfo );
61 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), $modulePrefix );
63 //TODO: update exception handling here to understand current getFile exceptions
64 } catch ( UploadStashNotAvailableException $e ) {
65 $this->dieUsage( "Session not available: " . $e->getMessage(), "nosession" );
66 } catch ( UploadStashFileNotFoundException $e ) {
67 $this->dieUsage( "File not found: " . $e->getMessage(), "invalidsessiondata" );
68 } catch ( UploadStashBadPathException $e ) {
69 $this->dieUsage( "Bad path: " . $e->getMessage(), "invalidsessiondata" );
73 private $propertyFilter = array(
74 'user', 'userid', 'comment', 'parsedcomment',
75 'mediatype', 'archivename',
78 public function getAllowedParams() {
79 return array(
80 'filekey' => array(
81 ApiBase::PARAM_ISMULTI => true,
82 ApiBase::PARAM_DFLT => null
84 'sessionkey' => array(
85 ApiBase::PARAM_ISMULTI => true,
86 ApiBase::PARAM_DEPRECATED => true,
87 ApiBase::PARAM_DFLT => null
89 'prop' => array(
90 ApiBase::PARAM_ISMULTI => true,
91 ApiBase::PARAM_DFLT => 'timestamp|url',
92 ApiBase::PARAM_TYPE => self::getPropertyNames( $this->propertyFilter )
94 'urlwidth' => array(
95 ApiBase::PARAM_TYPE => 'integer',
96 ApiBase::PARAM_DFLT => -1
98 'urlheight' => array(
99 ApiBase::PARAM_TYPE => 'integer',
100 ApiBase::PARAM_DFLT => -1
102 'urlparam' => array(
103 ApiBase::PARAM_TYPE => 'string',
104 ApiBase::PARAM_DFLT => '',
110 * Return the API documentation for the parameters.
111 * @return Array parameter documentation.
113 public function getParamDescription() {
114 $p = $this->getModulePrefix();
115 return array(
116 'prop' => self::getPropertyDescriptions( $this->propertyFilter, $p ),
117 'filekey' => 'Key that identifies a previous upload that was stashed temporarily.',
118 'sessionkey' => 'Alias for filekey, for backward compatibility.',
119 'urlwidth' => "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.",
120 'urlheight' => "Similar to {$p}urlwidth. Cannot be used without {$p}urlwidth",
121 'urlparam' => array( "A handler specific parameter string. For example, pdf's ",
122 "might use 'page15-100px'. {$p}urlwidth must be used and be consistent with {$p}urlparam" ),
126 public function getResultProperties() {
127 return ApiQueryImageInfo::getResultPropertiesFiltered( $this->propertyFilter );
130 public function getDescription() {
131 return 'Returns image information for stashed images';
134 public function getExamples() {
135 return array(
136 'api.php?action=query&prop=stashimageinfo&siifilekey=124sd34rsdf567',
137 'api.php?action=query&prop=stashimageinfo&siifilekey=b34edoe3|bceffd4&siiurlwidth=120&siiprop=url',