Alex Monk has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/259606

Change subject: [WIP] SET browser blacklisting checks
......................................................................

[WIP] SET browser blacklisting checks

This is untested at the moment.

Bug: T121298
Change-Id: I3a3e2632916ce359d8f91f3f9404b86353b87d31
---
M VisualEditor.hooks.php
1 file changed, 33 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/06/259606/1

diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php
index 536eec4..21febc2 100644
--- a/VisualEditor.hooks.php
+++ b/VisualEditor.hooks.php
@@ -58,6 +58,38 @@
                return true;
        }
 
+       // TODO: Detect incompatibility - T121298, P2373
+       private static function isUABlacklisted( WebRequest $req, $config ) {
+               if ( $req->getVal( 'vewhitelist' ) ) {
+                       return false;
+               }
+               $blacklist = $config->get( 'VisualEditorBrowserBlacklist' );
+               $ua = strtolower( $req->getHeader( 'User-Agent' ) );
+               foreach ( $blacklist as $uaSubstr => $rules ) {
+                       if ( !strpos( $ua, $uaSubstr ) ) {
+                               continue;
+                       }
+                       if ( !is_array( $rules ) ) {
+                               return true;
+                       }
+
+                       $version = preg_split( '/' . $uaSubstr . '\//', $ua )[ 
1 ];
+                       foreach ( $rules as $rule ) {
+                               list( $op, $matchVersion ) = $rule;
+                               if (
+                                       $op === '<' && $version < $matchVersion 
||
+                                       $op === '>' && $version > $matchVersion 
||
+                                       $op === '<=' && $version <= 
$matchVersion ||
+                                       $op === '>=' && $version >= 
$matchVersion
+                               ) {
+                                       return true;
+                               }
+                       }
+
+               }
+               return false;
+       }
+
        /**
         * Decide whether to bother showing the wikitext editor at all.
         * If not, we expect the VE initialisation JS to activate.
@@ -76,7 +108,7 @@
                        $user->getOption( 'visualeditor-tabs' ) === 'prefer-wt' 
||
                        $user->getOption( 'visualeditor-tabs' ) === 'multi-tab' 
||
                        ( $veConfig->get( 'VisualEditorDisableForAnons' ) && 
$user->isAnon() ) ||
-                       false // TODO: Detect incompatibility - T121298, P2373
+                       self::isUABlacklisted( $req, $veConfig )
                ) {
                        return true;
                }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3a3e2632916ce359d8f91f3f9404b86353b87d31
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to