[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
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( ApiQuery $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 if ( !$params['filekey'] && !$params['sessionkey'] ) { 45 $this->dieUsage( "One of filekey or sessionkey must be supplied", 'nofilekey' ); 46 } 47 48 // Alias sessionkey to filekey, but give an existing filekey precedence. 49 if ( !$params['filekey'] && $params['sessionkey'] ) { 50 $this->logFeatureUsage( 'prop=stashimageinfo&siisessionkey' ); 51 $params['filekey'] = $params['sessionkey']; 52 } 53 54 try { 55 $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash(); 56 57 foreach ( $params['filekey'] as $filekey ) { 58 $file = $stash->getFile( $filekey ); 59 $finalThumbParam = $this->mergeThumbParams( $file, $scale, $params['urlparam'] ); 60 $imageInfo = ApiQueryImageInfo::getInfo( $file, $prop, $result, $finalThumbParam ); 61 $result->addValue( array( 'query', $this->getModuleName() ), null, $imageInfo ); 62 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), $modulePrefix ); 63 } 64 // @todo Update exception handling here to understand current getFile exceptions 65 } catch ( UploadStashNotAvailableException $e ) { 66 $this->dieUsage( "Session not available: " . $e->getMessage(), "nosession" ); 67 } catch ( UploadStashFileNotFoundException $e ) { 68 $this->dieUsage( "File not found: " . $e->getMessage(), "invalidsessiondata" ); 69 } catch ( UploadStashBadPathException $e ) { 70 $this->dieUsage( "Bad path: " . $e->getMessage(), "invalidsessiondata" ); 71 } 72 } 73 74 private $propertyFilter = array( 75 'user', 'userid', 'comment', 'parsedcomment', 76 'mediatype', 'archivename', 'uploadwarning', 77 ); 78 79 public function getAllowedParams() { 80 return array( 81 'filekey' => array( 82 ApiBase::PARAM_ISMULTI => true, 83 ApiBase::PARAM_DFLT => null 84 ), 85 'sessionkey' => array( 86 ApiBase::PARAM_ISMULTI => true, 87 ApiBase::PARAM_DEPRECATED => true, 88 ApiBase::PARAM_DFLT => null 89 ), 90 'prop' => array( 91 ApiBase::PARAM_ISMULTI => true, 92 ApiBase::PARAM_DFLT => 'timestamp|url', 93 ApiBase::PARAM_TYPE => self::getPropertyNames( $this->propertyFilter ) 94 ), 95 'urlwidth' => array( 96 ApiBase::PARAM_TYPE => 'integer', 97 ApiBase::PARAM_DFLT => -1 98 ), 99 'urlheight' => array( 100 ApiBase::PARAM_TYPE => 'integer', 101 ApiBase::PARAM_DFLT => -1 102 ), 103 'urlparam' => array( 104 ApiBase::PARAM_TYPE => 'string', 105 ApiBase::PARAM_DFLT => '', 106 ), 107 ); 108 } 109 110 /** 111 * Return the API documentation for the parameters. 112 * @return array Parameter documentation. 113 */ 114 public function getParamDescription() { 115 $p = $this->getModulePrefix(); 116 117 return array( 118 'prop' => self::getPropertyDescriptions( $this->propertyFilter, $p ), 119 'filekey' => 'Key that identifies a previous upload that was stashed temporarily.', 120 'sessionkey' => 'Alias for filekey, for backward compatibility.', 121 'urlwidth' => "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.", 122 'urlheight' => "Similar to {$p}urlwidth. Cannot be used without {$p}urlwidth", 123 'urlparam' => array( "A handler specific parameter string. For example, pdf's ", 124 "might use 'page15-100px'. {$p}urlwidth must be used and be consistent with {$p}urlparam" ), 125 ); 126 } 127 128 public function getDescription() { 129 return 'Returns image information for stashed images.'; 130 } 131 132 public function getExamples() { 133 return array( 134 'api.php?action=query&prop=stashimageinfo&siifilekey=124sd34rsdf567', 135 'api.php?action=query&prop=stashimageinfo&siifilekey=b34edoe3|bceffd4&' . 136 'siiurlwidth=120&siiprop=url', 137 ); 138 } 139 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |