MediaWiki  1.29.1
HTMLRestrictionsField.php
Go to the documentation of this file.
1 <?php
2 
14  const DEFAULT_ROWS = 5;
15 
16  public function __construct( array $params ) {
17  parent::__construct( $params );
18  if ( !$this->mLabel ) {
19  $this->mLabel = $this->msg( 'restrictionsfield-label' )->parse();
20  }
21  }
22 
23  public function getHelpText() {
24  $helpText = parent::getHelpText();
25  if ( $helpText === null ) {
26  $helpText = $this->msg( 'restrictionsfield-help' )->parse();
27  }
28  return $helpText;
29  }
30 
35  public function loadDataFromRequest( $request ) {
36  if ( !$request->getCheck( $this->mName ) ) {
37  return $this->getDefault();
38  }
39 
40  $value = rtrim( $request->getText( $this->mName ), "\r\n" );
41  $ips = $value === '' ? [] : explode( PHP_EOL, $value );
42  try {
43  return MWRestrictions::newFromArray( [ 'IPAddresses' => $ips ] );
44  } catch ( InvalidArgumentException $e ) {
45  return $value;
46  }
47  }
48 
52  public function getDefault() {
53  $default = parent::getDefault();
54  if ( $default === null ) {
55  $default = MWRestrictions::newDefault();
56  }
57  return $default;
58  }
59 
67  public function validate( $value, $alldata ) {
68  if ( $this->isHidden( $alldata ) ) {
69  return true;
70  }
71 
72  if (
73  isset( $this->mParams['required'] ) && $this->mParams['required'] !== false
74  && $value instanceof MWRestrictions && !$value->toArray()['IPAddresses']
75  ) {
76  return $this->msg( 'htmlform-required' );
77  }
78 
79  if ( is_string( $value ) ) {
80  // MWRestrictions::newFromArray failed; one of the IP ranges must be invalid
82  foreach ( explode( PHP_EOL, $value ) as $range ) {
83  if ( !\IP::isIPAddress( $range ) ) {
84  $status->fatal( 'restrictionsfield-badip', $range );
85  }
86  }
87  if ( $status->isOK() ) {
88  $status->fatal( 'unknown-error' );
89  }
90  return $status->getMessage();
91  }
92 
93  if ( isset( $this->mValidationCallback ) ) {
94  return call_user_func( $this->mValidationCallback, $value, $alldata, $this->mParent );
95  }
96 
97  return true;
98  }
99 
104  public function getInputHTML( $value ) {
105  if ( $value instanceof MWRestrictions ) {
106  $value = implode( PHP_EOL, $value->toArray()['IPAddresses'] );
107  }
108  return parent::getInputHTML( $value );
109  }
110 
115  public function getInputOOUI( $value ) {
116  if ( $value instanceof MWRestrictions ) {
117  $value = implode( PHP_EOL, $value->toArray()['IPAddresses'] );
118  }
119  return parent::getInputOOUI( $value );
120  }
121 }
MWRestrictions
A class to check request restrictions expressed as a JSON object.
Definition: MWRestrictions.php:24
$request
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2612
$status
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1049
HTMLRestrictionsField\getDefault
getDefault()
Definition: HTMLRestrictionsField.php:52
$params
$params
Definition: styleTest.css.php:40
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
HTMLRestrictionsField\DEFAULT_ROWS
const DEFAULT_ROWS
Definition: HTMLRestrictionsField.php:14
HTMLRestrictionsField\getHelpText
getHelpText()
Determine the help text to display.
Definition: HTMLRestrictionsField.php:23
HTMLRestrictionsField
Class for updating an MWRestrictions value (which is, currently, basically just an IP address list).
Definition: HTMLRestrictionsField.php:13
HTMLRestrictionsField\loadDataFromRequest
loadDataFromRequest( $request)
Definition: HTMLRestrictionsField.php:35
MWRestrictions\newDefault
static newDefault()
Definition: MWRestrictions.php:41
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2122
HTMLFormField\isHidden
isHidden( $alldata)
Test whether this field is supposed to be hidden, based on the values of the other form fields.
Definition: HTMLFormField.php:269
$value
$value
Definition: styleTest.css.php:45
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:76
HTMLRestrictionsField\getInputHTML
getInputHTML( $value)
Definition: HTMLRestrictionsField.php:104
HTMLFormField\msg
msg()
Get a translated interface message.
Definition: HTMLFormField.php:77
HTMLRestrictionsField\validate
validate( $value, $alldata)
Definition: HTMLRestrictionsField.php:67
MWRestrictions\newFromArray
static newFromArray(array $restrictions)
Definition: MWRestrictions.php:50
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
HTMLRestrictionsField\__construct
__construct(array $params)
Definition: HTMLRestrictionsField.php:16
IP\isIPAddress
static isIPAddress( $ip)
Determine if a string is as valid IP address or network (CIDR prefix).
Definition: IP.php:79
HTMLRestrictionsField\getInputOOUI
getInputOOUI( $value)
Definition: HTMLRestrictionsField.php:115
array
the array() calling protocol came about after MediaWiki 1.4rc1.
HTMLTextAreaField
Definition: HTMLTextAreaField.php:3