mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CookieWarning
synced 2024-11-15 02:13:51 +00:00
bc100e294d
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
71 lines
1.8 KiB
PHP
71 lines
1.8 KiB
PHP
<?php
|
|
|
|
class CookieWarningHooks {
|
|
public static function onSkinTemplateOutputPageBeforeExec( SkinTemplate &$sk, &$tpl ) {
|
|
if ( self::showWarning( $sk ) ) {
|
|
$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()
|
|
) .
|
|
Html::element(
|
|
'a',
|
|
array( 'href' => 'https://www.droidwiki.de/DroidWiki:Impressum#Verwendung_von_Cookies' ),
|
|
'Mehr Informationen'
|
|
) .
|
|
Html::element(
|
|
'a',
|
|
array( 'class' => 'mw-cookiewarning-dismiss' ),
|
|
'OK'
|
|
) .
|
|
Html::closeElement( 'div' ) .
|
|
Html::closeElement( 'div' );
|
|
}
|
|
}
|
|
|
|
public static function onBeforePageDisplay( OutputPage $out ) {
|
|
if ( !$out->getRequest()->getCookie( 'cookiewarning_dismissed' ) ) {
|
|
$out->addModuleStyles( array( 'ext.CookieWarning.styles' ) );
|
|
$out->addModules( array( 'ext.CookieWarning' ) );
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|