Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / includes / api / ApiQueryStashImageInfo.php
blob59fe8adf9954c0e9ecbc7a431cccd697ec290ead
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( ApiQuery $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 $this->logFeatureUsage( 'prop=stashimageinfo&siisessionkey' );
51 $params['filekey'] = $params['sessionkey'];
54 try {
55 $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash( $this->getUser() );
57 foreach ( $params['filekey'] as $filekey ) {
58 $file = $stash->getFile( $filekey );
59 $finalThumbParam = $this->mergeThumbParams( $file, $scale, $params['urlparam'] );
60 $imageInfo = ApiQueryImageInfo::getInfo( $file, $prop, $result, $finalThumbParam );
61 $result->addValue( array( 'query', $this->getModuleName() ), null, $imageInfo );
62 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), $modulePrefix );
64 // @todo Update exception handling here to understand current getFile exceptions
65 } catch ( UploadStashNotAvailableException $e ) {
66 $this->dieUsage( "Session not available: " . $e->getMessage(), "nosession" );
67 } catch ( UploadStashFileNotFoundException $e ) {
68 $this->dieUsage( "File not found: " . $e->getMessage(), "invalidsessiondata" );
69 } catch ( UploadStashBadPathException $e ) {
70 $this->dieUsage( "Bad path: " . $e->getMessage(), "invalidsessiondata" );
74 private $propertyFilter = array(
75 'user', 'userid', 'comment', 'parsedcomment',
76 'mediatype', 'archivename', 'uploadwarning',
79 public function getAllowedParams() {
80 return array(
81 'filekey' => array(
82 ApiBase::PARAM_ISMULTI => true,
83 ApiBase::PARAM_DFLT => null
85 'sessionkey' => array(
86 ApiBase::PARAM_ISMULTI => true,
87 ApiBase::PARAM_DEPRECATED => true,
88 ApiBase::PARAM_DFLT => null
90 'prop' => array(
91 ApiBase::PARAM_ISMULTI => true,
92 ApiBase::PARAM_DFLT => 'timestamp|url',
93 ApiBase::PARAM_TYPE => self::getPropertyNames( $this->propertyFilter ),
94 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-prop',
95 ApiBase::PARAM_HELP_MSG_PER_VALUE => self::getPropertyMessages( $this->propertyFilter )
97 'urlwidth' => array(
98 ApiBase::PARAM_TYPE => 'integer',
99 ApiBase::PARAM_DFLT => -1,
100 ApiBase::PARAM_HELP_MSG => array(
101 'apihelp-query+imageinfo-param-urlwidth',
102 ApiQueryImageInfo::TRANSFORM_LIMIT,
105 'urlheight' => array(
106 ApiBase::PARAM_TYPE => 'integer',
107 ApiBase::PARAM_DFLT => -1,
108 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlheight',
110 'urlparam' => array(
111 ApiBase::PARAM_TYPE => 'string',
112 ApiBase::PARAM_DFLT => '',
113 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlparam',
118 protected function getExamplesMessages() {
119 return array(
120 'action=query&prop=stashimageinfo&siifilekey=124sd34rsdf567'
121 => 'apihelp-query+stashimageinfo-example-simple',
122 'action=query&prop=stashimageinfo&siifilekey=b34edoe3|bceffd4&' .
123 'siiurlwidth=120&siiprop=url'
124 => 'apihelp-query+stashimageinfo-example-params',