mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 09:49:31 +02:00
Prefix links with namespace if needed.
- Fix: Links to other namespaces were not prefixed properly.
This commit is contained in:
@ -62,6 +62,8 @@ class Target {
|
||||
|
||||
private $caseSensitiveLinkValueRegex;
|
||||
|
||||
private $nsText;
|
||||
|
||||
/**
|
||||
* Constructs a new Target object
|
||||
*
|
||||
@ -71,6 +73,7 @@ class Target {
|
||||
* @param String &$title Title of the target page
|
||||
*/
|
||||
public function __construct( $nameSpace, $title, Config &$config ) {
|
||||
// print "\n>>>nameSpace=$nameSpace;title=$title<<<\n";
|
||||
$this->title = \Title::makeTitleSafe( $nameSpace, $title );
|
||||
$this->titleValue = $this->title->getTitleValue();
|
||||
$this->config = $config;
|
||||
@ -91,6 +94,32 @@ class Target {
|
||||
return $this->title->getText();
|
||||
}
|
||||
|
||||
public function getPrefixedTitleText() {
|
||||
return $this->getNsPrefix() . $this->getTitleText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string representation of the target's namespace.
|
||||
*
|
||||
* May be false if the namespace is NS_MAIN. The value is cached.
|
||||
* @return String|bool Target's namespace
|
||||
*/
|
||||
public function getNsText() {
|
||||
if ( $this->nsText === null ) {
|
||||
$this->nsText = $this->title->getNsText();
|
||||
}
|
||||
return $this->nsText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the namespace prefix. This is the namespace text followed by a colon,
|
||||
* or an empty string if the namespace text evaluates to false (e.g. NS_MAIN).
|
||||
* @return String namespace prefix
|
||||
*/
|
||||
public function getNsPrefix() {
|
||||
return $this->getNsText() ? $this->getNsText() . ':' : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the title string with certain characters escaped that may interfere
|
||||
* with regular expressions.
|
||||
|
Reference in New Issue
Block a user