MediaWiki  1.28.0
TitleValue.php
Go to the documentation of this file.
1 <?php
26 
36 class TitleValue implements LinkTarget {
40  protected $namespace;
41 
45  protected $dbkey;
46 
50  protected $fragment;
51 
55  protected $interwiki;
56 
74  public function __construct( $namespace, $dbkey, $fragment = '', $interwiki = '' ) {
75  Assert::parameterType( 'integer', $namespace, '$namespace' );
76  Assert::parameterType( 'string', $dbkey, '$dbkey' );
77  Assert::parameterType( 'string', $fragment, '$fragment' );
78  Assert::parameterType( 'string', $interwiki, '$interwiki' );
79 
80  // Sanity check, no full validation or normalization applied here!
81  Assert::parameter( !preg_match( '/^_|[ \r\n\t]|_$/', $dbkey ), '$dbkey', 'invalid DB key' );
82  Assert::parameter( $dbkey !== '', '$dbkey', 'should not be empty' );
83 
84  $this->namespace = $namespace;
85  $this->dbkey = $dbkey;
86  $this->fragment = $fragment;
87  $this->interwiki = $interwiki;
88  }
89 
93  public function getNamespace() {
94  return $this->namespace;
95  }
96 
102  public function inNamespace( $ns ) {
103  return $this->namespace == $ns;
104  }
105 
109  public function getFragment() {
110  return $this->fragment;
111  }
112 
117  public function hasFragment() {
118  return $this->fragment !== '';
119  }
120 
127  public function getDBkey() {
128  return $this->dbkey;
129  }
130 
142  public function getText() {
143  return str_replace( '_', ' ', $this->getDBkey() );
144  }
145 
154  public function createFragmentTarget( $fragment ) {
155  return new TitleValue(
156  $this->namespace,
157  $this->dbkey,
158  $fragment,
159  $this->interwiki
160  );
161  }
162 
169  public function isExternal() {
170  return $this->interwiki !== '';
171  }
172 
179  public function getInterwiki() {
180  return $this->interwiki;
181  }
182 
190  public function __toString() {
191  $name = $this->namespace . ':' . $this->dbkey;
192 
193  if ( $this->fragment !== '' ) {
194  $name .= '#' . $this->fragment;
195  }
196 
197  if ( $this->interwiki !== '' ) {
198  $name = $this->interwiki . ':' . $name;
199  }
200 
201  return $name;
202  }
203 }
getText()
Returns the title in text form, without namespace prefix or fragment.
Definition: TitleValue.php:142
getInterwiki()
Returns the interwiki part.
Definition: TitleValue.php:179
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
string $dbkey
Definition: TitleValue.php:45
inNamespace($ns)
Definition: TitleValue.php:102
__toString()
Returns a string representation of the title, for logging.
Definition: TitleValue.php:190
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:36
int $namespace
Definition: TitleValue.php:40
isExternal()
Whether it has an interwiki part.
Definition: TitleValue.php:169
__construct($namespace, $dbkey, $fragment= '', $interwiki= '')
Constructs a TitleValue.
Definition: TitleValue.php:74
string $interwiki
Definition: TitleValue.php:55
if($IP===false)
Definition: WebStart.php:59
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:50
createFragmentTarget($fragment)
Creates a new TitleValue for a different fragment of the same page.
Definition: TitleValue.php:154
getDBkey()
Returns the title's DB key, as supplied to the constructor, without namespace prefix or fragment...
Definition: TitleValue.php:127
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:300