mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CookieWarning
synced 2024-11-23 22:03:41 +00:00
Show CookieWarning for mobile users and save setting to user
Enable the CookieWarning to be visible on a mobile device (bottom, instead of top). Instead of only rely on cookies to save, that a user accepted that we use cookies, save it as a user preference, too. Change-Id: Ib03d5eafd4392d14315115c158b547b9e26a173c
This commit is contained in:
parent
0b265c90c7
commit
bc100e294d
|
@ -18,6 +18,9 @@
|
|||
],
|
||||
"BeforePageDisplay": [
|
||||
"CookieWarningHooks::onBeforePageDisplay"
|
||||
],
|
||||
"GetPreferences": [
|
||||
"CookieWarningHooks::onGetPreferences"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
|
@ -26,13 +29,22 @@
|
|||
"ResourceModules": {
|
||||
"ext.CookieWarning": {
|
||||
"dependencies": [
|
||||
"mediawiki.api",
|
||||
"mediawiki.cookie"
|
||||
],
|
||||
"scripts": "resources/ext.CookieWarning/ext.CookieWarning.js"
|
||||
"scripts": "resources/ext.CookieWarning/ext.CookieWarning.js",
|
||||
"targets": [
|
||||
"mobile",
|
||||
"desktop"
|
||||
]
|
||||
},
|
||||
"ext.CookieWarning.styles": {
|
||||
"position": "top",
|
||||
"styles": "resources/ext.CookieWarning/ext.CookieWarning.less"
|
||||
"styles": "resources/ext.CookieWarning/ext.CookieWarning.less",
|
||||
"targets": [
|
||||
"mobile",
|
||||
"desktop"
|
||||
]
|
||||
}
|
||||
},
|
||||
"ResourceFileModulePaths": {
|
||||
|
|
|
@ -39,13 +39,32 @@ class CookieWarningHooks {
|
|||
}
|
||||
|
||||
private static function showWarning( IContextSource $context ) {
|
||||
$user = $context->getUser();
|
||||
$conf = ConfigFactory::getDefaultInstance()->makeConfig( 'cookiewarning' );
|
||||
if (
|
||||
$conf->get( 'CookieWarningEnabled' ) &&
|
||||
!$user->getBoolOption( 'cookiewarning_dismissed', false ) &&
|
||||
!$context->getRequest()->getCookie( 'cookiewarning_dismissed' )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* GetPreferences hook handler
|
||||
*
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences
|
||||
*
|
||||
* @param User $user
|
||||
* @param array $defaultPreferences
|
||||
* @return bool
|
||||
*/
|
||||
public static function onGetPreferences( User $user, &$defaultPreferences ) {
|
||||
$defaultPreferences['cookiewarning_dismissed'] = array(
|
||||
'type' => 'api',
|
||||
'default' => '0',
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,20 @@
|
|||
( function ( mw, $ ) {
|
||||
$( '.mw-cookiewarning-dismiss' ).on( 'click', function ( ev ) {
|
||||
function setCookie() {
|
||||
mw.cookie.set( 'cookiewarning_dismissed', true );
|
||||
}
|
||||
|
||||
$( '.mw-cookiewarning-dismiss' ).on( 'click', function ( ev ) {
|
||||
if ( !mw.user.isAnon() ) {
|
||||
new mw.Api().postWithToken( 'options', {
|
||||
action: 'options',
|
||||
change: 'cookiewarning_dismissed=1'
|
||||
} ).fail( function ( code, result ) {
|
||||
mw.log.warn( 'Failed to save dismissed CookieWarning: ' + code + '\n' + result.error + '. Using cookie now.' );
|
||||
setCookie();
|
||||
} );
|
||||
} else {
|
||||
setCookie();
|
||||
}
|
||||
$( '.mw-cookiewarning-container' ).detach();
|
||||
ev.preventDefault();
|
||||
} );
|
||||
|
|
|
@ -28,5 +28,13 @@
|
|||
text-decoration: none !important;
|
||||
color: white !important;
|
||||
margin-right: 0.5em;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.mw-mobile-mode {
|
||||
.mw-cookiewarning-container {
|
||||
bottom: 0;
|
||||
top: inherit;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue