2015-07-27 17:18:44 +00:00
|
|
|
<?php
|
|
|
|
|
2018-07-19 10:48:17 +00:00
|
|
|
namespace CookieWarning;
|
2016-09-14 15:11:38 +00:00
|
|
|
|
2018-07-19 10:48:17 +00:00
|
|
|
use Config;
|
|
|
|
use ConfigException;
|
|
|
|
use Html;
|
|
|
|
use MediaWiki;
|
2021-12-04 13:48:43 +00:00
|
|
|
use MediaWiki\Hook\BeforeInitializeHook;
|
|
|
|
use MediaWiki\Hook\BeforePageDisplayHook;
|
|
|
|
use MediaWiki\Hook\SkinAfterContentHook;
|
2018-07-19 10:48:17 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2021-12-04 13:48:43 +00:00
|
|
|
use MediaWiki\Preferences\Hook\GetPreferencesHook;
|
|
|
|
use MediaWiki\ResourceLoader\Hook\ResourceLoaderGetConfigVarsHook;
|
2018-07-19 10:48:17 +00:00
|
|
|
use MWException;
|
Move the warning outside sitenotice, tidy up code
There's a lot of things going on here, so a quick summary:
* Moved the warning outside sitenotice to avoid reflows and all
kinds of other issues, including those with dismissable notices.
* Placed the warning on the bottom of the page, on all skins, for
consistency and to avoid obstructing vital UI elements such as
site name, user tools, search box.
* Changed the UI to use OOUI for, again, consistency and to avoid
reinventing the wheel with button styling.
* Removed the cookie emoji as it was only taking up valuable space
on mobile and making designing a sensible layout much harder.
* Merged the mobile and desktop RL modules into a single, responsive
one. The warning will work correctly for any skin and screen width.
* The integration tests are truly horrible, I tried to at least
make them work. They deserve a proper rewrite, but that should be
done after the extension switches to the new hook system.
I will post screenshots of this in action in the first of the linked
tasks.
Bug: T271047
Bug: T173335
Change-Id: I6e2a3d7aeccc0d4df1b3238e52c67e72099d27d8
2021-02-01 09:54:49 +00:00
|
|
|
use OOUI\ButtonInputWidget;
|
|
|
|
use OOUI\ButtonWidget;
|
|
|
|
use OOUI\HorizontalLayout;
|
2018-07-19 10:48:17 +00:00
|
|
|
use OutputPage;
|
2020-10-03 18:13:17 +00:00
|
|
|
use Skin;
|
2018-07-19 10:48:17 +00:00
|
|
|
use Title;
|
|
|
|
use User;
|
|
|
|
use WebRequest;
|
|
|
|
|
2021-12-04 13:48:43 +00:00
|
|
|
class Hooks implements
|
|
|
|
SkinAfterContentHook,
|
|
|
|
GetPreferencesHook,
|
|
|
|
BeforeInitializeHook,
|
|
|
|
BeforePageDisplayHook,
|
|
|
|
ResourceLoaderGetConfigVarsHook
|
|
|
|
{
|
2016-09-14 15:11:38 +00:00
|
|
|
/**
|
|
|
|
* BeforeInitialize hook handler.
|
|
|
|
*
|
|
|
|
* If the disablecookiewarning POST data is send, disables the cookiewarning bar with a
|
|
|
|
* cookie or a user preference, if the user is logged in.
|
|
|
|
*
|
2021-12-04 13:48:43 +00:00
|
|
|
* @param Title $title
|
|
|
|
* @param null $unused
|
|
|
|
* @param OutputPage $output
|
|
|
|
* @param User $user
|
2016-09-14 15:11:38 +00:00
|
|
|
* @param WebRequest $request
|
|
|
|
* @param MediaWiki $mediawiki
|
2018-07-18 09:50:46 +00:00
|
|
|
* @throws MWException
|
2016-09-14 15:11:38 +00:00
|
|
|
*/
|
2021-12-04 13:48:43 +00:00
|
|
|
public function onBeforeInitialize( $title, $unused, $output, $user, $request, $mediawiki ) {
|
2016-09-14 15:11:38 +00:00
|
|
|
if ( !$request->wasPosted() || !$request->getVal( 'disablecookiewarning' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Move the warning outside sitenotice, tidy up code
There's a lot of things going on here, so a quick summary:
* Moved the warning outside sitenotice to avoid reflows and all
kinds of other issues, including those with dismissable notices.
* Placed the warning on the bottom of the page, on all skins, for
consistency and to avoid obstructing vital UI elements such as
site name, user tools, search box.
* Changed the UI to use OOUI for, again, consistency and to avoid
reinventing the wheel with button styling.
* Removed the cookie emoji as it was only taking up valuable space
on mobile and making designing a sensible layout much harder.
* Merged the mobile and desktop RL modules into a single, responsive
one. The warning will work correctly for any skin and screen width.
* The integration tests are truly horrible, I tried to at least
make them work. They deserve a proper rewrite, but that should be
done after the extension switches to the new hook system.
I will post screenshots of this in action in the first of the linked
tasks.
Bug: T271047
Bug: T173335
Change-Id: I6e2a3d7aeccc0d4df1b3238e52c67e72099d27d8
2021-02-01 09:54:49 +00:00
|
|
|
if ( $user->isRegistered() ) {
|
2021-04-13 22:46:28 +00:00
|
|
|
$userOptionsManager = MediaWikiServices::getInstance()->getUserOptionsManager();
|
|
|
|
$userOptionsManager->setOption( $user, 'cookiewarning_dismissed', 1 );
|
|
|
|
$userOptionsManager->saveOptions( $user );
|
2016-09-14 15:11:38 +00:00
|
|
|
} else {
|
|
|
|
$request->response()->setCookie( 'cookiewarning_dismissed', true );
|
|
|
|
}
|
|
|
|
$output->redirect( $request->getRequestURL() );
|
|
|
|
}
|
2018-07-18 09:50:46 +00:00
|
|
|
|
2016-01-10 17:58:21 +00:00
|
|
|
/**
|
Move the warning outside sitenotice, tidy up code
There's a lot of things going on here, so a quick summary:
* Moved the warning outside sitenotice to avoid reflows and all
kinds of other issues, including those with dismissable notices.
* Placed the warning on the bottom of the page, on all skins, for
consistency and to avoid obstructing vital UI elements such as
site name, user tools, search box.
* Changed the UI to use OOUI for, again, consistency and to avoid
reinventing the wheel with button styling.
* Removed the cookie emoji as it was only taking up valuable space
on mobile and making designing a sensible layout much harder.
* Merged the mobile and desktop RL modules into a single, responsive
one. The warning will work correctly for any skin and screen width.
* The integration tests are truly horrible, I tried to at least
make them work. They deserve a proper rewrite, but that should be
done after the extension switches to the new hook system.
I will post screenshots of this in action in the first of the linked
tasks.
Bug: T271047
Bug: T173335
Change-Id: I6e2a3d7aeccc0d4df1b3238e52c67e72099d27d8
2021-02-01 09:54:49 +00:00
|
|
|
* SkinAfterContent hook handler.
|
2016-01-10 17:58:21 +00:00
|
|
|
*
|
Move the warning outside sitenotice, tidy up code
There's a lot of things going on here, so a quick summary:
* Moved the warning outside sitenotice to avoid reflows and all
kinds of other issues, including those with dismissable notices.
* Placed the warning on the bottom of the page, on all skins, for
consistency and to avoid obstructing vital UI elements such as
site name, user tools, search box.
* Changed the UI to use OOUI for, again, consistency and to avoid
reinventing the wheel with button styling.
* Removed the cookie emoji as it was only taking up valuable space
on mobile and making designing a sensible layout much harder.
* Merged the mobile and desktop RL modules into a single, responsive
one. The warning will work correctly for any skin and screen width.
* The integration tests are truly horrible, I tried to at least
make them work. They deserve a proper rewrite, but that should be
done after the extension switches to the new hook system.
I will post screenshots of this in action in the first of the linked
tasks.
Bug: T271047
Bug: T173335
Change-Id: I6e2a3d7aeccc0d4df1b3238e52c67e72099d27d8
2021-02-01 09:54:49 +00:00
|
|
|
* Adds the CookieWarning information bar to the output html.
|
2016-01-10 17:58:21 +00:00
|
|
|
*
|
Move the warning outside sitenotice, tidy up code
There's a lot of things going on here, so a quick summary:
* Moved the warning outside sitenotice to avoid reflows and all
kinds of other issues, including those with dismissable notices.
* Placed the warning on the bottom of the page, on all skins, for
consistency and to avoid obstructing vital UI elements such as
site name, user tools, search box.
* Changed the UI to use OOUI for, again, consistency and to avoid
reinventing the wheel with button styling.
* Removed the cookie emoji as it was only taking up valuable space
on mobile and making designing a sensible layout much harder.
* Merged the mobile and desktop RL modules into a single, responsive
one. The warning will work correctly for any skin and screen width.
* The integration tests are truly horrible, I tried to at least
make them work. They deserve a proper rewrite, but that should be
done after the extension switches to the new hook system.
I will post screenshots of this in action in the first of the linked
tasks.
Bug: T271047
Bug: T173335
Change-Id: I6e2a3d7aeccc0d4df1b3238e52c67e72099d27d8
2021-02-01 09:54:49 +00:00
|
|
|
* @param string &$data
|
2020-10-03 18:13:17 +00:00
|
|
|
* @param Skin $skin
|
Move the warning outside sitenotice, tidy up code
There's a lot of things going on here, so a quick summary:
* Moved the warning outside sitenotice to avoid reflows and all
kinds of other issues, including those with dismissable notices.
* Placed the warning on the bottom of the page, on all skins, for
consistency and to avoid obstructing vital UI elements such as
site name, user tools, search box.
* Changed the UI to use OOUI for, again, consistency and to avoid
reinventing the wheel with button styling.
* Removed the cookie emoji as it was only taking up valuable space
on mobile and making designing a sensible layout much harder.
* Merged the mobile and desktop RL modules into a single, responsive
one. The warning will work correctly for any skin and screen width.
* The integration tests are truly horrible, I tried to at least
make them work. They deserve a proper rewrite, but that should be
done after the extension switches to the new hook system.
I will post screenshots of this in action in the first of the linked
tasks.
Bug: T271047
Bug: T173335
Change-Id: I6e2a3d7aeccc0d4df1b3238e52c67e72099d27d8
2021-02-01 09:54:49 +00:00
|
|
|
*
|
2018-07-18 09:50:46 +00:00
|
|
|
* @throws MWException
|
2016-01-10 17:58:21 +00:00
|
|
|
*/
|
2021-12-04 13:48:43 +00:00
|
|
|
public function onSkinAfterContent( &$data, $skin ) {
|
2018-07-19 10:48:17 +00:00
|
|
|
/** @var Decisions $cookieWarningDecisions */
|
2018-07-18 09:50:46 +00:00
|
|
|
$cookieWarningDecisions = MediaWikiServices::getInstance()
|
|
|
|
->getService( 'CookieWarning.Decisions' );
|
|
|
|
|
2020-10-03 18:13:17 +00:00
|
|
|
if ( !$cookieWarningDecisions->shouldShowCookieWarning( $skin->getContext() ) ) {
|
2016-09-14 15:11:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-10-03 18:13:17 +00:00
|
|
|
|
Move the warning outside sitenotice, tidy up code
There's a lot of things going on here, so a quick summary:
* Moved the warning outside sitenotice to avoid reflows and all
kinds of other issues, including those with dismissable notices.
* Placed the warning on the bottom of the page, on all skins, for
consistency and to avoid obstructing vital UI elements such as
site name, user tools, search box.
* Changed the UI to use OOUI for, again, consistency and to avoid
reinventing the wheel with button styling.
* Removed the cookie emoji as it was only taking up valuable space
on mobile and making designing a sensible layout much harder.
* Merged the mobile and desktop RL modules into a single, responsive
one. The warning will work correctly for any skin and screen width.
* The integration tests are truly horrible, I tried to at least
make them work. They deserve a proper rewrite, but that should be
done after the extension switches to the new hook system.
I will post screenshots of this in action in the first of the linked
tasks.
Bug: T271047
Bug: T173335
Change-Id: I6e2a3d7aeccc0d4df1b3238e52c67e72099d27d8
2021-02-01 09:54:49 +00:00
|
|
|
$data .= self::generateElements( $skin );
|
2020-10-03 18:13:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the elements for the banner.
|
|
|
|
*
|
|
|
|
* @param Skin $skin
|
|
|
|
* @return string|null The html for cookie notice.
|
|
|
|
*/
|
2021-07-22 06:56:11 +00:00
|
|
|
private static function generateElements( Skin $skin ): ?string {
|
2016-09-15 21:07:08 +00:00
|
|
|
$moreLink = self::getMoreLink();
|
2018-07-18 09:50:46 +00:00
|
|
|
|
Move the warning outside sitenotice, tidy up code
There's a lot of things going on here, so a quick summary:
* Moved the warning outside sitenotice to avoid reflows and all
kinds of other issues, including those with dismissable notices.
* Placed the warning on the bottom of the page, on all skins, for
consistency and to avoid obstructing vital UI elements such as
site name, user tools, search box.
* Changed the UI to use OOUI for, again, consistency and to avoid
reinventing the wheel with button styling.
* Removed the cookie emoji as it was only taking up valuable space
on mobile and making designing a sensible layout much harder.
* Merged the mobile and desktop RL modules into a single, responsive
one. The warning will work correctly for any skin and screen width.
* The integration tests are truly horrible, I tried to at least
make them work. They deserve a proper rewrite, but that should be
done after the extension switches to the new hook system.
I will post screenshots of this in action in the first of the linked
tasks.
Bug: T271047
Bug: T173335
Change-Id: I6e2a3d7aeccc0d4df1b3238e52c67e72099d27d8
2021-02-01 09:54:49 +00:00
|
|
|
$buttons = [];
|
2016-09-15 21:07:08 +00:00
|
|
|
if ( $moreLink ) {
|
Move the warning outside sitenotice, tidy up code
There's a lot of things going on here, so a quick summary:
* Moved the warning outside sitenotice to avoid reflows and all
kinds of other issues, including those with dismissable notices.
* Placed the warning on the bottom of the page, on all skins, for
consistency and to avoid obstructing vital UI elements such as
site name, user tools, search box.
* Changed the UI to use OOUI for, again, consistency and to avoid
reinventing the wheel with button styling.
* Removed the cookie emoji as it was only taking up valuable space
on mobile and making designing a sensible layout much harder.
* Merged the mobile and desktop RL modules into a single, responsive
one. The warning will work correctly for any skin and screen width.
* The integration tests are truly horrible, I tried to at least
make them work. They deserve a proper rewrite, but that should be
done after the extension switches to the new hook system.
I will post screenshots of this in action in the first of the linked
tasks.
Bug: T271047
Bug: T173335
Change-Id: I6e2a3d7aeccc0d4df1b3238e52c67e72099d27d8
2021-02-01 09:54:49 +00:00
|
|
|
$buttons[] = new ButtonWidget( [
|
|
|
|
'href' => $moreLink,
|
|
|
|
'label' => $skin->msg( 'cookiewarning-moreinfo-label' )->text(),
|
|
|
|
'flags' => [ 'progressive' ]
|
|
|
|
] );
|
2015-08-16 10:00:33 +00:00
|
|
|
}
|
Move the warning outside sitenotice, tidy up code
There's a lot of things going on here, so a quick summary:
* Moved the warning outside sitenotice to avoid reflows and all
kinds of other issues, including those with dismissable notices.
* Placed the warning on the bottom of the page, on all skins, for
consistency and to avoid obstructing vital UI elements such as
site name, user tools, search box.
* Changed the UI to use OOUI for, again, consistency and to avoid
reinventing the wheel with button styling.
* Removed the cookie emoji as it was only taking up valuable space
on mobile and making designing a sensible layout much harder.
* Merged the mobile and desktop RL modules into a single, responsive
one. The warning will work correctly for any skin and screen width.
* The integration tests are truly horrible, I tried to at least
make them work. They deserve a proper rewrite, but that should be
done after the extension switches to the new hook system.
I will post screenshots of this in action in the first of the linked
tasks.
Bug: T271047
Bug: T173335
Change-Id: I6e2a3d7aeccc0d4df1b3238e52c67e72099d27d8
2021-02-01 09:54:49 +00:00
|
|
|
$buttons[] = new ButtonInputWidget( [
|
|
|
|
'type' => 'submit',
|
|
|
|
'label' => $skin->msg( 'cookiewarning-ok-label' )->text(),
|
|
|
|
'name' => 'disablecookiewarning',
|
|
|
|
'value' => 'OK',
|
|
|
|
'flags' => [ 'primary', 'progressive' ]
|
|
|
|
] );
|
|
|
|
|
|
|
|
$form = Html::rawElement(
|
|
|
|
'form',
|
|
|
|
[ 'method' => 'POST' ],
|
|
|
|
new HorizontalLayout( [ 'items' => $buttons ] )
|
2018-08-10 18:20:42 +00:00
|
|
|
);
|
2016-11-04 16:47:15 +00:00
|
|
|
|
2020-10-03 18:13:17 +00:00
|
|
|
return Html::openElement(
|
2016-09-14 15:11:38 +00:00
|
|
|
'div',
|
Move the warning outside sitenotice, tidy up code
There's a lot of things going on here, so a quick summary:
* Moved the warning outside sitenotice to avoid reflows and all
kinds of other issues, including those with dismissable notices.
* Placed the warning on the bottom of the page, on all skins, for
consistency and to avoid obstructing vital UI elements such as
site name, user tools, search box.
* Changed the UI to use OOUI for, again, consistency and to avoid
reinventing the wheel with button styling.
* Removed the cookie emoji as it was only taking up valuable space
on mobile and making designing a sensible layout much harder.
* Merged the mobile and desktop RL modules into a single, responsive
one. The warning will work correctly for any skin and screen width.
* The integration tests are truly horrible, I tried to at least
make them work. They deserve a proper rewrite, but that should be
done after the extension switches to the new hook system.
I will post screenshots of this in action in the first of the linked
tasks.
Bug: T271047
Bug: T173335
Change-Id: I6e2a3d7aeccc0d4df1b3238e52c67e72099d27d8
2021-02-01 09:54:49 +00:00
|
|
|
[ 'class' => 'mw-cookiewarning-container' ]
|
2016-09-14 15:11:38 +00:00
|
|
|
) .
|
|
|
|
Html::openElement(
|
|
|
|
'div',
|
2016-09-14 15:23:11 +00:00
|
|
|
[ 'class' => 'mw-cookiewarning-text' ]
|
2016-09-14 15:11:38 +00:00
|
|
|
) .
|
|
|
|
Html::element(
|
|
|
|
'span',
|
2016-09-14 15:23:11 +00:00
|
|
|
[],
|
2020-10-03 18:13:17 +00:00
|
|
|
$skin->msg( 'cookiewarning-info' )->text()
|
2016-09-14 15:11:38 +00:00
|
|
|
) .
|
|
|
|
Html::closeElement( 'div' ) .
|
2020-10-03 18:13:17 +00:00
|
|
|
$form .
|
2016-09-14 15:11:38 +00:00
|
|
|
Html::closeElement( 'div' );
|
2015-07-27 17:18:44 +00:00
|
|
|
}
|
|
|
|
|
2016-09-15 21:07:08 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2018-07-18 09:50:46 +00:00
|
|
|
* @throws ConfigException
|
2016-09-15 21:07:08 +00:00
|
|
|
*/
|
2021-07-22 06:56:11 +00:00
|
|
|
private static function getMoreLink(): ?string {
|
2018-07-18 09:50:46 +00:00
|
|
|
$conf = self::getConfig();
|
2016-09-15 21:07:08 +00:00
|
|
|
if ( $conf->get( 'CookieWarningMoreUrl' ) ) {
|
|
|
|
return $conf->get( 'CookieWarningMoreUrl' );
|
|
|
|
}
|
2018-07-18 09:50:46 +00:00
|
|
|
|
2016-09-15 21:07:08 +00:00
|
|
|
$cookieWarningMessage = wfMessage( 'cookiewarning-more-link' );
|
|
|
|
if ( $cookieWarningMessage->exists() && !$cookieWarningMessage->isDisabled() ) {
|
2018-08-25 07:59:19 +00:00
|
|
|
return $cookieWarningMessage->text();
|
2016-09-15 21:07:08 +00:00
|
|
|
}
|
2018-07-18 09:50:46 +00:00
|
|
|
|
2016-09-15 21:07:08 +00:00
|
|
|
$cookiePolicyMessage = wfMessage( 'cookie-policy-link' );
|
|
|
|
if ( $cookiePolicyMessage->exists() && !$cookiePolicyMessage->isDisabled() ) {
|
2018-08-25 07:59:19 +00:00
|
|
|
return $cookiePolicyMessage->text();
|
2016-09-15 21:07:08 +00:00
|
|
|
}
|
2018-07-18 09:50:46 +00:00
|
|
|
|
2016-09-15 21:07:08 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-01-10 17:58:21 +00:00
|
|
|
/**
|
|
|
|
* BeforePageDisplay hook handler.
|
|
|
|
*
|
|
|
|
* Adds the required style and JS module, if cookiewarning is enabled.
|
|
|
|
*
|
|
|
|
* @param OutputPage $out
|
2021-12-04 13:48:43 +00:00
|
|
|
* @param Skin $skin
|
2018-07-18 09:50:46 +00:00
|
|
|
* @throws ConfigException
|
|
|
|
* @throws MWException
|
2016-01-10 17:58:21 +00:00
|
|
|
*/
|
2021-12-04 13:48:43 +00:00
|
|
|
public function onBeforePageDisplay( $out, $skin ): void {
|
2018-07-19 10:48:17 +00:00
|
|
|
/** @var Decisions $cookieWarningDecisions */
|
2018-07-18 09:50:46 +00:00
|
|
|
$cookieWarningDecisions = MediaWikiServices::getInstance()
|
|
|
|
->getService( 'CookieWarning.Decisions' );
|
|
|
|
|
|
|
|
if ( !$cookieWarningDecisions->shouldShowCookieWarning( $out->getContext() ) ) {
|
|
|
|
return;
|
Add option to limit the cookie warning to specific regions
With this change, CookieWarning gets two new ways to limit the warning
bar to users of specific (configurable) regions. Based on the geo location
service (which can be configured, too, defaults to freegeoip.net), the
extension will try to get the region of the user (based on the IP address)
and checks it against the configured regions.
With the configuration variable $wgCookieWarningGeoIPLookup, the wiki sysadmin
can configure, if the lookup should be done with PHP (the timeout for the
request is hardcoded to 2 sedonds max), which will save the paylod sent to
the user, or with JavaScript, which will be asynchronous.
Deactivating this feature is easily done by simply setting the configured regions
to false, instead of an object.
Bug: T145780
Change-Id: I4d9371b8608ef270c11c42bdb3a773675977ab3a
2016-09-16 19:18:49 +00:00
|
|
|
}
|
2018-07-18 09:50:46 +00:00
|
|
|
|
|
|
|
$modules = [ 'ext.CookieWarning' ];
|
Move the warning outside sitenotice, tidy up code
There's a lot of things going on here, so a quick summary:
* Moved the warning outside sitenotice to avoid reflows and all
kinds of other issues, including those with dismissable notices.
* Placed the warning on the bottom of the page, on all skins, for
consistency and to avoid obstructing vital UI elements such as
site name, user tools, search box.
* Changed the UI to use OOUI for, again, consistency and to avoid
reinventing the wheel with button styling.
* Removed the cookie emoji as it was only taking up valuable space
on mobile and making designing a sensible layout much harder.
* Merged the mobile and desktop RL modules into a single, responsive
one. The warning will work correctly for any skin and screen width.
* The integration tests are truly horrible, I tried to at least
make them work. They deserve a proper rewrite, but that should be
done after the extension switches to the new hook system.
I will post screenshots of this in action in the first of the linked
tasks.
Bug: T271047
Bug: T173335
Change-Id: I6e2a3d7aeccc0d4df1b3238e52c67e72099d27d8
2021-02-01 09:54:49 +00:00
|
|
|
$moduleStyles = [ 'ext.CookieWarning.styles' ];
|
2018-07-18 09:50:46 +00:00
|
|
|
|
|
|
|
if ( $cookieWarningDecisions->shouldAddResourceLoaderComponents() ) {
|
|
|
|
$modules[] = 'ext.CookieWarning.geolocation';
|
|
|
|
$moduleStyles[] = 'ext.CookieWarning.geolocation.styles';
|
|
|
|
}
|
|
|
|
$out->addModules( $modules );
|
|
|
|
$out->addModuleStyles( $moduleStyles );
|
Move the warning outside sitenotice, tidy up code
There's a lot of things going on here, so a quick summary:
* Moved the warning outside sitenotice to avoid reflows and all
kinds of other issues, including those with dismissable notices.
* Placed the warning on the bottom of the page, on all skins, for
consistency and to avoid obstructing vital UI elements such as
site name, user tools, search box.
* Changed the UI to use OOUI for, again, consistency and to avoid
reinventing the wheel with button styling.
* Removed the cookie emoji as it was only taking up valuable space
on mobile and making designing a sensible layout much harder.
* Merged the mobile and desktop RL modules into a single, responsive
one. The warning will work correctly for any skin and screen width.
* The integration tests are truly horrible, I tried to at least
make them work. They deserve a proper rewrite, but that should be
done after the extension switches to the new hook system.
I will post screenshots of this in action in the first of the linked
tasks.
Bug: T271047
Bug: T173335
Change-Id: I6e2a3d7aeccc0d4df1b3238e52c67e72099d27d8
2021-02-01 09:54:49 +00:00
|
|
|
$out->enableOOUI();
|
Add option to limit the cookie warning to specific regions
With this change, CookieWarning gets two new ways to limit the warning
bar to users of specific (configurable) regions. Based on the geo location
service (which can be configured, too, defaults to freegeoip.net), the
extension will try to get the region of the user (based on the IP address)
and checks it against the configured regions.
With the configuration variable $wgCookieWarningGeoIPLookup, the wiki sysadmin
can configure, if the lookup should be done with PHP (the timeout for the
request is hardcoded to 2 sedonds max), which will save the paylod sent to
the user, or with JavaScript, which will be asynchronous.
Deactivating this feature is easily done by simply setting the configured regions
to false, instead of an object.
Bug: T145780
Change-Id: I4d9371b8608ef270c11c42bdb3a773675977ab3a
2016-09-16 19:18:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ResourceLoaderGetConfigVars hook handler.
|
|
|
|
*
|
2018-01-11 20:09:29 +00:00
|
|
|
* @param array &$vars
|
2021-12-04 13:48:43 +00:00
|
|
|
* @param string $skin
|
|
|
|
* @param Config $config
|
|
|
|
*
|
2018-07-18 09:50:46 +00:00
|
|
|
* @throws ConfigException
|
Add option to limit the cookie warning to specific regions
With this change, CookieWarning gets two new ways to limit the warning
bar to users of specific (configurable) regions. Based on the geo location
service (which can be configured, too, defaults to freegeoip.net), the
extension will try to get the region of the user (based on the IP address)
and checks it against the configured regions.
With the configuration variable $wgCookieWarningGeoIPLookup, the wiki sysadmin
can configure, if the lookup should be done with PHP (the timeout for the
request is hardcoded to 2 sedonds max), which will save the paylod sent to
the user, or with JavaScript, which will be asynchronous.
Deactivating this feature is easily done by simply setting the configured regions
to false, instead of an object.
Bug: T145780
Change-Id: I4d9371b8608ef270c11c42bdb3a773675977ab3a
2016-09-16 19:18:49 +00:00
|
|
|
*/
|
2021-12-04 13:48:43 +00:00
|
|
|
public function onResourceLoaderGetConfigVars( array &$vars, $skin, Config $config ): void {
|
2018-07-19 10:48:17 +00:00
|
|
|
/** @var Decisions $cookieWarningDecisions */
|
2018-07-18 09:50:46 +00:00
|
|
|
$cookieWarningDecisions = MediaWikiServices::getInstance()
|
|
|
|
->getService( 'CookieWarning.Decisions' );
|
Add option to limit the cookie warning to specific regions
With this change, CookieWarning gets two new ways to limit the warning
bar to users of specific (configurable) regions. Based on the geo location
service (which can be configured, too, defaults to freegeoip.net), the
extension will try to get the region of the user (based on the IP address)
and checks it against the configured regions.
With the configuration variable $wgCookieWarningGeoIPLookup, the wiki sysadmin
can configure, if the lookup should be done with PHP (the timeout for the
request is hardcoded to 2 sedonds max), which will save the paylod sent to
the user, or with JavaScript, which will be asynchronous.
Deactivating this feature is easily done by simply setting the configured regions
to false, instead of an object.
Bug: T145780
Change-Id: I4d9371b8608ef270c11c42bdb3a773675977ab3a
2016-09-16 19:18:49 +00:00
|
|
|
$conf = self::getConfig();
|
2018-07-18 09:50:46 +00:00
|
|
|
|
|
|
|
if ( $cookieWarningDecisions->shouldAddResourceLoaderComponents() ) {
|
Add option to limit the cookie warning to specific regions
With this change, CookieWarning gets two new ways to limit the warning
bar to users of specific (configurable) regions. Based on the geo location
service (which can be configured, too, defaults to freegeoip.net), the
extension will try to get the region of the user (based on the IP address)
and checks it against the configured regions.
With the configuration variable $wgCookieWarningGeoIPLookup, the wiki sysadmin
can configure, if the lookup should be done with PHP (the timeout for the
request is hardcoded to 2 sedonds max), which will save the paylod sent to
the user, or with JavaScript, which will be asynchronous.
Deactivating this feature is easily done by simply setting the configured regions
to false, instead of an object.
Bug: T145780
Change-Id: I4d9371b8608ef270c11c42bdb3a773675977ab3a
2016-09-16 19:18:49 +00:00
|
|
|
$vars += [
|
|
|
|
'wgCookieWarningGeoIPServiceURL' => $conf->get( 'CookieWarningGeoIPServiceURL' ),
|
|
|
|
'wgCookieWarningForCountryCodes' => $conf->get( 'CookieWarningForCountryCodes' ),
|
|
|
|
];
|
2015-07-27 17:18:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add option to limit the cookie warning to specific regions
With this change, CookieWarning gets two new ways to limit the warning
bar to users of specific (configurable) regions. Based on the geo location
service (which can be configured, too, defaults to freegeoip.net), the
extension will try to get the region of the user (based on the IP address)
and checks it against the configured regions.
With the configuration variable $wgCookieWarningGeoIPLookup, the wiki sysadmin
can configure, if the lookup should be done with PHP (the timeout for the
request is hardcoded to 2 sedonds max), which will save the paylod sent to
the user, or with JavaScript, which will be asynchronous.
Deactivating this feature is easily done by simply setting the configured regions
to false, instead of an object.
Bug: T145780
Change-Id: I4d9371b8608ef270c11c42bdb3a773675977ab3a
2016-09-16 19:18:49 +00:00
|
|
|
/**
|
2018-08-14 09:40:21 +00:00
|
|
|
* Returns the Config object for the CookieWarning extension.
|
Add option to limit the cookie warning to specific regions
With this change, CookieWarning gets two new ways to limit the warning
bar to users of specific (configurable) regions. Based on the geo location
service (which can be configured, too, defaults to freegeoip.net), the
extension will try to get the region of the user (based on the IP address)
and checks it against the configured regions.
With the configuration variable $wgCookieWarningGeoIPLookup, the wiki sysadmin
can configure, if the lookup should be done with PHP (the timeout for the
request is hardcoded to 2 sedonds max), which will save the paylod sent to
the user, or with JavaScript, which will be asynchronous.
Deactivating this feature is easily done by simply setting the configured regions
to false, instead of an object.
Bug: T145780
Change-Id: I4d9371b8608ef270c11c42bdb3a773675977ab3a
2016-09-16 19:18:49 +00:00
|
|
|
*
|
|
|
|
* @return Config
|
|
|
|
*/
|
2021-12-04 13:48:43 +00:00
|
|
|
private static function getConfig(): Config {
|
2018-07-18 09:50:46 +00:00
|
|
|
return MediaWikiServices::getInstance()->getService( 'CookieWarning.Config' );
|
Add option to limit the cookie warning to specific regions
With this change, CookieWarning gets two new ways to limit the warning
bar to users of specific (configurable) regions. Based on the geo location
service (which can be configured, too, defaults to freegeoip.net), the
extension will try to get the region of the user (based on the IP address)
and checks it against the configured regions.
With the configuration variable $wgCookieWarningGeoIPLookup, the wiki sysadmin
can configure, if the lookup should be done with PHP (the timeout for the
request is hardcoded to 2 sedonds max), which will save the paylod sent to
the user, or with JavaScript, which will be asynchronous.
Deactivating this feature is easily done by simply setting the configured regions
to false, instead of an object.
Bug: T145780
Change-Id: I4d9371b8608ef270c11c42bdb3a773675977ab3a
2016-09-16 19:18:49 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 09:49:05 +00:00
|
|
|
/**
|
|
|
|
* GetPreferences hook handler
|
|
|
|
*
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences
|
|
|
|
*
|
|
|
|
* @param User $user
|
2018-01-11 20:09:29 +00:00
|
|
|
* @param array &$defaultPreferences
|
2015-08-16 09:49:05 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2021-12-04 13:48:43 +00:00
|
|
|
public function onGetPreferences( $user, &$defaultPreferences ): bool {
|
2016-09-14 15:23:11 +00:00
|
|
|
$defaultPreferences['cookiewarning_dismissed'] = [
|
2015-08-16 09:49:05 +00:00
|
|
|
'type' => 'api',
|
|
|
|
'default' => '0',
|
2016-09-14 15:23:11 +00:00
|
|
|
];
|
2015-08-16 09:49:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-07-27 17:18:44 +00:00
|
|
|
}
|