mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CookieWarning
synced 2024-11-27 23:50:35 +00:00
Merge "Add the possibility to edit the more information link on-wiki"
This commit is contained in:
commit
2b7bd1be97
|
@ -6,5 +6,6 @@
|
||||||
},
|
},
|
||||||
"cookiewarning-info": "Cookies help us deliver our services. By using our services, you agree to our use of cookies.",
|
"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.",
|
"cookiewarning-desc": "Provides a notice at the top of the page about cookies.",
|
||||||
"cookiewarning-moreinfo-label": "More information"
|
"cookiewarning-moreinfo-label": "More information",
|
||||||
|
"cookiewarning-more-link": "-"
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,5 +6,6 @@
|
||||||
},
|
},
|
||||||
"cookiewarning-info": "Information message for visitors of the wiki, informing them that this wiki uses cookies.",
|
"cookiewarning-info": "Information message for visitors of the wiki, informing them that this wiki uses cookies.",
|
||||||
"cookiewarning-desc": "{{desc|name=CookieWarning|url=https://www.mediawiki.org/wiki/Extension:CookieWarning}}",
|
"cookiewarning-desc": "{{desc|name=CookieWarning|url=https://www.mediawiki.org/wiki/Extension:CookieWarning}}",
|
||||||
"cookiewarning-moreinfo-label": "Label for the \"More information\" link in the cookiewarning information bar."
|
"cookiewarning-moreinfo-label": "Label for the \"More information\" link in the cookiewarning information bar.",
|
||||||
|
"cookiewarning-more-link": "{{notranslate}}\nUsed as an on-wiki way to edit the target of the more information link."
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,15 +12,13 @@ class CookieWarningHooks {
|
||||||
public static function onSkinTemplateOutputPageBeforeExec(
|
public static function onSkinTemplateOutputPageBeforeExec(
|
||||||
SkinTemplate &$sk, QuickTemplate &$tpl
|
SkinTemplate &$sk, QuickTemplate &$tpl
|
||||||
) {
|
) {
|
||||||
// Config instance of CookieWarning
|
$moreLink = self::getMoreLink();
|
||||||
$conf = ConfigFactory::getDefaultInstance()->makeConfig( 'cookiewarning' );
|
|
||||||
$moreLink = '';
|
|
||||||
// if a "more information" URL was configured, add a link to it in the cookiewarning
|
// if a "more information" URL was configured, add a link to it in the cookiewarning
|
||||||
// information bar
|
// information bar
|
||||||
if ( $conf->get( 'CookieWarningMoreUrl' ) ) {
|
if ( $moreLink ) {
|
||||||
$moreLink = Html::element(
|
$moreLink = Html::element(
|
||||||
'a',
|
'a',
|
||||||
array( 'href' => $conf->get( 'CookieWarningMoreUrl' ) ),
|
array( 'href' => $moreLink ),
|
||||||
$sk->msg( 'cookiewarning-moreinfo-label' )->text()
|
$sk->msg( 'cookiewarning-moreinfo-label' )->text()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -51,6 +49,32 @@ class CookieWarningHooks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the target for the "More information" link of the cookie warning bar, if one is set.
|
||||||
|
* The link can be set by either (checked in this order):
|
||||||
|
* - the configuration variable $wgCookieWarningMoreUrl
|
||||||
|
* - the interface message MediaWiki:Cookiewarning-more-link
|
||||||
|
* - the interface message MediaWiki:Cookie-policy-link (bc T145781)
|
||||||
|
*
|
||||||
|
* @return string|null The url or null if none set
|
||||||
|
*/
|
||||||
|
private static function getMoreLink() {
|
||||||
|
// Config instance of CookieWarning
|
||||||
|
$conf = ConfigFactory::getDefaultInstance()->makeConfig( 'cookiewarning' );
|
||||||
|
if ( $conf->get( 'CookieWarningMoreUrl' ) ) {
|
||||||
|
return $conf->get( 'CookieWarningMoreUrl' );
|
||||||
|
}
|
||||||
|
$cookieWarningMessage = wfMessage( 'cookiewarning-more-link' );
|
||||||
|
if ( $cookieWarningMessage->exists() && !$cookieWarningMessage->isDisabled() ) {
|
||||||
|
return $cookieWarningMessage->escaped();
|
||||||
|
}
|
||||||
|
$cookiePolicyMessage = wfMessage( 'cookie-policy-link' );
|
||||||
|
if ( $cookiePolicyMessage->exists() && !$cookiePolicyMessage->isDisabled() ) {
|
||||||
|
return $cookiePolicyMessage->escaped();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BeforePageDisplay hook handler.
|
* BeforePageDisplay hook handler.
|
||||||
*
|
*
|
||||||
|
|
124
tests/phpunit/includes/CookieWarning.hooksTest.php
Normal file
124
tests/phpunit/includes/CookieWarning.hooksTest.php
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @group Database
|
||||||
|
*/
|
||||||
|
class CookieWarningHooksTest extends MediaWikiLangTestCase {
|
||||||
|
protected function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
MessageCache::singleton()->enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerOnSkinTemplateOutputPageBeforeExec
|
||||||
|
*/
|
||||||
|
public function testOnSkinTemplateOutputPageBeforeExec( $enabled, $morelinkConfig,
|
||||||
|
$morelinkCookieWarningMsg, $morelinkCookiePolicyMsg, $expectedLink
|
||||||
|
) {
|
||||||
|
$this->setMwGlobals( array(
|
||||||
|
'wgCookieWarningEnabled' => $enabled,
|
||||||
|
'wgCookieWarningMoreUrl' => $morelinkConfig,
|
||||||
|
) );
|
||||||
|
if ( $morelinkCookieWarningMsg ) {
|
||||||
|
$title = Title::newFromText( 'cookiewarning-more-link', NS_MEDIAWIKI );
|
||||||
|
$wikiPage = WikiPage::factory( $title );
|
||||||
|
$wikiPage->doEditContent( new WikitextContent( $morelinkCookieWarningMsg ),
|
||||||
|
"CookieWarning test" );
|
||||||
|
}
|
||||||
|
if ( $morelinkCookiePolicyMsg ) {
|
||||||
|
$title = Title::newFromText( 'cookie-policy-link', NS_MEDIAWIKI );
|
||||||
|
$wikiPage = WikiPage::factory( $title );
|
||||||
|
$wikiPage->doEditContent( new WikitextContent( $morelinkCookiePolicyMsg ),
|
||||||
|
"CookieWarning test" );
|
||||||
|
}
|
||||||
|
$sk = new SkinTemplate();
|
||||||
|
$tpl = new CookieWarningTestTemplate();
|
||||||
|
CookieWarningHooks::onSkinTemplateOutputPageBeforeExec( $sk, $tpl );
|
||||||
|
$headElement = '';
|
||||||
|
if ( isset( $tpl->data['headelement'] ) ) {
|
||||||
|
$headElement = $tpl->data['headelement'];
|
||||||
|
}
|
||||||
|
if ( $expectedLink === false ) {
|
||||||
|
$expected = '';
|
||||||
|
} else {
|
||||||
|
// @codingStandardsIgnoreStart Generic.Files.LineLength
|
||||||
|
$expected =
|
||||||
|
str_replace( '$1', $expectedLink,
|
||||||
|
'<div class="mw-cookiewarning-container"><div class="mw-cookiewarning-text"><span>Cookies help us deliver our services. By using our services, you agree to our use of cookies.</span>$1<a class="mw-cookiewarning-dismiss">OK</a></div></div>' );
|
||||||
|
// @codingStandardsIgnoreEnd
|
||||||
|
}
|
||||||
|
$this->assertEquals( $expected, $headElement );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerOnSkinTemplateOutputPageBeforeExec() {
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
// $wgCookieWarningEnabled
|
||||||
|
true,
|
||||||
|
// $wgCookieWarningMoreUrl
|
||||||
|
'',
|
||||||
|
// MediaWiki:Cookiewarning-more-link
|
||||||
|
false,
|
||||||
|
// MediaWiki:Cookie-policy-link
|
||||||
|
false,
|
||||||
|
// expected cookie warning link (when string), nothing if false
|
||||||
|
'',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
false,
|
||||||
|
'',
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
true,
|
||||||
|
'http://google.de',
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
'<a href="http://google.de">More information</a>',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
true,
|
||||||
|
'',
|
||||||
|
'http://google.de',
|
||||||
|
false,
|
||||||
|
'<a href="http://google.de">More information</a>',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
true,
|
||||||
|
'',
|
||||||
|
false,
|
||||||
|
'http://google.de',
|
||||||
|
'<a href="http://google.de">More information</a>',
|
||||||
|
),
|
||||||
|
// the config should be the used, if set (no matter if the messages are used or not)
|
||||||
|
array(
|
||||||
|
true,
|
||||||
|
'http://google.de',
|
||||||
|
false,
|
||||||
|
'http://google123.de',
|
||||||
|
'<a href="http://google.de">More information</a>',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
true,
|
||||||
|
'http://google.de',
|
||||||
|
'http://google1234.de',
|
||||||
|
'http://google123.de',
|
||||||
|
'<a href="http://google.de">More information</a>',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
true,
|
||||||
|
'',
|
||||||
|
'http://google.de',
|
||||||
|
'http://google123.de',
|
||||||
|
'<a href="http://google.de">More information</a>',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class CookieWarningTestTemplate extends BaseTemplate {
|
||||||
|
public function execute() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue