[MediaWiki-commits] [Gerrit] mediawiki...CookieWarning[master]: Allow non-JS users to dismiss the CookieWarning bar
Florianschmidtwelzow has submitted this change and it was merged. 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, 72 insertions(+), 26 deletions(-) Approvals: Florianschmidtwelzow: Verified; Looks good to me, approved 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 feef6ef..8e4758c 100644 --- a/includes/CookieWarning.hooks.php +++ b/includes/CookieWarning.hooks.php @@ -1,6 +1,36 @@ 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,10 @@ 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; + } $moreLink = self::getMoreLink(); // if a "more information" URL was configured, add a link to it in the cookiewarning // information bar @@ -22,31 +56,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( +
[MediaWiki-commits] [Gerrit] mediawiki...CookieWarning[master]: Allow non-JS users to dismiss the CookieWarning bar
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 @@ 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',