Text_Wiki
[ class tree: Text_Wiki ] [ index: Text_Wiki ] [ all elements ]

Source for file Interwiki.php

Documentation is available at Interwiki.php

  1. <?php
  2. // $Id: Interwiki.php,v 1.2 2004/09/25 19:05:13 pmjones Exp $
  3.  
  4.  
  5. /**
  6. * This class implements a Text_Wiki_Parse to find source text marked as
  7. * an Interwiki link.  See the regex for a detailed explanation of the
  8. * text matching procedure; e.g., "InterWikiName:PageName".
  9. *
  10. @author Paul M. Jones <pmjones@ciaweb.net>
  11. *
  12. @package Text_Wiki
  13. *
  14. */
  15.  
  16.     
  17.     
  18.     var $regex = '([A-Za-z0-9_]+):([\/=&~#A-Za-z0-9_]+)';
  19.     
  20.     
  21.     /**
  22.     * 
  23.     * Parser.  We override the standard parser so we can
  24.     * find both described interwiki links and standalone links.
  25.     * 
  26.     * @access public
  27.     * 
  28.     * @return void 
  29.     * 
  30.     */
  31.     
  32.     function parse()
  33.     {
  34.         // described interwiki links
  35.         $tmp_regex '/\[' $this->regex . ' (.+?)\]/';
  36.         $this->wiki->source = preg_replace_callback(
  37.             $tmp_regex,
  38.             array(&$this'processDescr'),
  39.             $this->wiki->source
  40.         );
  41.         
  42.         // standalone interwiki links
  43.         $tmp_regex '/' $this->regex . '/';
  44.         $this->wiki->source = preg_replace_callback(
  45.             $tmp_regex,
  46.             array(&$this'process'),
  47.             $this->wiki->source
  48.         );
  49.        
  50.     }
  51.     
  52.     
  53.     /**
  54.     * 
  55.     * Generates a replacement for the matched standalone interwiki text.
  56.     * Token options are:
  57.     * 
  58.     * 'site' => The key name for the Text_Wiki interwiki array map,
  59.     * usually the name of the interwiki site.
  60.     * 
  61.     * 'page' => The page on the target interwiki to link to.
  62.     * 
  63.     * 'text' => The text to display as the link.
  64.     * 
  65.     * @access public
  66.     *
  67.     * @param array &$matches The array of matches from parse().
  68.     *
  69.     * @return delimited token to be used as a placeholder in
  70.     *  the source text, plus any text priot to the match.
  71.     *
  72.     */
  73.     
  74.     function process(&$matches)
  75.     {
  76.         $options = array(
  77.             'site' => $matches[1],
  78.             'page' => $matches[2],
  79.             'text' => $matches[0]
  80.         );
  81.         
  82.         return $this->wiki->addToken($this->rule$options);
  83.     }
  84.     
  85.     
  86.     /**
  87.     * 
  88.     * Generates a replacement for described interwiki links. Token
  89.     * options are:
  90.     * 
  91.     * 'site' => The key name for the Text_Wiki interwiki array map,
  92.     * usually the name of the interwiki site.
  93.     * 
  94.     * 'page' => The page on the target interwiki to link to.
  95.     * 
  96.     * 'text' => The text to display as the link.
  97.     * 
  98.     * @access public
  99.     *
  100.     * @param array &$matches The array of matches from parse().
  101.     *
  102.     * @return delimited token to be used as a placeholder in
  103.     *  the source text, plus any text priot to the match.
  104.     *
  105.     */
  106.     
  107.     function processDescr(&$matches)
  108.     {
  109.         $options = array(
  110.             'site' => $matches[1],
  111.             'page' => $matches[2],
  112.             'text' => $matches[3]
  113.         );
  114.         
  115.         return $this->wiki->addToken($this->rule$options);
  116.     }
  117. }
  118. ?>

Documentation generated on Mon, 11 Mar 2019 13:56:10 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.