2020-01-17 06:21:28 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program 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.
|
|
|
|
|
*
|
|
|
|
|
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace MediaWiki\User;
|
|
|
|
|
|
2020-05-28 18:40:49 +00:00
|
|
|
use IDBAccessObject;
|
|
|
|
|
|
2020-01-17 06:21:28 +00:00
|
|
|
/**
|
|
|
|
|
* Provides access to user options
|
|
|
|
|
* @since 1.35
|
|
|
|
|
*/
|
2020-05-28 18:40:49 +00:00
|
|
|
abstract class UserOptionsLookup implements IDBAccessObject {
|
2020-01-17 06:21:28 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Exclude user options that are set to their default value.
|
|
|
|
|
*/
|
|
|
|
|
public const EXCLUDE_DEFAULTS = 1;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Combine the language default options with any site-specific options
|
|
|
|
|
* and add the default language variants.
|
|
|
|
|
*
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return array
|
2020-01-17 06:21:28 +00:00
|
|
|
*/
|
|
|
|
|
abstract public function getDefaultOptions(): array;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a given default option value.
|
|
|
|
|
*
|
|
|
|
|
* @param string $opt Name of option to retrieve
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return mixed|null Default option value
|
2020-01-17 06:21:28 +00:00
|
|
|
*/
|
2021-05-12 06:04:14 +00:00
|
|
|
public function getDefaultOption( string $opt ) {
|
|
|
|
|
$defaultOptions = $this->getDefaultOptions();
|
|
|
|
|
return $defaultOptions[$opt] ?? null;
|
|
|
|
|
}
|
2020-01-17 06:21:28 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the user's current setting for a given option.
|
|
|
|
|
*
|
|
|
|
|
* @param UserIdentity $user The user to get the option for
|
|
|
|
|
* @param string $oname The option to check
|
|
|
|
|
* @param mixed|null $defaultOverride A default value returned if the option does not exist
|
|
|
|
|
* @param bool $ignoreHidden Whether to ignore the effects of $wgHiddenPrefs
|
2020-05-28 18:40:49 +00:00
|
|
|
* @param int $queryFlags A bit field composed of READ_XXX flags
|
2020-01-17 06:21:28 +00:00
|
|
|
* @return mixed|null User's current value for the option
|
|
|
|
|
* @see getBoolOption()
|
|
|
|
|
* @see getIntOption()
|
|
|
|
|
*/
|
|
|
|
|
abstract public function getOption(
|
|
|
|
|
UserIdentity $user,
|
|
|
|
|
string $oname,
|
|
|
|
|
$defaultOverride = null,
|
2020-05-28 18:40:49 +00:00
|
|
|
bool $ignoreHidden = false,
|
|
|
|
|
int $queryFlags = self::READ_NORMAL
|
2020-01-17 06:21:28 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all user's options
|
|
|
|
|
*
|
|
|
|
|
* @param UserIdentity $user The user to get the option for
|
|
|
|
|
* @param int $flags Bitwise combination of:
|
|
|
|
|
* UserOptionsManager::EXCLUDE_DEFAULTS Exclude user options that are set
|
|
|
|
|
* to the default value.
|
2020-05-28 18:40:49 +00:00
|
|
|
* @param int $queryFlags A bit field composed of READ_XXX flags
|
2020-01-17 06:21:28 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
2020-05-28 18:40:49 +00:00
|
|
|
abstract public function getOptions(
|
|
|
|
|
UserIdentity $user,
|
|
|
|
|
int $flags = 0,
|
|
|
|
|
int $queryFlags = self::READ_NORMAL
|
|
|
|
|
): array;
|
2020-01-17 06:21:28 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the user's current setting for a given option, as a boolean value.
|
|
|
|
|
*
|
|
|
|
|
* @param UserIdentity $user The user to get the option for
|
|
|
|
|
* @param string $oname The option to check
|
2020-05-28 18:40:49 +00:00
|
|
|
* @param int $queryFlags A bit field composed of READ_XXX flags
|
2020-01-17 06:21:28 +00:00
|
|
|
* @return bool User's current value for the option
|
|
|
|
|
* @see getOption()
|
|
|
|
|
*/
|
2020-05-28 18:40:49 +00:00
|
|
|
public function getBoolOption(
|
|
|
|
|
UserIdentity $user,
|
|
|
|
|
string $oname,
|
|
|
|
|
int $queryFlags = self::READ_NORMAL
|
|
|
|
|
): bool {
|
|
|
|
|
return (bool)$this->getOption(
|
|
|
|
|
$user, $oname, null, false, $queryFlags );
|
2020-01-17 06:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the user's current setting for a given option, as an integer value.
|
|
|
|
|
*
|
|
|
|
|
* @param UserIdentity $user The user to get the option for
|
|
|
|
|
* @param string $oname The option to check
|
|
|
|
|
* @param int $defaultOverride A default value returned if the option does not exist
|
2020-05-28 18:40:49 +00:00
|
|
|
* @param int $queryFlags A bit field composed of READ_XXX flags
|
2020-01-17 06:21:28 +00:00
|
|
|
* @return int User's current value for the option
|
|
|
|
|
* @see getOption()
|
|
|
|
|
*/
|
2020-05-28 18:40:49 +00:00
|
|
|
public function getIntOption(
|
|
|
|
|
UserIdentity $user,
|
|
|
|
|
string $oname,
|
|
|
|
|
int $defaultOverride = 0,
|
|
|
|
|
int $queryFlags = self::READ_NORMAL
|
|
|
|
|
): int {
|
|
|
|
|
$val = $this->getOption(
|
|
|
|
|
$user, $oname, $defaultOverride, false, $queryFlags );
|
2020-01-17 06:21:28 +00:00
|
|
|
if ( $val == '' ) {
|
|
|
|
|
$val = $defaultOverride;
|
|
|
|
|
}
|
|
|
|
|
return intval( $val );
|
|
|
|
|
}
|
|
|
|
|
}
|