MediaWiki  master
TitleValue.php
Go to the documentation of this file.
1 <?php
26 
36 class TitleValue implements LinkTarget {
37 
42  protected $namespace;
43 
48  protected $dbkey;
49 
54  protected $fragment;
55 
60  protected $interwiki;
61 
70  public $prefixedText = null;
71 
89  public function __construct( $namespace, $dbkey, $fragment = '', $interwiki = '' ) {
90  if ( !is_int( $namespace ) ) {
91  throw new ParameterTypeException( '$namespace', 'int' );
92  }
93  if ( !is_string( $dbkey ) ) {
94  throw new ParameterTypeException( '$dbkey', 'string' );
95  }
96  if ( !is_string( $fragment ) ) {
97  throw new ParameterTypeException( '$fragment', 'string' );
98  }
99  if ( !is_string( $interwiki ) ) {
100  throw new ParameterTypeException( '$interwiki', 'string' );
101  }
102 
103  // Sanity check, no full validation or normalization applied here!
104  Assert::parameter( !preg_match( '/^_|[ \r\n\t]|_$/', $dbkey ), '$dbkey',
105  "invalid DB key '$dbkey'" );
106  Assert::parameter( $dbkey !== '' || ( $fragment !== '' && $namespace === NS_MAIN ),
107  '$dbkey', 'should not be empty unless namespace is main and fragment is non-empty' );
108 
109  $this->namespace = $namespace;
110  $this->dbkey = $dbkey;
111  $this->fragment = $fragment;
112  $this->interwiki = $interwiki;
113  }
114 
119  public function getNamespace() {
120  return $this->namespace;
121  }
122 
128  public function inNamespace( $ns ) {
129  return $this->namespace == $ns;
130  }
131 
136  public function getFragment() {
137  return $this->fragment;
138  }
139 
144  public function hasFragment() {
145  return $this->fragment !== '';
146  }
147 
155  public function getDBkey() {
156  return $this->dbkey;
157  }
158 
171  public function getText() {
172  return str_replace( '_', ' ', $this->dbkey );
173  }
174 
183  public function createFragmentTarget( $fragment ) {
184  return new TitleValue(
185  $this->namespace,
186  $this->dbkey,
187  $fragment,
188  $this->interwiki
189  );
190  }
191 
198  public function isExternal() {
199  return $this->interwiki !== '';
200  }
201 
208  public function getInterwiki() {
209  return $this->interwiki;
210  }
211 
220  public function __toString() {
221  $name = $this->namespace . ':' . $this->dbkey;
222 
223  if ( $this->fragment !== '' ) {
224  $name .= '#' . $this->fragment;
225  }
226 
227  if ( $this->interwiki !== '' ) {
228  $name = $this->interwiki . ':' . $name;
229  }
230 
231  return $name;
232  }
233 }
getText()
Returns the title in text form, without namespace prefix or fragment.
Definition: TitleValue.php:171
getInterwiki()
Returns the interwiki part.
Definition: TitleValue.php:208
const NS_MAIN
Definition: Defines.php:60
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
string $dbkey
Definition: TitleValue.php:48
__toString()
Returns a string representation of the title, for logging.
Definition: TitleValue.php:220
__construct( $namespace, $dbkey, $fragment='', $interwiki='')
Constructs a TitleValue.
Definition: TitleValue.php:89
inNamespace( $ns)
Definition: TitleValue.php:128
string $prefixedText
Text form including namespace/interwiki, initialised on demand.
Definition: TitleValue.php:70
int $namespace
Definition: TitleValue.php:42
isExternal()
Whether it has an interwiki part.
Definition: TitleValue.php:198
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
if(ini_get('mbstring.func_overload'))
Pre-config setup: Before loading LocalSettings.php.
Definition: Setup.php:51
string $interwiki
Definition: TitleValue.php:60
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
string $fragment
Definition: TitleValue.php:54
createFragmentTarget( $fragment)
Creates a new TitleValue for a different fragment of the same page.
Definition: TitleValue.php:183
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
getDBkey()
Returns the title&#39;s DB key, as supplied to the constructor, without namespace prefix or fragment...
Definition: TitleValue.php:155