26use InvalidArgumentException;
30use Wikimedia\Parsoid\Core\LinkTarget;
82 public function formatTitle( $namespace, $text, $fragment =
'', $interwiki =
'' ) {
84 if ( $interwiki !==
'' ) {
85 $out = $interwiki .
':';
88 if ( $namespace != 0 ) {
91 }
catch ( InvalidArgumentException $e ) {
93 $nsName = $this->language->getNsText(
NS_SPECIAL ) .
":Badtitle/NS{$namespace}";
96 $out .= $nsName .
':';
100 if ( $fragment !==
'' ) {
101 $out .=
'#' . $fragment;
104 $out = str_replace(
'_',
' ', $out );
118 return $title->getText();
120 return strtr( $title->getDBKey(),
'_',
' ' );
122 throw new InvalidArgumentException(
'$title has invalid type: ' . get_class( $title ) );
136 if ( !isset( $title->prefixedText ) ) {
138 $title->getNamespace(),
141 $title->getInterwiki()
144 return $title->prefixedText;
146 $title->assertWiki( PageReference::LOCAL );
148 $title->getNamespace(),
149 $this->getText( $title )
152 throw new InvalidArgumentException(
'$title has invalid type: ' . get_class( $title ) );
168 $target->getNamespace(),
171 $target->getInterwiki()
174 $target->assertWiki( PageReference::LOCAL );
176 $target->getNamespace(),
180 throw new InvalidArgumentException(
'$title has invalid type: ' . get_class( $target ) );
194 $title->getNamespace(),
196 $title->getFragment(),
197 $title->getInterwiki()
200 $title->assertWiki( PageReference::LOCAL );
202 $title->getNamespace(),
203 $this->getText( $title )
206 throw new InvalidArgumentException(
'$title has invalid type: ' . get_class( $title ) );
222 if ( $this->language->needsGenderDistinction() &&
223 $this->nsInfo->hasGenderDistinction( $namespace )
226 $gender = $this->genderCache->getGenderOf( $text, __METHOD__ );
227 $name = $this->language->getGenderNsText( $namespace, $gender );
229 $name = $this->language->getNsText( $namespace );
232 if ( $name ===
false ) {
233 throw new InvalidArgumentException(
'Unknown namespace ID: ' . $namespace );
242class_alias( TitleFormatter::class,
'TitleFormatter' );