Merge "Localisation updates from https://translatewiki.net."
[lhc/web/wiklou.git] / includes / api / ApiMain.php
index 554ab6a..efa4b04 100644 (file)
@@ -153,6 +153,7 @@ class ApiMain extends ApiBase {
        private $mModule;
 
        private $mCacheMode = 'private';
+       /** @var array */
        private $mCacheControl = [];
        private $mParamsUsed = [];
        private $mParamsSensitive = [];
@@ -166,6 +167,7 @@ class ApiMain extends ApiBase {
         * @param IContextSource|WebRequest|null $context If this is an instance of
         *    FauxRequest, errors are thrown and no printing occurs
         * @param bool $enableWrite Should be set to true if the api may modify data
+        * @suppress PhanUndeclaredMethod
         */
        public function __construct( $context = null, $enableWrite = false ) {
                if ( $context === null ) {
@@ -1410,8 +1412,8 @@ class ApiMain extends ApiBase {
         */
        protected function checkExecutePermissions( $module ) {
                $user = $this->getUser();
-               if ( $module->isReadMode() && !User::isEveryoneAllowed( 'read' ) &&
-                       !$user->isAllowed( 'read' )
+               if ( $module->isReadMode() && !$this->getPermissionManager()->isEveryoneAllowed( 'read' ) &&
+                       !$this->getPermissionManager()->userHasRight( $user, 'read' )
                ) {
                        $this->dieWithError( 'apierror-readapidenied' );
                }
@@ -1419,7 +1421,7 @@ class ApiMain extends ApiBase {
                if ( $module->isWriteMode() ) {
                        if ( !$this->mEnableWrite ) {
                                $this->dieWithError( 'apierror-noapiwrite' );
-                       } elseif ( !$user->isAllowed( 'writeapi' ) ) {
+                       } elseif ( !$this->getPermissionManager()->userHasRight( $user, 'writeapi' ) ) {
                                $this->dieWithError( 'apierror-writeapidenied' );
                        } elseif ( $this->getRequest()->getHeader( 'Promise-Non-Write-API-Action' ) ) {
                                $this->dieWithError( 'apierror-promised-nonwrite-api' );
@@ -1504,7 +1506,7 @@ class ApiMain extends ApiBase {
                                        }
                                        break;
                                case 'bot':
-                                       if ( !$user->isAllowed( 'bot' ) ) {
+                                       if ( !$this->getPermissionManager()->userHasRight( $user, 'bot' ) ) {
                                                $this->dieWithError( 'apierror-assertbotfailed' );
                                        }
                                        break;
@@ -1539,6 +1541,12 @@ class ApiMain extends ApiBase {
                        $this->dieWithErrorOrDebug( [ 'apierror-mustbeposted', $this->mAction ] );
                }
 
+               if ( $request->wasPosted() && !$request->getHeader( 'Content-Type' ) ) {
+                       $this->addDeprecation(
+                               'apiwarn-deprecation-post-without-content-type', 'post-without-content-type'
+                       );
+               }
+
                // See if custom printer is used
                $this->mPrinter = $module->getCustomPrinter();
                if ( is_null( $this->mPrinter ) ) {
@@ -1939,7 +1947,7 @@ class ApiMain extends ApiBase {
 
                        $groups = array_map( function ( $group ) {
                                return $group == '*' ? 'all' : $group;
-                       }, User::getGroupsWithPermission( $right ) );
+                       }, $this->getPermissionManager()->getGroupsWithPermission( $right ) );
 
                        $help['permissions'] .= Html::rawElement( 'dd', null,
                                $this->msg( 'api-help-permissions-granted-to' )
@@ -2052,7 +2060,8 @@ class ApiMain extends ApiBase {
         */
        public function canApiHighLimits() {
                if ( !isset( $this->mCanApiHighLimits ) ) {
-                       $this->mCanApiHighLimits = $this->getUser()->isAllowed( 'apihighlimits' );
+                       $this->mCanApiHighLimits = $this->getPermissionManager()
+                               ->userHasRight( $this->getUser(), 'apihighlimits' );
                }
 
                return $this->mCanApiHighLimits;