mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CookieWarning
synced 2024-11-23 13:56:53 +00:00
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
This commit is contained in:
parent
2b7bd1be97
commit
b8686223e5
|
@ -22,6 +22,9 @@
|
|||
],
|
||||
"GetPreferences": [
|
||||
"CookieWarningHooks::onGetPreferences"
|
||||
],
|
||||
"BeforeInitialize": [
|
||||
"CookieWarningHooks::onBeforeInitialize"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
|
|
|
@ -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,10 @@ class CookieWarningHooks {
|
|||
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 @@ class CookieWarningHooks {
|
|||
$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' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue