mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CookieWarning
synced 2024-11-23 13:56:53 +00:00
Move classes into CookieWarning namespace
This should make the code a bit more structured and easier to navigate through. It also removes some lines from extension.json as the autoload classes list is replaced by an autoload namespaces property. This also changes the minimum requirement of MediaWiki to 1.31 for this extension to work. Change-Id: I249ccc3035297c99202a5f83fcc8d3fda68b682c
This commit is contained in:
parent
c0a1ba6bfb
commit
90d2e58096
|
@ -11,7 +11,7 @@
|
|||
"type": "other",
|
||||
"license-name": "MIT",
|
||||
"requires": {
|
||||
"MediaWiki": ">= 1.25.0"
|
||||
"MediaWiki": ">= 1.31.0"
|
||||
},
|
||||
"MessagesDirs": {
|
||||
"CookieWarning": [
|
||||
|
@ -19,11 +19,11 @@
|
|||
]
|
||||
},
|
||||
"Hooks": {
|
||||
"SkinTemplateOutputPageBeforeExec": "CookieWarningHooks::onSkinTemplateOutputPageBeforeExec",
|
||||
"BeforePageDisplay": "CookieWarningHooks::onBeforePageDisplay",
|
||||
"GetPreferences": "CookieWarningHooks::onGetPreferences",
|
||||
"BeforeInitialize": "CookieWarningHooks::onBeforeInitialize",
|
||||
"ResourceLoaderGetConfigVars": "CookieWarningHooks::onResourceLoaderGetConfigVars"
|
||||
"SkinTemplateOutputPageBeforeExec": "CookieWarning\\Hooks::onSkinTemplateOutputPageBeforeExec",
|
||||
"BeforePageDisplay": "CookieWarning\\Hooks::onBeforePageDisplay",
|
||||
"GetPreferences": "CookieWarning\\Hooks::onGetPreferences",
|
||||
"BeforeInitialize": "CookieWarning\\Hooks::onBeforeInitialize",
|
||||
"ResourceLoaderGetConfigVars": "CookieWarning\\Hooks::onResourceLoaderGetConfigVars"
|
||||
},
|
||||
"config": {
|
||||
"CookieWarningEnabled": false,
|
||||
|
@ -125,11 +125,8 @@
|
|||
"localBasePath": "",
|
||||
"remoteExtPath": "CookieWarning"
|
||||
},
|
||||
"AutoloadClasses": {
|
||||
"CookieWarningHooks": "includes/CookieWarningHooks.php",
|
||||
"CookieWarningDecisions": "includes/CookieWarningDecisions.php",
|
||||
"CookieWarningTestTemplate": "tests/phpunit/includes/CookieWarningTestTemplate.php",
|
||||
"GeoLocation": "includes/GeoLocation.php"
|
||||
"AutoloadNamespaces": {
|
||||
"CookieWarning\\": "includes/"
|
||||
},
|
||||
"ConfigRegistry": {
|
||||
"cookiewarning": "GlobalVarConfig::newInstance"
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
<?php
|
||||
|
||||
class CookieWarningDecisions {
|
||||
namespace CookieWarning;
|
||||
|
||||
use Config;
|
||||
use ConfigException;
|
||||
use IContextSource;
|
||||
use MWException;
|
||||
use WANObjectCache;
|
||||
|
||||
class Decisions {
|
||||
private $config;
|
||||
private $geoLocation;
|
||||
private $cache;
|
|
@ -1,8 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace CookieWarning;
|
||||
|
||||
/**
|
||||
* GeoLocation implementation
|
||||
*/
|
||||
|
||||
use Config;
|
||||
use ConfigException;
|
||||
use Http;
|
||||
use InvalidArgumentException;
|
||||
use IP;
|
||||
|
||||
/**
|
||||
* Implements the GeoLocation class, which allows to locate the user based on the IP address.
|
||||
*/
|
||||
|
|
|
@ -1,8 +1,23 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
namespace CookieWarning;
|
||||
|
||||
class CookieWarningHooks {
|
||||
use Config;
|
||||
use ConfigException;
|
||||
use ExtensionRegistry;
|
||||
use Html;
|
||||
use MediaWiki;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MobileContext;
|
||||
use MWException;
|
||||
use OutputPage;
|
||||
use QuickTemplate;
|
||||
use SkinTemplate;
|
||||
use Title;
|
||||
use User;
|
||||
use WebRequest;
|
||||
|
||||
class Hooks {
|
||||
/**
|
||||
* BeforeInitialize hook handler.
|
||||
*
|
||||
|
@ -46,7 +61,7 @@ class CookieWarningHooks {
|
|||
public static function onSkinTemplateOutputPageBeforeExec(
|
||||
SkinTemplate &$sk, QuickTemplate &$tpl
|
||||
) {
|
||||
/** @var CookieWarningDecisions $cookieWarningDecisions */
|
||||
/** @var Decisions $cookieWarningDecisions */
|
||||
$cookieWarningDecisions = MediaWikiServices::getInstance()
|
||||
->getService( 'CookieWarning.Decisions' );
|
||||
|
||||
|
@ -145,7 +160,7 @@ class CookieWarningHooks {
|
|||
* @throws MWException
|
||||
*/
|
||||
public static function onBeforePageDisplay( OutputPage $out ) {
|
||||
/** @var CookieWarningDecisions $cookieWarningDecisions */
|
||||
/** @var Decisions $cookieWarningDecisions */
|
||||
$cookieWarningDecisions = MediaWikiServices::getInstance()
|
||||
->getService( 'CookieWarning.Decisions' );
|
||||
|
||||
|
@ -178,7 +193,7 @@ class CookieWarningHooks {
|
|||
* @throws ConfigException
|
||||
*/
|
||||
public static function onResourceLoaderGetConfigVars( array &$vars ) {
|
||||
/** @var CookieWarningDecisions $cookieWarningDecisions */
|
||||
/** @var Decisions $cookieWarningDecisions */
|
||||
$cookieWarningDecisions = MediaWikiServices::getInstance()
|
||||
->getService( 'CookieWarning.Decisions' );
|
||||
$conf = self::getConfig();
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use CookieWarning\Decisions;
|
||||
use CookieWarning\GeoLocation;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
return [
|
||||
|
@ -11,7 +13,7 @@ return [
|
|||
return new GeoLocation( $services->getService( 'CookieWarning.Config' ) );
|
||||
},
|
||||
'CookieWarning.Decisions' => function ( MediaWikiServices $services ) {
|
||||
return new CookieWarningDecisions( $services->getService( 'CookieWarning.Config' ),
|
||||
return new Decisions( $services->getService( 'CookieWarning.Config' ),
|
||||
$services->getService( 'GeoLocation' ), $services->getMainWANObjectCache() );
|
||||
},
|
||||
];
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
class CookieWarningTestTemplate extends BaseTemplate {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute() {
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -1,10 +1,20 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
namespace CookieWarning\Tests;
|
||||
|
||||
class CookieWarningDecisionsTest extends MediaWikiTestCase {
|
||||
use ConfigException;
|
||||
use CookieWarning\Decisions;
|
||||
use CookieWarning\GeoLocation;
|
||||
use HashBagOStuff;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWikiTestCase;
|
||||
use MWException;
|
||||
use RequestContext;
|
||||
use WANObjectCache;
|
||||
|
||||
class DecisionsTest extends MediaWikiTestCase {
|
||||
/**
|
||||
* @covers CookieWarningDecisions::shouldShowCookieWarning()
|
||||
* @covers \CookieWarning\Decisions::shouldShowCookieWarning()
|
||||
* @throws ConfigException
|
||||
* @throws MWException
|
||||
*/
|
||||
|
@ -22,7 +32,7 @@ class CookieWarningDecisionsTest extends MediaWikiTestCase {
|
|||
$geoLocation->method( 'getCountryCode' )->willReturn( 'EU' );
|
||||
|
||||
$geoLocation->expects( $this->once() )->method( 'locate' );
|
||||
$cookieWarningDecisions = new CookieWarningDecisions(
|
||||
$cookieWarningDecisions = new Decisions(
|
||||
MediaWikiServices::getInstance()->getService( 'CookieWarning.Config' ),
|
||||
$geoLocation,
|
||||
new WANObjectCache( [ 'cache' => new HashBagOStuff() ] )
|
|
@ -1,9 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace CookieWarning\Tests;
|
||||
|
||||
use CookieWarning\GeoLocation;
|
||||
use CookieWarning\Hooks;
|
||||
use DerivativeContext;
|
||||
use FauxRequest;
|
||||
use MediaWikiLangTestCase;
|
||||
use MessageCache;
|
||||
use RequestContext;
|
||||
use SkinTemplate;
|
||||
use Title;
|
||||
use WikiPage;
|
||||
use WikitextContent;
|
||||
|
||||
/**
|
||||
* @covers CookieWarningHooks
|
||||
* @covers Hooks
|
||||
* @group Database
|
||||
*/
|
||||
class CookieWarningHooksTest extends MediaWikiLangTestCase {
|
||||
class HooksTest extends MediaWikiLangTestCase {
|
||||
/**
|
||||
* @throws \MWException
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
MessageCache::singleton()->enable();
|
||||
|
@ -11,6 +29,8 @@ class CookieWarningHooksTest extends MediaWikiLangTestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider providerOnSkinTemplateOutputPageBeforeExec
|
||||
* @throws \MWException
|
||||
* @throws \ConfigException
|
||||
*/
|
||||
public function testOnSkinTemplateOutputPageBeforeExec( $enabled, $morelinkConfig,
|
||||
$morelinkCookieWarningMsg, $morelinkCookiePolicyMsg, $expectedLink
|
||||
|
@ -33,8 +53,8 @@ class CookieWarningHooksTest extends MediaWikiLangTestCase {
|
|||
"CookieWarning test" );
|
||||
}
|
||||
$sk = new SkinTemplate();
|
||||
$tpl = new CookieWarningTestTemplate();
|
||||
CookieWarningHooks::onSkinTemplateOutputPageBeforeExec( $sk, $tpl );
|
||||
$tpl = new \SkinFallbackTemplate();
|
||||
Hooks::onSkinTemplateOutputPageBeforeExec( $sk, $tpl );
|
||||
$headElement = '';
|
||||
if ( isset( $tpl->data['headelement'] ) ) {
|
||||
$headElement = $tpl->data['headelement'];
|
||||
|
@ -120,6 +140,8 @@ class CookieWarningHooksTest extends MediaWikiLangTestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider providerOnSkinTemplateOutputPageBeforeExecGeoLocation
|
||||
* @throws \MWException
|
||||
* @throws \ConfigException
|
||||
*/
|
||||
public function testOnSkinTemplateOutputPageBeforeExecGeoLocation( $ipAddress, $countryCodes,
|
||||
$expected
|
||||
|
@ -137,8 +159,8 @@ class CookieWarningHooksTest extends MediaWikiLangTestCase {
|
|||
$context->setRequest( $request );
|
||||
$sk = new SkinTemplate();
|
||||
$sk->setContext( $context );
|
||||
$tpl = new CookieWarningTestTemplate();
|
||||
CookieWarningHooks::onSkinTemplateOutputPageBeforeExec( $sk, $tpl );
|
||||
$tpl = new \SkinFallbackTemplate();
|
||||
Hooks::onSkinTemplateOutputPageBeforeExec( $sk, $tpl );
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
Loading…
Reference in a new issue