Merge "API: Use message-per-value for apihelp-query+alllinks-param-prop"
[lhc/web/wiklou.git] / includes / api / ApiFormatJson.php
index 41d7051..9538842 100644 (file)
@@ -35,12 +35,21 @@ class ApiFormatJson extends ApiFormatBase {
        public function __construct( ApiMain $main, $format ) {
                parent::__construct( $main, $format );
                $this->isRaw = ( $format === 'rawfm' );
+
+               if ( $this->getMain()->getCheck( 'callback' ) ) {
+                       # T94015: jQuery appends a useless '_' parameter in jsonp mode.
+                       # Mark the parameter as used in that case to avoid a warning that's
+                       # outside the control of the end user.
+                       # (and do it here because ApiMain::reportUnusedParams() gets called
+                       # before our ::execute())
+                       $this->getMain()->getCheck( '_' );
+               }
        }
 
        public function getMimeType() {
                $params = $this->extractRequestParams();
                // callback:
-               if ( $params['callback'] ) {
+               if ( isset( $params['callback'] ) ) {
                        return 'text/javascript';
                }
 
@@ -91,7 +100,7 @@ class ApiFormatJson extends ApiFormatBase {
                                        break;
 
                                default:
-                                       self::dieUsage( __METHOD__ . ': Unknown value for \'formatversion\'' );
+                                       $this->dieUsage( __METHOD__ . ': Unknown value for \'formatversion\'', 'unknownformatversion' );
                        }
                }
                $data = $this->getResult()->getResultData( null, $transform );
@@ -106,9 +115,8 @@ class ApiFormatJson extends ApiFormatBase {
                        );
                }
 
-               $callback = $params['callback'];
-               if ( $callback !== null ) {
-                       $callback = preg_replace( "/[^][.\\'\\\"_A-Za-z0-9]/", '', $callback );
+               if ( isset( $params['callback'] ) ) {
+                       $callback = preg_replace( "/[^][.\\'\\\"_A-Za-z0-9]/", '', $params['callback'] );
                        # Prepend a comment to try to avoid attacks against content
                        # sniffers, such as bug 68187.
                        $this->printText( "/**/$callback($json)" );