Merge "libs/Message: Improve documentation"
[lhc/web/wiklou.git] / includes / AjaxDispatcher.php
index 2adbc80..ea10a2e 100644 (file)
@@ -23,6 +23,9 @@
 
 use MediaWiki\MediaWikiServices;
 
+// Use superglobals, but since it's deprecated, it's not worth fixing
+// phpcs:disable MediaWiki.Usage.SuperGlobalsUsage.SuperGlobals
+
 /**
  * @defgroup Ajax Ajax
  */
@@ -56,6 +59,7 @@ class AjaxDispatcher {
 
        /**
         * Load up our object with user supplied data
+        * @param Config $config
         */
        function __construct( Config $config ) {
                $this->config = $config;
@@ -72,7 +76,7 @@ class AjaxDispatcher {
 
                switch ( $this->mode ) {
                        case 'get':
-                               $this->func_name = isset( $_GET["rs"] ) ? $_GET["rs"] : '';
+                               $this->func_name = $_GET["rs"] ?? '';
                                if ( !empty( $_GET["rsargs"] ) ) {
                                        $this->args = $_GET["rsargs"];
                                } else {
@@ -80,7 +84,7 @@ class AjaxDispatcher {
                                }
                                break;
                        case 'post':
-                               $this->func_name = isset( $_POST["rs"] ) ? $_POST["rs"] : '';
+                               $this->func_name = $_POST["rs"] ?? '';
                                if ( !empty( $_POST["rsargs"] ) ) {
                                        $this->args = $_POST["rsargs"];
                                } else {
@@ -100,6 +104,9 @@ class AjaxDispatcher {
         * they should be carefully handled in the function processing the
         * request.
         *
+        * phan-taint-check triggers as it is not smart enough to understand
+        * the early return if func_name not in AjaxExportList.
+        * @suppress SecurityCheck-XSS
         * @param User $user
         */
        function performAction( User $user ) {
@@ -107,6 +114,7 @@ class AjaxDispatcher {
                        return;
                }
 
+               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
                if ( !in_array( $this->func_name, $this->config->get( 'AjaxExportList' ) ) ) {
                        wfDebug( __METHOD__ . ' Bad Request for unknown function ' . $this->func_name . "\n" );
                        wfHttpError(
@@ -114,7 +122,8 @@ class AjaxDispatcher {
                                'Bad Request',
                                "unknown function " . $this->func_name
                        );
-               } elseif ( !User::isEveryoneAllowed( 'read' ) && !$user->isAllowed( 'read' ) ) {
+               } elseif ( !$permissionManager->isEveryoneAllowed( 'read' ) &&
+                                  !$permissionManager->userHasRight( $user, 'read' ) ) {
                        wfHttpError(
                                403,
                                'Forbidden',