X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiFormatJson.php;h=e5dafae602087e6c663df09894b869b786ebb611;hb=e7ea585d7f0f404230b4d49c37f40db81ebcaa09;hp=1566a0ff49255107d81df23615782d2892275150;hpb=b85192c7a7cd5f2b5c03c55c1627c14510ef6a1a;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiFormatJson.php b/includes/api/ApiFormatJson.php index 1566a0ff49..e5dafae602 100644 --- a/includes/api/ApiFormatJson.php +++ b/includes/api/ApiFormatJson.php @@ -42,7 +42,7 @@ class ApiFormatJson extends ApiFormatBase { # outside the control of the end user. # (and do it here because ApiMain::reportUnusedParams() gets called # before our ::execute()) - $this->getMain()->getCheck( '_' ); + $this->getMain()->markParamsUsed( '_' ); } } @@ -56,63 +56,54 @@ class ApiFormatJson extends ApiFormatBase { return 'application/json'; } - /** - * @deprecated since 1.25 - */ - public function getWantsHelp() { - wfDeprecated( __METHOD__, '1.25' ); - // Help is always ugly in JSON - return false; - } - public function execute() { $params = $this->extractRequestParams(); $opt = 0; if ( $this->isRaw ) { $opt |= FormatJson::ALL_OK; - $transform = array(); + $transform = []; } else { switch ( $params['formatversion'] ) { case 1: $opt |= $params['utf8'] ? FormatJson::ALL_OK : FormatJson::XMLMETA_OK; - $transform = array( - 'BC' => array(), - 'Types' => array( 'AssocAsObject' => true ), + $transform = [ + 'BC' => [], + 'Types' => [ 'AssocAsObject' => true ], 'Strip' => 'all', - ); + ]; break; case 2: case 'latest': $opt |= $params['ascii'] ? FormatJson::XMLMETA_OK : FormatJson::ALL_OK; - $transform = array( - 'Types' => array( 'AssocAsObject' => true ), + $transform = [ + 'Types' => [ 'AssocAsObject' => true ], 'Strip' => 'all', - ); + ]; break; default: - $this->dieUsage( __METHOD__ . - ': Unknown value for \'formatversion\'', 'unknownformatversion' ); + // Should have been caught during parameter validation + $this->dieDebug( __METHOD__, 'Unknown value for \'formatversion\'' ); } } $data = $this->getResult()->getResultData( null, $transform ); $json = FormatJson::encode( $data, $this->getIsHtml(), $opt ); - // Bug 66776: wfMangleFlashPolicy() is needed to avoid a nasty bug in + // T68776: wfMangleFlashPolicy() is needed to avoid a nasty bug in // Flash, but what it does isn't friendly for the API, so we need to // work around it. - if ( preg_match( '/\<\s*cross-domain-policy\s*\>/i', $json ) ) { + if ( preg_match( '/\<\s*cross-domain-policy(?=\s|\>)/i', $json ) ) { $json = preg_replace( - '/\<(\s*cross-domain-policy\s*)\>/i', '\\u003C$1\\u003E', $json + '/\<(\s*cross-domain-policy(?=\s|\>))/i', '\\u003C$1', $json ); } 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. + # sniffers, such as T70187. $this->printText( "/**/$callback($json)" ); } else { $this->printText( $json ); @@ -124,24 +115,24 @@ class ApiFormatJson extends ApiFormatBase { return parent::getAllowedParams(); } - $ret = parent::getAllowedParams() + array( - 'callback' => array( + $ret = parent::getAllowedParams() + [ + 'callback' => [ ApiBase::PARAM_HELP_MSG => 'apihelp-json-param-callback', - ), - 'utf8' => array( + ], + 'utf8' => [ ApiBase::PARAM_DFLT => false, ApiBase::PARAM_HELP_MSG => 'apihelp-json-param-utf8', - ), - 'ascii' => array( + ], + 'ascii' => [ ApiBase::PARAM_DFLT => false, ApiBase::PARAM_HELP_MSG => 'apihelp-json-param-ascii', - ), - 'formatversion' => array( - ApiBase::PARAM_TYPE => array( 1, 2, 'latest' ), + ], + 'formatversion' => [ + ApiBase::PARAM_TYPE => [ 1, 2, 'latest' ], ApiBase::PARAM_DFLT => 1, ApiBase::PARAM_HELP_MSG => 'apihelp-json-param-formatversion', - ), - ); + ], + ]; return $ret; } }