mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 09:49:31 +02:00
Add linker tests, fix firstOnly behavior.
- Fix: The firstOnly option finally also works if a page contains a link to a given other page that was not currently added by the extension, i.e. that existed prior to an edit or that was manually added. Closes #12.
This commit is contained in:
@ -60,6 +60,8 @@ class Target {
|
||||
*/
|
||||
private $config;
|
||||
|
||||
private $caseSensitiveLinkValueRegex;
|
||||
|
||||
/**
|
||||
* Constructs a new Target object
|
||||
*
|
||||
@ -103,20 +105,7 @@ class Target {
|
||||
* @return String regular expression for this title.
|
||||
*/
|
||||
public function getCaseSensitiveRegex() {
|
||||
$regexSafeTitle = $this->getRegexSafeTitle();
|
||||
|
||||
// Depending on the $config->capitalLinks setting,
|
||||
// the title has to be searched for either in a strictly case-sensitive
|
||||
// way, or in a 'fuzzy' way where the first letter of the title may
|
||||
// be either case.
|
||||
//
|
||||
if ( $this->config->capitalLinks && ( $regexSafeTitle[0] != '\\' )) {
|
||||
$searchTerm = '((?i)' . $regexSafeTitle[0] . '(?-i)' . substr($regexSafeTitle, 1) . ')';
|
||||
} else {
|
||||
$searchTerm = '(' . $regexSafeTitle . ')';
|
||||
}
|
||||
|
||||
return $this->buildRegex( $searchTerm );
|
||||
return $this->buildRegex( $this->getCaseSensitiveLinkValueRegex() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -138,6 +127,27 @@ class Target {
|
||||
return '/(?<![\:\.\@\/\?\&])' . $this->wordStart . $searchTerm . $this->wordEnd . '/S';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the (cached) regex for the link value.
|
||||
*
|
||||
* Depending on the $config->capitalLinks setting, the title has to be
|
||||
* searched for either in a strictly case-sensitive way, or in a 'fuzzy' way
|
||||
* where the first letter of the title may be either case.
|
||||
*
|
||||
* @return String regular expression pattern for the link value.
|
||||
*/
|
||||
public function getCaseSensitiveLinkValueRegex() {
|
||||
if ( $this->caseSensitiveLinkValueRegex === null ) {
|
||||
$regexSafeTitle = $this->getRegexSafeTitle();
|
||||
if ( $this->config->capitalLinks && ( $regexSafeTitle[0] != '\\' )) {
|
||||
$this->caseSensitiveLinkValueRegex = '((?i)' . $regexSafeTitle[0] . '(?-i)' . substr($regexSafeTitle, 1) . ')';
|
||||
} else {
|
||||
$this->caseSensitiveLinkValueRegex = '(' . $regexSafeTitle . ')';
|
||||
}
|
||||
}
|
||||
return $this->caseSensitiveLinkValueRegex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the \Content of the target page.
|
||||
*
|
||||
|
Reference in New Issue
Block a user