MediaWiki REL1_29
TitleValue.php
Go to the documentation of this file.
1<?php
25use Wikimedia\Assert\Assert;
26
36class 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',
82 "invalid DB key '$dbkey'" );
83 Assert::parameter( $dbkey !== '', '$dbkey', 'should not be empty' );
84
85 $this->namespace = $namespace;
86 $this->dbkey = $dbkey;
87 $this->fragment = $fragment;
88 $this->interwiki = $interwiki;
89 }
90
94 public function getNamespace() {
95 return $this->namespace;
96 }
97
103 public function inNamespace( $ns ) {
104 return $this->namespace == $ns;
105 }
106
110 public function getFragment() {
111 return $this->fragment;
112 }
113
118 public function hasFragment() {
119 return $this->fragment !== '';
120 }
121
128 public function getDBkey() {
129 return $this->dbkey;
130 }
131
143 public function getText() {
144 return str_replace( '_', ' ', $this->getDBkey() );
145 }
146
155 public function createFragmentTarget( $fragment ) {
156 return new TitleValue(
157 $this->namespace,
158 $this->dbkey,
159 $fragment,
160 $this->interwiki
161 );
162 }
163
170 public function isExternal() {
171 return $this->interwiki !== '';
172 }
173
180 public function getInterwiki() {
181 return $this->interwiki;
182 }
183
191 public function __toString() {
192 $name = $this->namespace . ':' . $this->dbkey;
193
194 if ( $this->fragment !== '' ) {
195 $name .= '#' . $this->fragment;
196 }
197
198 if ( $this->interwiki !== '' ) {
199 $name = $this->interwiki . ':' . $name;
200 }
201
202 return $name;
203 }
204}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
if($IP===false)
Definition WebStart.php:59
Represents a page (or page fragment) title within MediaWiki.
isExternal()
Whether it has an interwiki part.
string $fragment
__construct( $namespace, $dbkey, $fragment='', $interwiki='')
Constructs a TitleValue.
getInterwiki()
Returns the interwiki part.
inNamespace( $ns)
getText()
Returns the title in text form, without namespace prefix or fragment.
createFragmentTarget( $fragment)
Creates a new TitleValue for a different fragment of the same page.
string $interwiki
getDBkey()
Returns the title's DB key, as supplied to the constructor, without namespace prefix or fragment.
string $dbkey
__toString()
Returns a string representation of the title, for logging.
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:304
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:37