2017-07-06 18:16:05 +00:00
|
|
|
<?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;
|
|
|
|
|
2017-07-21 17:06:08 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2017-07-06 18:16:05 +00:00
|
|
|
use User;
|
2018-05-25 16:48:41 +00:00
|
|
|
use HTMLForm;
|
2017-07-06 18:16:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* User Preferences save change listener
|
|
|
|
*
|
|
|
|
* @package Popups
|
|
|
|
*/
|
|
|
|
class UserPreferencesChangeHandler {
|
2019-02-26 10:55:57 +00:00
|
|
|
|
2017-07-06 18:16:05 +00:00
|
|
|
/**
|
|
|
|
* @var PopupsContext
|
|
|
|
*/
|
|
|
|
private $popupsContext;
|
|
|
|
|
|
|
|
/**
|
2017-07-12 20:16:55 +00:00
|
|
|
* @param PopupsContext $context Popups context instance
|
2017-07-06 18:16:05 +00:00
|
|
|
*/
|
2017-07-21 17:06:08 +00:00
|
|
|
public function __construct( $context ) {
|
2017-07-06 18:16:05 +00:00
|
|
|
$this->popupsContext = $context;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook executed on Preferences Form Save, when user disables Page Previews call PopupsContext
|
|
|
|
* to log `disabled` event.
|
|
|
|
*
|
2017-07-12 20:16:55 +00:00
|
|
|
* @param User $user Logged-in user
|
|
|
|
* @param array $oldUserOptions Old user options array
|
2017-07-06 18:16:05 +00:00
|
|
|
*/
|
|
|
|
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() {
|
2017-07-21 17:06:08 +00:00
|
|
|
return MediaWikiServices::getInstance()->getService( 'Popups.UserPreferencesChangeHandler' );
|
2017-07-06 18:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-07-12 20:16:55 +00:00
|
|
|
* @param array $formData Form data submitted by user
|
2018-05-25 16:48:41 +00:00
|
|
|
* @param HTMLForm $form A preferences form
|
2017-07-12 20:16:55 +00:00
|
|
|
* @param User $user Logged-in user
|
2017-08-10 11:23:37 +00:00
|
|
|
* @param bool &$result Variable defining is form save successful
|
2017-07-12 20:16:55 +00:00
|
|
|
* @param array $oldUserOptions Old user options array
|
2017-07-06 18:16:05 +00:00
|
|
|
*/
|
|
|
|
public static function onPreferencesFormPreSave(
|
|
|
|
array $formData,
|
2018-05-25 16:48:41 +00:00
|
|
|
HTMLForm $form,
|
2017-07-06 18:16:05 +00:00
|
|
|
User $user,
|
|
|
|
&$result,
|
2019-01-24 14:44:26 +00:00
|
|
|
$oldUserOptions
|
|
|
|
) {
|
2017-07-06 18:16:05 +00:00
|
|
|
self::newFromGlobalState()->doPreferencesFormPreSave( $user, $oldUserOptions );
|
|
|
|
}
|
2019-02-26 10:55:57 +00:00
|
|
|
|
2017-07-06 18:16:05 +00:00
|
|
|
}
|