API: Add iiprop=canonicaltitle
authorBrad Jorsch <bjorsch@wikimedia.org>
Mon, 9 Dec 2013 16:22:27 +0000 (11:22 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Mon, 9 Dec 2013 16:25:52 +0000 (11:25 -0500)
With recent changes to the filerepo backends, prop=imageinfo will now
return information for the target file when file redirects are queried.
To make this more transparent to clients, add an iiprop to return the
canonical title for the imageinfo data.

Change-Id: I62e368ffe09512f1af6677994f1ccca776b97651

includes/api/ApiQueryImageInfo.php

index 86cba83..bf11a76 100644 (file)
@@ -385,6 +385,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                        }
                }
 
+               $canonicaltitle = isset( $prop['canonicaltitle'] );
                $url = isset( $prop['url'] );
                $sha1 = isset( $prop['sha1'] );
                $meta = isset( $prop['metadata'] );
@@ -395,7 +396,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                $bitdepth = isset( $prop['bitdepth'] );
                $uploadwarning = isset( $prop['uploadwarning'] );
 
-               if ( ( $url || $sha1 || $meta || $mime || $mediatype || $archive || $bitdepth )
+               if ( ( $canonicaltitle || $url || $sha1 || $meta || $mime || $mediatype || $archive || $bitdepth )
                        && $file->isDeleted( File::DELETED_FILE )
                ) {
                        $vals['filehidden'] = '';
@@ -404,6 +405,10 @@ class ApiQueryImageInfo extends ApiQueryBase {
                        return $vals;
                }
 
+               if ( $canonicaltitle ) {
+                       $vals['canonicaltitle'] = $file->getTitle()->getPrefixedText();
+               }
+
                if ( $url ) {
                        if ( !is_null( $thumbParams ) ) {
                                $mto = $file->transform( $thumbParams );
@@ -618,6 +623,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                        'userid' =>         ' userid        - Add the user ID that uploaded the image version',
                        'comment' =>        ' comment       - Comment on the version',
                        'parsedcomment' =>  ' parsedcomment - Parse the comment on the version',
+                       'canonicaltitle' => ' canonicaltitle - Adds the canonical title of the image file',
                        'url' =>            ' url           - Gives URL to the image and the description page',
                        'size' =>           ' size          - Adds the size of the image in bytes ' .
                                'and the height, width and page count (if applicable)',
@@ -737,6 +743,12 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                        ApiBase::PROP_NULLABLE => true
                                )
                        ),
+                       'canonicaltitle' => array(
+                               'canonicaltitle' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       ),
                        'url' => array(
                                'filehidden' => 'boolean',
                                'thumburl' => array(