Florianschmidtwelzow has uploaded a new change for review.

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

Change subject: Allow non-JS users to dismiss the CookieWarning bar
......................................................................

Allow non-JS users to dismiss the CookieWarning bar

This commit change sthe "OK"-link to dismiss the cookiewarning bar
from a link to a POST-based form, so that non-JS users are able to
click it, too. If clicked, the dismiss is saved int he user prefs
(if the user is logged in) or in a cookie.

The JS version still works without reloading the page.

Bug: T145647
Change-Id: I711413abcbc131aaba34e8b285630ef1a1c9bda1
---
M extension.json
M includes/CookieWarning.hooks.php
M resources/ext.CookieWarning/ext.CookieWarning.less
3 files changed, 73 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CookieWarning 
refs/changes/62/310562/1

diff --git a/extension.json b/extension.json
index 722db7f..3e4f2d6 100644
--- a/extension.json
+++ b/extension.json
@@ -22,6 +22,9 @@
                ],
                "GetPreferences": [
                        "CookieWarningHooks::onGetPreferences"
+               ],
+               "BeforeInitialize": [
+                       "CookieWarningHooks::onBeforeInitialize"
                ]
        },
        "config": {
diff --git a/includes/CookieWarning.hooks.php b/includes/CookieWarning.hooks.php
index 6826bd3..781c1f5 100644
--- a/includes/CookieWarning.hooks.php
+++ b/includes/CookieWarning.hooks.php
@@ -1,6 +1,36 @@
 <?php
 
 class CookieWarningHooks {
+
+       /**
+        * BeforeInitialize hook handler.
+        *
+        * If the disablecookiewarning POST data is send, disables the 
cookiewarning bar with a
+        * cookie or a user preference, if the user is logged in.
+        *
+        * @param Title $title
+        * @param null $unused
+        * @param OutputPage $output
+        * @param User $user
+        * @param WebRequest $request
+        * @param MediaWiki $mediawiki
+        */
+       public static function onBeforeInitialize( Title &$title, &$unused, 
OutputPage &$output,
+               User &$user, WebRequest $request, MediaWiki $mediawiki
+       ) {
+               if ( !$request->wasPosted() || !$request->getVal( 
'disablecookiewarning' ) ) {
+                       return;
+               }
+
+               if ( $user->isLoggedIn() ) {
+                       $user->setOption( 'cookiewarning_dismissed', 1 );
+                       $user->saveSettings();
+               } else {
+                       $request->response()->setCookie( 
'cookiewarning_dismissed', true );
+               }
+               $output->redirect( $request->getRequestURL() );
+       }
+
        /**
         * SkinTemplateOutputPageBeforeExec hook handler.
         *
@@ -12,6 +42,11 @@
        public static function onSkinTemplateOutputPageBeforeExec(
                SkinTemplate &$sk, QuickTemplate &$tpl
        ) {
+               // if the cookiewarning should not be visible to the user, exit.
+               if ( !self::showWarning( $sk->getContext() ) ) {
+                       return;
+               }
+
                // Config instance of CookieWarning
                $conf = ConfigFactory::getDefaultInstance()->makeConfig( 
'cookiewarning' );
                $moreLink = '';
@@ -24,31 +59,32 @@
                                $sk->msg( 'cookiewarning-moreinfo-label' 
)->text()
                        );
                }
-               // if the cookiewarning should be visible to the user, append 
the element to
-               // the head data.
-               if ( self::showWarning( $sk->getContext() ) ) {
-                       $tpl->data['headelement'] .= Html::openElement(
-                                       'div',
-                                       array( 'class' => 
'mw-cookiewarning-container' )
-                               ) .
-                               Html::openElement(
-                                       'div',
-                                       array( 'class' => 
'mw-cookiewarning-text' )
-                               ) .
-                               Html::element(
-                                       'span',
-                                       array(),
-                                       $sk->msg( 'cookiewarning-info' )->text()
-                               ) .
-                               $moreLink .
-                               Html::element(
-                                       'a',
-                                       array( 'class' => 
'mw-cookiewarning-dismiss' ),
-                                       'OK'
-                               ) .
-                               Html::closeElement( 'div' ) .
-                               Html::closeElement( 'div' );
-               }
+
+               $tpl->data['headelement'] .= Html::openElement(
+                               'div',
+                               array( 'class' => 'mw-cookiewarning-container' )
+                       ) .
+                       Html::openElement(
+                               'div',
+                               array( 'class' => 'mw-cookiewarning-text' )
+                       ) .
+                       Html::element(
+                               'span',
+                               array(),
+                               $sk->msg( 'cookiewarning-info' )->text()
+                       ) .
+                       $moreLink .
+                       Html::openElement( 'form', array( 'method' => 'POST' ) 
) .
+                       Html::submitButton(
+                               'OK',
+                               array(
+                                       'name' => 'disablecookiewarning',
+                                       'class' => 'mw-cookiewarning-dismiss'
+                               )
+                       ) .
+                       Html::closeElement( 'form' ) .
+                       Html::closeElement( 'div' ) .
+                       Html::closeElement( 'div' );
        }
 
        /**
diff --git a/resources/ext.CookieWarning/ext.CookieWarning.less 
b/resources/ext.CookieWarning/ext.CookieWarning.less
index 1330b38..40bbe80 100644
--- a/resources/ext.CookieWarning/ext.CookieWarning.less
+++ b/resources/ext.CookieWarning/ext.CookieWarning.less
@@ -19,16 +19,24 @@
                margin-right: 1em;
        }
 
-       a {
+       form {
+               display: inline;
+       }
+
+       .mw-cookiewarning-dismiss, a {
                background-color: #3C3C3C;
                height: 100%;
                padding: 3px 10px;
                border-radius: 2px;
+               border: none;
                cursor: pointer;
                text-decoration: none !important;
                color: white !important;
                margin-right: 0.5em;
                white-space: nowrap;
+               font-weight: bold;
+               font-family: arial;
+               font-size: 13px;
        }
 }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I711413abcbc131aaba34e8b285630ef1a1c9bda1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CookieWarning
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>

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

Reply via email to