Merge "Added some extra tests for ORMRow class"
[lhc/web/wiklou.git] / includes / api / ApiQueryImageInfo.php
index 2ccee27..969293b 100644 (file)
  * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( 'ApiQueryBase.php' );
-}
-
 /**
  * A query action to get image information and upload history.
  *
@@ -217,7 +212,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
         * to know which handler, since handlers can make their own parameters.
         * @param File $image Image that params are for.
         * @param Array $thumbParams thumbnail parameters from getScale
-        * @param String String of otherParams (iiurlparam).
+        * @param String $otherParams of otherParams (iiurlparam).
         * @return Array of parameters for transform.
         */
        protected function mergeThumbParams ( $image, $thumbParams, $otherParams ) {
@@ -228,7 +223,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
 
                $h = $image->getHandler();
                if ( !$h ) {
-                       $this->setWarning( 'Could not create thumbnail because ' . 
+                       $this->setWarning( 'Could not create thumbnail because ' .
                                $image->getName() . ' does not have an associated image handler' );
                        return $thumbParams;
                }
@@ -267,7 +262,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
         * @param $prop Array of properties to get (in the keys)
         * @param $result ApiResult object
         * @param $thumbParams Array containing 'width' and 'height' items, or null
-        * @param $version Version of image metadata (for things like jpeg which have different versions).
+        * @param $version string Version of image metadata (for things like jpeg which have different versions).
         * @return Array: result array
         */
        static function getInfo( $file, $prop, $result, $thumbParams = null, $version = 'latest' ) {
@@ -318,8 +313,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                $vals['commenthidden'] = '';
                        } else {
                                if ( $pcomment ) {
-                                       global $wgUser;
-                                       $vals['parsedcomment'] = $wgUser->getSkin()->formatComment(
+                                       $vals['parsedcomment'] = Linker::formatComment(
                                                $file->getDescription(), $file->getTitle() );
                                }
                                if ( $comment ) {
@@ -348,7 +342,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                        if ( !is_null( $thumbParams ) ) {
                                $mto = $file->transform( $thumbParams );
                                if ( $mto && !$mto->isError() ) {
-                                       $vals['thumburl'] = wfExpandUrl( $mto->getUrl() );
+                                       $vals['thumburl'] = wfExpandUrl( $mto->getUrl(), PROTO_CURRENT );
 
                                        // bug 23834 - If the URL's are the same, we haven't resized it, so shouldn't give the wanted
                                        // thumbnail sizes for the thumbnail actual size
@@ -361,17 +355,17 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                        }
 
                                        if ( isset( $prop['thumbmime'] ) && $file->getHandler() ) {
-                                               list( $ext, $mime ) = $file->getHandler()->getThumbType( 
-                                                       substr( $mto->getPath(), strrpos( $mto->getPath(), '.' ) + 1 ), 
+                                               list( $ext, $mime ) = $file->getHandler()->getThumbType(
+                                                       substr( $mto->getPath(), strrpos( $mto->getPath(), '.' ) + 1 ),
                                                        $file->getMimeType(), $thumbParams );
                                                $vals['thumbmime'] = $mime;
                                        }
-                               } else if ( $mto && $mto->isError() ) {
+                               } elseif ( $mto && $mto->isError() ) {
                                        $vals['thumberror'] = $mto->toText();
                                }
                        }
-                       $vals['url'] = $file->getFullURL();
-                       $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl() );
+                       $vals['url'] = wfExpandUrl( $file->getFullURL(), PROTO_CURRENT );
+                       $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl(), PROTO_CURRENT );
                }
 
                if ( $sha1 ) {
@@ -436,7 +430,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
         * @param $img File
         * @return string
         */
-       private function getContinueStr( $img ) {
+       protected function getContinueStr( $img ) {
                return $img->getOriginalTitle()->getText() .
                        '|' .  $img->getTimestamp();
        }
@@ -519,7 +513,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
 
        /**
         * Returns the descriptions for the properties provided by getPropertyNames()
-        * 
+        *
         * @param array $filter List of properties to filter out
         *
         * @return array
@@ -533,7 +527,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
 
        /**
         * Return the API documentation for the parameters.
-        * @return {Array} parameter documentation.
+        * @return Array parameter documentation.
         */
        public function getParamDescription() {
                $p = $this->getModulePrefix();
@@ -547,12 +541,120 @@ class ApiQueryImageInfo extends ApiQueryBase {
                        'limit' => 'How many image revisions to return',
                        'start' => 'Timestamp to start listing from',
                        'end' => 'Timestamp to stop listing at',
-                       'metadataversion' => array( "Version of metadata to use. if 'latest' is specified, use latest version.", 
+                       'metadataversion' => array( "Version of metadata to use. if 'latest' is specified, use latest version.",
                                                "Defaults to '1' for backwards compatibility" ),
                        'continue' => 'If the query response includes a continue value, use it here to get another page of results'
                );
        }
 
+       public static function getResultPropertiesFiltered( $filter = array() ) {
+               $props = array(
+                       'timestamp' => array(
+                               'timestamp' => 'timestamp'
+                       ),
+                       'user' => array(
+                               'userhidden' => 'boolean',
+                               'user' => 'string',
+                               'anon' => 'boolean'
+                       ),
+                       'userid' => array(
+                               'userhidden' => 'boolean',
+                               'userid' => 'integer',
+                               'anon' => 'boolean'
+                       ),
+                       'size' => array(
+                               'size' => 'integer',
+                               'width' => 'integer',
+                               'height' => 'integer',
+                               'pagecount' => array(
+                                       ApiBase::PROP_TYPE => 'integer',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       ),
+                       'comment' => array(
+                               'commenthidden' => 'boolean',
+                               'comment' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       ),
+                       'parsedcomment' => array(
+                               'commenthidden' => 'boolean',
+                               'parsedcomment' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       ),
+                       'url' => array(
+                               'filehidden' => 'boolean',
+                               'thumburl' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               ),
+                               'thumbwidth' => array(
+                                       ApiBase::PROP_TYPE => 'integer',
+                                       ApiBase::PROP_NULLABLE => true
+                               ),
+                               'thumbheight' => array(
+                                       ApiBase::PROP_TYPE => 'integer',
+                                       ApiBase::PROP_NULLABLE => true
+                               ),
+                               'thumberror' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               ),
+                               'url' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               ),
+                               'descriptionurl' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       ),
+                       'sha1' => array(
+                               'filehidden' => 'boolean',
+                               'sha1' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       ),
+                       'mime' => array(
+                               'filehidden' => 'boolean',
+                               'mime' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       ),
+                       'mediatype' => array(
+                               'filehidden' => 'boolean',
+                               'mediatype' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       ),
+                       'archivename' => array(
+                               'filehidden' => 'boolean',
+                               'archivename' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       ),
+                       'bitdepth' => array(
+                               'filehidden' => 'boolean',
+                               'bitdepth' => array(
+                                       ApiBase::PROP_TYPE => 'integer',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       ),
+               );
+               return array_diff_key( $props, array_flip( $filter ) );
+       }
+
+       public function getResultProperties() {
+               return self::getResultPropertiesFiltered();
+       }
+
        public function getDescription() {
                return 'Returns image information and upload history';
        }
@@ -564,17 +666,21 @@ class ApiQueryImageInfo extends ApiQueryBase {
                        array( 'code' => 'urlparam', 'info' => "Invalid value for {$p}urlparam" ),
                        array( 'code' => 'urlparam_no_width', 'info' => "{$p}urlparam requires {$p}urlwidth" ),
                        array( 'code' => 'urlparam_urlwidth_mismatch', 'info' => "The width set in {$p}urlparm doesnt't " .
-                               "match the one in {$p}urlwidth" ), 
+                               "match the one in {$p}urlwidth" ),
                ) );
        }
 
-       protected function getExamples() {
+       public function getExamples() {
                return array(
                        'api.php?action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo',
                        'api.php?action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&iiend=20071231235959&iiprop=timestamp|user|url',
                );
        }
 
+       public function getHelpUrls() {
+               return 'https://www.mediawiki.org/wiki/API:Properties#imageinfo_.2F_ii';
+       }
+
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }