Make the UploadStash repo specific by creating FileRepo::getUploadStash(). In practic...
[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( $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 try {
45 $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash();
46
47 foreach ( $params['sessionkey'] as $sessionkey ) {
48 $file = $stash->getFile( $sessionkey );
49 $imageInfo = self::getInfo( $file, $prop, $result, $scale );
50 $result->addValue( array( 'query', $this->getModuleName() ), null, $imageInfo );
51 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), $modulePrefix );
52 }
53
54 } catch ( UploadStashNotAvailableException $e ) {
55 $this->dieUsage( "Session not available: " . $e->getMessage(), "nosession" );
56 } catch ( UploadStashFileNotFoundException $e ) {
57 $this->dieUsage( "File not found: " . $e->getMessage(), "invalidsessiondata" );
58 } catch ( UploadStashBadPathException $e ) {
59 $this->dieUsage( "Bad path: " . $e->getMessage(), "invalidsessiondata" );
60 }
61 }
62
63 /**
64 * Returns all valid parameters to siiprop
65 */
66 public static function getPropertyNames() {
67 return array(
68 'timestamp',
69 'url',
70 'size',
71 'dimensions', // For backwards compatibility with Allimages
72 'sha1',
73 'mime',
74 'thumbmime',
75 'metadata',
76 'bitdepth',
77 );
78 }
79
80
81 public function getAllowedParams() {
82 return array(
83 'sessionkey' => array(
84 ApiBase::PARAM_ISMULTI => true,
85 ApiBase::PARAM_REQUIRED => true,
86 ApiBase::PARAM_DFLT => null
87 ),
88 'prop' => array(
89 ApiBase::PARAM_ISMULTI => true,
90 ApiBase::PARAM_DFLT => 'timestamp|url',
91 ApiBase::PARAM_TYPE => self::getPropertyNames()
92 ),
93 'urlwidth' => array(
94 ApiBase::PARAM_TYPE => 'integer',
95 ApiBase::PARAM_DFLT => -1
96 ),
97 'urlheight' => array(
98 ApiBase::PARAM_TYPE => 'integer',
99 ApiBase::PARAM_DFLT => -1
100 )
101 );
102 }
103
104 /**
105 * Return the API documentation for the parameters.
106 * @return {Array} parameter documentation.
107 */
108 public function getParamDescription() {
109 $p = $this->getModulePrefix();
110 return array(
111 'prop' => array(
112 'What image information to get:',
113 ' timestamp - Adds timestamp for the uploaded version',
114 ' url - Gives URL to the image and the description page',
115 ' size - Adds the size of the image in bytes and the height and width',
116 ' dimensions - Alias for size',
117 ' sha1 - Adds sha1 hash for the image',
118 ' mime - Adds MIME of the image',
119 ' thumbmime - Adds MIME of the image thumbnail (requires url)',
120 ' metadata - Lists EXIF metadata for the version of the image',
121 ' bitdepth - Adds the bit depth of the version',
122 ),
123 'sessionkey' => 'Session key that identifies a previous upload that was stashed temporarily.',
124 'urlwidth' => "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.",
125 'urlheight' => "Similar to {$p}urlwidth. Cannot be used without {$p}urlwidth"
126 );
127 }
128
129 public function getDescription() {
130 return 'Returns image information for stashed images';
131 }
132
133 public function getPossibleErrors() {
134 return array_merge( parent::getPossibleErrors(), array(
135 array( 'code' => 'siiurlwidth', 'info' => 'siiurlheight cannot be used without iiurlwidth' ),
136 ) );
137 }
138
139 protected function getExamples() {
140 return array(
141 'api.php?action=query&prop=stashimageinfo&siisessionkey=124sd34rsdf567',
142 'api.php?action=query&prop=stashimageinfo&siisessionkey=b34edoe3|bceffd4&siiurlwidth=120&siiprop=url',
143 );
144 }
145
146 public function getVersion() {
147 return __CLASS__ . ': $Id$';
148 }
149
150 }
151