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 
88  public function __construct( $namespace, $title, $fragment = '', $interwiki = '' ) {
89  if ( !is_int( $namespace ) ) {
90  throw new ParameterTypeException( '$namespace', 'int' );
91  }
92  if ( !is_string( $title ) ) {
93  throw new ParameterTypeException( '$title', 'string' );
94  }
95  if ( !is_string( $fragment ) ) {
96  throw new ParameterTypeException( '$fragment', 'string' );
97  }
98  if ( !is_string( $interwiki ) ) {
99  throw new ParameterTypeException( '$interwiki', 'string' );
100  }
101 
102  // Sanity check, no full validation or normalization applied here!
103  Assert::parameter( !preg_match( '/^[_ ]|[\r\n\t]|[_ ]$/', $title ), '$title',
104  "invalid name '$title'" );
105  Assert::parameter(
106  $title !== '' ||
107  ( $namespace === NS_MAIN && ( $fragment !== '' || $interwiki !== '' ) ),
108  '$title',
109  'should not be empty unless namespace is main and fragment or interwiki is non-empty'
110  );
111 
112  $this->namespace = $namespace;
113  $this->dbkey = strtr( $title, ' ', '_' );
114  $this->fragment = $fragment;
115  $this->interwiki = $interwiki;
116  }
117 
122  public function getNamespace() {
123  return $this->namespace;
124  }
125 
131  public function inNamespace( $ns ) {
132  return $this->namespace == $ns;
133  }
134 
139  public function getFragment() {
140  return $this->fragment;
141  }
142 
147  public function hasFragment() {
148  return $this->fragment !== '';
149  }
150 
158  public function getDBkey() {
159  return $this->dbkey;
160  }
161 
174  public function getText() {
175  return str_replace( '_', ' ', $this->dbkey );
176  }
177 
186  public function createFragmentTarget( $fragment ) {
187  return new TitleValue(
188  $this->namespace,
189  $this->dbkey,
190  $fragment,
191  $this->interwiki
192  );
193  }
194 
201  public function isExternal() {
202  return $this->interwiki !== '';
203  }
204 
211  public function getInterwiki() {
212  return $this->interwiki;
213  }
214 
223  public function __toString() {
224  $name = $this->namespace . ':' . $this->dbkey;
225 
226  if ( $this->fragment !== '' ) {
227  $name .= '#' . $this->fragment;
228  }
229 
230  if ( $this->interwiki !== '' ) {
231  $name = $this->interwiki . ':' . $name;
232  }
233 
234  return $name;
235  }
236 }
getText()
Returns the title in text form, without namespace prefix or fragment.
Definition: TitleValue.php:174
getInterwiki()
Returns the interwiki part.
Definition: TitleValue.php:211
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:223
__construct( $namespace, $title, $fragment='', $interwiki='')
Constructs a TitleValue.
Definition: TitleValue.php:88
inNamespace( $ns)
Definition: TitleValue.php:131
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:201
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:773
if(ini_get('mbstring.func_overload'))
Pre-config setup: Before loading LocalSettings.php.
Definition: Setup.php:51
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:918
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:186
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:277
getDBkey()
Returns the title&#39;s DB key, as supplied to the constructor, without namespace prefix or fragment...
Definition: TitleValue.php:158