cvs: pear /Text_Wiki package.xml /Text_Wiki/Text Wiki.php /Text_Wiki/Text/Wiki Default.php /Text_Wiki/doc test_Text_Wiki.php

From: Date: Wed, 01 Mar 2006 16:58:17 +0000
Subject: cvs: pear /Text_Wiki package.xml /Text_Wiki/Text Wiki.php /Text_Wiki/Text/Wiki Default.php /Text_Wiki/doc test_Text_Wiki.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-38797@lists.php.net to get a copy of this message
justinpatrin Wed Mar 1 16:58:17 2006 UTC Added files: /pear/Text_Wiki/Text/Wiki Default.php Modified files: /pear/Text_Wiki package.xml /pear/Text_Wiki/Text Wiki.php /pear/Text_Wiki/doc test_Text_Wiki.php Log: Revert changes to constructor as it cannot instantiate the parser class as it should Reverse parameter order to singleton() as it no longer matches the constructor and $parser it the mor eimportant parameter Add a factory() method to complement singleton() Update factory()/singleton() to return/handle errors

http://cvs.php.net/viewcvs.cgi/pear/Text_Wiki/package.xml?r1=1.50&r2=1.51&diff_format=u Index: pear/Text_Wiki/package.xml diff -u pear/Text_Wiki/package.xml:1.50 pear/Text_Wiki/package.xml:1.51 --- pear/Text_Wiki/package.xml:1.50 Mon Feb 27 20:40:49 2006 +++ pear/Text_Wiki/package.xml Wed Mar 1 16:58:17 2006 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> -<!-- $Id: package.xml,v 1.50 2006/02/27 20:40:49 toggg Exp $ --> +<!-- $Id: package.xml,v 1.51 2006/03/01 16:58:17 justinpatrin Exp $ --> <package version="1.0"> <name>Text_Wiki</name> <summary>Abstracts parsing and rendering rules for any markup as Wiki or BBCode in structured plain text.</summary> @@ -37,26 +37,37 @@ <date>2006-03-01</date> <license>LGPL</license> <state>stable</state> - <notes> -This is a major release as we reduce globaly resource usage -# instanciate renders only as needed + <notes><![CDATA[ +This is a major release as we reduce global resource usage +# instantiate renderers only as needed # singleton() static method to get a single object instanciated pro parser (merci davidc for advices) + +A factory() method has been introduced for instantiating Renderer objects + +The constructor is now deprecated in favor of the new singleton() or factory() methods + Renders now have their own methods for: # text: textEncode() defaulted to php htmlspecialchars() for Xhtml render to the text encoding choosed in conf (#5953, thanks jocke at selincite dot com) # url: urlEncode() defaulted to the php rawurlencode() + Wiki general: -Correct the key used in changeRule(), ensure no double new rule. -Page names and anchors Urlencode() as render required (e.g. may contain spaces) -Interwiki: parser may now give the full url instead of site+page (Mediawiki need) -Improved test. +# Correct the key used in changeRule(), ensure no double new rule. +# Page names and anchors Urlencode() as render required (e.g. may contain spaces) +# Interwiki: parser may now give the full url instead of site+page (Mediawiki need) +# Improved test. + Latex render: -Only variables should be assigned by reference (#6010, thanks twells at smarterliving dot com) +# Only variables should be assigned by reference (#6010, thanks twells at smarterliving dot com) + Plain render: # Interwiki: Complete the rendering with indication of (url) or (site:page) + Xhtml render: # Rendering Fix for Tables (Missing Whitespace) (thanks ritzmo) - </notes> +# Added support for two-token URLs +## This allows formatting within URL text and proper rendering into other Wiki dialects (assuming that your parser supports the new feature. The Default parser does not yet support this.) + ]]></notes> <filelist> <file role="php" name="Text/Wiki.php"> http://cvs.php.net/viewcvs.cgi/pear/Text_Wiki/Text/Wiki.php?r1=1.41&r2=1.42&diff_format=u Index: pear/Text_Wiki/Text/Wiki.php diff -u pear/Text_Wiki/Text/Wiki.php:1.41 pear/Text_Wiki/Text/Wiki.php:1.42 --- pear/Text_Wiki/Text/Wiki.php:1.41 Wed Mar 1 15:43:21 2006 +++ pear/Text_Wiki/Text/Wiki.php Wed Mar 1 16:58:17 2006 @@ -9,7 +9,7 @@ * @package Text_Wiki * @author Paul M. Jones <pmjones@php.net> * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 - * @version CVS: $Id: Wiki.php,v 1.41 2006/03/01 15:43:21 justinpatrin Exp $ + * @version CVS: $Id: Wiki.php,v 1.42 2006/03/01 16:58:17 justinpatrin Exp $ * @link http://pear.php.net/package/Text_Wiki */ @@ -340,17 +340,16 @@ * * Constructor. * + * **DEPRECATED** + * Please use the singleton() or factory() methods. + * * @access public * * @param array $rules The set of rules to load for this object. Defaults * to null, which will load the default ruleset for this parser. - * @param string $parser The parser to be used (defaults to 'Default'). - * For non-Default parsers, consider using the singleton() method instead - * as the fetching of the rulesets from non-Default parsers causes an - * extra object instantiation, which is slower. */ - function Text_Wiki($rules = null, $parser = 'Default') + function Text_Wiki($rules = null) { if (is_array($rules)) { $this->rules = $rules; @@ -360,26 +359,6 @@ 'parse', $this->fixPath(dirname(__FILE__)) . 'Wiki/Parse/Default/' ); - if ($parser != 'Default') { - $this->addPath( - 'parse', - $this->fixPath(dirname(__FILE__)) . 'Wiki/Parse/' . $parser . '/' - ); - - // - // Get ruleset from class by creating a throw-away object. It - // would be good to be able to return the object, but this would - // (a) risk causing recursion and (b) break PHP 4 < 4.3 that can't - // return an object from a constructor of the wrong type. - // - if (empty($rules)) { - include_once 'Text/Wiki/' . $parser . '.php'; - $class = 'Text_Wiki_' . $parser; - $testobject =& new $class; - $this->rules = $testobject->rules; - } - } - $this->addPath( 'render', $this->fixPath(dirname(__FILE__)) . 'Wiki/Render/' @@ -398,13 +377,12 @@ * * or * - * $single = & singleton( array('Prefilter', 'Delimiter', 'Code', 'Function', + * $single = & singleton('Parser', array('Prefilter', 'Delimiter', 'Code', 'Function', * 'Html', 'Raw', 'Include', 'Embed', 'Anchor', 'Heading', 'Toc', 'Horiz', * 'Break', 'Blockquote', 'List', 'Deflist', 'Table', 'Image', 'Phplookup', * 'Center', 'Newline', 'Paragraph', 'Url', 'Freelink', 'Interwiki', 'Wikilink', * 'Colortext', 'Strong', 'Bold', 'Emphasis', 'Italic', 'Underline', 'Tt', - * 'Superscript', 'Subscript', 'Revise', 'Tighten'), - * 'parser' ); + * 'Superscript', 'Subscript', 'Revise', 'Tighten')); * * Call using a subset of this list. The order of passing rulesets in the * $rules array is important! @@ -420,26 +398,56 @@ * @access public * @static * @since Method available since Release 1.1.0 - * @param array $rules The set of rules to instantiate the object. * @param string $parser The parser to be used (defaults to 'Default'). + * @param array $rules The set of rules to instantiate the object. This + * will only be used when the first call to singleton is made, if included + * in further calls it will be effectively ignored. * @return &object a reference to the Text_Wiki unique instantiation. */ - function &singleton($rules = null, $parser = 'Default') + function &singleton($parser = 'Default', $rules = null) { static $only = array(); if (!isset($only[$parser])) { - $class = 'Text_Wiki'; - // load the class file if not this one - if ($parser != 'Default') { - include_once 'Text/Wiki/' . $parser . '.php'; - $class = 'Text_Wiki_' . $parser; + $ret =& Text_Wiki::factory($parser, $rules); + if (PEAR::isError($ret)) { + return $ret; } - $only[$parser] = & new $class($rules); + $only[$parser] =& $ret; } return $only[$parser]; } /** + * Returns a Text_Wiki Parser class for the specified parser. + * + * @access public + * @static + * @param string $parser The name of the parse to instantiate + * @param array $rules The rules to pass into the constructor + * {@see Text_Wiki::singleton} for a list of rules + * @return Text_Wiki a Parser object extended from Text_Wiki + */ + function &factory($parser = 'Default', $rules = null) + { + $class = 'Text_Wiki_' . $parser; + $file = str_replace('_', '/', $class) . '.php'; + if (class_exists($class)) { + $obj =& new $class($rules); + return $obj; + } + if (include_once $file) { + if (class_exists($class)) { + $obj =& new $class($rules); + return $obj; + } else { + return PEAR::raiseError('Class '.$class.' does not exist after including '.$file); + } + } else { + return PEAR::raiseError('Could not include '.$file); + } + } + + /** * * Set parser configuration for a specific rule and key. * http://cvs.php.net/viewcvs.cgi/pear/Text_Wiki/doc/test_Text_Wiki.php?r1=1.17&r2=1.18&diff_format=u Index: pear/Text_Wiki/doc/test_Text_Wiki.php diff -u pear/Text_Wiki/doc/test_Text_Wiki.php:1.17 pear/Text_Wiki/doc/test_Text_Wiki.php:1.18 --- pear/Text_Wiki/doc/test_Text_Wiki.php:1.17 Wed Mar 1 15:43:21 2006 +++ pear/Text_Wiki/doc/test_Text_Wiki.php Wed Mar 1 16:58:17 2006 @@ -7,7 +7,7 @@ require_once 'Text/Wiki.php'; /** * Eventually set an include path if all parsers/renderers not installed - * $Id: test_Text_Wiki.php,v 1.17 2006/03/01 15:43:21 justinpatrin Exp $ + * $Id: test_Text_Wiki.php,v 1.18 2006/03/01 16:58:17 justinpatrin Exp $ */ $parser = $render = $source = ''; $plist = array('Default', 'BBCode', 'Cowiki', 'Doku', 'Mediawiki', 'Tiki'); @@ -53,18 +53,17 @@ } // instantiate a Text_Wiki object from the given class -$wiki = & Text_Wiki::singleton(null, $parser); +$wiki = & Text_Wiki::singleton($parser); -// Wiki.php 1.37 and prior, use this: -#$wiki = & Text_Wiki::singleton($parser); +// If you want to include rules, use +//$wiki = & Text_Wiki::singleton($parser, $rules); -// include this line of code instead to test creating an object -// using the constructor rather than the singleton method. -#$wiki = new Text_Wiki(null, $parser); - -#print "<pre>\n"; -#print_r($wiki); -#print "</pre>\n"; +// If you want to get a new copy of the class use factory +//$wiki =& Text_Wiki::factory($parser); + +//print "<pre>\n"; +//print_r($wiki); +//print "</pre>\n"; // when rendering XHTML, make sure wiki links point to a // specific base URL http://cvs.php.net/viewcvs.cgi/pear/Text_Wiki/Text/Wiki/Default.php?view=markup&rev=1.1 Index: pear/Text_Wiki/Text/Wiki/Default.php +++ pear/Text_Wiki/Text/Wiki/Default.php <?php // vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: /** * Parse structured wiki text and render into arbitrary formats such as XHTML. * * PHP versions 4 and 5 * * @category Text * @package Text_Wiki * @author Justin Patrin <justinpatrin@php.net> * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Default.php,v 1.1 2006/03/01 16:58:17 justinpatrin Exp $ * @link http://pear.php.net/package/Text_Wiki */ require_once('Text/Wiki.php'); /** * This is the parser for the Default ruleset. For now, this simply extends Text_Wiki. * * @category Text * @package Text_Wiki * @version Release: @package_version@ * @author Justin Patrin <justinpatrin@php.net> */ class Text_Wiki_Default extends Text_Wiki { }
« previous php.pear.cvs (#38797) next »