49 private static $locked = 0;
57 $this->config = $config;
73 if ( self::$locked > 0 || !$source->
canBeLinked() ) {
77 ( $this->config->firstOnly ) ? $limit = 1 : $limit = -1;
78 $limitReached =
false;
81 $splitter = Splitter::singleton( $this->config );
82 $targets = Targets::singleton( $source->
getTitle(), $this->config );
85 foreach( $targets->queryResult as $row ) {
86 $target =
new Target( $row->page_namespace, $row->page_title, $this->config );
91 if ( $target->isSameTitle( $source ) || !$target->mayLinkTo( $source ) ) {
99 if ( $limit == 1 && preg_match(
'/\[\[' . $target->getCaseSensitiveLinkValueRegex() .
']]/' , $source->
getText() ) ) {
106 $arr = $splitter->split( $newText );
110 $this->linkValue = $target->getPrefixedTitleText();
113 for ( $i = 0; $i < count( $arr ); $i += 2 ) {
114 $arr[$i] = preg_replace_callback( $target->getCaseSensitiveRegex(),
115 array( $this,
'simpleModeCallback'),
116 $arr[$i], $limit, $replacements );
117 $count += $replacements;
118 if ( $this->config->firstOnly && ( $count > 0 ) ) {
119 $limitReached =
true;
125 $newText = implode(
'', $arr );
131 if ( $this->config->smartMode && !$limitReached ) {
134 $arr = $splitter->split( $newText );
137 for ( $i = 0; $i < count( $arr ); $i+=2 ) {
139 $arr[$i] = preg_replace_callback( $target->getCaseInsensitiveRegex(),
140 array( $this,
'smartModeCallback'),
141 $arr[$i], $limit, $replacements );
142 $count += $replacements;
143 if ( $this->config->firstOnly && ( $count > 0 )) {
149 $newText = implode(
'', $arr );
168 if ( strlen( $this->linkValue ) > strlen( $matches[0] ) ) {
169 return '[[' . $this->linkValue .
'|' . $matches[0] .
']]';
171 return '[[' . $matches[0] .
']]';
193 if ( $this->config->capitalLinks ) {
194 $needPipe = strcmp( substr( $this->linkValue, 1 ), substr( $matches[ 0 ], 1 ) ) != 0;
196 $needPipe = strcmp( $this->linkValue, $matches[ 0 ] ) != 0;
199 return '[[' . $this->linkValue .
'|' . $matches[ 0 ] .
']]';
201 return '[[' . $matches[ 0 ] .
']]';
212 public static function lock() {
__construct(Config &$config)
Constructs a new instance of the Linker class.
linkContent(Source $source)
Core function of the extension, performs the actual parsing of the content.
canBeLinked()
Determines whether or not this page may be linked to.
getTitle()
Gets the title.
smartModeCallback(array $matches)
Callback function for use with preg_replace_callback.
$config
LinkTitles configuration.
static lock()
Increases an internal static lock counter by 1.
getText()
Gets the text of the corresponding Wiki page.
Represents a page that is a potential link target.
simpleModeCallback(array $matches)
Callback for preg_replace_callback in simple mode.
$linkValue
The link value of the target page that is currently being evaluated.
static unlock()
Decreases an internal static lock counter by 1.
Holds LinkTitles configuration.
The LinkTitles class holds configuration for the LinkTitles extension.
Performs the actual linking of content to existing pages.
Represents a page that is a potential link target.