http://www.mediawiki.org/wiki/Special:Code/MediaWiki/90196

Revision: 90196
Author:   ning
Date:     2011-06-16 08:45:37 +0000 (Thu, 16 Jun 2011)
Log Message:
-----------
Wiki Object Model release v1.0

Modified Paths:
--------------
    trunk/extensions/WikiObjectModel/includes/WOM_Processor.php
    trunk/extensions/WikiObjectModel/includes/WOM_Setup.php
    trunk/extensions/WikiObjectModel/includes/apis/WOM_GetObjectModel.php
    trunk/extensions/WikiObjectModel/includes/apis/WOM_SetObjectModel.php
    trunk/extensions/WikiObjectModel/includes/models/WOMFactory.php
    trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Category.php
    trunk/extensions/WikiObjectModel/includes/models/WOM_OM_HTMLTag.php
    trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Link.php
    trunk/extensions/WikiObjectModel/includes/models/WOM_OM_ListItem.php
    trunk/extensions/WikiObjectModel/includes/models/WOM_OM_MagicWord.php
    trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Page.php
    trunk/extensions/WikiObjectModel/includes/models/WOM_OM_ParamValue.php
    trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Parameter.php
    trunk/extensions/WikiObjectModel/includes/models/WOM_OM_ParserFunction.php
    trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Property.php
    trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Section.php
    trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Sentence.php
    trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Table.php
    trunk/extensions/WikiObjectModel/includes/models/WOM_OM_TblCell.php
    trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Template.php
    trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Text.php
    trunk/extensions/WikiObjectModel/includes/models/WOM_OM_TmplField.php
    trunk/extensions/WikiObjectModel/includes/parsers/WOMHTMLTagParser.php
    trunk/extensions/WikiObjectModel/includes/parsers/WOMLinkParser.php
    trunk/extensions/WikiObjectModel/includes/parsers/WOMListItemParser.php
    trunk/extensions/WikiObjectModel/includes/parsers/WOMMagicWordParser.php
    trunk/extensions/WikiObjectModel/includes/parsers/WOMParamValueParser.php
    trunk/extensions/WikiObjectModel/includes/parsers/WOMParameterParser.php
    trunk/extensions/WikiObjectModel/includes/parsers/WOMSectionParser.php
    trunk/extensions/WikiObjectModel/includes/parsers/WOMTblCellParser.php
    trunk/extensions/WikiObjectModel/includes/parsers/WikiObjectModelParser.php

Modified: trunk/extensions/WikiObjectModel/includes/WOM_Processor.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/WOM_Processor.php 2011-06-16 
07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/WOM_Processor.php 2011-06-16 
08:45:37 UTC (rev 90196)
@@ -36,15 +36,16 @@
                        WOMProcessor::setupParsers();
                }
                global $wgOMModelParserMapping;
-               $id = $wgOMModelParserMapping[$obj->getTypeID()];
-               if ( isset( WOMProcessor::$parsers[$id] ) ) {
-                       $result = WOMProcessor::$parsers[$id];
-               } else {
-                       $result = WOMProcessor::$base_parser;
+               if ( isset( $wgOMModelParserMapping[$obj->getTypeID()] ) ) {
+                       $id = $wgOMModelParserMapping[$obj->getTypeID()];
+                       if ( isset( WOMProcessor::$parsers[$id] ) ) {
+                               wfProfileOut( $fname );
+                               return WOMProcessor::$parsers[$id];
+                       }
                }
                wfProfileOut( $fname );
 
-               return $result;
+               return WOMProcessor::$base_parser;
        }
 
        private static function applyObjID( WikiObjectModel $wom, WOMPageModel 
$root ) {
@@ -67,7 +68,7 @@
 
                $root = new WOMPageModel();
                WOMProcessor::parseNext( $text, $root, $root );
-               WOMProcessor::parseSentences($root);
+               WOMProcessor::parseSentences( $root );
                WOMProcessor::applyObjID( $root, $root );
                wfProfileOut( $fname );
                return $root;
@@ -187,6 +188,11 @@
                        } else {
                                $parserInstance2 = $parserInstance;
                                $result = $parserInstance->parseNext( $text, 
$parentObj, $offset );
+                               if ( $result == null ) {
+                                       // FIXME: just omit current char, this 
will not fit for Wiki parser
+                                       ++ $offset;
+                                       continue;
+                               }
                        }
 
                        $next_obj = $result['obj'];
@@ -204,10 +210,12 @@
 
                        WOMProcessor::assemble( $next_obj );
 
