MediaWiki  master
DeprecationHelper.php
Go to the documentation of this file.
1 <?php
46 
55  protected $deprecatedPublicProperties = [];
56 
68  protected function deprecatePublicProperty(
69  $property, $version, $class = null, $component = null
70  ) {
71  $this->deprecatedPublicProperties[$property] = [ $version, $class ?: __CLASS__, $component ];
72  }
73 
74  public function __get( $name ) {
75  if ( isset( $this->deprecatedPublicProperties[$name] ) ) {
76  list( $version, $class, $component ) = $this->deprecatedPublicProperties[$name];
77  $qualifiedName = $class . '::$' . $name;
78  wfDeprecated( $qualifiedName, $version, $component, 3 );
79  return $this->$name;
80  }
81 
82  $qualifiedName = __CLASS__ . '::$' . $name;
83  if ( $this->deprecationHelperGetPropertyOwner( $name ) ) {
84  // Someone tried to access a normal non-public property. Try to behave like PHP would.
85  trigger_error( "Cannot access non-public property $qualifiedName", E_USER_ERROR );
86  } else {
87  // Non-existing property. Try to behave like PHP would.
88  trigger_error( "Undefined property: $qualifiedName", E_USER_NOTICE );
89  }
90  return null;
91  }
92 
93  public function __set( $name, $value ) {
94  if ( isset( $this->deprecatedPublicProperties[$name] ) ) {
95  list( $version, $class, $component ) = $this->deprecatedPublicProperties[$name];
96  $qualifiedName = $class . '::$' . $name;
97  wfDeprecated( $qualifiedName, $version, $component, 3 );
98  $this->$name = $value;
99  return;
100  }
101 
102  $qualifiedName = __CLASS__ . '::$' . $name;
103  if ( $this->deprecationHelperGetPropertyOwner( $name ) ) {
104  // Someone tried to access a normal non-public property. Try to behave like PHP would.
105  trigger_error( "Cannot access non-public property $qualifiedName", E_USER_ERROR );
106  } else {
107  // Non-existing property. Try to behave like PHP would.
108  $this->$name = $value;
109  }
110  }
111 
119  // Easy branch: check for protected property / private property of the current class.
120  if ( property_exists( $this, $property ) ) {
121  // The class name is not necessarily correct here but getting the correct class
122  // name would be expensive, this will work most of the time and getting it
123  // wrong is not a big deal.
124  return __CLASS__;
125  }
126  // property_exists() returns false when the property does exist but is private (and not
127  // defined by the current class, for some value of "current" that differs slightly
128  // between engines).
129  // Since PHP triggers an error on public access of non-public properties but happily
130  // allows public access to undefined properties, we need to detect this case as well.
131  // Reflection is slow so use array cast hack to check for that:
132  $obfuscatedProps = array_keys( (array)$this );
133  $obfuscatedPropTail = "\0$property";
134  foreach ( $obfuscatedProps as $obfuscatedProp ) {
135  // private props are in the form \0<classname>\0<propname>
136  if ( strpos( $obfuscatedProp, $obfuscatedPropTail, 1 ) !== false ) {
137  $classname = substr( $obfuscatedProp, 1, -strlen( $obfuscatedPropTail ) );
138  if ( $classname === '*' ) {
139  // sanity; this shouldn't be possible as protected properties were handled earlier
140  $classname = __CLASS__;
141  }
142  return $classname;
143  }
144  }
145  return false;
146  }
147 
148 }
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
$property
__get( $name)
$value
deprecationHelperGetPropertyOwner( $property)
Like property_exists but also check for non-visible private properties and returns which class in the...
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
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
deprecatePublicProperty( $property, $version, $class=null, $component=null)
Mark a property as deprecated.
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
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
__set( $name, $value)
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271