LinkTitles extension for MediaWiki
Automatically add links to existing pages.
All Classes Namespaces Functions Variables Modules Pages
LinkTitles\Linker Class Reference

Performs the actual linking of content to existing pages. More...

Public Member Functions

 __construct (Config &$config)
 Constructs a new instance of the Linker class. More...
 
 linkContent (Source $source)
 Core function of the extension, performs the actual parsing of the content. More...
 

Static Public Member Functions

static lock ()
 Increases an internal static lock counter by 1. More...
 
static unlock ()
 Decreases an internal static lock counter by 1. More...
 

Public Attributes

 $config
 LinkTitles configuration.
 

Private Member Functions

 simpleModeCallback (array $matches)
 Callback for preg_replace_callback in simple mode. More...
 
 smartModeCallback (array $matches)
 Callback function for use with preg_replace_callback. More...
 

Private Attributes

 $linkValue
 The link value of the target page that is currently being evaluated. More...
 

Static Private Attributes

static $locked = 0
 

Detailed Description

Performs the actual linking of content to existing pages.

Definition at line 29 of file Linker.php.

Constructor & Destructor Documentation

LinkTitles\Linker::__construct ( Config $config)

Constructs a new instance of the Linker class.

Parameters
Config$configLinkTitles configuration object.

Definition at line 56 of file Linker.php.

Member Function Documentation

LinkTitles\Linker::linkContent ( Source  $source)

Core function of the extension, performs the actual parsing of the content.

This method receives a Title object and the string representation of the source page. It does not work on a WikiPage object directly because the callbacks in the Extension class do not always get a WikiPage object in the first place.

Parameters
\Title&$titleTitle object for the current page.
String$textString that holds the article content
Returns
String|null Source page text with links to target pages, or null if no links were added

Definition at line 72 of file Linker.php.

static LinkTitles\Linker::lock ( )
static

Increases an internal static lock counter by 1.

If the Linker class is locked (counter > 0), linkContent() will be a no-op. Locking is necessary to enable nested <noautolinks> and <autolinks> tags in parseOnRender mode.

Definition at line 212 of file Linker.php.

LinkTitles\Linker::simpleModeCallback ( array  $matches)
private

Callback for preg_replace_callback in simple mode.

Parameters
array$matchesMatches provided by preg_replace_callback
Returns
string Target page title with or without link markup

Definition at line 165 of file Linker.php.

LinkTitles\Linker::smartModeCallback ( array  $matches)
private

Callback function for use with preg_replace_callback.

This essentially performs a case-sensitive comparison of the current page title and the occurrence found on the page; if the cases do not match, it builds an aliased (piped) link. If $wgCapitalLinks is set to true, the case of the first letter is ignored by MediaWiki and we don't need to build a piped link if only the case of the first letter is different.

Parameters
array$matchesMatches provided by preg_replace_callback
Returns
string Target page title with or without link markup

Definition at line 187 of file Linker.php.

static LinkTitles\Linker::unlock ( )
static

Decreases an internal static lock counter by 1.

If the Linker class is locked (counter > 0), linkContent() will be a no-op. Locking is necessary to enable nested <noautolinks> and <autolinks> tags in parseOnRender mode.

Definition at line 223 of file Linker.php.

Member Data Documentation

String LinkTitles\Linker::$linkValue
private

The link value of the target page that is currently being evaluated.

This may be either the page name or the page name prefixed with the name space if the target's name space is not NS_MAIN.

This is an instance variable (rather than a local method variable) so it can be accessed in the preg_replace_callback callbacks.

Definition at line 47 of file Linker.php.


The documentation for this class was generated from the following file: