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

Documentation generated on Mon, 11 Mar 2019 14:22:32 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.