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( 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 $params['filekey'] = $params['sessionkey'];
54 $stash = RepoGroup
::singleton()->getLocalRepo()->getUploadStash( $this->getUser() );
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->addIndexedTagName( array( 'query', $this->getModuleName() ), $modulePrefix );
63 // @todo Update exception handling here to understand current getFile exceptions
64 } catch ( UploadStashFileNotFoundException
$e ) {
65 $this->dieUsage( "File not found: " . $e->getMessage(), "invalidsessiondata" );
66 } catch ( UploadStashBadPathException
$e ) {
67 $this->dieUsage( "Bad path: " . $e->getMessage(), "invalidsessiondata" );
71 private $propertyFilter = array(
72 'user', 'userid', 'comment', 'parsedcomment',
73 'mediatype', 'archivename', 'uploadwarning',
76 public function getAllowedParams() {
79 ApiBase
::PARAM_ISMULTI
=> true,
81 'sessionkey' => array(
82 ApiBase
::PARAM_ISMULTI
=> true,
83 ApiBase
::PARAM_DEPRECATED
=> true,
86 ApiBase
::PARAM_ISMULTI
=> true,
87 ApiBase
::PARAM_DFLT
=> 'timestamp|url',
88 ApiBase
::PARAM_TYPE
=> self
::getPropertyNames( $this->propertyFilter
),
89 ApiBase
::PARAM_HELP_MSG
=> 'apihelp-query+imageinfo-param-prop',
90 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> self
::getPropertyMessages( $this->propertyFilter
)
93 ApiBase
::PARAM_TYPE
=> 'integer',
94 ApiBase
::PARAM_DFLT
=> -1,
95 ApiBase
::PARAM_HELP_MSG
=> array(
96 'apihelp-query+imageinfo-param-urlwidth',
97 ApiQueryImageInfo
::TRANSFORM_LIMIT
,
100 'urlheight' => array(
101 ApiBase
::PARAM_TYPE
=> 'integer',
102 ApiBase
::PARAM_DFLT
=> -1,
103 ApiBase
::PARAM_HELP_MSG
=> 'apihelp-query+imageinfo-param-urlheight',
106 ApiBase
::PARAM_TYPE
=> 'string',
107 ApiBase
::PARAM_DFLT
=> '',
108 ApiBase
::PARAM_HELP_MSG
=> 'apihelp-query+imageinfo-param-urlparam',
113 protected function getExamplesMessages() {
115 'action=query&prop=stashimageinfo&siifilekey=124sd34rsdf567'
116 => 'apihelp-query+stashimageinfo-example-simple',
117 'action=query&prop=stashimageinfo&siifilekey=b34edoe3|bceffd4&' .
118 'siiurlwidth=120&siiprop=url'
119 => 'apihelp-query+stashimageinfo-example-params',
123 public function getHelpUrls() {
124 return 'https://www.mediawiki.org/wiki/API:Stashimageinfo';