MediaWiki master
MediaWiki\Utils\MWRestrictions Class Reference

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

Inherits Stringable.

Collaboration diagram for MediaWiki\Utils\MWRestrictions:

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.
 userCan (LinkTarget $target)
 Test whether an action on the target is allowed by the restrictions.

Static Public Member Functions

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

Public Attributes

StatusValue $validity

Protected Member Functions

 __construct (?array $restrictions=null)

Detailed Description

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

Definition at line 25 of file MWRestrictions.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Utils\MWRestrictions::__construct ( ?array $restrictions = null)
protected
Parameters
array | null$restrictions
Exceptions
InvalidArgumentException

Definition at line 39 of file MWRestrictions.php.

Member Function Documentation

◆ __toString()

MediaWiki\Utils\MWRestrictions::__toString ( )

Definition at line 130 of file MWRestrictions.php.

References toJson().

◆ check()

MediaWiki\Utils\MWRestrictions::check ( WebRequest $request)

Test against the passed WebRequest.

Parameters
WebRequest$request
Returns
Status

Definition at line 139 of file MWRestrictions.php.

References $request, and checkIP().

◆ checkIP()

MediaWiki\Utils\MWRestrictions::checkIP ( $ip)

Test if an IP address is allowed by the restrictions.

Parameters
string$ip
Returns
bool

Definition at line 167 of file MWRestrictions.php.

Referenced by check().

◆ newDefault()

MediaWiki\Utils\MWRestrictions::newDefault ( )
static
Returns
MWRestrictions

Definition at line 49 of file MWRestrictions.php.

Referenced by MediaWiki\HTMLForm\Field\HTMLRestrictionsField\getDefault().

◆ newFromArray()

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

Definition at line 58 of file MWRestrictions.php.

Referenced by MediaWiki\HTMLForm\Field\HTMLRestrictionsField\loadDataFromRequest().

◆ newFromJson()

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

Definition at line 67 of file MWRestrictions.php.

◆ toArray()

MediaWiki\Utils\MWRestrictions::toArray ( )

Return the restrictions as an array.

Returns
array

Definition at line 113 of file MWRestrictions.php.

Referenced by toJson().

◆ toJson()

MediaWiki\Utils\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 126 of file MWRestrictions.php.

References toArray().

Referenced by __toString().

◆ userCan()

MediaWiki\Utils\MWRestrictions::userCan ( LinkTarget $target)

Test whether an action on the target is allowed by the restrictions.

Access: internal
Parameters
LinkTarget$target
Returns
StatusValue

Definition at line 155 of file MWRestrictions.php.

Member Data Documentation

◆ $validity

StatusValue MediaWiki\Utils\MWRestrictions::$validity

Definition at line 33 of file MWRestrictions.php.


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