X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiBase.php;h=3e57e8997abd9e27929e8e20bf4c0d4fb54aa819;hb=64f0f6816d3e1bd1888495ccb7b332c30358b1ad;hp=da64c038affe35ed83de34e45253bd283e9326ba;hpb=46202ee2b218e7f2813ec97ece046b4850fd78a7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index da64c038af..3e57e8997a 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -503,7 +503,13 @@ abstract class ApiBase extends ContextSource { * @return bool */ public function lacksSameOriginSecurity() { - return $this->getMain()->getRequest()->getVal( 'callback' ) !== null; + // Main module has this method overridden + // Safety - avoid infinite loop: + if ( $this->isMain() ) { + ApiBase::dieDebug( __METHOD__, 'base method was called on main module.' ); + } + + return $this->getMain()->lacksSameOriginSecurity(); } /** @@ -1522,20 +1528,20 @@ abstract class ApiBase extends ContextSource { throw new MWException( 'Successful status passed to ApiBase::dieStatus' ); } - $errors = $status->getErrorsArray(); + $errors = $status->getErrorsByType( 'error' ); if ( !$errors ) { // No errors? Assume the warnings should be treated as errors - $errors = $status->getWarningsArray(); + $errors = $status->getErrorsByType( 'warning' ); } if ( !$errors ) { // Still no errors? Punt - $errors = [ [ 'unknownerror-nocode' ] ]; + $errors = [ [ 'message' => 'unknownerror-nocode', 'params' => [] ] ]; } // Cannot use dieUsageMsg() because extensions might return custom // error messages. - if ( $errors[0] instanceof Message ) { - $msg = $errors[0]; + if ( $errors[0]['message'] instanceof Message ) { + $msg = $errors[0]['message']; if ( $msg instanceof IApiMessage ) { $extraData = $msg->getApiData(); $code = $msg->getApiCode(); @@ -1543,8 +1549,8 @@ abstract class ApiBase extends ContextSource { $code = $msg->getKey(); } } else { - $code = array_shift( $errors[0] ); - $msg = wfMessage( $code, $errors[0] ); + $code = $errors[0]['message']; + $msg = wfMessage( $code, $errors[0]['params'] ); } if ( isset( ApiBase::$messageMap[$code] ) ) { // Translate message to code, for backwards compatibility @@ -2087,7 +2093,7 @@ abstract class ApiBase extends ContextSource { /** * Output the error message related to a certain array - * @param array|string $error Element of a getUserPermissionsErrors()-style array + * @param array|string|MessageSpecifier $error Element of a getUserPermissionsErrors()-style array * @throws UsageException always */ public function dieUsageMsg( $error ) { @@ -2104,7 +2110,7 @@ abstract class ApiBase extends ContextSource { /** * Will only set a warning instead of failing if the global $wgDebugAPI * is set to true. Otherwise behaves exactly as dieUsageMsg(). - * @param array|string $error Element of a getUserPermissionsErrors()-style array + * @param array|string|MessageSpecifier $error Element of a getUserPermissionsErrors()-style array * @throws UsageException * @since 1.21 */ @@ -2137,32 +2143,38 @@ abstract class ApiBase extends ContextSource { /** * Return the error message related to a certain array - * @param array $error Element of a getUserPermissionsErrors()-style array + * @param array|string|MessageSpecifier $error Element of a getUserPermissionsErrors()-style array * @return array('code' => code, 'info' => info) */ public function parseMsg( $error ) { - $error = (array)$error; // It seems strings sometimes make their way in here - $key = array_shift( $error ); - - // Check whether the error array was nested - // array( array( , ), array( , ) ) - if ( is_array( $key ) ) { - $error = $key; - $key = array_shift( $error ); + // Check whether someone passed the whole array, instead of one element as + // documented. This breaks if it's actually an array of fallback keys, but + // that's long-standing misbehavior introduced in r87627 to incorrectly + // fix T30797. + if ( is_array( $error ) ) { + $first = reset( $error ); + if ( is_array( $first ) ) { + wfDebug( __METHOD__ . ' was passed an array of arrays. ' . wfGetAllCallers( 5 ) ); + $error = $first; + } } - if ( $key instanceof IApiMessage ) { + $msg = Message::newFromSpecifier( $error ); + + if ( $msg instanceof IApiMessage ) { return [ - 'code' => $key->getApiCode(), - 'info' => $key->inLanguage( 'en' )->useDatabase( false )->text(), - 'data' => $key->getApiData() + 'code' => $msg->getApiCode(), + 'info' => $msg->inLanguage( 'en' )->useDatabase( false )->text(), + 'data' => $msg->getApiData() ]; } + $key = $msg->getKey(); if ( isset( self::$messageMap[$key] ) ) { + $params = $msg->getParams(); return [ - 'code' => wfMsgReplaceArgs( self::$messageMap[$key]['code'], $error ), - 'info' => wfMsgReplaceArgs( self::$messageMap[$key]['info'], $error ) + 'code' => wfMsgReplaceArgs( self::$messageMap[$key]['code'], $params ), + 'info' => wfMsgReplaceArgs( self::$messageMap[$key]['info'], $params ) ]; }