Drop more unused hard deprecated hooks
None are used in WMF-deployed extensions and have been hard deprecated for multiple releases as well. Change-Id: I62cfa22291f81295b4908192de8657a750c6716d
This commit is contained in:
parent
9172885602
commit
02e5a33057
18 changed files with 7 additions and 391 deletions
|
|
@ -213,6 +213,10 @@ because of Phabricator reports.
|
|||
- InternalParseBeforeSanitize, deprecated in 1.35
|
||||
- LinksUpdateConstructed, deprecated in 1.38
|
||||
- LinksUpdateAfterInsert, deprecated in 1.38
|
||||
- ParserSectionCreate, deprecated in 1.35
|
||||
- ResourceLoaderTestModules, deprecated in 1.33
|
||||
- UserLoadFromDatabase, deprecated in 1.37
|
||||
- UserSetCookies, deprecated in 1.27
|
||||
* RemexDriver::__construct() now only accepts a ServiceOptions instance as
|
||||
the only argument. Passing an array was deprecated since 1.36.
|
||||
* TidyDriverBase::supportsValidate(), deprecated since 1.36, has been removed.
|
||||
|
|
|
|||
|
|
@ -1286,7 +1286,6 @@ $wgAutoloadLocalClasses = [
|
|||
'MediaWiki\\Hook\\ParserOptionsRegisterHook' => __DIR__ . '/includes/parser/Hook/ParserOptionsRegisterHook.php',
|
||||
'MediaWiki\\Hook\\ParserOutputPostCacheTransformHook' => __DIR__ . '/includes/parser/Hook/ParserOutputPostCacheTransformHook.php',
|
||||
'MediaWiki\\Hook\\ParserPreSaveTransformCompleteHook' => __DIR__ . '/includes/parser/Hook/ParserPreSaveTransformCompleteHook.php',
|
||||
'MediaWiki\\Hook\\ParserSectionCreateHook' => __DIR__ . '/includes/parser/Hook/ParserSectionCreateHook.php',
|
||||
'MediaWiki\\Hook\\ParserTestGlobalsHook' => __DIR__ . '/includes/Hook/ParserTestGlobalsHook.php',
|
||||
'MediaWiki\\Hook\\ParserTestTablesHook' => __DIR__ . '/includes/Hook/ParserTestTablesHook.php',
|
||||
'MediaWiki\\Hook\\PasswordPoliciesForUserHook' => __DIR__ . '/includes/password/Hook/PasswordPoliciesForUserHook.php',
|
||||
|
|
@ -1637,7 +1636,6 @@ $wgAutoloadLocalClasses = [
|
|||
'MediaWiki\\ResourceLoader\\Hook\\ResourceLoaderRegisterModulesHook' => __DIR__ . '/includes/ResourceLoader/Hook/ResourceLoaderRegisterModulesHook.php',
|
||||
'MediaWiki\\ResourceLoader\\Hook\\ResourceLoaderSiteModulePagesHook' => __DIR__ . '/includes/ResourceLoader/Hook/ResourceLoaderSiteModulePagesHook.php',
|
||||
'MediaWiki\\ResourceLoader\\Hook\\ResourceLoaderSiteStylesModulePagesHook' => __DIR__ . '/includes/ResourceLoader/Hook/ResourceLoaderSiteStylesModulePagesHook.php',
|
||||
'MediaWiki\\ResourceLoader\\Hook\\ResourceLoaderTestModulesHook' => __DIR__ . '/includes/ResourceLoader/Hook/ResourceLoaderTestModulesHook.php',
|
||||
'MediaWiki\\ResourceLoader\\Image' => __DIR__ . '/includes/ResourceLoader/Image.php',
|
||||
'MediaWiki\\ResourceLoader\\ImageModule' => __DIR__ . '/includes/ResourceLoader/ImageModule.php',
|
||||
'MediaWiki\\ResourceLoader\\LanguageDataModule' => __DIR__ . '/includes/ResourceLoader/LanguageDataModule.php',
|
||||
|
|
@ -1793,7 +1791,6 @@ $wgAutoloadLocalClasses = [
|
|||
'MediaWiki\\Session\\CsrfTokenSetProvider' => __DIR__ . '/includes/session/CsrfTokenSetProvider.php',
|
||||
'MediaWiki\\Session\\Hook\\SessionCheckInfoHook' => __DIR__ . '/includes/session/Hook/SessionCheckInfoHook.php',
|
||||
'MediaWiki\\Session\\Hook\\SessionMetadataHook' => __DIR__ . '/includes/session/Hook/SessionMetadataHook.php',
|
||||
'MediaWiki\\Session\\Hook\\UserSetCookiesHook' => __DIR__ . '/includes/session/Hook/UserSetCookiesHook.php',
|
||||
'MediaWiki\\Session\\ImmutableSessionProviderWithCookie' => __DIR__ . '/includes/session/ImmutableSessionProviderWithCookie.php',
|
||||
'MediaWiki\\Session\\MetadataMergeException' => __DIR__ . '/includes/session/MetadataMergeException.php',
|
||||
'MediaWiki\\Session\\PHPSessionHandler' => __DIR__ . '/includes/session/PHPSessionHandler.php',
|
||||
|
|
@ -1945,7 +1942,6 @@ $wgAutoloadLocalClasses = [
|
|||
'MediaWiki\\User\\Hook\\UserIsLockedHook' => __DIR__ . '/includes/user/Hook/UserIsLockedHook.php',
|
||||
'MediaWiki\\User\\Hook\\UserLoadAfterLoadFromSessionHook' => __DIR__ . '/includes/user/Hook/UserLoadAfterLoadFromSessionHook.php',
|
||||
'MediaWiki\\User\\Hook\\UserLoadDefaultsHook' => __DIR__ . '/includes/user/Hook/UserLoadDefaultsHook.php',
|
||||
'MediaWiki\\User\\Hook\\UserLoadFromDatabaseHook' => __DIR__ . '/includes/user/Hook/UserLoadFromDatabaseHook.php',
|
||||
'MediaWiki\\User\\Hook\\UserLogoutHook' => __DIR__ . '/includes/user/Hook/UserLogoutHook.php',
|
||||
'MediaWiki\\User\\Hook\\UserRemoveGroupHook' => __DIR__ . '/includes/user/Hook/UserRemoveGroupHook.php',
|
||||
'MediaWiki\\User\\Hook\\UserSaveSettingsHook' => __DIR__ . '/includes/user/Hook/UserSaveSettingsHook.php',
|
||||
|
|
|
|||
|
|
@ -4694,7 +4694,7 @@ config-schema:
|
|||
SessionProviders:
|
||||
type: object
|
||||
default:
|
||||
MediaWiki\Session\CookieSessionProvider: { class: MediaWiki\Session\CookieSessionProvider, args: [{ priority: 30, callUserSetCookiesHook: true }] }
|
||||
MediaWiki\Session\CookieSessionProvider: { class: MediaWiki\Session\CookieSessionProvider, args: [{ priority: 30 }] }
|
||||
MediaWiki\Session\BotPasswordSessionProvider: { class: MediaWiki\Session\BotPasswordSessionProvider, args: [{ priority: 75 }], services: [GrantsInfo] }
|
||||
description: |-
|
||||
MediaWiki\Session\SessionProvider configuration.
|
||||
|
|
|
|||
|
|
@ -39,15 +39,11 @@ class DeprecatedHooks {
|
|||
'LocalFile::getHistory' => [ 'deprecatedVersion' => '1.37' ],
|
||||
'MagicWordwgVariableIDs' => [ 'deprecatedVersion' => '1.35', 'silent' => true ],
|
||||
'PageContentSave' => [ 'deprecatedVersion' => '1.35', 'silent' => true ],
|
||||
'ParserSectionCreate' => [ 'deprecatedVersion' => '1.35' ],
|
||||
'ParserTestTables' => [ 'deprecatedVersion' => '1.36', 'silent' => true ],
|
||||
'PrefixSearchBackend' => [ 'deprecatedVersion' => '1.27', 'silent' => true ],
|
||||
'ProtectionForm::buildForm' => [ 'deprecatedVersion' => '1.36', 'silent' => true ],
|
||||
'ResourceLoaderTestModules' => [ 'deprecatedVersion' => '1.33' ],
|
||||
'RollbackComplete' => [ 'deprecatedVersion' => '1.36', 'silent' => true ],
|
||||
'SpecialMuteSubmit' => [ 'deprecatedVersion' => '1.35', 'silent' => true ],
|
||||
'UserLoadFromDatabase' => [ 'deprecatedVersion' => '1.37' ],
|
||||
'UserSetCookies' => [ 'deprecatedVersion' => '1.27' ],
|
||||
'WikiPageDeletionUpdates' => [ 'deprecatedVersion' => '1.32', 'silent' => true ],
|
||||
'userCan' => [ 'deprecatedVersion' => '1.37' ],
|
||||
'ArticleDelete' => [ 'deprecatedVersion' => '1.37', 'silent' => true ],
|
||||
|
|
|
|||
|
|
@ -295,7 +295,6 @@ class HookRunner implements
|
|||
\MediaWiki\Hook\ParserOptionsRegisterHook,
|
||||
\MediaWiki\Hook\ParserOutputPostCacheTransformHook,
|
||||
\MediaWiki\Hook\ParserPreSaveTransformCompleteHook,
|
||||
\MediaWiki\Hook\ParserSectionCreateHook,
|
||||
\MediaWiki\Hook\ParserTestGlobalsHook,
|
||||
\MediaWiki\Hook\ParserTestTablesHook,
|
||||
\MediaWiki\Hook\PasswordPoliciesForUserHook,
|
||||
|
|
@ -505,7 +504,6 @@ class HookRunner implements
|
|||
\MediaWiki\Search\Hook\SpecialSearchProfileFormHook,
|
||||
\MediaWiki\Session\Hook\SessionCheckInfoHook,
|
||||
\MediaWiki\Session\Hook\SessionMetadataHook,
|
||||
\MediaWiki\Session\Hook\UserSetCookiesHook,
|
||||
\MediaWiki\Shell\Hook\WfShellWikiCmdHook,
|
||||
\MediaWiki\Skins\Hook\SkinAfterPortletHook,
|
||||
\MediaWiki\Skins\Hook\SkinPageReadyConfigHook,
|
||||
|
|
@ -550,7 +548,6 @@ class HookRunner implements
|
|||
\MediaWiki\User\Hook\UserIsLockedHook,
|
||||
\MediaWiki\User\Hook\UserLoadAfterLoadFromSessionHook,
|
||||
\MediaWiki\User\Hook\UserLoadDefaultsHook,
|
||||
\MediaWiki\User\Hook\UserLoadFromDatabaseHook,
|
||||
\MediaWiki\User\Hook\UserLogoutHook,
|
||||
\MediaWiki\User\Hook\UserRemoveGroupHook,
|
||||
\MediaWiki\User\Hook\UserSaveSettingsHook,
|
||||
|
|
@ -2973,15 +2970,6 @@ class HookRunner implements
|
|||
);
|
||||
}
|
||||
|
||||
public function onParserSectionCreate( $parser, $section, &$sectionContent,
|
||||
$showEditLinks
|
||||
) {
|
||||
return $this->container->run(
|
||||
'ParserSectionCreate',
|
||||
[ $parser, $section, &$sectionContent, $showEditLinks ]
|
||||
);
|
||||
}
|
||||
|
||||
public function onParserTestGlobals( &$globals ) {
|
||||
return $this->container->run(
|
||||
'ParserTestGlobals',
|
||||
|
|
@ -4252,13 +4240,6 @@ class HookRunner implements
|
|||
);
|
||||
}
|
||||
|
||||
public function onUserLoadFromDatabase( $user, &$s ) {
|
||||
return $this->container->run(
|
||||
'UserLoadFromDatabase',
|
||||
[ $user, &$s ]
|
||||
);
|
||||
}
|
||||
|
||||
public function onLoadUserOptions( UserIdentity $user, array &$options ): void {
|
||||
$this->container->run(
|
||||
'LoadUserOptions',
|
||||
|
|
@ -4353,13 +4334,6 @@ class HookRunner implements
|
|||
);
|
||||
}
|
||||
|
||||
public function onUserSetCookies( $user, &$session, &$cookies ) {
|
||||
return $this->container->run(
|
||||
'UserSetCookies',
|
||||
[ $user, &$session, &$cookies ]
|
||||
);
|
||||
}
|
||||
|
||||
public function onUserSetEmail( $user, &$email ) {
|
||||
return $this->container->run(
|
||||
'UserSetEmail',
|
||||
|
|
|
|||
|
|
@ -7391,7 +7391,6 @@ class MainConfigSchema {
|
|||
'class' => \MediaWiki\Session\CookieSessionProvider::class,
|
||||
'args' => [ [
|
||||
'priority' => 30,
|
||||
'callUserSetCookiesHook' => true,
|
||||
] ],
|
||||
],
|
||||
\MediaWiki\Session\BotPasswordSessionProvider::class => [
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\ResourceLoader\Hook;
|
||||
|
||||
use MediaWiki\ResourceLoader\ResourceLoader;
|
||||
|
||||
/**
|
||||
* This is a hook handler interface, see docs/Hooks.md.
|
||||
* Use the hook name "ResourceLoaderTestModules" to register handlers implementing this interface.
|
||||
*
|
||||
* @deprecated since 1.33; use the QUnitTestModule static extension registration attribute instead.
|
||||
* @ingroup ResourceLoaderHooks
|
||||
*/
|
||||
interface ResourceLoaderTestModulesHook {
|
||||
/**
|
||||
* Register QUnit tests to load on [[Special:JavaScriptTest]].
|
||||
*
|
||||
* The tests files take the form of a ResourceLoader module that will only be registered
|
||||
* when $wgEnableJavaScriptTest is true, and automatically discovered and loaded when
|
||||
* visiting [[Special:JavaScriptTest]].
|
||||
*
|
||||
* The `$testModules` array follows the same format as $wgResourceModules, and is additionally
|
||||
* keyed by test framework.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* $testModules['qunit']['test.Example'] = [
|
||||
* 'localBasePath' => __DIR__ . '/tests/qunit',
|
||||
* 'remoteExtPath' => 'Example/tests/qunit',
|
||||
* 'script' => [ 'tests/qunit/foo.test.js' ],
|
||||
* 'dependencies' => [ 'ext.Example.foo' ]
|
||||
* ];
|
||||
*
|
||||
* @since 1.35
|
||||
* @param array &$testModules
|
||||
* @param ResourceLoader $rl
|
||||
* @return void This hook must not abort, it must return no value
|
||||
*/
|
||||
public function onResourceLoaderTestModules( array &$testModules, ResourceLoader $rl ): void;
|
||||
}
|
||||
|
|
@ -14,8 +14,7 @@ class HookRunner implements
|
|||
\MediaWiki\ResourceLoader\Hook\ResourceLoaderForeignApiModulesHook,
|
||||
\MediaWiki\ResourceLoader\Hook\ResourceLoaderRegisterModulesHook,
|
||||
\MediaWiki\ResourceLoader\Hook\ResourceLoaderSiteModulePagesHook,
|
||||
\MediaWiki\ResourceLoader\Hook\ResourceLoaderSiteStylesModulePagesHook,
|
||||
\MediaWiki\ResourceLoader\Hook\ResourceLoaderTestModulesHook
|
||||
\MediaWiki\ResourceLoader\Hook\ResourceLoaderSiteStylesModulePagesHook
|
||||
{
|
||||
/** @var HookContainer */
|
||||
private $container;
|
||||
|
|
@ -63,12 +62,4 @@ class HookRunner implements
|
|||
[ 'abortable' => false ]
|
||||
);
|
||||
}
|
||||
|
||||
public function onResourceLoaderTestModules( array &$testModules, ResourceLoader $rl ): void {
|
||||
$this->container->run(
|
||||
'ResourceLoaderTestModules',
|
||||
[ &$testModules, $rl ],
|
||||
[ 'abortable' => false ]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -303,13 +303,8 @@ class ResourceLoader implements LoggerAwareInterface {
|
|||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function registerTestModules(): void {
|
||||
$testModulesMeta = [ 'qunit' => [] ];
|
||||
$this->hookRunner->onResourceLoaderTestModules( $testModulesMeta, $this );
|
||||
|
||||
$extRegistry = ExtensionRegistry::getInstance();
|
||||
// In case of conflict, the deprecated hook has precedence.
|
||||
$testModules = $testModulesMeta['qunit']
|
||||
+ $extRegistry->getAttribute( 'QUnitTestModules' );
|
||||
$testModules = $extRegistry->getAttribute( 'QUnitTestModules' );
|
||||
|
||||
$testModuleNames = [];
|
||||
foreach ( $testModules as $name => &$module ) {
|
||||
|
|
|
|||
|
|
@ -1087,7 +1087,6 @@ return [
|
|||
'args' => [
|
||||
0 => [
|
||||
'priority' => 30,
|
||||
'callUserSetCookiesHook' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Hook;
|
||||
|
||||
use Parser;
|
||||
|
||||
/**
|
||||
* This is a hook handler interface, see docs/Hooks.md.
|
||||
* Use the hook name "ParserSectionCreate" to register handlers implementing this interface.
|
||||
*
|
||||
* @deprecated since 1.35
|
||||
* @ingroup Hooks
|
||||
*/
|
||||
interface ParserSectionCreateHook {
|
||||
/**
|
||||
* This hook is called each time the parser creates a document section
|
||||
* from wikitext. Use this to apply per-section modifications to HTML (like
|
||||
* wrapping the section in a DIV). Caveat: DIVs are valid wikitext, and a DIV
|
||||
* can begin in one section and end in another. Make sure your code can handle
|
||||
* that case gracefully. See the EditSectionClearerLink extension for an example.
|
||||
*
|
||||
* @since 1.35
|
||||
*
|
||||
* @param Parser $parser Calling Parser instance
|
||||
* @param int $section Section number, zero-based, but section 0 is usually empty
|
||||
* @param string &$sectionContent Reference to the content of the section, which
|
||||
* can be modified by the hook
|
||||
* @param bool $showEditLinks Whether this section has an edit link
|
||||
* @return bool|void True or no return value to continue or false to abort
|
||||
*/
|
||||
public function onParserSectionCreate( $parser, $section, &$sectionContent,
|
||||
$showEditLinks
|
||||
);
|
||||
}
|
||||
|
|
@ -4523,18 +4523,6 @@ class Parser {
|
|||
$sections[$i] = $head[$i - 1] . $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a hook, one per section.
|
||||
* The idea here is to be able to make section-level DIVs, but to do so in a
|
||||
* lower-impact, more correct way than r50769
|
||||
*
|
||||
* $this : caller
|
||||
* $section : the section number
|
||||
* &$sectionContent : ref to the content of the section
|
||||
* $maybeShowEditLinks : boolean describing whether this section has an edit link
|
||||
*/
|
||||
$this->hookRunner->onParserSectionCreate( $this, $i, $sections[$i], $maybeShowEditLink );
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ class CookieSessionProvider extends SessionProvider {
|
|||
/**
|
||||
* @param array $params Keys include:
|
||||
* - priority: (required) Priority of the returned sessions
|
||||
* - callUserSetCookiesHook: Whether to call the deprecated hook
|
||||
* - sessionName: Session cookie name. Doesn't honor 'prefix'. Defaults to
|
||||
* $wgSessionName, or $wgCookiePrefix . '_session' if that is unset.
|
||||
* - cookieOptions: Options to pass to WebRequest::setCookie():
|
||||
|
|
@ -89,10 +88,7 @@ class CookieSessionProvider extends SessionProvider {
|
|||
}
|
||||
|
||||
protected function postInitSetup() {
|
||||
// @codeCoverageIgnoreStart
|
||||
$this->params += [
|
||||
// @codeCoverageIgnoreEnd
|
||||
'callUserSetCookiesHook' => false,
|
||||
'sessionName' =>
|
||||
$this->getConfig()->get( MainConfigNames::SessionName )
|
||||
?: $this->getConfig()->get( MainConfigNames::CookiePrefix ) . '_session',
|
||||
|
|
@ -209,11 +205,6 @@ class CookieSessionProvider extends SessionProvider {
|
|||
$cookies = $this->cookieDataToExport( $user, $session->shouldRememberUser() );
|
||||
$sessionData = $this->sessionDataToExport( $user );
|
||||
|
||||
// Legacy hook
|
||||
if ( $this->params['callUserSetCookiesHook'] && !$user->isAnon() ) {
|
||||
$this->getHookRunner()->onUserSetCookies( $user, $sessionData, $cookies );
|
||||
}
|
||||
|
||||
$options = $this->cookieOptions;
|
||||
|
||||
$forceHTTPS = $session->shouldForceHTTPS() || $user->requiresHTTPS();
|
||||
|
|
@ -401,16 +392,6 @@ class CookieSessionProvider extends SessionProvider {
|
|||
* @return array
|
||||
*/
|
||||
protected function sessionDataToExport( $user ) {
|
||||
// If we're calling the legacy hook, we should populate $session
|
||||
// like User::setCookies() did.
|
||||
if ( !$user->isAnon() && $this->params['callUserSetCookiesHook'] ) {
|
||||
return [
|
||||
'wsUserID' => $user->getId(),
|
||||
'wsToken' => $user->getToken(),
|
||||
'wsUserName' => $user->getName(),
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Session\Hook;
|
||||
|
||||
use User;
|
||||
|
||||
/**
|
||||
* This is a hook handler interface, see docs/Hooks.md.
|
||||
* Use the hook name "UserSetCookies" to register handlers implementing this interface.
|
||||
*
|
||||
* @deprecated since 1.27 If you're trying to replace core session
|
||||
* cookie handling, you want to create a subclass of
|
||||
* MediaWiki\Session\CookieSessionProvider instead. Otherwise,
|
||||
* you can no longer count on user data being saved to cookies
|
||||
* versus some other mechanism.
|
||||
* @ingroup Hooks
|
||||
*/
|
||||
interface UserSetCookiesHook {
|
||||
/**
|
||||
* This hook is called when setting user cookies.
|
||||
*
|
||||
* @since 1.35
|
||||
*
|
||||
* @param User $user
|
||||
* @param array &$session Session array, will be added to the session
|
||||
* @param string[] &$cookies Cookies array mapping cookie name to its value
|
||||
* @return bool|void True or no return value to continue or false to abort
|
||||
*/
|
||||
public function onUserSetCookies( $user, &$session, &$cookies );
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\User\Hook;
|
||||
|
||||
use stdClass;
|
||||
use User;
|
||||
|
||||
/**
|
||||
* This is a hook handler interface, see docs/Hooks.md.
|
||||
* Use the hook name "UserLoadFromDatabase" to register handlers implementing this interface.
|
||||
*
|
||||
* @deprecated since 1.37
|
||||
* @ingroup Hooks
|
||||
*/
|
||||
interface UserLoadFromDatabaseHook {
|
||||
/**
|
||||
* This hook is called when loading a user from the database.
|
||||
*
|
||||
* @since 1.35
|
||||
*
|
||||
* @param User $user
|
||||
* @param stdClass|bool &$s Database query object
|
||||
* @return bool|void True or no return value to continue or false to abort
|
||||
*/
|
||||
public function onUserLoadFromDatabase( $user, &$s );
|
||||
}
|
||||
|
|
@ -1151,9 +1151,6 @@ class User implements Authority, UserIdentity, UserEmailContact {
|
|||
|
||||
$this->queryFlagsUsed = $flags;
|
||||
|
||||
// hook is hard deprecated since 1.37
|
||||
$this->getHookRunner()->onUserLoadFromDatabase( $this, $s );
|
||||
|
||||
if ( $s !== false ) {
|
||||
// Initialise user table data
|
||||
$this->loadFromRow( $s );
|
||||
|
|
|
|||
|
|
@ -97,7 +97,6 @@ class TestSetup {
|
|||
'class' => MediaWiki\Session\CookieSessionProvider::class,
|
||||
'args' => [ [
|
||||
'priority' => 30,
|
||||
'callUserSetCookiesHook' => true,
|
||||
] ],
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -107,7 +107,6 @@ class CookieSessionProviderTest extends MediaWikiIntegrationTestCase {
|
|||
$this->initProvider( $provider, new TestLogger(), $config );
|
||||
$this->assertSame( 1, $providerPriv->priority );
|
||||
$this->assertEquals( [
|
||||
'callUserSetCookiesHook' => false,
|
||||
'sessionName' => 'CookiePrefix_session',
|
||||
], $providerPriv->params );
|
||||
$this->assertEquals( [
|
||||
|
|
@ -125,7 +124,6 @@ class CookieSessionProviderTest extends MediaWikiIntegrationTestCase {
|
|||
$this->initProvider( $provider, new TestLogger(), $config );
|
||||
$this->assertEquals( 3, $providerPriv->priority );
|
||||
$this->assertEquals( [
|
||||
'callUserSetCookiesHook' => false,
|
||||
'sessionName' => 'SessionName',
|
||||
], $providerPriv->params );
|
||||
$this->assertEquals( [
|
||||
|
|
@ -139,7 +137,6 @@ class CookieSessionProviderTest extends MediaWikiIntegrationTestCase {
|
|||
|
||||
$provider = new CookieSessionProvider( [
|
||||
'priority' => 10,
|
||||
'callUserSetCookiesHook' => true,
|
||||
'cookieOptions' => [
|
||||
'prefix' => 'XPrefix',
|
||||
'path' => 'XPath',
|
||||
|
|
@ -154,7 +151,6 @@ class CookieSessionProviderTest extends MediaWikiIntegrationTestCase {
|
|||
$this->initProvider( $provider, new TestLogger(), $config );
|
||||
$this->assertEquals( 10, $providerPriv->priority );
|
||||
$this->assertEquals( [
|
||||
'callUserSetCookiesHook' => true,
|
||||
'sessionName' => 'XSession',
|
||||
], $providerPriv->params );
|
||||
$this->assertEquals( [
|
||||
|
|
@ -200,13 +196,6 @@ class CookieSessionProviderTest extends MediaWikiIntegrationTestCase {
|
|||
$id = $user->getId();
|
||||
$name = $user->getName();
|
||||
$token = $user->getToken( true );
|
||||
|
||||
$this->hideDeprecated(
|
||||
'UserSetCookies hook (used in '
|
||||
. get_class( $this->getMockBuilder( __CLASS__ ) )
|
||||
. '::onUserSetCookies)'
|
||||
);
|
||||
|
||||
$sessionId = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
|
||||
|
||||
// No data
|
||||
|
|
@ -421,7 +410,6 @@ class CookieSessionProviderTest extends MediaWikiIntegrationTestCase {
|
|||
$provider = new CookieSessionProvider( [
|
||||
'priority' => 1,
|
||||
'sessionName' => 'MySessionName',
|
||||
'callUserSetCookiesHook' => false,
|
||||
'cookieOptions' => [ 'prefix' => 'x' ],
|
||||
] );
|
||||
$config = $this->getConfig();
|
||||
|
|
@ -453,12 +441,6 @@ class CookieSessionProviderTest extends MediaWikiIntegrationTestCase {
|
|||
);
|
||||
TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = false;
|
||||
|
||||
$mock = $this->getMockBuilder( \stdClass::class )
|
||||
->addMethods( [ 'onUserSetCookies' ] )
|
||||
->getMock();
|
||||
$mock->expects( $this->never() )->method( 'onUserSetCookies' );
|
||||
$this->mergeMwGlobalArrayValue( 'wgHooks', [ 'UserSetCookies' => [ $mock ] ] );
|
||||
|
||||
// Anonymous user
|
||||
$backend->setUser( $anon );
|
||||
$backend->setRememberUser( true );
|
||||
|
|
@ -527,7 +509,6 @@ class CookieSessionProviderTest extends MediaWikiIntegrationTestCase {
|
|||
$provider = new CookieSessionProvider( [
|
||||
'priority' => 1,
|
||||
'sessionName' => 'MySessionName',
|
||||
'callUserSetCookiesHook' => false,
|
||||
'cookieOptions' => [ 'prefix' => 'x' ],
|
||||
] );
|
||||
$config = $this->getConfig();
|
||||
|
|
@ -631,150 +612,6 @@ class CookieSessionProviderTest extends MediaWikiIntegrationTestCase {
|
|||
return $sentRequest;
|
||||
}
|
||||
|
||||
public function testPersistSessionWithHook() {
|
||||
$hookContainer = $this->getHookContainer();
|
||||
$provider = new CookieSessionProvider( [
|
||||
'priority' => 1,
|
||||
'sessionName' => 'MySessionName',
|
||||
'callUserSetCookiesHook' => true,
|
||||
'cookieOptions' => [ 'prefix' => 'x' ],
|
||||
] );
|
||||
$this->initProvider( $provider, null, $this->getConfig(), SessionManager::singleton(), $hookContainer );
|
||||
|
||||
// For User::requiresHTTPS
|
||||
$this->overrideConfigValue( MainConfigNames::ForceHTTPS, false );
|
||||
|
||||
$sessionId = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
|
||||
$store = new TestBagOStuff();
|
||||
$user = static::getTestSysop()->getUser();
|
||||
$anon = new User;
|
||||
|
||||
$backend = new SessionBackend(
|
||||
new SessionId( $sessionId ),
|
||||
new SessionInfo( SessionInfo::MIN_PRIORITY, [
|
||||
'provider' => $provider,
|
||||
'id' => $sessionId,
|
||||
'persisted' => true,
|
||||
'idIsSafe' => true,
|
||||
] ),
|
||||
$store,
|
||||
new NullLogger(),
|
||||
$hookContainer,
|
||||
10
|
||||
);
|
||||
TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = false;
|
||||
|
||||
// Anonymous user
|
||||
$mock = $this->getMockBuilder( \stdClass::class )
|
||||
->addMethods( [ 'onUserSetCookies' ] )->getMock();
|
||||
$mock->expects( $this->never() )->method( 'onUserSetCookies' );
|
||||
$this->mergeMwGlobalArrayValue( 'wgHooks', [ 'UserSetCookies' => [ $mock ] ] );
|
||||
$backend->setUser( $anon );
|
||||
$backend->setRememberUser( true );
|
||||
$backend->setForceHTTPS( false );
|
||||
$request = new \MediaWiki\Request\FauxRequest();
|
||||
$provider->persistSession( $backend, $request );
|
||||
$this->assertSame( $sessionId, $request->response()->getCookie( 'MySessionName' ) );
|
||||
$this->assertSame( '', $request->response()->getCookie( 'xUserID' ) );
|
||||
$this->assertSame( null, $request->response()->getCookie( 'xUserName' ) );
|
||||
$this->assertSame( '', $request->response()->getCookie( 'xToken' ) );
|
||||
$this->assertSame( '', $request->response()->getCookie( 'forceHTTPS' ) );
|
||||
$this->assertSame( [], $backend->getData() );
|
||||
|
||||
$provider->persistSession( $backend, $this->getSentRequest() );
|
||||
|
||||
// Logged-in user, no remember
|
||||
$mock = $this->getMockBuilder( __CLASS__ )
|
||||
->onlyMethods( [ 'onUserSetCookies' ] )->getMock();
|
||||
$mock->expects( $this->once() )->method( 'onUserSetCookies' )
|
||||
->willReturnCallback( function ( $u, &$sessionData, &$cookies ) use ( $user ) {
|
||||
$this->assertSame( $user, $u );
|
||||
$this->assertEquals( [
|
||||
'wsUserID' => $user->getId(),
|
||||
'wsUserName' => $user->getName(),
|
||||
'wsToken' => $user->getToken(),
|
||||
], $sessionData );
|
||||
$this->assertEquals( [
|
||||
'UserID' => $user->getId(),
|
||||
'UserName' => $user->getName(),
|
||||
'Token' => false,
|
||||
], $cookies );
|
||||
|
||||
$sessionData['foo'] = 'foo!';
|
||||
$cookies['bar'] = 'bar!';
|
||||
return true;
|
||||
} );
|
||||
$this->mergeMwGlobalArrayValue( 'wgHooks', [ 'UserSetCookies' => [ $mock ] ] );
|
||||
$backend->setUser( $user );
|
||||
$backend->setRememberUser( false );
|
||||
$backend->setForceHTTPS( false );
|
||||
$backend->setLoggedOutTimestamp( $loggedOut = time() );
|
||||
$request = new \MediaWiki\Request\FauxRequest();
|
||||
|
||||
$this->hideDeprecated( 'UserSetCookies hook (used in onUserSetCookies)' );
|
||||
|
||||
$provider->persistSession( $backend, $request );
|
||||
$this->assertSame( $sessionId, $request->response()->getCookie( 'MySessionName' ) );
|
||||
$this->assertSame( (string)$user->getId(), $request->response()->getCookie( 'xUserID' ) );
|
||||
$this->assertSame( $user->getName(), $request->response()->getCookie( 'xUserName' ) );
|
||||
$this->assertSame( '', $request->response()->getCookie( 'xToken' ) );
|
||||
$this->assertSame( '', $request->response()->getCookie( 'forceHTTPS' ) );
|
||||
$this->assertSame( 'bar!', $request->response()->getCookie( 'xbar' ) );
|
||||
$this->assertSame( (string)$loggedOut, $request->response()->getCookie( 'xLoggedOut' ) );
|
||||
$this->assertEquals( [
|
||||
'wsUserID' => $user->getId(),
|
||||
'wsUserName' => $user->getName(),
|
||||
'wsToken' => $user->getToken(),
|
||||
'foo' => 'foo!',
|
||||
], $backend->getData() );
|
||||
|
||||
$provider->persistSession( $backend, $this->getSentRequest() );
|
||||
|
||||
// Logged-in user, remember
|
||||
$mock = $this->getMockBuilder( __CLASS__ )
|
||||
->onlyMethods( [ 'onUserSetCookies' ] )->getMock();
|
||||
$mock->expects( $this->once() )->method( 'onUserSetCookies' )
|
||||
->willReturnCallback( function ( $u, &$sessionData, &$cookies ) use ( $user ) {
|
||||
$this->assertSame( $user, $u );
|
||||
$this->assertEquals( [
|
||||
'wsUserID' => $user->getId(),
|
||||
'wsUserName' => $user->getName(),
|
||||
'wsToken' => $user->getToken(),
|
||||
], $sessionData );
|
||||
$this->assertEquals( [
|
||||
'UserID' => $user->getId(),
|
||||
'UserName' => $user->getName(),
|
||||
'Token' => $user->getToken(),
|
||||
], $cookies );
|
||||
|
||||
$sessionData['foo'] = 'foo 2!';
|
||||
$cookies['bar'] = 'bar 2!';
|
||||
return true;
|
||||
} );
|
||||
$this->mergeMwGlobalArrayValue( 'wgHooks', [ 'UserSetCookies' => [ $mock ] ] );
|
||||
$backend->setUser( $user );
|
||||
$backend->setRememberUser( true );
|
||||
$backend->setForceHTTPS( true );
|
||||
$backend->setLoggedOutTimestamp( 0 );
|
||||
$request = new \MediaWiki\Request\FauxRequest();
|
||||
$provider->persistSession( $backend, $request );
|
||||
$this->assertSame( $sessionId, $request->response()->getCookie( 'MySessionName' ) );
|
||||
$this->assertSame( (string)$user->getId(), $request->response()->getCookie( 'xUserID' ) );
|
||||
$this->assertSame( $user->getName(), $request->response()->getCookie( 'xUserName' ) );
|
||||
$this->assertSame( $user->getToken(), $request->response()->getCookie( 'xToken' ) );
|
||||
$this->assertSame( 'true', $request->response()->getCookie( 'forceHTTPS' ) );
|
||||
$this->assertSame( 'bar 2!', $request->response()->getCookie( 'xbar' ) );
|
||||
$this->assertSame( null, $request->response()->getCookie( 'xLoggedOut' ) );
|
||||
$this->assertEquals( [
|
||||
'wsUserID' => $user->getId(),
|
||||
'wsUserName' => $user->getName(),
|
||||
'wsToken' => $user->getToken(),
|
||||
'foo' => 'foo 2!',
|
||||
], $backend->getData() );
|
||||
|
||||
$provider->persistSession( $backend, $this->getSentRequest() );
|
||||
}
|
||||
|
||||
public function testUnpersistSession() {
|
||||
$provider = new CookieSessionProvider( [
|
||||
'priority' => 1,
|
||||
|
|
@ -829,16 +666,6 @@ class CookieSessionProviderTest extends MediaWikiIntegrationTestCase {
|
|||
$this->assertSame( null, $request->response()->getCookie( 'xLoggedOut' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* To be mocked for hooks, since PHPUnit can't otherwise mock methods that
|
||||
* take references.
|
||||
* @param User $user
|
||||
* @param array &$sessionData
|
||||
* @param string[] &$cookies
|
||||
*/
|
||||
public function onUserSetCookies( $user, &$sessionData, &$cookies ) {
|
||||
}
|
||||
|
||||
public function testGetCookie() {
|
||||
$provider = new CookieSessionProvider( [
|
||||
'priority' => 1,
|
||||
|
|
|
|||
Loading…
Reference in a new issue