mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CookieWarning
synced 2024-11-27 15:40:16 +00:00
Initial commit
Change-Id: I75ba290d33d981c1c3789868f4ac21916faabde0
This commit is contained in:
parent
7b7d5dd508
commit
b60d6e857a
13
CookieWarning.php
Normal file
13
CookieWarning.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
if ( function_exists( 'wfLoadExtension' ) ) {
|
||||
wfLoadExtension( 'CookieWarning' );
|
||||
// Keep i18n globals so mergeMessageFileList.php doesn't break
|
||||
$wgMessagesDirs['CookieWarning'] = __DIR__ . '/i18n';
|
||||
/* wfWarn(
|
||||
'Deprecated PHP entry point used for CookieWarning extension. Please use wfLoadExtension instead, ' .
|
||||
'see https://www.mediawiki.org/wiki/Extension_registration for more details.'
|
||||
); */
|
||||
return true;
|
||||
} else {
|
||||
die( 'This version of the CookieWarning extension requires MediaWiki 1.25+' );
|
||||
}
|
49
extension.json
Normal file
49
extension.json
Normal file
|
@ -0,0 +1,49 @@
|
|||
{
|
||||
"name": "CookieWarning",
|
||||
"version": "0.1.0",
|
||||
"author": [
|
||||
"Florian Schmidt"
|
||||
],
|
||||
"url": "https://www.droidwiki.de",
|
||||
"descriptionmsg": "cookiewarning-desc",
|
||||
"type": "other",
|
||||
"MessagesDirs": {
|
||||
"CookieWarning": [
|
||||
"i18n"
|
||||
]
|
||||
},
|
||||
"Hooks": {
|
||||
"SkinTemplateOutputPageBeforeExec": [
|
||||
"CookieWarningHooks::onSkinTemplateOutputPageBeforeExec"
|
||||
],
|
||||
"BeforePageDisplay": [
|
||||
"CookieWarningHooks::onBeforePageDisplay"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"CookieWarningEnabled": true
|
||||
},
|
||||
"ResourceModules": {
|
||||
"ext.CookieWarning": {
|
||||
"dependencies": [
|
||||
"mediawiki.cookie"
|
||||
],
|
||||
"scripts": "resources/ext.CookieWarning/ext.CookieWarning.js"
|
||||
},
|
||||
"ext.CookieWarning.styles": {
|
||||
"position": "top",
|
||||
"styles": "resources/ext.CookieWarning/ext.CookieWarning.less"
|
||||
}
|
||||
},
|
||||
"ResourceFileModulePaths": {
|
||||
"localBasePath": "",
|
||||
"remoteExtPath": "CookieWarning"
|
||||
},
|
||||
"AutoloadClasses": {
|
||||
"CookieWarningHooks": "includes/CookieWarning.hooks.php"
|
||||
},
|
||||
"ConfigRegistry": {
|
||||
"cookiewarning": "GlobalVarConfig::newInstance"
|
||||
},
|
||||
"manifest_version": 1
|
||||
}
|
4
i18n/de.json
Normal file
4
i18n/de.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"cookiewarning-info": "Wir verwenden Cookies, die für die Funktionen dieser Seite, zu Analyse- und Werbezwecke und für soziale Medien verwendet werden und uns helfen, {{SITENAME}} besser zu machen.",
|
||||
"cookiewarning-desc": "Stellt einern Warnhinweis über die Vernwendung von Cookies beim Seitenbesuch zur Verfügung."
|
||||
}
|
4
i18n/en.json
Normal file
4
i18n/en.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"cookiewarning-info": "Cookies help us deliver our services. By using our services, you agree to our use of cookies.",
|
||||
"cookiewarning-desc": "Provides a notice at the top of the page about cookies."
|
||||
}
|
51
includes/CookieWarning.hooks.php
Normal file
51
includes/CookieWarning.hooks.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?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 ) {
|
||||
$conf = ConfigFactory::getDefaultInstance()->makeConfig( 'cookiewarning' );
|
||||
if (
|
||||
$conf->get( 'CookieWarningEnabled' ) &&
|
||||
!$context->getRequest()->getCookie( 'cookiewarning_dismissed' )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
7
resources/ext.CookieWarning/ext.CookieWarning.js
Normal file
7
resources/ext.CookieWarning/ext.CookieWarning.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
( function ( mw, $ ) {
|
||||
$( '.mw-cookiewarning-dismiss' ).on( 'click', function ( ev ) {
|
||||
mw.cookie.set( 'cookiewarning_dismissed', true );
|
||||
$( '.mw-cookiewarning-container' ).detach();
|
||||
ev.preventDefault();
|
||||
} );
|
||||
} )( mediaWiki, jQuery );
|
32
resources/ext.CookieWarning/ext.CookieWarning.less
Normal file
32
resources/ext.CookieWarning/ext.CookieWarning.less
Normal file
|
@ -0,0 +1,32 @@
|
|||
.mw-cookiewarning-container {
|
||||
position: fixed;
|
||||
background-color: #5a5a5a;
|
||||
box-sizing: border-box;
|
||||
opacity: 0.85;
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
font-family: arial;
|
||||
font-size: 13px;
|
||||
padding: 7px 15px;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
z-index: 1999;
|
||||
}
|
||||
|
||||
.mw-cookiewarning-text {
|
||||
span {
|
||||
margin-right: 1em;
|
||||
}
|
||||
|
||||
a {
|
||||
background-color: #3C3C3C;
|
||||
height: 100%;
|
||||
padding: 3px 10px;
|
||||
border-radius: 2px;
|
||||
cursor: pointer;
|
||||
text-decoration: none !important;
|
||||
color: white !important;
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue