Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Text/Wiki/Parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ function parse()
{
$this->wiki->source = preg_replace_callback(
$this->regex,
array(&$this, 'process'),
function ($matches) {
return $this->process($matches);
},
$this->wiki->source
);
}
Expand Down
88 changes: 46 additions & 42 deletions Text/Wiki/Parse/Default/Interwiki.php
Original file line number Diff line number Diff line change
@@ -1,87 +1,91 @@
<?php

/**
*
*
* Parses for interwiki links.
*
*
* @category Text
*
*
* @package Text_Wiki
*
*
* @author Paul M. Jones <pmjones@php.net>
*
*
* @license LGPL
*
*
* @version $Id$
*
*
*/

/**
*
*
* Parses for interwiki links.
*
*
* This class implements a Text_Wiki_Parse_Default to find source text marked as
* an Interwiki link. See the regex for a detailed explanation of the
* text matching procedure; e.g., "InterWikiName:PageName".
*
* @category Text
*
*
* @package Text_Wiki
*
*
* @author Paul M. Jones <pmjones@php.net>
*
*
*/

class Text_Wiki_Parse_Default_Interwiki extends Text_Wiki_Parse {

// double-colons wont trip up now
var $regex = '([A-Za-z0-9_]+):((?!:)[A-Za-z0-9_\/=&~#.:;-]+)';


/**
*
*
* Parser. We override the standard parser so we can
* find both described interwiki links and standalone links.
*
*
* @access public
*
*
* @return void
*
*
*/

function parse()
{
// described interwiki links
$tmp_regex = '/\[' . $this->regex . ' (.+?)\]/';
$this->wiki->source = preg_replace_callback(
$tmp_regex,
array(&$this, 'processDescr'),
function ($matches) {
return $this->processDescr($matches);
},
$this->wiki->source
);

// standalone interwiki links
$tmp_regex = '/' . $this->regex . '/';
$this->wiki->source = preg_replace_callback(
$tmp_regex,
array(&$this, 'process'),
function ($matches) {
return $this->process($matches);
},
$this->wiki->source
);

}


/**
*
*
* Generates a replacement for the matched standalone interwiki text.
* Token options are:
*
*
* 'site' => The key name for the Text_Wiki interwiki array map,
* usually the name of the interwiki site.
*
*
* 'page' => The page on the target interwiki to link to.
*
*
* 'text' => The text to display as the link.
*
*
* @access public
*
* @param array &$matches The array of matches from parse().
Expand All @@ -90,31 +94,31 @@ function parse()
* the source text, plus any text priot to the match.
*
*/

function process(&$matches)
{
$options = array(
'site' => $matches[1],
'page' => $matches[2],
'text' => $matches[0]
);

return $this->wiki->addToken($this->rule, $options);
}


/**
*
*
* Generates a replacement for described interwiki links. Token
* options are:
*
*
* 'site' => The key name for the Text_Wiki interwiki array map,
* usually the name of the interwiki site.
*
*
* 'page' => The page on the target interwiki to link to.
*
*
* 'text' => The text to display as the link.
*
*
* @access public
*
* @param array &$matches The array of matches from parse().
Expand All @@ -123,15 +127,15 @@ function process(&$matches)
* the source text, plus any text priot to the match.
*
*/

function processDescr(&$matches)
{
$options = array(
'site' => $matches[1],
'page' => $matches[2],
'text' => $matches[3]
);

return $this->wiki->addToken($this->rule, $options);
}
}
Expand Down
6 changes: 3 additions & 3 deletions Text/Wiki/Parse/Default/Smiley.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ function __construct(&$obj)
$cur = $smiley;
}
$len = strlen($cur);
if (($cur{0} == ':') && ($len > 2) && ($cur{$len - 1} == ':')) {
if (($cur[0] == ':') && ($len > 2) && ($cur[$len - 1] == ':')) {
$reg1 .= $sep1 . preg_quote(substr($cur, 1, -1), '#');
$sep1 = '|';
continue;
}
if ($autoNose && ($len === 2)) {
$variante = $cur{0} . '-' . $cur{1};
$variante = $cur[0] . '-' . $cur[1];
$this->_smileys[$variante] = &$this->_smileys[$smiley];
$cur = preg_quote($cur{0}, '#') . '-?' . preg_quote($cur{1}, '#');
$cur = preg_quote($cur[0], '#') . '-?' . preg_quote($cur[1], '#');
} else {
$cur = preg_quote($cur, '#');
}
Expand Down
Loading