MediaWiki REL1_31
|
Helper class to keep track of options when mixing links and form elements. More...
Public Member Functions | |
ArrayAccess functions | |
These functions implement the ArrayAccess PHP interface. | |
offsetExists ( $name) | |
Whether the option exists. | |
offsetGet ( $name) | |
Retrieve an option value. | |
offsetSet ( $name, $value) | |
Set an option to given value. | |
offsetUnset ( $name) | |
Delete the option. | |
Type constants | |
Used internally to map an option value to a WebRequest accessor | |
const | AUTO = -1 |
Mark value for automatic detection (for simple data types only) | |
const | STRING = 0 |
String type, maps guessType() to WebRequest::getText() | |
const | INT = 1 |
Integer type, maps guessType() to WebRequest::getInt() | |
const | FLOAT = 4 |
Float type, maps guessType() to WebRequest::getFloat() | |
const | BOOL = 2 |
Boolean type, maps guessType() to WebRequest::getBool() | |
const | INTNULL = 3 |
Integer type or null, maps to WebRequest::getIntOrNull() This is useful for the namespace selector. | |
const | ARR = 5 |
Array type, maps guessType() to WebRequest::getArray() | |
$options = [] | |
Map of known option names to information about them. | |
add ( $name, $default, $type=self::AUTO) | |
Add an option to be handled by this FormOptions instance. | |
delete ( $name) | |
Remove an option being handled by this FormOptions instance. | |
validateName ( $name, $strict=false) | |
Verify that the given option name exists. | |
setValue ( $name, $value, $force=false) | |
Use to set the value of an option. | |
getValue ( $name) | |
Get the value for the given option name. | |
reset ( $name) | |
Delete the option value. | |
consumeValue ( $name) | |
Get the value of given option and mark it as 'consumed'. | |
consumeValues ( $names) | |
Get the values of given options and mark them as 'consumed'. | |
validateIntBounds ( $name, $min, $max) | |
validateBounds ( $name, $min, $max) | |
Constrain a numeric value for a given option to a given range. | |
getUnconsumedValues ( $all=false) | |
Get all remaining values which have not been consumed by consumeValue() or consumeValues(). | |
getChangedValues () | |
Return options modified as an array ( name => value ) | |
getAllValues () | |
Format options to an array ( name => value ) | |
fetchValuesFromRequest (WebRequest $r, $optionKeys=null) | |
Fetch values for all options (or selected options) from the given WebRequest, making them available for accessing with getValue() or consumeValue() etc. | |
static | guessType ( $data) |
Used to find out which type the data is. | |
getValueReal ( $option) | |
Return current option value, based on a structure taken from $options. | |
Helper class to keep track of options when mixing links and form elements.
Definition at line 35 of file FormOptions.php.
FormOptions::add | ( | $name, | |
$default, | |||
$type = self::AUTO ) |
Add an option to be handled by this FormOptions instance.
string | $name | Request parameter name |
mixed | $default | Default value when the request parameter is not present |
int | $type | One of the type constants (optional, defaults to AUTO) |
Definition at line 81 of file FormOptions.php.
References $name, $type, guessType(), and options().
Referenced by ChangesListBooleanFilterGroup\addOptions(), ChangesListStringOptionsFilterGroup\addOptions(), SpecialLog\execute(), SpecialNewFiles\execute(), SpecialWhatLinksHere\execute(), SpecialNewpages\setup(), and FormOptionsTest\setUp().
FormOptions::consumeValue | ( | $name | ) |
Get the value of given option and mark it as 'consumed'.
Consumed options are not returned by getUnconsumedValues().
MWException | If the option does not exist |
string | $name | Option name |
Definition at line 219 of file FormOptions.php.
References $name, getValueReal(), options(), and validateName().
FormOptions::consumeValues | ( | $names | ) |
Get the values of given options and mark them as 'consumed'.
Consumed options are not returned by getUnconsumedValues().
MWException | If any option does not exist |
array | $names | Array of option names as strings |
Definition at line 235 of file FormOptions.php.
References $name, $out, getValueReal(), options(), and validateName().
FormOptions::delete | ( | $name | ) |
Remove an option being handled by this FormOptions instance.
This is the inverse of add().
string | $name | Request parameter name |
Definition at line 101 of file FormOptions.php.
References options(), and validateName().
FormOptions::fetchValuesFromRequest | ( | WebRequest | $r, |
$optionKeys = null ) |
Fetch values for all options (or selected options) from the given WebRequest, making them available for accessing with getValue() or consumeValue() etc.
WebRequest | $r | The request to fetch values from |
array | $optionKeys | Which options to fetch the values for (default: all of them). Note that passing an empty array will also result in values for all keys being fetched. |
MWException | If the type of any option is invalid |
Definition at line 344 of file FormOptions.php.
References $name, $type, $value, ARR, BOOL, FLOAT, WebRequest\getArray(), WebRequest\getBool(), WebRequest\getFloat(), WebRequest\getInt(), WebRequest\getIntOrNull(), WebRequest\getText(), INT, INTNULL, options(), and STRING.
Referenced by SpecialNewFiles\execute(), SpecialWhatLinksHere\execute(), and SpecialNewpages\setup().
FormOptions::getAllValues | ( | ) |
Format options to an array ( name => value )
Definition at line 322 of file FormOptions.php.
References $name, getValueReal(), and options().
FormOptions::getChangedValues | ( | ) |
Return options modified as an array ( name => value )
Definition at line 306 of file FormOptions.php.
References $name, and options().
Referenced by SpecialWatchlist\setTopText(), and ChangesListSpecialPage\validateOptions().
FormOptions::getUnconsumedValues | ( | $all = false | ) |
Get all remaining values which have not been consumed by consumeValue() or consumeValues().
bool | $all | Whether to include unchanged options (default: false) |
Definition at line 288 of file FormOptions.php.
References $name, getValueReal(), and options().
FormOptions::getValue | ( | $name | ) |
Get the value for the given option name.
Uses getValueReal() internally.
string | $name | Option name |
Definition at line 180 of file FormOptions.php.
References getValueReal(), options(), and validateName().
Referenced by NewFilesPager\__construct(), ActiveUsersPager\__construct(), SpecialNewFiles\execute(), SpecialWhatLinksHere\execute(), NewFilesPager\getQueryInfo(), offsetGet(), and SpecialLog\show().
|
protected |
Return current option value, based on a structure taken from $options.
array | $option | Array structure describing the option |
Definition at line 192 of file FormOptions.php.
Referenced by consumeValue(), consumeValues(), getAllValues(), getUnconsumedValues(), getValue(), and validateBounds().
|
static |
Used to find out which type the data is.
All types are defined in the 'Type constants' section of this class.
Detection of the INTNULL type is not supported; INT will be assumed if the data is an integer, MWException will be thrown if it's null.
mixed | $data | Value to guess the type for |
MWException | If unable to guess the type |
Definition at line 117 of file FormOptions.php.
References ARR, BOOL, FLOAT, INT, and STRING.
Referenced by add(), FormOptionsTest\guess(), and AbstractChangesListSpecialPageTestCase\testParseParameters().
FormOptions::offsetExists | ( | $name | ) |
Whether the option exists.
string | $name |
Definition at line 392 of file FormOptions.php.
References options().
FormOptions::offsetGet | ( | $name | ) |
Retrieve an option value.
string | $name |
Definition at line 401 of file FormOptions.php.
References getValue().
FormOptions::offsetSet | ( | $name, | |
$value ) |
Set an option to given value.
string | $name | |
mixed | $value |
Definition at line 410 of file FormOptions.php.
References $value, and setValue().
FormOptions::offsetUnset | ( | $name | ) |
Delete the option.
string | $name |
Definition at line 418 of file FormOptions.php.
References $name.
FormOptions::reset | ( | $name | ) |
Delete the option value.
This will make future calls to getValue() return the default value.
string | $name | Option name |
Definition at line 205 of file FormOptions.php.
References $name, options(), and validateName().
Referenced by ChangesListSpecialPage\buildQuery(), ChangesListSpecialPage\fixBackwardsCompatibilityOptions(), and ChangesListSpecialPage\replaceOldOptions().
FormOptions::setValue | ( | $name, | |
$value, | |||
$force = false ) |
Use to set the value of an option.
string | $name | Option name |
mixed | $value | Value for the option |
bool | $force | Whether to set the value when it is equivalent to the default value for this option (default false). |
Definition at line 163 of file FormOptions.php.
References $name, $value, options(), and validateName().
Referenced by SpecialNewFiles\execute(), SpecialWhatLinksHere\execute(), offsetSet(), SpecialLog\parseParams(), and validateBounds().
FormOptions::validateBounds | ( | $name, | |
$min, | |||
$max ) |
Constrain a numeric value for a given option to a given range.
The value will be altered to fit in the range.
string | $name | Option name |
int | float | $min | Minimum value |
int | float | $max | Maximum value |
MWException | If option is not of type INT |
Definition at line 268 of file FormOptions.php.
References $name, $type, $value, getValueReal(), options(), setValue(), and validateName().
Referenced by validateIntBounds(), and ChangesListSpecialPage\validateOptions().
FormOptions::validateIntBounds | ( | $name, | |
$min, | |||
$max ) |
string | $name | |
int | $min | |
int | $max |
Definition at line 253 of file FormOptions.php.
References validateBounds().
Referenced by SpecialNewFiles\execute(), SpecialWhatLinksHere\execute(), SpecialNewpages\setup(), and ChangesListSpecialPage\validateOptions().
FormOptions::validateName | ( | $name, | |
$strict = false ) |
Verify that the given option name exists.
string | $name | Option name |
bool | $strict | Throw an exception when the option doesn't exist instead of returning false |
MWException |
Definition at line 143 of file FormOptions.php.
References options().
Referenced by consumeValue(), consumeValues(), delete(), getValue(), reset(), setValue(), and validateBounds().
|
protected |
Map of known option names to information about them.
Each value is an array with the following keys:
Definition at line 70 of file FormOptions.php.
Referenced by FormOptionsExposed\getOptions().
const FormOptions::ARR = 5 |
Array type, maps guessType() to WebRequest::getArray()
Definition at line 57 of file FormOptions.php.
Referenced by FormOptionsTest\assertGuessArray(), fetchValuesFromRequest(), and guessType().
const FormOptions::AUTO = -1 |
Mark value for automatic detection (for simple data types only)
Definition at line 41 of file FormOptions.php.
const FormOptions::BOOL = 2 |
Boolean type, maps guessType() to WebRequest::getBool()
Definition at line 50 of file FormOptions.php.
Referenced by FormOptionsTest\assertGuessBoolean(), SpecialActiveUsers\execute(), fetchValuesFromRequest(), and guessType().
const FormOptions::FLOAT = 4 |
Float type, maps guessType() to WebRequest::getFloat()
Definition at line 48 of file FormOptions.php.
Referenced by FormOptionsTest\assertGuessFloat(), fetchValuesFromRequest(), ChangesListSpecialPage\getDefaultOptions(), and guessType().
const FormOptions::INT = 1 |
Integer type, maps guessType() to WebRequest::getInt()
Definition at line 45 of file FormOptions.php.
Referenced by FormOptionsTest\assertGuessInt(), fetchValuesFromRequest(), ChangesListSpecialPage\getDefaultOptions(), guessType(), and FormOptionsInitializationTest\testAddIntegers().
const FormOptions::INTNULL = 3 |
Integer type or null, maps to WebRequest::getIntOrNull() This is useful for the namespace selector.
Definition at line 54 of file FormOptions.php.
Referenced by SpecialLog\execute(), SpecialWhatLinksHere\execute(), fetchValuesFromRequest(), and FormOptionsTest\setUp().
const FormOptions::STRING = 0 |
String type, maps guessType() to WebRequest::getText()
Definition at line 43 of file FormOptions.php.
Referenced by FormOptionsTest\assertGuessString(), fetchValuesFromRequest(), ChangesListSpecialPage\getDefaultOptions(), guessType(), and FormOptionsInitializationTest\testAddStringOption().