MediaWiki REL1_31
MWRestrictions Class Reference

A class to check request restrictions expressed as a JSON object. More...

Public Member Functions

 __toString ()
 
 check (WebRequest $request)
 Test against the passed WebRequest.
 
 checkIP ( $ip)
 Test if an IP address is allowed by the restrictions.
 
 toArray ()
 Return the restrictions as an array.
 
 toJson ( $pretty=false)
 Return the restrictions as a JSON string.
 

Static Public Member Functions

static newDefault ()
 
static newFromArray (array $restrictions)
 
static newFromJson ( $json)
 

Protected Member Functions

 __construct (array $restrictions=null)
 

Private Member Functions

 loadFromArray (array $restrictions)
 

Private Attributes

 $ipAddresses = [ '0.0.0.0/0', '::/0' ]
 

Detailed Description

A class to check request restrictions expressed as a JSON object.

Definition at line 26 of file MWRestrictions.php.

Constructor & Destructor Documentation

◆ __construct()

MWRestrictions::__construct ( array $restrictions = null)
protected
Parameters
array$restrictions
Exceptions
InvalidArgumentException

Definition at line 34 of file MWRestrictions.php.

References loadFromArray().

Member Function Documentation

◆ __toString()

MWRestrictions::__toString ( )

Definition at line 117 of file MWRestrictions.php.

References toJson().

◆ check()

MWRestrictions::check ( WebRequest $request)

Test against the passed WebRequest.

Parameters
WebRequest$request
Returns
Status

Definition at line 126 of file MWRestrictions.php.

References checkIP(), and WebRequest\getIP().

◆ checkIP()

MWRestrictions::checkIP ( $ip)

Test if an IP address is allowed by the restrictions.

Parameters
string$ip
Returns
bool

Definition at line 140 of file MWRestrictions.php.

Referenced by check().

◆ loadFromArray()

MWRestrictions::loadFromArray ( array $restrictions)
private

Definition at line 69 of file MWRestrictions.php.

References $keys.

Referenced by __construct().

◆ newDefault()

◆ newFromArray()

static MWRestrictions::newFromArray ( array $restrictions)
static
Parameters
array$restrictions
Returns
MWRestrictions
Exceptions
InvalidArgumentException

Definition at line 52 of file MWRestrictions.php.

Referenced by HTMLRestrictionsField\loadDataFromRequest(), MWRestrictionsTest\setUpBeforeClass(), MWRestrictionsTest\testArray(), and BotPasswordTest\testSaveValidation().

◆ newFromJson()

static MWRestrictions::newFromJson ( $json)
static
Parameters
string$jsonJSON representation of the restrictions
Returns
MWRestrictions
Exceptions
InvalidArgumentException

Definition at line 61 of file MWRestrictions.php.

Referenced by BotPassword\__construct(), MWRestrictionsTest\testJson(), BotPasswordTest\testSave(), and BotPasswordTest\testUnsaved().

◆ toArray()

MWRestrictions::toArray ( )

Return the restrictions as an array.

Returns
array

Definition at line 102 of file MWRestrictions.php.

References $ipAddresses.

Referenced by toJson(), and HTMLRestrictionsField\validate().

◆ toJson()

MWRestrictions::toJson ( $pretty = false)

Return the restrictions as a JSON string.

Parameters
bool | string$prettyPretty-print the JSON output, see FormatJson::encode
Returns
string

Definition at line 113 of file MWRestrictions.php.

References toArray().

Referenced by __toString(), and BotPassword\save().

Member Data Documentation

◆ $ipAddresses

MWRestrictions::$ipAddresses = [ '0.0.0.0/0', '::/0' ]
private

Definition at line 28 of file MWRestrictions.php.

Referenced by toArray().


The documentation for this class was generated from the following file: