Florianschmidtwelzow has submitted this change and it was merged.

Change subject: Add the possibility to edit the more information link on-wiki
......................................................................


Add the possibility to edit the more information link on-wiki

Instead of just the configuration variable $wgCookieWarningMoreUrl,
CookirWarning now allows also to set the link on-wiki using the interface
message MediaWiki:Cookiewarning-more-link. It also "listens" for the
MediaWiki:Cookie-policy-link interface message, which is introduced by
Cookie Policy as a first step for merging these both extensions.

Bug: T145781
Change-Id: I818008b2da6d9acd4295857e2916cd1b4637bee9
---
M i18n/en.json
M i18n/qqq.json
M includes/CookieWarning.hooks.php
A tests/phpunit/includes/CookieWarning.hooksTest.php
4 files changed, 157 insertions(+), 7 deletions(-)

Approvals:
  Florianschmidtwelzow: Verified; Looks good to me, approved
  Jack Phoenix: Looks good to me, but someone else must approve



diff --git a/i18n/en.json b/i18n/en.json
index ddbe41c..90aade8 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -6,5 +6,6 @@
        },
        "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-moreinfo-label": "More information"
+       "cookiewarning-moreinfo-label": "More information",
+       "cookiewarning-more-link": "-"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 691a8c3..5130213 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -6,5 +6,6 @@
        },
        "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-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."
 }
diff --git a/includes/CookieWarning.hooks.php b/includes/CookieWarning.hooks.php
index 6826bd3..feef6ef 100644
--- a/includes/CookieWarning.hooks.php
+++ b/includes/CookieWarning.hooks.php
@@ -12,15 +12,13 @@
        public static function onSkinTemplateOutputPageBeforeExec(
                SkinTemplate &$sk, QuickTemplate &$tpl
        ) {
-               // Config instance of CookieWarning
-               $conf = ConfigFactory::getDefaultInstance()->makeConfig( 
'cookiewarning' );
-               $moreLink = '';
+               $moreLink = self::getMoreLink();
                // if a "more information" URL was configured, add a link to it 
in the cookiewarning
                // information bar
-               if ( $conf->get( 'CookieWarningMoreUrl' ) ) {
+               if ( $moreLink ) {
                        $moreLink = Html::element(
                                'a',
-                               array( 'href' => $conf->get( 
'CookieWarningMoreUrl' ) ),
+                               array( 'href' => $moreLink ),
                                $sk->msg( 'cookiewarning-moreinfo-label' 
)->text()
                        );
                }
@@ -52,6 +50,32 @@
        }
 
        /**
+        * 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.
         *
         * Adds the required style and JS module, if cookiewarning is enabled.
diff --git a/tests/phpunit/includes/CookieWarning.hooksTest.php 
b/tests/phpunit/includes/CookieWarning.hooksTest.php
new file mode 100644
index 0000000..a5c3095
--- /dev/null
+++ b/tests/phpunit/includes/CookieWarning.hooksTest.php
@@ -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;
+       }
+}
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/311033
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I818008b2da6d9acd4295857e2916cd1b4637bee9
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/CookieWarning
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>
Gerrit-Reviewer: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>
Gerrit-Reviewer: Jack Phoenix <j...@countervandalism.net>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to