MediaWiki
REL1_24
|
00001 <?php 00028 class ApiQueryStashImageInfo extends ApiQueryImageInfo { 00029 00030 public function __construct( ApiQuery $query, $moduleName ) { 00031 parent::__construct( $query, $moduleName, 'sii' ); 00032 } 00033 00034 public function execute() { 00035 $params = $this->extractRequestParams(); 00036 $modulePrefix = $this->getModulePrefix(); 00037 00038 $prop = array_flip( $params['prop'] ); 00039 00040 $scale = $this->getScale( $params ); 00041 00042 $result = $this->getResult(); 00043 00044 if ( !$params['filekey'] && !$params['sessionkey'] ) { 00045 $this->dieUsage( "One of filekey or sessionkey must be supplied", 'nofilekey' ); 00046 } 00047 00048 // Alias sessionkey to filekey, but give an existing filekey precedence. 00049 if ( !$params['filekey'] && $params['sessionkey'] ) { 00050 $this->logFeatureUsage( 'prop=stashimageinfo&siisessionkey' ); 00051 $params['filekey'] = $params['sessionkey']; 00052 } 00053 00054 try { 00055 $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash(); 00056 00057 foreach ( $params['filekey'] as $filekey ) { 00058 $file = $stash->getFile( $filekey ); 00059 $finalThumbParam = $this->mergeThumbParams( $file, $scale, $params['urlparam'] ); 00060 $imageInfo = ApiQueryImageInfo::getInfo( $file, $prop, $result, $finalThumbParam ); 00061 $result->addValue( array( 'query', $this->getModuleName() ), null, $imageInfo ); 00062 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), $modulePrefix ); 00063 } 00064 // @todo Update exception handling here to understand current getFile exceptions 00065 } catch ( UploadStashNotAvailableException $e ) { 00066 $this->dieUsage( "Session not available: " . $e->getMessage(), "nosession" ); 00067 } catch ( UploadStashFileNotFoundException $e ) { 00068 $this->dieUsage( "File not found: " . $e->getMessage(), "invalidsessiondata" ); 00069 } catch ( UploadStashBadPathException $e ) { 00070 $this->dieUsage( "Bad path: " . $e->getMessage(), "invalidsessiondata" ); 00071 } 00072 } 00073 00074 private $propertyFilter = array( 00075 'user', 'userid', 'comment', 'parsedcomment', 00076 'mediatype', 'archivename', 'uploadwarning', 00077 ); 00078 00079 public function getAllowedParams() { 00080 return array( 00081 'filekey' => array( 00082 ApiBase::PARAM_ISMULTI => true, 00083 ApiBase::PARAM_DFLT => null 00084 ), 00085 'sessionkey' => array( 00086 ApiBase::PARAM_ISMULTI => true, 00087 ApiBase::PARAM_DEPRECATED => true, 00088 ApiBase::PARAM_DFLT => null 00089 ), 00090 'prop' => array( 00091 ApiBase::PARAM_ISMULTI => true, 00092 ApiBase::PARAM_DFLT => 'timestamp|url', 00093 ApiBase::PARAM_TYPE => self::getPropertyNames( $this->propertyFilter ) 00094 ), 00095 'urlwidth' => array( 00096 ApiBase::PARAM_TYPE => 'integer', 00097 ApiBase::PARAM_DFLT => -1 00098 ), 00099 'urlheight' => array( 00100 ApiBase::PARAM_TYPE => 'integer', 00101 ApiBase::PARAM_DFLT => -1 00102 ), 00103 'urlparam' => array( 00104 ApiBase::PARAM_TYPE => 'string', 00105 ApiBase::PARAM_DFLT => '', 00106 ), 00107 ); 00108 } 00109 00114 public function getParamDescription() { 00115 $p = $this->getModulePrefix(); 00116 00117 return array( 00118 'prop' => self::getPropertyDescriptions( $this->propertyFilter, $p ), 00119 'filekey' => 'Key that identifies a previous upload that was stashed temporarily.', 00120 'sessionkey' => 'Alias for filekey, for backward compatibility.', 00121 'urlwidth' => "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.", 00122 'urlheight' => "Similar to {$p}urlwidth. Cannot be used without {$p}urlwidth", 00123 'urlparam' => array( "A handler specific parameter string. For example, pdf's ", 00124 "might use 'page15-100px'. {$p}urlwidth must be used and be consistent with {$p}urlparam" ), 00125 ); 00126 } 00127 00128 public function getDescription() { 00129 return 'Returns image information for stashed images.'; 00130 } 00131 00132 public function getExamples() { 00133 return array( 00134 'api.php?action=query&prop=stashimageinfo&siifilekey=124sd34rsdf567', 00135 'api.php?action=query&prop=stashimageinfo&siifilekey=b34edoe3|bceffd4&' . 00136 'siiurlwidth=120&siiprop=url', 00137 ); 00138 } 00139 }