* (bug 27586) Remove duplication of props in ApiQueryStashImageInfo by using ApiQuery...
[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 $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 );
53 }
54
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" );
61 }
62 }
63
64 private $propertyFilter = array(
65 'user', 'userid', 'comment', 'parsedcomment',
66 'mediatype', 'archivename',
67 );
68
69 public function getAllowedParams() {
70 return array(
71 'sessionkey' => array(
72 ApiBase::PARAM_ISMULTI => true,
73 ApiBase::PARAM_REQUIRED => true,
74 ApiBase::PARAM_DFLT => null
75 ),
76 'prop' => array(
77 ApiBase::PARAM_ISMULTI => true,
78 ApiBase::PARAM_DFLT => 'timestamp|url',
79 ApiBase::PARAM_TYPE => self::getPropertyNames( $this->propertyFilter )
80 ),
81 'urlwidth' => array(
82 ApiBase::PARAM_TYPE => 'integer',
83 ApiBase::PARAM_DFLT => -1
84 ),
85 'urlheight' => array(
86 ApiBase::PARAM_TYPE => 'integer',
87 ApiBase::PARAM_DFLT => -1
88 ),
89 'urlparam' => array(
90 ApiBase::PARAM_TYPE => 'string',
91 ApiBase::PARAM_DFLT => '',
92 ),
93 );
94 }
95
96 /**
97 * Return the API documentation for the parameters.
98 * @return {Array} parameter documentation.
99 */
100 public function getParamDescription() {
101 $p = $this->getModulePrefix();
102 return array(
103 'prop' => self::getPropertyDescriptions( $this->propertyFilter ),
104 'sessionkey' => 'Session key that identifies a previous upload that was stashed temporarily.',
105 'urlwidth' => "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.",
106 'urlheight' => "Similar to {$p}urlwidth. Cannot be used without {$p}urlwidth",
107 'urlparam' => array( "A handler specific parameter string. For example, pdf's ",
108 "might use 'page15-100px'. {$p}urlwidth must be used and be consistent with {$p}urlparam" ),
109 );
110 }
111
112 public function getDescription() {
113 return 'Returns image information for stashed images';
114 }
115
116 protected function getExamples() {
117 return array(
118 'api.php?action=query&prop=stashimageinfo&siisessionkey=124sd34rsdf567',
119 'api.php?action=query&prop=stashimageinfo&siisessionkey=b34edoe3|bceffd4&siiurlwidth=120&siiprop=url',
120 );
121 }
122
123 public function getVersion() {
124 return __CLASS__ . ': $Id$';
125 }
126
127 }
128