Merge "Drop index oi_name_archive_name on table oldimage"
[lhc/web/wiklou.git] / includes / api / ApiQueryImageInfo.php
index 0bbfad3..e5e45b3 100644 (file)
@@ -58,6 +58,15 @@ class ApiQueryImageInfo extends ApiQueryBase {
                        'revdelUser' => $this->getUser(),
                ];
 
+               if ( isset( $params['badfilecontexttitle'] ) ) {
+                       $badFileContextTitle = Title::newFromText( $params['badfilecontexttitle'] );
+                       if ( !$badFileContextTitle ) {
+                               $this->dieUsage( 'Invalid title in badfilecontexttitle parameter', 'invalid-title' );
+                       }
+               } else {
+                       $badFileContextTitle = false;
+               }
+
                $pageIds = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
                if ( !empty( $pageIds[NS_FILE] ) ) {
                        $titles = array_keys( $pageIds[NS_FILE] );
@@ -95,13 +104,16 @@ class ApiQueryImageInfo extends ApiQueryBase {
 
                        $result = $this->getResult();
                        foreach ( $titles as $title ) {
+                               $info = [];
                                $pageId = $pageIds[NS_FILE][$title];
                                $start = $title === $fromTitle ? $fromTimestamp : $params['start'];
 
                                if ( !isset( $images[$title] ) ) {
-                                       if ( isset( $prop['uploadwarning'] ) ) {
-                                               // Uploadwarning needs info about non-existing files
+                                       if ( isset( $prop['uploadwarning'] ) || isset( $prop['badfile'] ) ) {
+                                               // uploadwarning and badfile need info about non-existing files
                                                $images[$title] = wfLocalFile( $title );
+                                               // Doesn't exist, so set an empty image repository
+                                               $info['imagerepository'] = '';
                                        } else {
                                                $result->addValue(
                                                        [ 'query', 'pages', intval( $pageId ) ],
@@ -128,10 +140,14 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                        break;
                                }
 
-                               $fit = $result->addValue(
-                                       [ 'query', 'pages', intval( $pageId ) ],
-                                       'imagerepository', $img->getRepoName()
-                               );
+                               if ( !isset( $info['imagerepository'] ) ) {
+                                       $info['imagerepository'] = $img->getRepoName();
+                               }
+                               if ( isset( $prop['badfile'] ) ) {
+                                       $info['badfile'] = (bool)wfIsBadImage( $title, $badFileContextTitle );
+                               }
+
+                               $fit = $result->addValue( [ 'query', 'pages' ], intval( $pageId ), $info );
                                if ( !$fit ) {
                                        if ( count( $pageIds[NS_FILE] ) == 1 ) {
                                                // The user is screwed. imageinfo can't be solely
@@ -493,7 +509,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                if ( $mto && !$mto->isError() ) {
                                        $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
+                                       // T25834 - If the URLs are the same, we haven't resized it, so shouldn't give the wanted
                                        // thumbnail sizes for the thumbnail actual size
                                        if ( $mto->getUrl() !== $file->getUrl() ) {
                                                $vals['thumbwidth'] = intval( $mto->getWidth() );
@@ -688,6 +704,9 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                ApiBase::PARAM_DFLT => '',
                                ApiBase::PARAM_TYPE => 'string',
                        ],
+                       'badfilecontexttitle' => [
+                               ApiBase::PARAM_TYPE => 'string',
+                       ],
                        'continue' => [
                                ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
                        ],
@@ -733,6 +752,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                'archivename' => 'apihelp-query+imageinfo-paramvalue-prop-archivename',
                                'bitdepth' => 'apihelp-query+imageinfo-paramvalue-prop-bitdepth',
                                'uploadwarning' => 'apihelp-query+imageinfo-paramvalue-prop-uploadwarning',
+                               'badfile' => 'apihelp-query+imageinfo-paramvalue-prop-badfile',
                        ],
                        array_flip( $filter )
                );