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 if ( !$this->getUser()->isLoggedIn() ) {
36 $this->dieUsage( 'You must be logged-in to have an upload stash', 'notloggedin' );
39 $params = $this->extractRequestParams();
40 $modulePrefix = $this->getModulePrefix();
42 $prop = array_flip( $params['prop'] );
44 $scale = $this->getScale( $params );
46 $result = $this->getResult();
48 if ( !$params['filekey'] && !$params['sessionkey'] ) {
49 $this->dieUsage( 'One of filekey or sessionkey must be supplied', 'nofilekey' );
52 // Alias sessionkey to filekey, but give an existing filekey precedence.
53 if ( !$params['filekey'] && $params['sessionkey'] ) {
54 $params['filekey'] = $params['sessionkey'];
58 $stash = RepoGroup
::singleton()->getLocalRepo()->getUploadStash( $this->getUser() );
60 foreach ( $params['filekey'] as $filekey ) {
61 $file = $stash->getFile( $filekey );
62 $finalThumbParam = $this->mergeThumbParams( $file, $scale, $params['urlparam'] );
63 $imageInfo = ApiQueryImageInfo
::getInfo( $file, $prop, $result, $finalThumbParam );
64 $result->addValue( [ 'query', $this->getModuleName() ], null, $imageInfo );
65 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], $modulePrefix );
67 // @todo Update exception handling here to understand current getFile exceptions
68 } catch ( UploadStashFileNotFoundException
$e ) {
69 $this->dieUsage( 'File not found: ' . $e->getMessage(), 'invalidsessiondata' );
70 } catch ( UploadStashBadPathException
$e ) {
71 $this->dieUsage( 'Bad path: ' . $e->getMessage(), 'invalidsessiondata' );
75 private $propertyFilter = [
76 'user', 'userid', 'comment', 'parsedcomment',
77 'mediatype', 'archivename', 'uploadwarning',
80 public function getAllowedParams() {
83 ApiBase
::PARAM_ISMULTI
=> true,
86 ApiBase
::PARAM_ISMULTI
=> true,
87 ApiBase
::PARAM_DEPRECATED
=> true,
90 ApiBase
::PARAM_ISMULTI
=> true,
91 ApiBase
::PARAM_DFLT
=> 'timestamp|url',
92 ApiBase
::PARAM_TYPE
=> self
::getPropertyNames( $this->propertyFilter
),
93 ApiBase
::PARAM_HELP_MSG
=> 'apihelp-query+imageinfo-param-prop',
94 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> self
::getPropertyMessages( $this->propertyFilter
)
97 ApiBase
::PARAM_TYPE
=> 'integer',
98 ApiBase
::PARAM_DFLT
=> -1,
99 ApiBase
::PARAM_HELP_MSG
=> [
100 'apihelp-query+imageinfo-param-urlwidth',
101 ApiQueryImageInfo
::TRANSFORM_LIMIT
,
105 ApiBase
::PARAM_TYPE
=> 'integer',
106 ApiBase
::PARAM_DFLT
=> -1,
107 ApiBase
::PARAM_HELP_MSG
=> 'apihelp-query+imageinfo-param-urlheight',
110 ApiBase
::PARAM_TYPE
=> 'string',
111 ApiBase
::PARAM_DFLT
=> '',
112 ApiBase
::PARAM_HELP_MSG
=> 'apihelp-query+imageinfo-param-urlparam',
117 protected function getExamplesMessages() {
119 'action=query&prop=stashimageinfo&siifilekey=124sd34rsdf567'
120 => 'apihelp-query+stashimageinfo-example-simple',
121 'action=query&prop=stashimageinfo&siifilekey=b34edoe3|bceffd4&' .
122 'siiurlwidth=120&siiprop=url'
123 => 'apihelp-query+stashimageinfo-example-params',
127 public function getHelpUrls() {
128 return 'https://www.mediawiki.org/wiki/API:Stashimageinfo';