MediaWiki  1.29.2
TitleValue.php
Go to the documentation of this file.
1 <?php
25 use Wikimedia\Assert\Assert;
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',
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 }
if
if($IP===false)
Definition: cleanupArchiveUserText.php:4
TitleValue\$namespace
int $namespace
Definition: TitleValue.php:40
TitleValue\isExternal
isExternal()
Whether it has an interwiki part.
Definition: TitleValue.php:170
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:304
TitleValue\createFragmentTarget
createFragmentTarget( $fragment)
Creates a new TitleValue for a different fragment of the same page.
Definition: TitleValue.php:155
TitleValue\$interwiki
string $interwiki
Definition: TitleValue.php:55
php
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
TitleValue\$fragment
string $fragment
Definition: TitleValue.php:50
TitleValue\getDBkey
getDBkey()
Returns the title's DB key, as supplied to the constructor, without namespace prefix or fragment.
Definition: TitleValue.php:128
TitleValue\__toString
__toString()
Returns a string representation of the title, for logging.
Definition: TitleValue.php:191
TitleValue\hasFragment
hasFragment()
Definition: TitleValue.php:118
TitleValue\getFragment
getFragment()
Definition: TitleValue.php:110
TitleValue\getText
getText()
Returns the title in text form, without namespace prefix or fragment.
Definition: TitleValue.php:143
TitleValue\getInterwiki
getInterwiki()
Returns the interwiki part.
Definition: TitleValue.php:180
TitleValue\getNamespace
getNamespace()
Definition: TitleValue.php:94
TitleValue\$dbkey
string $dbkey
Definition: TitleValue.php:45
TitleValue\__construct
__construct( $namespace, $dbkey, $fragment='', $interwiki='')
Constructs a TitleValue.
Definition: TitleValue.php:74
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:27
TitleValue\inNamespace
inNamespace( $ns)
Definition: TitleValue.php:103
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:36