-                       if ( $next_obj->isCollection() && !$result['closed'] ) {
+                       if ( $next_obj->isCollection() && !( isset( 
$result['closed'] ) && $result['closed'] ) ) {
                                $collection_start = $offset;
-                               $d = WOMProcessor::parseNext( $text, $next_obj, 
$rootObj, $offset, ( $parserInstance2 == null ? null :
-                                       
WOMProcessor::$parsers[$parserInstance2->getSubParserID()] ) );
+                               $d = WOMProcessor::parseNext( $text, $next_obj, 
$rootObj, $offset,
+                                       ( ( $parserInstance2 != null && isset( 
WOMProcessor::$parsers[$parserInstance2->getSubParserID()] ) ) ?
+                                       
WOMProcessor::$parsers[$parserInstance2->getSubParserID()] :
+                                       null ) );
                                if ( $d == 100 && 
$parserInstance2->isObjectClosed( $next_obj, $text, $offset ) === false ) {
                                        // rollback
                                        $p = WOMProcessor::getObjectParser( 
$parentObj );
@@ -491,7 +499,7 @@
 
                wfProfileOut( $fname );
        }
-       
+
        public static function appendPageObject( $object, $title, $obj_id = '', 
$summary = '', $revision_id = 0, $force_update = true ) {
                $fname = 'WikiObjectModel::appendPageObject (WOM)';
                wfProfileIn( $fname );
@@ -627,7 +635,7 @@
 
                wfProfileOut( $fname );
        }
-       
+
        public static function updatePageText( $text, $title, $obj_id, $summary 
= '', $revision_id = 0, $force_update = true ) {
                $fname = 'WikiObjectModel::updatePageText (WOM)';
                wfProfileIn( $fname );

Modified: trunk/extensions/WikiObjectModel/includes/WOM_Setup.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/WOM_Setup.php     2011-06-16 
07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/WOM_Setup.php     2011-06-16 
08:45:37 UTC (rev 90196)
@@ -130,9 +130,3 @@
 $wgAutoloadClasses['ApiWOMGetObjectModel'] = $wgOMIP . 
'/includes/apis/WOM_GetObjectModel.php';
 
 
-
-
-// constants for special properties
-define( 'WOM_WF_SP_HAS_TEMPLATE', 1 );
-define( 'WOM_WF_SP_HAS_MULTIPLE_TEMPLATE', 2 );
-define( 'WOM_WF_SP_HAS_TEMPLATEFIELD_CONNECTOR', 3 );

Modified: trunk/extensions/WikiObjectModel/includes/apis/WOM_GetObjectModel.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/apis/WOM_GetObjectModel.php       
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/apis/WOM_GetObjectModel.php       
2011-06-16 08:45:37 UTC (rev 90196)
@@ -50,24 +50,38 @@
                        $result['result'] = 'Success';
 
                        // pay attention to special xml tag, e.g., 
<property><value>...</value></property>
+                       $result['return'] = array();
                        if ( $type == 'count' ) {
                                $count = 0;
                                foreach ( $objs as $id ) {
                                        if ( $id == '' ) continue;
                                        ++ $count;
                                }
-                               $result['return'] = $count;
+                               $this->getResult()->setContent( 
$result['return'], $count );
                        } else {
-                               $result['return'] = array();
+                               $xml = '';
+                               $page_obj = WOMProcessor::getPageObject( 
$articleTitle, $rid );
                                foreach ( $objs as $id ) {
                                        if ( $id == '' ) continue;
+                                       $wobj = $page_obj->getObject( $id );
                                        $result['return'][$id] = array();
                                        if ( $type == 'xml' ) {
-                                               $this->getResult()->setContent( 
$result['return'][$id], WOMProcessor::getPageObject( $articleTitle, $rid 
)->getObject( $id )->toXML() );
+                                               $xml .= "<{$id} 
xml:space=\"preserve\">{$wobj->toXML()}</{$id}>";
+//                                             $this->getResult()->setContent( 
$result['return'][$id], $wobj->toXML() );
                                        } else {
-                                               $this->getResult()->setContent( 
$result['return'][$id], WOMProcessor::getPageObject( $articleTitle, $rid 
)->getObject( $id )->getWikiText() );
+                                               $this->getResult()->setContent( 
$result['return'][$id], $wobj->getWikiText() );
                                        }
                                }
+                               if ( $type == 'xml' ) {
+                                       header ( "Content-Type: 
application/rdf+xml" );
+                                       echo <<<OUTPUT
+<?xml version="1.0" encoding="UTF-8" ?>
+<api><womget result="Success"><return>
+{$xml}
+</return></womget></api>
+OUTPUT;
+                                       exit( 1 );
+                               }
                        }
                }
                $this->getResult()->addValue( null, $this->getModuleName(), 
$result );
@@ -78,9 +92,9 @@
                        'page' => null,
                        'xpath' => null,
                        'type' => array(
-                               ApiBase :: PARAM_DFLT => 'get',
+                               ApiBase :: PARAM_DFLT => 'wiki',
                                ApiBase :: PARAM_TYPE => array(
-                                       'get',
+                                       'wiki',
                                        'count',
                                        'xml',
                                ),
@@ -99,9 +113,9 @@
                        'xpath' => 'DOM-like xpath to locate WOM object 
instances (http://www.w3schools.com/xpath/xpath_syntax.asp)',
                        'type' => array (
                                'Type to fetch useful wiki object data',
-                               'type = get, get specified object',
+                               'type = wiki, get wiki text of specified 
object',
                                'type = count, get objects count with specified 
xpath',
-                               'type = xml, view objects\' xml format with 
specified xpath, usually use with format=xml',
+                               'type = xml, view "encoded objects\' xml" with 
specified xpath, usually use with format=xml',
                        ),
                        'rid' => 'Revision id of specified page - by dafault 
latest updated revision (0) is used',
                );

Modified: trunk/extensions/WikiObjectModel/includes/apis/WOM_SetObjectModel.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/apis/WOM_SetObjectModel.php       
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/apis/WOM_SetObjectModel.php       
2011-06-16 08:45:37 UTC (rev 90196)
@@ -19,12 +19,12 @@
                        $this->dieUsage( 'Must specify xpath', 1 );
 
                $page = $params['page'];
-               $type = $params['type'];
+               $verb = $params['verb'];
                $xpath = $params['xpath'];
                $value = $params['value'];
                $summary = $params['summary'];
                $rid = $params['rid'];
-               $force_update = $params['force_update'];
+               $force_update = ( intval( $params['force_update'] ) == 1 );
 
                $articleTitle = Title::newFromText( $page );
                if ( !$articleTitle )
@@ -52,9 +52,9 @@
                                throw new MWException( __METHOD__ . ": object 
does not found, xpath: {$xpath}" );
                        }
 
-                       if ( $type == 'remove' ) {
+                       if ( $verb == 'remove' ) {
                                WOMProcessor::removePageObject( $articleTitle, 
$oid, $summary, $rid, $force_update );
-                       } else if ( $type == 'removeall' ) {
+                       } else if ( $verb == 'removeall' ) {
                                $wom = WOMProcessor::getPageObject( 
$articleTitle, $rid );
                                foreach ( $objs as $id ) {
                                        if ( $id == '' ) continue;
@@ -76,13 +76,13 @@
                                if ( is_null( $params['value'] ) )
                                        $this->dieUsage( 'Must specify value', 
2 );
 
-                               if ( $type == 'insert' ) {
+                               if ( $verb == 'insert' ) {
                                        WOMProcessor::insertPageText( $value, 
$articleTitle, $oid, $summary, $rid, $force_update );
-                               } else if ( $type == 'update' ) {
+                               } else if ( $verb == 'update' ) {
                                        WOMProcessor::updatePageText( $value, 
$articleTitle, $oid, $summary, $rid, $force_update );
-                               } else if ( $type == 'append' ) {
+                               } else if ( $verb == 'append' ) {
                                        WOMProcessor::appendPageText( $value, 
$articleTitle, $oid, $summary, $rid, $force_update );
-                               } else if ( $type == 'attribute' ) {
+                               } else if ( $verb == 'attribute' ) {
                                        $wom = WOMProcessor::getPageObject( 
$articleTitle, $rid );
                                        $obj = $wom->getObject( $oid );
                                        $kv = explode( '=', $value, 2 );
@@ -119,7 +119,7 @@
        protected function getAllowedParams() {
                return array (
                        'page' => null,
-                       'type' => array(
+                       'verb' => array(
                                ApiBase :: PARAM_DFLT => 'update',
                                ApiBase :: PARAM_TYPE => array(
                                        'update',
@@ -141,10 +141,10 @@
                 ApiBase :: PARAM_MIN => 0
             ),
                        'force_update' => array(
-                               ApiBase :: PARAM_DFLT => 'true',
+                               ApiBase :: PARAM_DFLT => '1',
                                ApiBase :: PARAM_TYPE => array(
-                                       'true',
-                                       'false',
+                                       '1',
+                                       '0',
                                ),
                        ),
                );
@@ -153,23 +153,27 @@
        protected function getParamDescription() {
                return array (
                        'page' => 'Title of the page to modify',
-                       'type' => 'Type to set to change wiki object instances',
+                       'verb' => 'Action verb to set to change wiki object 
instances',
                        'xpath' => array(
                                'DOM-like xpath to locate WOM object instances 
(http://www.w3schools.com/xpath/xpath_syntax.asp)',
-                               'type = update, xpath to elements to be 
updated',
-                               'type = attribute, xpath to elements, the 
attribute will be updated',
-                               'type = insert, the element will be inserted 
right before the element specified by xpath',
-                               'type = append, the element will be appended 
right to the element children elements specified by xpath',
-                               'type = remove, xpath to element to be removed',
-                               'type = removeall, xpath to elements to be 
removed',
+                               'verb = update, xpath to elements to be 
updated',
+                               'verb = attribute, xpath to elements, the 
attribute will be updated',
+                               'verb = insert, the element will be inserted 
right before the element specified by xpath',
+                               'verb = append, the element will be appended 
right to the element children elements specified by xpath',
+                               'verb = remove, xpath to element to be removed',
+                               'verb = removeall, xpath to elements to be 
removed',
                        ),
                        'value' => array(
                                'Value to set',
-                               'type = attribute, 
attribute_name=attribute_value',
+                               'verb = attribute, 
attribute_name=attribute_value',
                        ),
                        'summary' => 'Edit summary',
                        'rid' => 'Revision id of specified page - by dafault 
latest updated revision (0) is used',
-                       'force_update' => 'Force to update even if the revision 
id does not match the latest edition',
+                       'force_update' => array(
+                               'Force to update even if the revision id does 
not match the latest edition',
+                               'force_update = 0, return "revision not match" 
exception if rid is not the latest one',
+                               'force_update = 1, update anyway',
+                       ),
                );
        }
 

Modified: trunk/extensions/WikiObjectModel/includes/models/WOMFactory.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOMFactory.php     
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOMFactory.php     
2011-06-16 08:45:37 UTC (rev 90196)
@@ -1,9 +1,9 @@
 <?php
 /**
  * This file contains the WikiObjectModelFactory class.
- * 
+ *
  * @author Ning
- * 
+ *
  * @file
  * @ingroup WikiObjectModels
  */
@@ -12,14 +12,14 @@
 
        /**
         * Array of type labels indexed by type ids. Used for model type 
resolution.
-        * 
+        *
         * @var array
         */
        static private $mTypeLabels;
 
        /**
         * Array of class names for creating new WikiObjectModel, indexed by 
type id.
-        * 
+        *
         * @var array of WikiObjectModel
         */
        static private $mTypeClasses;
@@ -27,9 +27,9 @@
        /**
         * Create a value from a type id. If no $value is given, an empty 
container
         * is created, the value of which can be set later on.
-        * 
+        *
         * @param $typeid id string for the given type
-        * 
+        *
         * @return WikiObjectModel
         */
        static public function newTypeIDValue( $typeid ) {
@@ -78,7 +78,7 @@
        /**
         * A function for registering/overwriting pomtypes for WOM. Should be
         * called from within the hook 'mwInitWOMTypes'.
-        * 
+        *
         * @param string $id
         * @param string $className
         * @param mixed $label
@@ -100,7 +100,7 @@
         *
         * This method may or may not take aliases into account. For unknown
         * labels, the normalised (DB-version) label is used as an ID.
-        * 
+        *
         * @param string $label
         */
        static public function findTypeID( $label ) {
@@ -118,7 +118,7 @@
         * Get the translated user label for a given internal ID. If the ID does
         * not have a label associated with it in the current language, the ID
         * itself is transformed into a label (appropriate for user defined 
types).
-        * 
+        *
         * @param string $id
         */
        static public function findTypeLabel( $id ) {
@@ -142,7 +142,7 @@
         * a property, and that are internal (i.e. not user defined). No labels 
are
         * returned for internal types without user labels (e.g. the special 
types
         * for wome special properties), and for user defined types.
-        * 
+        *
         * @return array
         */
        static public function getKnownTypeLabels() {

Modified: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Category.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Category.php        
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Category.php        
2011-06-16 08:45:37 UTC (rev 90196)
@@ -5,7 +5,7 @@
  * @author Ning
  * @file
  * @ingroup WikiObjectModels
- * 
+ *
  */
 
 class WOMCategoryModel extends WikiObjectModel {
@@ -13,13 +13,19 @@
 
        public function __construct( $name ) {
                parent::__construct( WOM_TYPE_CATEGORY );
-               $this->m_name = $name;
+               $title = Title::newFromText( $name, NS_CATEGORY );
+               if ( $title == null ) {
+                       // no idea why, just leave it
+                       $this->m_name = $name;
+               } else {
+                       $this->m_name = $title->getText();
+               }
        }
 
        public function getName() {
                return $this->m_name;
        }
-       
+
        public function setName( $name ) {
                $this->m_name = $name;
        }

Modified: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_HTMLTag.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOM_OM_HTMLTag.php 
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOM_OM_HTMLTag.php 
2011-06-16 08:45:37 UTC (rev 90196)
@@ -5,7 +5,7 @@
  * @author Ning
  * @file
  * @ingroup WikiObjectModels
- * 
+ *
  */
 
 class WOMHTMLTagModel extends WikiObjectModelCollection {
@@ -21,7 +21,7 @@
        public function getName() {
                return $this->m_name;
        }
-       
+
        public function setName( $name ) {
                $this->m_name = $name;
        }
@@ -29,11 +29,11 @@
        public function getAttributes() {
                return $this->m_attributes;
        }
-       
+
        public function setAttributes( $attrs ) {
                $this->m_attributes = $attrs;
        }
-       
+
        public function getWikiText() {
                return "<{$this->m_name}>" . parent::getWikiText() . 
"</{$this->m_name}>";
        }

Modified: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Link.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Link.php    
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Link.php    
2011-06-16 08:45:37 UTC (rev 90196)
@@ -5,14 +5,14 @@
  * @author Ning
  * @file
  * @ingroup WikiObjectModels
- * 
+ *
  */
 
 class WOMLinkModel extends WikiObjectModel {
        protected $m_link;
        protected $m_caption;
 
-       public function __construct( $link, $caption = '' ) {
+       public function __construct( $link, $caption = null ) {
                parent::__construct( WOM_TYPE_LINK );
                $this->m_link = $link;
                $this->m_caption = $caption;
@@ -31,11 +31,11 @@
        public function setLink( $link ) {
                $this->m_link = $link;
        }
-       
+
        public function getCaption() {
                return $this->m_caption;
        }
-       
+
        public function setCaption( $caption ) {
                $this->m_caption = $caption;
        }
@@ -44,14 +44,18 @@
                if ( $this->isInline() ) {
                        return "[[{$this->m_link}" . ( $this->m_caption ? 
"|{$this->m_caption}" : "" ) . "]]";
                } else {
-                       return "[{$this->m_link}" . ( $this->m_caption ? " 
{$this->m_caption}" : "" ) . "]";
+                       if ( $this->m_caption === null ) {
+                               return $this->m_link;
+                       } else {
+                               return "[{$this->m_link}" . ( $this->m_caption 
? " {$this->m_caption}" : "" ) . "]";
+                       }
                }
        }
 
        protected function getXMLContent() {
                return "
-<url>{$this->m_link}</url>
-<caption>{$this->m_caption}</caption>
+<url><![CDATA[{$this->m_link}]]></url>
+<caption><![CDATA[{$this->m_caption}]]></caption>
 ";
        }
 }

Modified: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_ListItem.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOM_OM_ListItem.php        
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOM_OM_ListItem.php        
2011-06-16 08:45:37 UTC (rev 90196)
@@ -5,7 +5,7 @@
  * @author Ning
  * @file
  * @ingroup WikiObjectModels
- * 
+ *
  */
 
 class WOMListItemModel extends WikiObjectModelCollection {

Modified: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_MagicWord.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOM_OM_MagicWord.php       
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOM_OM_MagicWord.php       
2011-06-16 08:45:37 UTC (rev 90196)
@@ -5,27 +5,29 @@
  * @author Ning
  * @file
  * @ingroup WikiObjectModels
- * 
+ *
  */
 
 class WOMMagicWordModel extends WikiObjectModel {
        protected $m_magicword;
+       protected $m_doubleUnderscore;
 
-       public function __construct( $magicword ) {
+       public function __construct( $magicword, $doubleUnderscore = false ) {
                parent::__construct( WOM_TYPE_MAGICWORD );
                $this->m_magicword = $magicword;
+               $this->m_doubleUnderscore = $doubleUnderscore;
        }
 
        public function getMagicWord() {
                return $this->m_magicword;
        }
-       
+
        public function setMagicWord( $magicword ) {
                $this->m_magicword = $magicword;
        }
 
        public function getWikiText() {
-               return "{{{$this->m_magicword}}}";
+               return $this->m_doubleUnderscore ? $this->m_magicword : 
"{{{$this->m_magicword}}}";
        }
 
        public function setXMLAttribute( $key, $value ) {

Modified: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Page.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Page.php    
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Page.php    
2011-06-16 08:45:37 UTC (rev 90196)
@@ -66,16 +66,20 @@
        }
 
        public function appendChildObject( WikiObjectModel $obj, $id = '' ) {
-               $p = $this->m_page_objs[$id];
-               if ( !( $p instanceof WikiObjectModelCollection ) ) {
-                       return;
+               if ( $id == '' ) {
+                       $p = $this;
+               } else {
+                       $p = $this->m_page_objs[$id];
+                       if ( !( $p instanceof WikiObjectModelCollection ) ) {
+                               return;
+                       }
                }
                $obj->setObjectID( $this->getNextId() );
                $p->insertObject( $obj );
 
                $this->addToPageObjectSet( $obj );
        }
-       
+
        public function removePageObject( $id ) {
                $old_obj = $this->m_page_objs[$id];
                if ( $old_obj == null ) return;

Modified: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_ParamValue.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOM_OM_ParamValue.php      
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOM_OM_ParamValue.php      
2011-06-16 08:45:37 UTC (rev 90196)
@@ -5,7 +5,7 @@
  * @author Ning
  * @file
  * @ingroup WikiObjectModels
- * 
+ *
  */
 
 class WOMParamValueModel extends WikiObjectModelCollection {

Modified: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Parameter.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Parameter.php       
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Parameter.php       
2011-06-16 08:45:37 UTC (rev 90196)
@@ -5,7 +5,7 @@
  * @author Ning
  * @file
  * @ingroup WikiObjectModels
- * 
+ *
  */
 
 class WOMParameterModel extends WikiObjectModelCollection {

Modified: 
trunk/extensions/WikiObjectModel/includes/models/WOM_OM_ParserFunction.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOM_OM_ParserFunction.php  
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOM_OM_ParserFunction.php  
2011-06-16 08:45:37 UTC (rev 90196)
@@ -5,7 +5,7 @@
  * @author Ning
  * @file
  * @ingroup WikiObjectModels
- * 
+ *
  */
 class WOMParserFunctionModel extends WikiObjectModelCollection {
        protected $m_function_key;

Modified: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Property.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Property.php        
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Property.php        
2011-06-16 08:45:37 UTC (rev 90196)
@@ -5,12 +5,13 @@
  * @author Ning
  * @file
  * @ingroup WikiObjectModels
- * 
+ *
  */
 
 class WOMPropertyModel extends WikiObjectModel {
        protected $m_property; // name
        protected $m_smwdatavalue; // value, caption, type
+       protected $m_visible;
 
        public function __construct( $property, $value, $caption = '' ) {
                parent::__construct( WOM_TYPE_PROPERTY );
@@ -25,6 +26,7 @@
 
                $this->m_property = $property;
                $this->m_smwdatavalue = $smwdatavalue;
+               $this->m_visible = !preg_match( '/\s+/', $caption );
        }
 
        public function getProperty() {
@@ -34,7 +36,7 @@
        public function setProperty( $property ) {
                $this->m_property = $property;
        }
-       
+
        public function getSMWDataValue() {
                return $this->m_smwdatavalue;
        }
@@ -42,12 +44,14 @@
        public function setSMWDataValue( $smwdatavalue ) {
                $this->m_smwdatavalue = $smwdatavalue;
        }
-       
+
        public function getWikiText() {
                $res = 
"[[{$this->getPropertyName()}::{$this->getPropertyValue()}";
                if ( $this->getPropertyValue() != $this->getCaption()
                        && $this->getCaption() != '' ) {
                                $res .= "|{$this->getCaption()}";
+               } else if ( !$this->m_visible ) {
+                       $res .= "| ";
                }
                $res .= "]]";
 

Modified: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Section.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Section.php 
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Section.php 
2011-06-16 08:45:37 UTC (rev 90196)
@@ -5,7 +5,7 @@
  * @author Ning
  * @file
  * @ingroup WikiObjectModels
- * 
+ *
  */
 
 class WOMSectionModel extends WikiObjectModelCollection {
@@ -27,7 +27,7 @@
        public function setName( $name ) {
                $this->m_name = $name;
        }
-       
+
        public function getLevel() {
                return $this->m_level;
        }
@@ -35,9 +35,9 @@
        public function setLevel( $level ) {
                $this->m_level = $level;
        }
-       
+
        public function getHeaderText() {
-//             return "\n" . 
+//             return "\n" .
                return substr( WOMSectionModel::$heading, 0, $this->m_level ) .
                        $this->m_name .
                        substr( WOMSectionModel::$heading, 0, $this->m_level ) .
@@ -47,7 +47,7 @@
        public function getWikiText() {
                return $this->getHeaderText() . parent::getWikiText();
        }
-       
+
        public function getContent() {
                return parent::getWikiText();
        }

Modified: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Sentence.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Sentence.php        
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Sentence.php        
2011-06-16 08:45:37 UTC (rev 90196)
@@ -5,7 +5,7 @@
  * @author Ning
  * @file
  * @ingroup WikiObjectModels
- * 
+ *
  */
 
 class WOMSentenceModel extends WikiObjectModelCollection {

Modified: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Table.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Table.php   
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Table.php   
2011-06-16 08:45:37 UTC (rev 90196)
@@ -5,7 +5,7 @@
  * @author Ning
  * @file
  * @ingroup WikiObjectModels
- * 
+ *
  */
 
 class WOMTableModel extends WikiObjectModelCollection {
@@ -24,8 +24,20 @@
        public function setStyle( $style ) {
                $this->m_style = $style;
        }
-       
+
        public function getWikiText() {
                return "{| {$this->m_style}" . parent::getWikiText() . "\n|}";
        }
+
+       public function setXMLAttribute( $key, $value ) {
+               if ( $key == 'style' ) {
+                       $this->m_style = $value;
+                       return;
+               }
+               throw new MWException( __METHOD__ . ": invalid key/value pair: 
style=table_style" );
+       }
+
+       protected function getXMLAttributes() {
+               return "style=\"{$this->m_style}\"";
+       }
 }

Modified: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_TblCell.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOM_OM_TblCell.php 
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOM_OM_TblCell.php 
2011-06-16 08:45:37 UTC (rev 90196)
@@ -5,7 +5,7 @@
  * @author Ning
  * @file
  * @ingroup WikiObjectModels
- * 
+ *
  */
 
 class WOMTableCellModel extends WikiObjectModelCollection {
@@ -21,7 +21,7 @@
        public function getPrefix() {
                return $this->m_prefix;
        }
-       
+
        public function setPrefix( $prefix ) {
                $this->m_prefix = $prefix;
        }
@@ -29,4 +29,20 @@
        public function getWikiText() {
                return "{$this->m_prefix}" . parent::getWikiText();
        }
+
+       public function setXMLAttribute( $key, $value ) {
+               if ( $value == '' ) throw new MWException( __METHOD__ . ": 
value cannot be empty" );
+
+               $value = str_replace( '\n', "\n", $value );
+               if ( $key == 'prefix' ) {
+                       $this->m_prefix = $value;
+                       return;
+               }
+               throw new MWException( __METHOD__ . ": invalid key/value pair: 
prefix=table_cell_prefix (! / | / ||)" );
+       }
+
+       protected function getXMLAttributes() {
+               $prefix = str_replace( "\n", '\n', $this->m_prefix );
+               return "prefix=\"{$prefix}\"";
+       }
 }

Modified: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Template.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Template.php        
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Template.php        
2011-06-16 08:45:37 UTC (rev 90196)
@@ -5,7 +5,7 @@
  * @author Ning
  * @file
  * @ingroup WikiObjectModels
- * 
+ *
  */
 
 class WOMTemplateModel extends WikiObjectModelCollection {
@@ -20,10 +20,10 @@
 
                if ( $this->m_title->getNamespace() == NS_MAIN ) {
                        // http://www.mediawiki.org/wiki/Help:Transclusion
-                       // If the source is in the Main article namespace 
(e.g., "Cat"), 
+                       // If the source is in the Main article namespace 
(e.g., "Cat"),
                        // you must put a colon (:) in front of the name, thus: 
{{:Cat}}
 
-                       // If the source is in the Template namespace (e.g., 
"Template:Villagepumppages"), 
+                       // If the source is in the Template namespace (e.g., 
"Template:Villagepumppages"),
                        // just use the name itself, alone, thus: 
{{Villagepumppages}}
                        if ( $this->m_name { 0 } != ':' ) {
                                $this->m_title = Title::makeTitleSafe( 
NS_TEMPLATE, $this->m_name );
@@ -34,7 +34,7 @@
        public function getName() {
                return $this->m_name;
        }
-       
+
        public function setName( $name ) {
                $this->m_name = $name;
        }

Modified: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Text.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Text.php    
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Text.php    
2011-06-16 08:45:37 UTC (rev 90196)
@@ -5,7 +5,7 @@
  * @author Ning
  * @file
  * @ingroup WikiObjectModels
- * 
+ *
  */
 
 class WOMTextModel extends WikiObjectModel {
@@ -29,6 +29,6 @@
        }
 
        public function toXML() {
-               return htmlentities( $this->m_text );
+               return htmlspecialchars( $this->m_text );
        }
 }

Modified: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_TmplField.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/models/WOM_OM_TmplField.php       
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/models/WOM_OM_TmplField.php       
2011-06-16 08:45:37 UTC (rev 90196)
@@ -5,7 +5,7 @@
  * @author Ning
  * @file
  * @ingroup WikiObjectModels
- * 
+ *
  */
 
 class WOMTemplateFieldModel extends WOMParameterModel {

Modified: trunk/extensions/WikiObjectModel/includes/parsers/WOMHTMLTagParser.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/parsers/WOMHTMLTagParser.php      
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/parsers/WOMHTMLTagParser.php      
2011-06-16 08:45:37 UTC (rev 90196)
@@ -24,7 +24,7 @@
                        $closed = false;
                        if ( isset( $m[2] ) ) {
                                $attr = $m[2];
-                               $closed = ( $attr { strlen( $attr ) - 1 } == 
'/' );
+                               $closed = ( $attr != '' && $attr { strlen( 
$attr ) - 1 } == '/' );
                                if ( $closed ) $attr = substr( $attr, 0, 
strlen( $attr ) - 1 );
                                while ( preg_match( '/^\s*([\w]+)\s*=\s*/', 
$attr, $m1 ) ) {
                                        $attr = substr( $attr, strlen( $m1[0] ) 
);

Modified: trunk/extensions/WikiObjectModel/includes/parsers/WOMLinkParser.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/parsers/WOMLinkParser.php 
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/parsers/WOMLinkParser.php 
2011-06-16 08:45:37 UTC (rev 90196)
@@ -20,12 +20,12 @@
                if ( $r && !preg_match( '/^(?:' . wfUrlProtocols() . ')/', 
$m[1] ) ) {
                        return array( 'len' => strlen( $m[0] ), 'obj' => new 
WOMLinkModel( $m[1], isset( $m[3] ) ? $m[3] : '' ) );
                }
-               $r = preg_match( '/^\[((?:' . wfUrlProtocols() . ')[^ 
\[\]]+)(\s+([^\]]+))?\]/', $text, $m );
+               $r = preg_match( '/^\[((?:' . wfUrlProtocols() . ')[^ 
\]]+)(\s+([^\]]+))?\]/', $text, $m );
                if ( $r ) {
                        return array( 'len' => strlen( $m[0] ), 'obj' => new 
WOMLinkModel( $m[1], isset( $m[3] ) ? $m[3] : '' ) );
                }
                // includes/Parser.php Parser->doMagicLinks
-               $r = preg_match( '/^(?:' . wfUrlProtocols() . 
')[^][<>"\\x00-\\x20\\x7F]+/', $text, $m );
+               $r = preg_match( '/^(?:' . wfUrlProtocols() . 
')[^][<>"|\\x00-\\x20\\x7F]+/', $text, $m );
                if ( $r ) {
                        return array( 'len' => strlen( $m[0] ), 'obj' => new 
WOMLinkModel( $m[0] ) );
                }

Modified: 
trunk/extensions/WikiObjectModel/includes/parsers/WOMListItemParser.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/parsers/WOMListItemParser.php     
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/parsers/WOMListItemParser.php     
2011-06-16 08:45:37 UTC (rev 90196)
@@ -16,9 +16,9 @@
        public function parseNext( $text, WikiObjectModelCollection $parentObj, 
$offset = 0 ) {
                $lastLF = ( $offset == 0 || $text { $offset - 1 } == "\n" );
                $text = substr( $text, $offset );
-               if ( $lastLF ) {
-                       $r = preg_match( '/^([\*#]+)/', $text, $m );
-               }
+               if ( !$lastLF ) return null;
+
+               $r = preg_match( '/^([\*#]+)/', $text, $m );
                if ( $r ) {
                        $len = strlen( $m[0] );
                        $obj = new WOMListItemModel( $m[1] );

Modified: 
trunk/extensions/WikiObjectModel/includes/parsers/WOMMagicWordParser.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/parsers/WOMMagicWordParser.php    
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/parsers/WOMMagicWordParser.php    
2011-06-16 08:45:37 UTC (rev 90196)
@@ -13,8 +13,45 @@
                $this->m_parserId = WOM_PARSER_ID_MAGICWORD;
        }
 
+       static $underscores = array( '0' => '', '1' => '' );
+       static $mwa = null;
+       static function getDoubleUnderscoreRegex() {
+               if ( WOMMagicWordParser::$mwa === null ) {
+                       WOMMagicWordParser::$mwa = 
MagicWord::getDoubleUnderscoreArray();
+                       foreach ( WOMMagicWordParser::$mwa->names as $name ) {
+                               $magic = MagicWord::get( $name );
+                               $case = intval( $magic->isCaseSensitive() );
+                               foreach ( $magic->getSynonyms() as $i => $syn ) 
{
+                                       $group = '(' . preg_quote( $syn, '/' ) 
. ')';
+                                       if ( 
WOMMagicWordParser::$underscores[$case] === '' ) {
+                                               
WOMMagicWordParser::$underscores[$case] = $group;
+                                       } else {
+                                               
WOMMagicWordParser::$underscores[$case] .= '|' . $group;
+                                       }
+                               }
+                       }
+                       if ( WOMMagicWordParser::$underscores[0] !== '' ) {
+                               WOMMagicWordParser::$underscores[0] = "/^(" . 
WOMMagicWordParser::$underscores[0] . ")/i";
+                       }
+                       if ( WOMMagicWordParser::$underscores[1] !== '' ) {
+                               WOMMagicWordParser::$underscores[1] = "/^(" . 
WOMMagicWordParser::$underscores[1] . ")/";
+                       }
+               }
+               return WOMMagicWordParser::$underscores;
+       }
        public function parseNext( $text, WikiObjectModelCollection $parentObj, 
$offset = 0 ) {
                $text = substr( $text, $offset );
+
+               $regex = WOMMagicWordParser::getDoubleUnderscoreRegex();
+               foreach ( $regex as $reg ) {
+                       if ( $reg === '' ) continue;
+                       $r = preg_match( $reg, $text, $m );
+                       if ( $r ) {
+                               $len = strlen( $m[0] );
+                               $magicword = trim( $m[0] );
+                               return array( 'len' => $len, 'obj' => new 
WOMMagicWordModel( $magicword, true ) );
+                       }
+               }
                $r = preg_match( '/^\{\{([^{|}]+)\}\}/', $text, $m );
 
                if ( $r ) {

Modified: 
trunk/extensions/WikiObjectModel/includes/parsers/WOMParamValueParser.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/parsers/WOMParamValueParser.php   
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/parsers/WOMParamValueParser.php   
2011-06-16 08:45:37 UTC (rev 90196)
@@ -17,7 +17,7 @@
                if ( !( $parentObj instanceof WOMParameterModel ) )
                        return null;
 
-               return array( 'len' => $len, 'obj' => new WOMParamValueModel() 
);
+               return array( 'len' => 0, 'obj' => new WOMParamValueModel() );
        }
 
        public function isObjectClosed( $obj, $text, $offset ) {

Modified: 
trunk/extensions/WikiObjectModel/includes/parsers/WOMParameterParser.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/parsers/WOMParameterParser.php    
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/parsers/WOMParameterParser.php    
2011-06-16 08:45:37 UTC (rev 90196)
@@ -37,11 +37,11 @@
                        return array( 'len' => $len, 'obj' => new 
WOMParameterModel( $key ) );
                }
        }
-       
+
        public function getSubParserID() {
                return WOM_PARSER_ID_PARAM_VALUE;
        }
-       
+
        public function isObjectClosed( $obj, $text, $offset ) {
                if ( !( ( $obj instanceof WOMTemplateFieldModel )
                        || ( $obj instanceof WOMParameterModel ) ) )

Modified: trunk/extensions/WikiObjectModel/includes/parsers/WOMSectionParser.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/parsers/WOMSectionParser.php      
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/parsers/WOMSectionParser.php      
2011-06-16 08:45:37 UTC (rev 90196)
@@ -18,9 +18,9 @@
        public function parseNext( $text, WikiObjectModelCollection $parentObj, 
$offset = 0 ) {
                $lastLF = ( $offset == 0 || $text { $offset - 1 } == "\n" );
                $text = substr( $text, $offset );
-               if ( $lastLF ) {
-                       $r = preg_match( '/^(={1,6})/', $text, $m );
-               }
+               if ( !$lastLF ) return null;
+
+               $r = preg_match( '/^(={1,6})/', $text, $m );
                if ( $r ) {
                        $text1 = substr( $text, strlen( $m[0] ) );
                        $s = explode( "\n", $text1, 2 );
@@ -30,9 +30,9 @@
                                $len = strlen( $m[0] ) + strlen( $s[0] ) + 1/* 
\n */;
                                $level = strlen( $m[1] ) < strlen( $m1[1][0] ) 
? strlen( $m[1] ) : strlen( $m1[1][0] );
 
-                               $obj = new WOMSectionModel(
+                               $obj = new WOMSectionModel( trim(
                                        substr( WOMSectionParser::$heading, 0, 
strlen( $m[1] ) - $level ) .
-                                               substr( $s[0], 0, $m1[1][1] + 
strlen( $m1[1][0] ) - $level ),
+                                               substr( $s[0], 0, $m1[1][1] + 
strlen( $m1[1][0] ) - $level ) ),
                                        $level );
 
                                while ( $parentObj != null &&

Modified: trunk/extensions/WikiObjectModel/includes/parsers/WOMTblCellParser.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/parsers/WOMTblCellParser.php      
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/parsers/WOMTblCellParser.php      
2011-06-16 08:45:37 UTC (rev 90196)
@@ -13,39 +13,65 @@
                $this->m_parserId = WOM_PARSER_ID_TABLECELL;
        }
 
+       private function getFirstLineChar( $text, $offset ) {
+               for ( $i = $offset; $i >= 0; --$i ) {
+                       if ( $text { $i } == "\n" ) {
+                               $s = substr( $text, $i );
+                               if ( preg_match( '/^\s*([!|])/', $s, $m ) ) {
+                                       return $m[1];
+                               }
+                               break;
+                       }
+               }
+
+               return '';
+       }
        // FIXME: what if table cell style uses parser function which contains 
'return' or '|'
        public function parseNext( $text, WikiObjectModelCollection $parentObj, 
$offset = 0 ) {
                if ( !( $parentObj instanceof WOMTableModel ) ) return null;
 
                $lastLF = ( $text { $offset } == "\n" || ( $offset == 0 || 
$text { $offset - 1 } == "\n" ) );
+               // get the first char of current line
+               $fch = $this->getFirstLineChar( $text, $offset );
+               if ( $fch == '' ) return null;
+
                $text = substr( $text, $offset );
-               
-               $r = preg_match( '/^(!!|\|\||(\s*(\|\+|\|-|[!|])))/', $text, $m 
);
+
+               $r = preg_match( '/^(' . ( ( $fch == '!' ) ? '!!|' : '' ) . 
'\|\||(\s*(\|\+|\|-|[!|])))/', $text, $m );
                if ( !$r ) return null;
 
                if ( isset( $m[2] ) && !$lastLF ) return null;
-               
+
                $len = strlen( $m[0] );
                $text = substr( $text, $len );
-               $r = preg_match( '/^[^\n|]*\|/', $text, $m1 );
-
-               if ( $r && preg_match( '/\{\{/', $m1[0] ) ) {
+               $r = preg_match( '/^([^\n|]*\|)[^|]/', $text, $m1 );
+               if ( !$r || preg_match( '/\{\{/', $m1[1] ) ) {
                        // FIXME: what if matched style contains '{{', just 
think it is table body
-                       return array( 'len' => strlen( $m[0] ), 'obj' => new 
WOMTableCellModel( $m[0] ) );
+                       return array( 'len' => $len, 'obj' => new 
WOMTableCellModel( $m[0] ) );
                }
 
-               return array( 'len' => strlen( $m[0] ) + strlen( $m1[0] ), 
'obj' => new WOMTableCellModel( $m[0] . $m1[0] ) );
+               if ( $fch == '!' ) {
+                       $pos = strpos( $text, '!!', $len );
+                       if ( $pos !== false && $pos < strlen( $m1[1] ) ) {
+                               return array( 'len' => $len, 'obj' => new 
WOMTableCellModel( $m[0] ) );
+                       }
+               }
+
+               return array( 'len' => $len + strlen( $m1[1] ), 'obj' => new 
WOMTableCellModel( $m[0] . $m1[1] ) );
        }
 
        public function isObjectClosed( $obj, $text, $offset ) {
                if ( !( $obj instanceof WOMTableCellModel ) ) return false;
-               
+
+               $fch = $this->getFirstLineChar( $text, $offset );
+
                $lastLF = ( $text { $offset } == "\n" || ( $offset == 0 || 
$text { $offset - 1 } == "\n" ) );
-               
+
                $text = substr( $text, $offset );
                if ( strlen( $text ) == 0 ) return 0;
                if ( $lastLF && preg_match( '/^(\s*[!|])/', $text ) ) return 0;
-               if ( preg_match( '/^(!!)|(\|\|)/', $text ) ) return 0;
+               if ( $fch == '' ) return false;
+               if ( preg_match( '/^(' . ( ( $fch == '!' ) ? '!!|':'' ) . 
'\|\|)/', $text ) ) return 0;
 
                return false;
        }

Modified: 
trunk/extensions/WikiObjectModel/includes/parsers/WikiObjectModelParser.php
===================================================================
--- trunk/extensions/WikiObjectModel/includes/parsers/WikiObjectModelParser.php 
2011-06-16 07:10:51 UTC (rev 90195)
+++ trunk/extensions/WikiObjectModel/includes/parsers/WikiObjectModelParser.php 
2011-06-16 08:45:37 UTC (rev 90196)
@@ -1,7 +1,7 @@
 <?php
 /**
  * File holding class WikiObjectModelParser, the base for all object model 
parser in WOM.
- * 
+ *
  * Deal plain text only, just get next text token
  *
  * @author Ning
@@ -34,7 +34,7 @@
 // /// Processing methods /////
        public function parseNext( $text, WikiObjectModelCollection $parentObj, 
$offset = 0 ) {
                $text = substr( $text, $offset );
-               $r = preg_match( '/^\w+/', $text, $m );
+               $r = preg_match( '/^[a-zA-Z0-9]+/', $text, $m );
                if ( $r ) return array( 'len' => strlen( $m[0] ), 'obj' => new 
WOMTextModel( $m[0] ) );
                // special case, <nowiki>, <noinclude>
                $idx = stripos( $text, '<nowiki>' );
@@ -53,7 +53,7 @@
                return array( 'len' => 1, 'obj' => new WOMTextModel( $text { 0 
} ) );
        }
 
-       // E.g., 
+       // E.g.,
        // semantic property is extended from internal links
        // parser functions is extended from templates
        public function subclassOf( $parserInstance ) {


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to