mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-24 15:44:09 +00:00
7ca5d1fc9b
This does make generic `array` type hints more specific when possible. I'm also applying my personal best practice to not have any @return documentation on test @dataProviders. These don't provide any useful information, and can't. The best type we could use is `@return array[]`, but that would be the same for every single data provider. Copy pasting these comments around is of no real value. Also it was already inconsistent as some did not had this comment. Change-Id: Id401c7e32493b6a9faaf6d47cddc01e2227102af
89 lines
2.5 KiB
PHP
89 lines
2.5 KiB
PHP
<?php
|
|
/*
|
|
* This file is part of the MediaWiki extension Popups.
|
|
*
|
|
* Popups is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Popups is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with Popups. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* @file
|
|
* @ingroup extensions
|
|
*/
|
|
namespace Popups;
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
use User;
|
|
use HTMLForm;
|
|
|
|
/**
|
|
* User Preferences save change listener
|
|
*
|
|
* @package Popups
|
|
*/
|
|
class UserPreferencesChangeHandler {
|
|
/**
|
|
* @var PopupsContext
|
|
*/
|
|
private $popupsContext;
|
|
|
|
/**
|
|
* @param PopupsContext $context Popups context instance
|
|
*/
|
|
public function __construct( $context ) {
|
|
$this->popupsContext = $context;
|
|
}
|
|
|
|
/**
|
|
* Hook executed on Preferences Form Save, when user disables Page Previews call PopupsContext
|
|
* to log `disabled` event.
|
|
*
|
|
* @param User $user Logged-in user
|
|
* @param array $oldUserOptions Old user options array
|
|
*/
|
|
public function doPreferencesFormPreSave( User $user, array $oldUserOptions ) {
|
|
if ( !array_key_exists( PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME, $oldUserOptions ) ) {
|
|
return;
|
|
}
|
|
$oldSetting = $oldUserOptions[ PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME ];
|
|
$newSetting = $user->getOption( PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME );
|
|
|
|
if ( $oldSetting == PopupsContext::PREVIEWS_ENABLED
|
|
&& $newSetting == PopupsContext::PREVIEWS_DISABLED ) {
|
|
$this->popupsContext->logUserDisabledPagePreviewsEvent();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return UserPreferencesChangeHandler
|
|
*/
|
|
private static function newFromGlobalState() {
|
|
return MediaWikiServices::getInstance()->getService( 'Popups.UserPreferencesChangeHandler' );
|
|
}
|
|
|
|
/**
|
|
* @param array $formData Form data submitted by user
|
|
* @param HTMLForm $form A preferences form
|
|
* @param User $user Logged-in user
|
|
* @param bool &$result Variable defining is form save successful
|
|
* @param array $oldUserOptions Old user options array
|
|
*/
|
|
public static function onPreferencesFormPreSave(
|
|
array $formData,
|
|
HTMLForm $form,
|
|
User $user,
|
|
&$result,
|
|
$oldUserOptions
|
|
) {
|
|
self::newFromGlobalState()->doPreferencesFormPreSave( $user, $oldUserOptions );
|
|
}
|
|
}
|