MarkAHershberger has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/404779 )

Change subject: Fix Lockdown deprecation notice
......................................................................

Fix Lockdown deprecation notice

Also address some codesniffer problems

Bug: T185105
Change-Id: I5a66085ad7eb228fa82b2a8d6ea9919f25667864
---
M src/Hooks.php
1 file changed, 37 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Lockdown 
refs/changes/79/404779/1

diff --git a/src/Hooks.php b/src/Hooks.php
index 9b1cb87..dc9dac6 100644
--- a/src/Hooks.php
+++ b/src/Hooks.php
@@ -44,6 +44,33 @@
  */
 class Hooks {
 
+       private static function shouldNotLockdown( Title $title, $action ) {
+               global $wgWhitelistRead;
+
+               // don't impose extra restrictions on UI pages
+               if ( $title->isCssJsSubpage() ) {
+                       return true;
+               }
+
+               if ( $action == 'read' && is_array( $wgWhitelistRead ) ) {
+                       // don't impose read restrictions on whitelisted pages
+                       if ( in_array( $title->getPrefixedText(), 
$wgWhitelistRead ) ) {
+                               return true;
+                       }
+               }
+               return false;
+       }
+
+       // Shim to avoid deprecation notice while still being usable on 1.27
+       private static function getGroupLinks( $groups ) {
+               if ( method_exists( 'UserGroupMembership', 'getGroupName' ) ) {
+                       $groupLinks = array_map( [ 'UserGroupMembership', 
'getGroupName' ], $groups );
+               } else {
+                       $groupLinks = array_map( [ 'User', 'makeGroupLinkWiki' 
], $groups );
+               }
+               return $groupLinks;
+       }
+
        /**
         * Fetch an appropriate permission error (or none!)
         *
@@ -56,6 +83,7 @@
         *   error message keys when multiple messages are needed
         * @return bool
         * @see 
https://www.mediawiki.org/wiki/Manual:Hooks/getUserPermissionsErrors
+        * @SuppressWarnings(ShortVariable)
         */
        public static function onGetUserPermissionsErrors(
                Title $title,
@@ -63,20 +91,12 @@
                $action,
                &$result = null
        ) {
-               global $wgSpecialPageLockdown, $wgWhitelistRead, $wgLang;
+               global $wgSpecialPageLockdown, $wgLang;
 
                $result = null;
 
-               // don't impose extra restrictions on UI pages
-               if ( $title->isCssJsSubpage() ) {
+               if ( self::shouldNotLockdown( $title, $action ) ) {
                        return true;
-               }
-
-               if ( $action == 'read' && is_array( $wgWhitelistRead ) ) {
-                       // don't impose read restrictions on whitelisted pages
-                       if ( in_array( $title->getPrefixedText(), 
$wgWhitelistRead ) ) {
-                               return true;
-                       }
                }
 
                $groups = null;
@@ -118,7 +138,7 @@
                        return true;
                } else {
                        # group is denied - abort
-                       $groupLinks = array_map( [ 'User', 'makeGroupLinkWiki' 
], $groups );
+                       $groupLinks = self::getGroupLinks( $groups );
 
                        $result = [
                                'badaccess-groups',
@@ -142,6 +162,7 @@
         * @param MediaWiki $wiki used to get the parsed action
         * @return bool
         * @see 
https://www.mediawiki.org/wiki/Manual:Hooks/MediaWikiPerformAction
+        * @SuppressWarnings(UnusedFormalParameter)
         */
        public static function onMediawikiPerformAction(
                OutputPage $output,
@@ -173,7 +194,7 @@
                if ( $match ) {
                        return true;
                } else {
-                       $groupLinks = array_map( [ 'User', 'makeGroupLinkWiki' 
], $groups );
+                       $groupLinks = self::getGroupLinks( $groups );
 
                        $err = [
                                'badaccess-groups', $wgLang->commaList( 
$groupLinks ),
@@ -195,7 +216,7 @@
                $user = RequestContext::getMain()->getUser();
                $ugroups = $user->getEffectiveGroups();
 
-               foreach ( $searchableNs as $ns => $name ) {
+               foreach ( array_keys( $searchableNs ) as $ns ) {
                        if ( !self::namespaceCheck( $ns, $ugroups ) ) {
                                unset( $searchableNs[$ns] );
                        }
@@ -208,6 +229,7 @@
         * @param int $ns to check
         * @param string $action to check (default: read)
         * @return null|array of groups
+        * @SuppressWarnings(ShortVariable)
         */
        protected static function namespaceGroups( $ns, $action = 'read' ) {
                global $wgNamespacePermissionLockdown;
@@ -234,6 +256,7 @@
         * @param int $ns to check
         * @param array $ugroups that the user is in
         * @return bool false if the user does not have permission
+        * @SuppressWarnings(ShortVariable)
         */
        protected static function namespaceCheck( $ns, array $ugroups ) {
                $groups = self::namespaceGroups( $ns );
@@ -251,6 +274,7 @@
         * @param string $searchterm the term being searched
         * @param Title $title Title the user is being sent to
         * @see 
https://www.mediawiki.org/wiki/Manual:Hooks/SearchGetNearMatchComplete
+        * @SuppressWarnings(UnusedFormalParameter)
         */
        public static function onSearchGetNearMatchComplete(
                $searchterm,

-- 
To view, visit https://gerrit.wikimedia.org/r/404779
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5a66085ad7eb228fa82b2a8d6ea9919f25667864
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Lockdown
Gerrit-Branch: master
Gerrit-Owner: MarkAHershberger <m...@nichework.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to