Source for file wikilink.php
Documentation is available at wikilink.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pmjones@ciaweb.net> |
// +----------------------------------------------------------------------+
// $Id: wikilink.php,v 1.9 2004/03/25 14:53:59 pmjones Exp $
* This class implements a Text_Wiki_Rule to find source text marked as a
* wiki page name and automatically create a link to that page.
* Wiki page names are typically in StudlyCapsStyle made of
* You can also create described links to pages in this style:
* [WikiPageName nice text link to use for display]
* @author Paul M. Jones <pmjones@ciaweb.net>
* Constructor. We override the Text_Wiki_Rule constructor so we can
* explicitly comment each part of the $regex property.
* @param object &$obj The calling "parent" Text_Wiki object.
* @param string $name The token name to use for this rule.
"(!?" . // START WikiPage pattern (1)
"[A-Za-z]*" . // 0+ alpha
"[A-Za-z]*" . // 0+ or more alpha
")" . // END WikiPage pattern (/1)
"((\#" . // START Anchor pattern (2)(3)
"(" . // start sub pattern (4)
"[-A-Za-z0-9_:.]*" . // 0+ dash, alpha, digit, underscore, colon, dot
"[-A-Za-z0-9_]" . // 1 dash, alpha, digit, or underscore
")?)?)"; // end subpatterns (/4)(/3)(/2)
* First parses for described links, then for standalone links.
$tmp_regex = '/\[' . $this->regex . ' (.+?)\]/';
array (&$this, 'processDescr'),
$tmp_regex = '/(^|[^A-Za-z0-9\-_])' . $this->regex . '/';
array (&$this, 'process'),
* Generates a replacement for described links. Token options are:
* 'page' => the wiki page name.
* 'text' => the displayed link text.
* 'anchor' => a named anchor on the target wiki page.
* @param array &$matches The array of matches from parse().
* @return A delimited token to be used as a placeholder in
* the source text, plus any text priot to the match.
// create and return the replacement token and preceding text
return $this->addToken($options); // . $matches[7];
* Generates a replacement for standalone links. Token options are:
* 'page' => the wiki page name.
* 'text' => the displayed link text.
* 'anchor' => a named anchor on the target wiki page.
* @param array &$matches The array of matches from parse().
* @return A delimited token to be used as a placeholder in
* the source text, plus any text prior to the match.
// when prefixed with !, it's explicitly not a wiki link.
// return everything as it was.
if ($matches[2 ]{0 } == '!') {
return $matches[1 ] . substr($matches[2 ], 1 ) . $matches[3 ];
'text' => $matches[2 ] . $matches[3 ],
// create and return the replacement token and preceding text
return $matches[1 ] . $this->addToken($options);
* Renders a token into text matching the requested format.
* @param array $options The "options" portion of the token (second
* @return string The text rendered from the token options.
// make nice variable names (page, anchor, text)
if (in_array($page, $this->_conf['pages'])) {
// yes, link to the page view
$href = $this->_conf['view_url'] . $page . $anchor;
return " <a href=\"$href\">$text</a>";
// no, link to a create-page url, but only if new_url is set
if (! isset ($this->_conf['new_url']) ||
trim($this->_conf['new_url']) == '') {
$href = $this->_conf['new_url'];
return $text . " <a href=\"$href$page\">{$this->_conf['new_text']}</a>";
Documentation generated on Mon, 11 Mar 2019 10:14:15 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|