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
24 * A query action to get image information from temporarily stashed files.
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();
45 $stash = RepoGroup
::singleton()->getLocalRepo()->getUploadStash();
47 foreach ( $params['sessionkey'] as $sessionkey ) {
48 $file = $stash->getFile( $sessionkey );
49 $finalThumbParam = $this->mergeThumbParams( $file, $scale, $params['urlparam'] );
50 $imageInfo = ApiQueryImageInfo
::getInfo( $file, $prop, $result, $finalThumbParam );
51 $result->addValue( array( 'query', $this->getModuleName() ), null, $imageInfo );
52 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), $modulePrefix );
55 } catch ( UploadStashNotAvailableException
$e ) {
56 $this->dieUsage( "Session not available: " . $e->getMessage(), "nosession" );
57 } catch ( UploadStashFileNotFoundException
$e ) {
58 $this->dieUsage( "File not found: " . $e->getMessage(), "invalidsessiondata" );
59 } catch ( UploadStashBadPathException
$e ) {
60 $this->dieUsage( "Bad path: " . $e->getMessage(), "invalidsessiondata" );
65 * Returns all valid parameters to siiprop
67 public static function getPropertyNames() {
72 'dimensions', // For backwards compatibility with Allimages
81 public function getAllowedParams() {
83 'sessionkey' => array(
84 ApiBase
::PARAM_ISMULTI
=> true,
85 ApiBase
::PARAM_REQUIRED
=> true,
86 ApiBase
::PARAM_DFLT
=> null
89 ApiBase
::PARAM_ISMULTI
=> true,
90 ApiBase
::PARAM_DFLT
=> 'timestamp|url',
91 ApiBase
::PARAM_TYPE
=> self
::getPropertyNames()
94 ApiBase
::PARAM_TYPE
=> 'integer',
95 ApiBase
::PARAM_DFLT
=> -1
98 ApiBase
::PARAM_TYPE
=> 'integer',
99 ApiBase
::PARAM_DFLT
=> -1
102 ApiBase
::PARAM_TYPE
=> 'string',
103 ApiBase
::PARAM_DFLT
=> '',
109 * Return the API documentation for the parameters.
110 * @return {Array} parameter documentation.
112 public function getParamDescription() {
113 $p = $this->getModulePrefix();
116 'What image information to get:',
117 ' timestamp - Adds timestamp for the uploaded version',
118 ' url - Gives URL to the image and the description page',
119 ' size - Adds the size of the image in bytes and the height, width and page count (if applicable)',
120 ' dimensions - Alias for size',
121 ' sha1 - Adds sha1 hash for the image',
122 ' mime - Adds MIME of the image',
123 ' thumbmime - Adds MIME of the image thumbnail (requires url)',
124 ' metadata - Lists EXIF metadata for the version of the image',
125 ' bitdepth - Adds the bit depth of the version',
127 'sessionkey' => 'Session key that identifies a previous upload that was stashed temporarily.',
128 'urlwidth' => "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.",
129 'urlheight' => "Similar to {$p}urlwidth. Cannot be used without {$p}urlwidth",
130 'urlparam' => array( "A handler specific parameter string. For example, pdf's ",
131 "might use 'page15-100px'. {$p}urlwidth must be used and be consistent with {$p}urlparam" ),
135 public function getDescription() {
136 return 'Returns image information for stashed images';
139 protected function getExamples() {
141 'api.php?action=query&prop=stashimageinfo&siisessionkey=124sd34rsdf567',
142 'api.php?action=query&prop=stashimageinfo&siisessionkey=b34edoe3|bceffd4&siiurlwidth=120&siiprop=url',
146 public function getVersion() {
147 return __CLASS__
. ': $Id$';