X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fapi%2FApiBase.php;h=e798414a6f7206292a365b132c5aabd6896e66d1;hp=bc62906ab9076310d855fa6c0e6e603428418884;hb=a4d976fc833193c3a19c082de77d52b69cf2cb1d;hpb=3074a4521a18e78e52ba44cc7c185bac7af4a866 diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index bc62906ab9..e798414a6f 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -21,7 +21,10 @@ */ use MediaWiki\Block\AbstractBlock; +use MediaWiki\Block\DatabaseBlock; +use MediaWiki\Linker\LinkTarget; use MediaWiki\MediaWikiServices; +use MediaWiki\Permissions\PermissionManager; use Wikimedia\Rdbms\IDatabase; /** @@ -697,6 +700,16 @@ abstract class ApiBase extends ContextSource { $this->getMain()->setContinuationManager( $manager ); } + /** + * Obtain a PermissionManager instance that subclasses may use in their authorization checks. + * + * @since 1.34 + * @return PermissionManager + */ + protected function getPermissionManager(): PermissionManager { + return MediaWikiServices::getInstance()->getPermissionManager(); + } + /**@}*/ /************************************************************************//** @@ -1816,7 +1829,7 @@ abstract class ApiBase extends ContextSource { if ( is_string( $error[0] ) && isset( self::$blockMsgMap[$error[0]] ) && $user->getBlock() ) { list( $msg, $code ) = self::$blockMsgMap[$error[0]]; $status->fatal( ApiMessage::create( $msg, $code, - [ 'blockinfo' => $this->getBlockInfo( $user->getBlock() ) ] + [ 'blockinfo' => $this->getBlockDetails( $user->getBlock() ) ] ) ); } else { $status->fatal( ...$error ); @@ -1839,7 +1852,7 @@ abstract class ApiBase extends ContextSource { foreach ( self::$blockMsgMap as $msg => list( $apiMsg, $code ) ) { if ( $status->hasMessage( $msg ) && $user->getBlock() ) { $status->replaceMessage( $msg, ApiMessage::create( $apiMsg, $code, - [ 'blockinfo' => $this->getBlockInfo( $user->getBlock() ) ] + [ 'blockinfo' => $this->getBlockDetails( $user->getBlock() ) ] ) ); } } @@ -2029,28 +2042,28 @@ abstract class ApiBase extends ContextSource { * error handler and die with an error message including block info. * * @since 1.27 - * @param Block $block The block used to generate the ApiUsageException + * @param AbstractBlock $block The block used to generate the ApiUsageException * @throws ApiUsageException always */ public function dieBlocked( AbstractBlock $block ) { // Die using the appropriate message depending on block type - if ( $block->getType() == Block::TYPE_AUTO ) { + if ( $block->getType() == DatabaseBlock::TYPE_AUTO ) { $this->dieWithError( 'apierror-autoblocked', 'autoblocked', - [ 'blockinfo' => $this->getBlockInfo( $block ) ] + [ 'blockinfo' => $this->getBlockDetails( $block ) ] ); } elseif ( !$block->isSitewide() ) { $this->dieWithError( 'apierror-blocked-partial', 'blocked', - [ 'blockinfo' => $this->getBlockInfo( $block ) ] + [ 'blockinfo' => $this->getBlockDetails( $block ) ] ); } else { $this->dieWithError( 'apierror-blocked', 'blocked', - [ 'blockinfo' => $this->getBlockInfo( $block ) ] + [ 'blockinfo' => $this->getBlockDetails( $block ) ] ); } } @@ -2119,17 +2132,19 @@ abstract class ApiBase extends ContextSource { /** * Helper function for permission-denied errors - * @since 1.29 - * @since 1.33 Changed the third parameter from $user to $options. - * @param Title $title + * + * @param LinkTarget $linkTarget * @param string|string[] $actions * @param array $options Additional options * - user: (User) User to use rather than $this->getUser() * - autoblock: (bool, default false) Whether to spread autoblocks * For compatibility, passing a User object is treated as the value for the 'user' option. * @throws ApiUsageException if the user doesn't have all of the rights. + * + * @since 1.29 + * @since 1.33 Changed the third parameter from $user to $options. */ - public function checkTitleUserPermissions( Title $title, $actions, $options = [] ) { + public function checkTitleUserPermissions( LinkTarget $linkTarget, $actions, $options = [] ) { if ( !is_array( $options ) ) { wfDeprecated( '$user as the third parameter to ' . __METHOD__, '1.33' ); $options = [ 'user' => $options ]; @@ -2138,7 +2153,10 @@ abstract class ApiBase extends ContextSource { $errors = []; foreach ( (array)$actions as $action ) { - $errors = array_merge( $errors, $title->getUserPermissionsErrors( $action, $user ) ); + $errors = array_merge( + $errors, + $this->getPermissionManager()->getPermissionErrors( $action, $user, $linkTarget ) + ); } if ( $errors ) { @@ -2611,99 +2629,6 @@ abstract class ApiBase extends ContextSource { } /**@}*/ - - /************************************************************************//** - * @name Deprecated - * @{ - */ - - /** - * Returns the description string for this module - * - * Ignored if an i18n message exists for - * "apihelp-{$this->getModulePath()}-description". - * - * @deprecated since 1.25 - * @return Message|string|array|false - */ - protected function getDescription() { - wfDeprecated( __METHOD__, '1.25' ); - return false; - } - - /** - * Returns an array of parameter descriptions. - * - * For each parameter, ignored if an i18n message exists for the parameter. - * By default that message is - * "apihelp-{$this->getModulePath()}-param-{$param}", but it may be - * overridden using ApiBase::PARAM_HELP_MSG in the data returned by - * self::getFinalParams(). - * - * @deprecated since 1.25 - * @return array|bool False on no parameter descriptions - */ - protected function getParamDescription() { - wfDeprecated( __METHOD__, '1.25' ); - return []; - } - - /** - * Returns usage examples for this module. - * - * Return value as an array is either: - * - numeric keys with partial URLs ("api.php?" plus a query string) as - * values - * - sequential numeric keys with even-numbered keys being display-text - * and odd-numbered keys being partial urls - * - partial URLs as keys with display-text (string or array-to-be-joined) - * as values - * Return value as a string is the same as an array with a numeric key and - * that value, and boolean false means "no examples". - * - * @deprecated since 1.25, use getExamplesMessages() instead - * @return bool|string|array - */ - protected function getExamples() { - wfDeprecated( __METHOD__, '1.25' ); - return false; - } - - /** - * Return the description message. - * - * This is additional text to display on the help page after the summary. - * - * @deprecated since 1.30 - * @return string|array|Message - */ - protected function getDescriptionMessage() { - wfDeprecated( __METHOD__, '1.30' ); - return [ [ - "apihelp-{$this->getModulePath()}-description", - "apihelp-{$this->getModulePath()}-summary", - ] ]; - } - - /** - * Truncate an array to a certain length. - * @deprecated since 1.32, no replacement - * @param array &$arr Array to truncate - * @param int $limit Maximum length - * @return bool True if the array was truncated, false otherwise - */ - public static function truncateArray( &$arr, $limit ) { - wfDeprecated( __METHOD__, '1.32' ); - $modified = false; - while ( count( $arr ) > $limit ) { - array_pop( $arr ); - $modified = true; - } - - return $modified; - } - - /**@}*/ } /**