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