r114119 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114118‎ | r114119 | r114120 >
Date:00:35, 19 March 2012
Author:ning
Status:new
Tags:
Comment:
More object model support, smw ask query, mw redirect, etc.
Modified paths:
  • /trunk/extensions/WikiObjectModel/WikiObjectModel.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/WOM_Processor.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/WOM_Setup.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/apis/SRF_Xml.php (added) (history)
  • /trunk/extensions/WikiObjectModel/includes/apis/WOM_GetObjectModel.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/apis/WOM_GetWikiResult.php (added) (history)
  • /trunk/extensions/WikiObjectModel/includes/apis/WOM_OutputObjectModel.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/apis/WOM_OutputProcessor.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/models/WOM_OM_HTMLTag.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Parameter.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Property.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Redirect.php (added) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMAskParser.php (added) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMCategoryParser.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMHTMLTagParser.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMLinkParser.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMListItemParser.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMMagicWordParser.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMParamValueParser.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMParameterParser.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMParserFunctionParameterParser.php (added) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMParserFunctionParser.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMPropertyParser.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMPropertyValueParser.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMRedirectParser.php (added) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMSectionParser.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMTableParser.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMTblCellParser.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMTemplateFieldHolderParser.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WOMTemplateParser.php (modified) (history)
  • /trunk/extensions/WikiObjectModel/includes/parsers/WikiObjectModelParser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiObjectModel/WikiObjectModel.php
@@ -6,26 +6,17 @@
77 */
88 if ( !defined( 'MEDIAWIKI' ) ) die;
99
10 -define( 'WOM_VERSION', '1.0.1 alpha' );
 10+define( 'WOM_VERSION', '1.0.2 alpha' );
1111
12 -$wgExtensionCredits['parserhook'][] = array(
13 - 'path' => __FILE__,
14 - 'name' => 'Wiki ObjectModel Extension',
15 - 'version' => WOM_VERSION,
16 - 'author' => "Ning Hu, Justin Zhang, [http://smwforum.ontoprise.com/smwforum/index.php/Jesse_Wang Jesse Wang], sponsored by [http://projecthalo.com Project Halo], [http://www.vulcan.com Vulcan Inc.]",
17 - 'url' => 'http://wiking.vulcan.com/dev',
18 - 'descriptionmsg' => 'wom-desc'
19 -);
20 -
2112 $wgOMIP = $IP . '/extensions/WikiObjectModel';
2213 $wgOMScriptPath = $wgScriptPath . '/extensions/WikiObjectModel';
2314
24 -$wgExtensionFunctions[] = 'smwfOMInitLanguage';
 15+$wgExtensionFunctions[] = 'wfWOMSetupExtension';
2516 $wgExtensionMessagesFiles['WikiObjectModel'] = $wgOMIP . '/languages/Messages.php';
2617
2718 require_once( $wgOMIP . '/includes/WOM_Setup.php' );
2819
29 -function smwfOMInitLanguageObject( $langcode, $fallback = null ) {
 20+function wfWOMInitLanguageObject( $langcode, $fallback = null ) {
3021 global $wgOMIP;
3122
3223 $langClass = 'WOMLanguage' . str_replace( '-', '_', ucfirst( $langcode ) );
@@ -45,10 +36,34 @@
4637 return new $langClass();
4738 }
4839
49 -function smwfOMInitLanguage() {
 40+function wfWOMInitLanguage() {
5041 global $wgLanguageCode, $wgLang;
5142 global $wgOMContLang, $wgOMLang;
5243
53 - $wgOMContLang = smwfOMInitLanguageObject( $wgLanguageCode );
54 - $wgOMLang = smwfOMInitLanguageObject( $wgLang->getCode(), $wgOMContLang );
 44+ $wgOMContLang = wfWOMInitLanguageObject( $wgLanguageCode );
 45+ $wgOMLang = wfWOMInitLanguageObject( $wgLang->getCode(), $wgOMContLang );
5546 }
 47+
 48+function wfWOMRegisterParserFunctionParsers( &$parsers ) {
 49+ global $wgOMPFParsers;
 50+ $parsers += $wgOMPFParsers;
 51+ return true;
 52+}
 53+
 54+function wfWOMSetupExtension() {
 55+ global $wgHooks, $wgExtensionCredits;
 56+
 57+ wfWOMInitLanguage();
 58+
 59+ $wgHooks['womRegisterParserFunctionParsers'][] = 'wfWOMRegisterParserFunctionParsers';
 60+
 61+ $wgExtensionCredits['parserhook'][] = array(
 62+ 'path' => __FILE__,
 63+ 'name' => 'Wiki ObjectModel Extension',
 64+ 'version' => WOM_VERSION,
 65+ 'author' => "Ning Hu, Justin Zhang, [http://smwforum.ontoprise.com/smwforum/index.php/Jesse_Wang Jesse Wang], sponsored by [http://projecthalo.com Project Halo], [http://www.vulcan.com Vulcan Inc.]",
 66+ 'url' => 'http://wiking.vulcan.com/dev',
 67+ 'descriptionmsg' => 'wom-desc'
 68+ );
 69+ return true;
 70+}
\ No newline at end of file
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMListItemParser.php
@@ -13,6 +13,10 @@
1414 $this->m_parserId = WOM_PARSER_ID_LISTITEM;
1515 }
1616
 17+ public function getValidModelTypes() {
 18+ return array( WOM_TYPE_LISTITEM );
 19+ }
 20+
1721 public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) {
1822 $lastLF = ( $offset == 0 || $text { $offset - 1 } == "\n" );
1923 $text = substr( $text, $offset );
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMLinkParser.php
@@ -13,6 +13,10 @@
1414 $this->m_parserId = WOM_PARSER_ID_LINK;
1515 }
1616
 17+ public function getValidModelTypes() {
 18+ return array( WOM_TYPE_LINK );
 19+ }
 20+
1721 public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) {
1822 $text = substr( $text, $offset );
1923
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMParamValueParser.php
@@ -13,6 +13,10 @@
1414 $this->m_parserId = WOM_PARSER_ID_PARAM_VALUE;
1515 }
1616
 17+ public function getValidModelTypes() {
 18+ return array( WOM_TYPE_PARAM_VALUE );
 19+ }
 20+
1721 public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) {
1822 if ( !( ( $parentObj instanceof WOMParameterModel )
1923 || ( $parentObj instanceof WOMTemplateFieldHolderModel ) ) )
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMHTMLTagParser.php
@@ -13,6 +13,10 @@
1414 $this->m_parserId = WOM_PARSER_ID_HTMLTAG;
1515 }
1616
 17+ public function getValidModelTypes() {
 18+ return array( WOM_TYPE_HTMLTAG );
 19+ }
 20+
1721 public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) {
1822 $text = substr( $text, $offset );
1923 // this is not a proper html tag regex, for strings include char '>'
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMRedirectParser.php
@@ -0,0 +1,33 @@
 2+<?php
 3+/**
 4+ * @author Ning
 5+ *
 6+ * @file
 7+ * @ingroup WikiObjectModels
 8+ */
 9+
 10+class WOMRedirectParser extends WikiObjectModelParser {
 11+
 12+ public function __construct() {
 13+ parent::__construct();
 14+ $this->m_parserId = WOM_PARSER_ID_REDIRECT;
 15+ }
 16+
 17+ public function getValidModelTypes() {
 18+ return array( WOM_TYPE_REDIRECT );
 19+ }
 20+
 21+ public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) {
 22+ if ( $offset != 0 ) return null;
 23+
 24+ $redirect = MagicWord::get( 'redirect' );
 25+ if ( !preg_match( '/^\s*(?:' . $redirect->getBaseRegex() . ')/' . $redirect->getRegexCase(), $text, $m ) )
 26+ return null;
 27+ $len = strlen( $m[0] );
 28+ $text = substr( $text, $len );
 29+ if ( !preg_match( '/^\s*\[\[:?(.*?)(\|(.*?))*\]\]/', $text, $m ) )
 30+ return null;
 31+
 32+ return array( 'len' => $len + strlen( $m[0] ), 'obj' => new WOMRedirectModel( $m[1] ) );
 33+ }
 34+}
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMParserFunctionParser.php
@@ -13,6 +13,10 @@
1414 $this->m_parserId = WOM_PARSER_ID_PARSERFUNCTION;
1515 }
1616
 17+ public function getValidModelTypes() {
 18+ return array( WOM_TYPE_PARSERFUNCTION );
 19+ }
 20+
1721 public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) {
1822 $text = substr( $text, $offset );
1923 $r = preg_match( '/^\{\{\s*#([^\{\|\}:]+):/', $text, $m );
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMParserFunctionParameterParser.php
@@ -0,0 +1,59 @@
 2+<?php
 3+/**
 4+ * @author Ning
 5+ *
 6+ * @file
 7+ * @ingroup WikiObjectModels
 8+ */
 9+
 10+abstract class WOMParserFunctionParameterParser {
 11+ protected $m_parserId;
 12+
 13+ /**
 14+ * Array of error text messages. Private to allow us to track error insertion
 15+ * (PHP's count() is too slow when called often) by using $mHasErrors.
 16+ * @var array
 17+ */
 18+ protected $mErrors = array();
 19+
 20+ /**
 21+ * Boolean indicating if there where any errors.
 22+ * Should be modified accordingly when modifying $mErrors.
 23+ * @var boolean
 24+ */
 25+ protected $mHasErrors = false;
 26+
 27+// /// Processing methods /////
 28+ public abstract function parseParserFunctionParameter ( $text, WikiObjectModelCollection $parentObj );
 29+
 30+ public abstract function validate( $obj );
 31+
 32+ public abstract function getValidModelTypes();
 33+
 34+// /// Get methods /////
 35+ public function getParserID() {
 36+ return $this->m_parserId;
 37+ }
 38+
 39+ // specified next parser. e.g., template parser -> parameter parser
 40+ public function getSubParserID( $obj ) { return ''; }
 41+
 42+ /**
 43+ * Return a string that displays all error messages as a tooltip, or
 44+ * an empty string if no errors happened.
 45+ */
 46+ public function getErrorText() {
 47+ if ( defined( 'SMW_VERSION' ) )
 48+ return smwfEncodeMessages( $this->mErrors );
 49+
 50+ return $this->mErrors;
 51+ }
 52+
 53+ /**
 54+ * Return an array of error messages, or an empty array
 55+ * if no errors occurred.
 56+ */
 57+ public function getErrors() {
 58+ return $this->mErrors;
 59+ }
 60+}
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMSectionParser.php
@@ -15,6 +15,10 @@
1616 $this->m_parserId = WOM_PARSER_ID_SECTION;
1717 }
1818
 19+ public function getValidModelTypes() {
 20+ return array( WOM_TYPE_SECTION );
 21+ }
 22+
1923 public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) {
2024 $lastLF = ( $offset == 0 || $text { $offset - 1 } == "\n" );
2125 $text = substr( $text, $offset );
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMTemplateParser.php
@@ -13,6 +13,10 @@
1414 $this->m_parserId = WOM_PARSER_ID_TEMPLATE;
1515 }
1616
 17+ public function getValidModelTypes() {
 18+ return array( WOM_TYPE_TEMPLATE );
 19+ }
 20+
1721 public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) {
1822 $text = substr( $text, $offset );
1923 $r = preg_match( '/^(\{\{([^{|}]+))([|}])/', $text, $m );
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMMagicWordParser.php
@@ -13,6 +13,10 @@
1414 $this->m_parserId = WOM_PARSER_ID_MAGICWORD;
1515 }
1616
 17+ public function getValidModelTypes() {
 18+ return array( WOM_TYPE_MAGICWORD );
 19+ }
 20+
1721 static $underscores = array( '0' => '', '1' => '' );
1822 static $mwa = null;
1923 static function getDoubleUnderscoreRegex() {
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMTemplateFieldHolderParser.php
@@ -13,6 +13,10 @@
1414 $this->m_parserId = WOM_PARSER_ID_TEMPLATE_FIELD_HOLDER;
1515 }
1616
 17+ public function getValidModelTypes() {
 18+ return array( WOM_TYPE_TMPL_FIELD_HOLDER );
 19+ }
 20+
1721 public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) {
1822 $text = substr( $text, $offset );
1923 $r = preg_match( '/^(\{\{\{([^{|}]+))([|}])/', $text, $m );
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMCategoryParser.php
@@ -13,6 +13,10 @@
1414 $this->m_parserId = WOM_PARSER_ID_CATEGORY;
1515 }
1616
 17+ public function getValidModelTypes() {
 18+ return array( WOM_TYPE_CATEGORY );
 19+ }
 20+
1721 public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) {
1822 $text = substr( $text, $offset );
1923 global $wgContLang;
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMAskParser.php
@@ -0,0 +1,67 @@
 2+<?php
 3+/**
 4+ * @author Ning
 5+ *
 6+ * @file
 7+ * @ingroup WikiObjectModels
 8+ */
 9+
 10+class WOMAskParser extends WOMParserFunctionParameterParser {
 11+
 12+ public function __construct() {
 13+ $this->m_parserId = WOM_PFPARSER_ID_ASK;
 14+ }
 15+
 16+ public function getValidModelTypes() {
 17+ return array(
 18+ WOM_TYPE_QUERYSTRING,
 19+ WOM_TYPE_QUERYPRINTOUT
 20+ );
 21+ }
 22+
 23+ private function parseAskParameters ( $text, WikiObjectModelCollection $parentObj ) {
 24+ if ( defined( 'SMW_AGGREGATION_VERSION' ) ) {
 25+ $r = preg_match( '/^(\s*\?([^>=|}]+)(?:\>([^=|}]*))?(?:=([^|}]*))?)(\||\}|$)/', $text, $m );
 26+ if ( !$r ) return null;
 27+ return array(
 28+ 'len' => strlen( $m[5] == '|' ? $m[0] : $m[1] ),
 29+ 'obj' => new WOMQueryPrintoutModel( trim( $m[2] ), trim( $m[4] ), trim( $m[3] ) ) );
 30+ } else {
 31+ $r = preg_match( '/^(\s*\?([^=|}]+)(?:=([^|}]*))?)(\||\}|$)/', $text, $m );
 32+ if ( !$r ) return null;
 33+ return array(
 34+ 'len' => strlen( $m[4] == '|' ? $m[0] : $m[1] ),
 35+ 'obj' => new WOMQueryPrintoutModel( trim( $m[2] ), trim( $m[3] ) ) );
 36+ }
 37+ }
 38+
 39+ public function parseParserFunctionParameter ( $text, WikiObjectModelCollection $parentObj ) {
 40+ if ( !defined( 'SMW_VERSION' )
 41+ || !( $parentObj instanceof WOMParserFunctionModel ) )
 42+ return null;
 43+
 44+ if ( trim( strtolower( $parentObj->getFunctionKey() ) ) != 'ask' ) return null;
 45+
 46+ if ( count ( $parentObj->getObjects() ) == 0 ) {
 47+ return array( 'len' => 0, 'obj' => new WOMQuerystringModel() );
 48+ }
 49+
 50+ return $this->parseAskParameters( $text, $parentObj );
 51+ }
 52+
 53+ public function getSubParserID( $obj ) {
 54+ if ( ( $obj instanceof WOMQuerystringModel )
 55+ || ( $obj instanceof WOMQueryPrintoutModel ) )
 56+ return '';
 57+
 58+ return null;
 59+ }
 60+
 61+ public function validate ( $obj ) {
 62+ if ( !( ( $obj instanceof WOMQuerystringModel )
 63+ || ( $obj instanceof WOMQueryPrintoutModel ) ) )
 64+ return false;
 65+
 66+ return true;
 67+ }
 68+}
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMParameterParser.php
@@ -13,28 +13,8 @@
1414 $this->m_parserId = WOM_PARSER_ID_PARAMETER;
1515 }
1616
17 - private function parseAsk ( $text, WikiObjectModelCollection $parentObj ) {
18 - if ( !defined( 'SMW_VERSION' ) ) return null;
19 -
20 - if ( trim( strtolower( $parentObj->getFunctionKey() ) ) != 'ask' ) return null;
21 -
22 - if ( count ( $parentObj->getObjects() ) == 0 ) {
23 - return array( 'len' => 0, 'obj' => new WOMQuerystringModel() );
24 - }
25 -
26 - if ( defined( 'SMW_AGGREGATION_VERSION' ) ) {
27 - $r = preg_match( '/^(\s*\?([^>=|}]+)(?:\>([^=|}]*))?(?:=([^|}]*))?)(\||\}|$)/', $text, $m );
28 - if ( !$r ) return null;
29 - return array(
30 - 'len' => strlen( $m[5] == '|' ? $m[0] : $m[1] ),
31 - 'obj' => new WOMQueryPrintoutModel( trim( $m[2] ), trim( $m[4] ), trim( $m[3] ) ) );
32 - } else {
33 - $r = preg_match( '/^(\s*\?([^=|}]+)(?:=([^|}]*))?)(\||\}|$)/', $text, $m );
34 - if ( !$r ) return null;
35 - return array(
36 - 'len' => strlen( $m[4] == '|' ? $m[0] : $m[1] ),
37 - 'obj' => new WOMQueryPrintoutModel( trim( $m[2] ), trim( $m[3] ) ) );
38 - }
 17+ public function getValidModelTypes() {
 18+ return array( WOM_TYPE_PARAMETER, WOM_TYPE_TMPL_FIELD );
3919 }
4020
4121 public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) {
@@ -44,8 +24,12 @@
4525
4626 $text = substr( $text, $offset );
4727
48 - $ret = $this->parseAsk ( $text, $parentObj );
49 - if ( $ret != null ) return $ret;
 28+ if ( $parentObj instanceof WOMParserFunctionModel ) {
 29+ foreach ( WOMProcessor::$parserFuncParsers as $p ) {
 30+ $ret = $p->parseParserFunctionParameter ( $text, $parentObj );
 31+ if ( $ret != null ) return $ret;
 32+ }
 33+ }
5034
5135 $r = preg_match( '/^([^=|}]*)(\||=|\}|$)/', $text, $m );
5236 if ( !$r ) return null;
@@ -67,18 +51,26 @@
6852 }
6953
7054 public function getSubParserID( $obj ) {
71 - if ( ( $obj instanceof WOMQuerystringModel )
72 - || ( $obj instanceof WOMQueryPrintoutModel ) )
73 - return '';
 55+ foreach ( WOMProcessor::$parserFuncParsers as $p ) {
 56+ $ret = $p->getSubParserID ( $obj );
 57+ if ( $ret !== null ) return $ret;
 58+ }
7459
7560 return WOM_PARSER_ID_PARAM_VALUE;
7661 }
7762
7863 public function isObjectClosed( $obj, $text, $offset ) {
79 - if ( !( ( $obj instanceof WOMTemplateFieldModel )
80 - || ( $obj instanceof WOMParameterModel )
81 - || ( $obj instanceof WOMQuerystringModel )
82 - || ( $obj instanceof WOMQueryPrintoutModel ) ) )
 64+ $valid = false;
 65+ foreach ( WOMProcessor::$parserFuncParsers as $p ) {
 66+ if ( $p->validate ( $obj ) ) {
 67+ $valid = true;
 68+ break;
 69+ }
 70+ }
 71+
 72+ if ( !( $valid ||
 73+ ( $obj instanceof WOMTemplateFieldModel ) ||
 74+ ( $obj instanceof WOMParameterModel ) ) )
8375 return false;
8476
8577 if ( ( strlen( $text ) >= $offset + 1 ) && $text { $offset } == '|' ) {
@@ -86,7 +78,10 @@
8779 }
8880 $parentClose = WOMProcessor::getObjectParser( $obj->getParent() )
8981 ->isObjectClosed( $obj->getParent(), $text, $offset );
90 - if ( $parentClose !== false ) return 0;
 82+ if ( $parentClose !== false ) {
 83+ $obj->setPipe( false );
 84+ return 0;
 85+ }
9186
9287 return false;
9388 }
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMPropertyValueParser.php
@@ -13,6 +13,10 @@
1414 $this->m_parserId = WOM_PARSER_ID_PROPERTY_VALUE;
1515 }
1616
 17+ public function getValidModelTypes() {
 18+ return array( WOM_TYPE_NESTPROPERTYVAL );
 19+ }
 20+
1721 public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) {
1822 if ( !( $parentObj instanceof WOMNestPropertyModel ) )
1923 return null;
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMTblCellParser.php
@@ -13,6 +13,10 @@
1414 $this->m_parserId = WOM_PARSER_ID_TABLECELL;
1515 }
1616
 17+ public function getValidModelTypes() {
 18+ return array( WOM_TYPE_TBL_CELL );
 19+ }
 20+
1721 private function getFirstLineChar( $text, $offset ) {
1822 for ( $i = $offset; $i >= 0; --$i ) {
1923 if ( $text { $i } == "\n" ) {
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMPropertyParser.php
@@ -14,6 +14,10 @@
1515 $this->m_parserId = WOM_PARSER_ID_PROPERTY;
1616 }
1717
 18+ public function getValidModelTypes() {
 19+ return array( WOM_TYPE_PROPERTY, WOM_TYPE_NESTPROPERTY );
 20+ }
 21+
1822 public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) {
1923 if ( !defined( 'SMW_VERSION' ) ) {
2024 return null;
@@ -21,6 +25,26 @@
2226
2327 $text = substr( $text, $offset );
2428
 29+ global $smwgRecursivePropertyValues;
 30+
 31+ $inQuerystring = false;
 32+ $o = $parentObj;
 33+ do {
 34+ if ( $o instanceof WOMQuerystringModel ) {
 35+ $inQuerystring = true;
 36+ break;
 37+ }
 38+ $o = $o->getParent();
 39+ } while ( $o != null );
 40+
 41+ if ( $inQuerystring || $smwgRecursivePropertyValues ) {
 42+ $semanticPropPattern = '/^\[\[ # Beginning of the link
 43+ (?:([^:][^][]*?):[=:]) # Property name (or a list of those)
 44+ /xu';
 45+ if ( !preg_match( $semanticPropPattern, $text, $m ) ) return null;
 46+
 47+ return array( 'len' => strlen( $m[0] ), 'obj' => new WOMNestPropertyModel( $m[1] ) );
 48+ }
2549 // copied from SemanticMediaWiki, includes/SMW_ParserExtensions.php
2650 // not deal with <nowiki>, could be bug here. SMW has the same bug
2751 // E.g., [[text::this <nowiki> is ]] </nowiki> not good]]
@@ -45,24 +69,6 @@
4670 // }
4771 $r = preg_match( $semanticLinkPattern, $text, $m );
4872 if ( $r ) {
49 - $inQuerystring = false;
50 - $o = $parentObj;
51 - do {
52 - if ( $o instanceof WOMQuerystringModel ) {
53 - $inQuerystring = true;
54 - break;
55 - }
56 - $o = $o->getParent();
57 - } while ( $o != null );
58 -
59 - if ( $inQuerystring ) {
60 - $semanticPropPattern = '/\[\[ # Beginning of the link
61 - (?:([^:][^][]*):[=:])+ # Property name (or a list of those)
62 - /xu';
63 - preg_match( $semanticPropPattern, $text, $m );
64 - return array( 'len' => strlen( $m[0] ), 'obj' => new WOMNestPropertyModel( $m[1] ) );
65 - }
66 -
6773 return array( 'len' => strlen( $m[0] ), 'obj' => new WOMPropertyModel( $m[1], $m[2], isset( $m[3] ) ? $m[3] : '' ) );
6874 }
6975 return null;
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMTableParser.php
@@ -13,6 +13,10 @@
1414 $this->m_parserId = WOM_PARSER_ID_TABLE;
1515 }
1616
 17+ public function getValidModelTypes() {
 18+ return array( WOM_TYPE_TABLE );
 19+ }
 20+
1721 // FIXME: what if table style uses parser function which contains 'return'
1822 public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) {
1923 $text = substr( $text, $offset );
Index: trunk/extensions/WikiObjectModel/includes/parsers/WikiObjectModelParser.php
@@ -53,6 +53,10 @@
5454 return array( 'len' => 1, 'obj' => new WOMTextModel( $text { 0 } ) );
5555 }
5656
 57+ public function getValidModelTypes() {
 58+ return array( WOM_TYPE_TEXT );
 59+ }
 60+
5761 // E.g.,
5862 // semantic property is extended from internal links
5963 // parser functions is extended from templates
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Parameter.php
@@ -10,20 +10,26 @@
1111
1212 class WOMParameterModel extends WikiObjectModelCollection {
1313 protected $m_key;
 14+ protected $m_pipe;
1415
1516 public function __construct( $key = '' ) {
1617 parent::__construct( WOM_TYPE_PARAMETER );
1718 $this->m_key = $key;
 19+ $this->m_pipe = true;
1820 }
1921
2022 public function getKey() {
2123 return $this->m_key;
2224 }
2325
 26+ public function setPipe( $pipe ) {
 27+ $this->m_pipe = $pipe;
 28+ }
 29+
2430 public function getWikiText() {
2531 return ( $this->m_key == '' ? "" : ( $this->m_key . '=' ) ) .
2632 $this->getValueText() .
27 - '|';
 33+ ( $this->m_pipe ? '|' : '' );
2834 }
2935
3036 public function getValueText() {
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Property.php
@@ -72,7 +72,11 @@
7373 }
7474
7575 public function getWikiText() {
76 - $res = "[[{$this->getPropertyName()}::{$this->getPropertyValue()}";
 76+ $value = $this->getPropertyValue();
 77+ if ( substr( $value, 0, 1 ) == ':' ) {
 78+ $value = ' ' . $value;
 79+ }
 80+ $res = "[[{$this->getPropertyName()}::{$value}";
7781 if ( $this->getPropertyValue() != $this->getCaption()
7882 && $this->getCaption() != '' ) {
7983 $res .= "|{$this->getCaption()}";
@@ -89,7 +93,7 @@
9094 }
9195
9296 public function getPropertyValue() {
93 - return $this->m_smwdatavalue == null ? $this->m_value : $this->m_smwdatavalue->getWikiValue();
 97+ return trim( $this->m_smwdatavalue == null ? $this->m_value : $this->m_smwdatavalue->getWikiValue() );
9498 }
9599
96100 public function getCaption() {
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_HTMLTag.php
@@ -22,7 +22,7 @@
2323 return $this->m_name;
2424 }
2525
26 - public function setName( $name ) {
 26+ public function setTagName( $name ) {
2727 $this->m_name = $name;
2828 }
2929
@@ -37,6 +37,7 @@
3838 $v = preg_replace( '/^[\'"](.*)[\'"]$/', '$1', $v );
3939 if ( $attr == $a ) return $v;
4040 }
 41+ return null;
4142 }
4243
4344 public function setAttributes( $attrs ) {
@@ -62,14 +63,14 @@
6364 public function setXMLAttribute( $key, $value ) {
6465 if ( $value == '' ) throw new MWException( __METHOD__ . ": value cannot be empty" );
6566
66 - if ( $key == 'name' ) {
 67+ if ( $key == 'tag' ) {
6768 $this->m_name = $value;
6869 } else {
69 - throw new MWException( __METHOD__ . ": invalid key/value pair: name=html_tag_name" );
 70+ $attrs[$key] = $value;
7071 }
7172 }
7273 protected function getXMLAttributes() {
73 - $ret = 'name="' . self::xml_entities( $this->m_name ) . '"';
 74+ $ret = 'tag="' . self::xml_entities( $this->m_name ) . '"';
7475 foreach ( $this->m_attrs as $a => $v ) {
7576 $v = preg_replace( '/^"(.*)"$/', '$1', $v );
7677 if ( $a == 'id' ) $a = 'tag_id';
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Redirect.php
@@ -0,0 +1,29 @@
 2+<?php
 3+/**
 4+ * This model implements redirect models.
 5+ *
 6+ * #REDIRECT [[Pagename]]
 7+ * Consider that #REDIRECT can be localized.
 8+ *
 9+ * @author Ning
 10+ * @file
 11+ * @ingroup WikiObjectModels
 12+ *
 13+ */
 14+
 15+class WOMRedirectModel extends WikiObjectModel {
 16+ private $m_to_page;
 17+
 18+ public function __construct( $to_page ) {
 19+ parent::__construct( WOM_TYPE_REDIRECT );
 20+ $this->m_to_page = $to_page;
 21+ }
 22+
 23+ public function getWikiText() {
 24+ return '#REDIRECT [[' . $this->m_to_page . ']]';
 25+ }
 26+
 27+ protected function getXMLContent() {
 28+ return "<![CDATA[{$this->m_to_page}]]>";
 29+ }
 30+}
Index: trunk/extensions/WikiObjectModel/includes/WOM_Processor.php
@@ -14,7 +14,10 @@
1515 private static $isParsersRegistered = false;
1616 private static $parsers = array();
1717 private static $base_parser;
 18+ private static $modelParserMapping = array();
1819
 20+ public static $parserFuncParsers = array();
 21+
1922 private static function setupParsers() {
2023 if ( self::$isParsersRegistered ) return;
2124
@@ -22,9 +25,33 @@
2326 foreach ( $wgOMParsers as $p ) {
2427 $parser = new $p();
2528 self::$parsers[$parser->getParserID()] = $parser;
 29+ foreach ( $parser->getValidModelTypes() as $type ) {
 30+ self::$modelParserMapping[$type] = $parser->getParserID();
 31+ }
2632 }
2733 self::$base_parser = self::$parsers[WOM_PARSER_ID_TEXT];
2834
 35+ $parsers = array();
 36+ if ( wfRunHooks ( 'womRegisterParsers', array ( &$parsers ) ) ) {
 37+ foreach ( $parsers as $p ) {
 38+ $parser = new $p();
 39+ self::$parsers[$parser->getParserID()] = $parser;
 40+ foreach ( $parser->getValidModelTypes() as $type ) {
 41+ self::$modelParserMapping[$type] = $parser->getParserID();
 42+ }
 43+ }
 44+ }
 45+ $parsers = array();
 46+ if ( wfRunHooks ( 'womRegisterParserFunctionParsers', array ( &$parsers ) ) ) {
 47+ foreach ( $parsers as $p ) {
 48+ $parser = new $p();
 49+ self::$parserFuncParsers[$parser->getParserID()] = $parser;
 50+ foreach ( $parser->getValidModelTypes() as $type ) {
 51+ self::$modelParserMapping[$type] = WOM_PARSER_ID_PARAMETER;
 52+ }
 53+ }
 54+ }
 55+
2956 self::$isParsersRegistered = true;
3057 }
3158
@@ -35,9 +62,8 @@
3663 if ( !self::$isParsersRegistered ) {
3764 self::setupParsers();
3865 }
39 - global $wgOMModelParserMapping;
40 - if ( isset( $wgOMModelParserMapping[$obj->getTypeID()] ) ) {
41 - $id = $wgOMModelParserMapping[$obj->getTypeID()];
 66+ if ( isset( self::$modelParserMapping[$obj->getTypeID()] ) ) {
 67+ $id = self::$modelParserMapping[$obj->getTypeID()];
4268 if ( isset( self::$parsers[$id] ) ) {
4369 wfProfileOut( $fname );
4470 return self::$parsers[$id];
@@ -119,7 +145,10 @@
120146 if ( $obj->getTypeID() == WOM_TYPE_HTMLTAG ) {
121147 // special case, html tag
122148 } elseif ( $obj instanceof WikiObjectModelCollection ) {
123 - self::parseParagraphs( $obj );
 149+ // FIXME: hardcode, for querystring object
 150+ if ( $obj->getTypeID() != WOM_TYPE_QUERYSTRING ) {
 151+ self::parseParagraphs( $obj );
 152+ }
124153 }
125154 $new_objs[] = $obj;
126155 }
@@ -180,7 +209,10 @@
181210 if ( $obj->getTypeID() == WOM_TYPE_HTMLTAG ) {
182211 // special case, html tag
183212 } elseif ( $obj instanceof WikiObjectModelCollection ) {
184 - self::parseSentences( $obj );
 213+ // FIXME: hardcode, for querystring object
 214+ if ( $obj->getTypeID() != WOM_TYPE_QUERYSTRING ) {
 215+ self::parseSentences( $obj );
 216+ }
185217 }
186218 $new_objs[] = $obj;
187219 }
@@ -230,7 +262,9 @@
231263 foreach ( self::$parsers as $parser ) {
232264 $parser_res = $parser->parseNext( $text, $parentObj, $offset );
233265 if ( $parser_res == null ) continue;
234 - if ( $parserInstance == null || $parser->subclassOf( $parserInstance ) ) {
 266+ if ( ( $parserInstance == null || $parser->subclassOf( $parserInstance ) ) ||
 267+ ( $result != null && $parser_res['len'] > $result['len'] ) ) {
 268+
235269 $parserInstance = $parser;
236270 $result = $parser_res;
237271 }
Index: trunk/extensions/WikiObjectModel/includes/WOM_Setup.php
@@ -14,8 +14,6 @@
1515 $wgAutoloadClasses['WOMTemplateModel'] = $wgOMIP . '/includes/models/WOM_OM_Template.php';
1616 $wgAutoloadClasses['WOMParserFunctionModel'] = $wgOMIP . '/includes/models/WOM_OM_ParserFunction.php';
1717 $wgAutoloadClasses['WOMParameterModel'] = $wgOMIP . '/includes/models/WOM_OM_Parameter.php';
18 -$wgAutoloadClasses['WOMQuerystringModel'] = $wgOMIP . '/includes/models/WOM_OM_Querystring.php';
19 -$wgAutoloadClasses['WOMQueryPrintoutModel'] = $wgOMIP . '/includes/models/WOM_OM_QueryPrintout.php';
2018 $wgAutoloadClasses['WOMParamValueModel'] = $wgOMIP . '/includes/models/WOM_OM_ParamValue.php';
2119 $wgAutoloadClasses['WOMTemplateFieldModel'] = $wgOMIP . '/includes/models/WOM_OM_TmplField.php';
2220 $wgAutoloadClasses['WOMPropertyModel'] = $wgOMIP . '/includes/models/WOM_OM_Property.php';
@@ -32,6 +30,7 @@
3331 $wgAutoloadClasses['WOMMagicWordModel'] = $wgOMIP . '/includes/models/WOM_OM_MagicWord.php';
3432 $wgAutoloadClasses['WOMHTMLTagModel'] = $wgOMIP . '/includes/models/WOM_OM_HTMLTag.php';
3533 $wgAutoloadClasses['WOMTemplateFieldHolderModel'] = $wgOMIP . '/includes/models/WOM_OM_TmplFieldHolder.php';
 34+$wgAutoloadClasses['WOMRedirectModel'] = $wgOMIP . '/includes/models/WOM_OM_Redirect.php';
3635
3736 // Definitions
3837 define( 'WOM_TYPE_PAGE' , 'page' );
@@ -45,8 +44,6 @@
4645 define( 'WOM_TYPE_TEMPLATE' , 'template' );
4746 define( 'WOM_TYPE_PARSERFUNCTION' , 'parser_function' );
4847 define( 'WOM_TYPE_PARAMETER' , 'parameter' );
49 -define( 'WOM_TYPE_QUERYSTRING' , 'querystring' );
50 -define( 'WOM_TYPE_QUERYPRINTOUT' , 'printout' );
5148 define( 'WOM_TYPE_PARAM_VALUE' , 'value' );
5249 define( 'WOM_TYPE_TMPL_FIELD' , 'template_field' );
5350 define( 'WOM_TYPE_SENTENCE' , 'sentence' );
@@ -57,6 +54,7 @@
5855 define( 'WOM_TYPE_MAGICWORD' , 'magicword' );
5956 define( 'WOM_TYPE_HTMLTAG' , 'html' );
6057 define( 'WOM_TYPE_TMPL_FIELD_HOLDER', 'template_field_holder' );
 58+define( 'WOM_TYPE_REDIRECT' , 'redirect' );
6159
6260 // POM Parser
6361 $wgAutoloadClasses['WikiObjectModelParser'] = $wgOMIP . '/includes/parsers/WikiObjectModelParser.php';
@@ -76,6 +74,7 @@
7775 $wgAutoloadClasses['WOMMagicWordParser'] = $wgOMIP . '/includes/parsers/WOMMagicWordParser.php';
7876 $wgAutoloadClasses['WOMHTMLTagParser'] = $wgOMIP . '/includes/parsers/WOMHTMLTagParser.php';
7977 $wgAutoloadClasses['WOMTemplateFieldHolderParser'] = $wgOMIP . '/includes/parsers/WOMTemplateFieldHolderParser.php';
 78+$wgAutoloadClasses['WOMRedirectParser'] = $wgOMIP . '/includes/parsers/WOMRedirectParser.php';
8079
8180 // Definitions
8281 define( 'WOM_PARSER_ID_CATEGORY' , 'category' );
@@ -94,6 +93,7 @@
9594 define( 'WOM_PARSER_ID_MAGICWORD' , 'magicword' );
9695 define( 'WOM_PARSER_ID_HTMLTAG' , 'html' );
9796 define( 'WOM_PARSER_ID_TEMPLATE_FIELD_HOLDER', 'template_field_holder' );
 97+define( 'WOM_PARSER_ID_REDIRECT' , 'redirect' );
9898
9999 global $wgOMParsers, $wgOMModelParserMapping;
100100 $wgOMParsers = array(
@@ -113,29 +113,21 @@
114114 'WOMMagicWordParser',
115115 'WOMHTMLTagParser',
116116 'WOMTemplateFieldHolderParser',
 117+ 'WOMRedirectParser',
117118 );
118119
119 -$wgOMModelParserMapping = array(
120 - WOM_TYPE_TEXT => WOM_PARSER_ID_TEXT,
121 - WOM_TYPE_CATEGORY => WOM_PARSER_ID_CATEGORY,
122 - WOM_TYPE_SECTION => WOM_PARSER_ID_SECTION,
123 - WOM_TYPE_PROPERTY => WOM_PARSER_ID_PROPERTY,
124 - WOM_TYPE_NESTPROPERTY => WOM_PARSER_ID_PROPERTY,
125 - WOM_TYPE_NESTPROPERTYVAL => WOM_PARSER_ID_PROPERTY_VALUE,
126 - WOM_TYPE_LINK => WOM_PARSER_ID_LINK,
127 - WOM_TYPE_TEMPLATE => WOM_PARSER_ID_TEMPLATE,
128 - WOM_TYPE_PARSERFUNCTION => WOM_PARSER_ID_PARSERFUNCTION,
129 - WOM_TYPE_PARAMETER => WOM_PARSER_ID_PARAMETER,
130 - WOM_TYPE_TMPL_FIELD => WOM_PARSER_ID_PARAMETER,
131 - WOM_TYPE_QUERYSTRING => WOM_PARSER_ID_PARAMETER,
132 - WOM_TYPE_QUERYPRINTOUT => WOM_PARSER_ID_PARAMETER,
133 - WOM_TYPE_PARAM_VALUE => WOM_PARSER_ID_PARAM_VALUE,
134 - WOM_TYPE_LISTITEM => WOM_PARSER_ID_LISTITEM,
135 - WOM_TYPE_TABLE => WOM_PARSER_ID_TABLE,
136 - WOM_TYPE_TBL_CELL => WOM_PARSER_ID_TABLECELL,
137 - WOM_TYPE_MAGICWORD => WOM_PARSER_ID_MAGICWORD,
138 - WOM_TYPE_HTMLTAG => WOM_PARSER_ID_HTMLTAG,
139 - WOM_TYPE_TMPL_FIELD_HOLDER => WOM_PARSER_ID_TEMPLATE_FIELD_HOLDER,
 120+// Parser function parameter
 121+$wgAutoloadClasses['WOMQuerystringModel'] = $wgOMIP . '/includes/models/WOM_OM_Querystring.php';
 122+$wgAutoloadClasses['WOMQueryPrintoutModel'] = $wgOMIP . '/includes/models/WOM_OM_QueryPrintout.php';
 123+define( 'WOM_TYPE_QUERYSTRING' , 'querystring' );
 124+define( 'WOM_TYPE_QUERYPRINTOUT' , 'printout' );
 125+
 126+$wgAutoloadClasses['WOMParserFunctionParameterParser'] = $wgOMIP . '/includes/parsers/WOMParserFunctionParameterParser.php';
 127+
 128+$wgAutoloadClasses['WOMAskParser'] = $wgOMIP . '/includes/parsers/WOMAskParser.php';
 129+define( 'WOM_PFPARSER_ID_ASK' , 'ask' );
 130+$wgOMPFParsers = array(
 131+ 'WOMAskParser',
140132 );
141133
142134 global $wgOMSentenceObjectTypes;
@@ -164,4 +156,5 @@
165157 $wgAutoloadClasses['ApiWOMQuery'] = $wgOMIP . '/includes/apis/WOM_Query.php';
166158 $wgAPIModules['womoutput'] = 'ApiWOMOutputObjectModel';
167159 $wgAutoloadClasses['ApiWOMOutputObjectModel'] = $wgOMIP . '/includes/apis/WOM_OutputObjectModel.php';
168 -
 160+$wgAPIModules['womwiki'] = 'ApiWOMGetWikiResult';
 161+$wgAutoloadClasses['ApiWOMGetWikiResult'] = $wgOMIP . '/includes/apis/WOM_GetWikiResult.php';
Index: trunk/extensions/WikiObjectModel/includes/apis/WOM_GetObjectModel.php
@@ -33,7 +33,8 @@
3434 $this->dieUsage( "Article doesn't exist ($page_name)", 3 );
3535
3636 try {
37 - $objs = WOMProcessor::getObjIdByXPath( $articleTitle, $xpath, $rid );
 37+ $page_obj = WOMProcessor::getPageObject( $articleTitle, $rid );
 38+ $objs = WOMProcessor::getObjIdByXPath2( $page_obj, $xpath );
3839 } catch ( Exception $e ) {
3940 $err = $e->getMessage();
4041 }
@@ -48,6 +49,7 @@
4950 $this->getResult()->setContent( $result['message'], $err );
5051 } else {
5152 $result['result'] = 'Success';
 53+ $result['revisionID'] = $page_obj->getRevisionID();
5254
5355 // pay attention to special xml tag, e.g., <property><value>...</value></property>
5456 $result['return'] = array();
@@ -60,7 +62,6 @@
6163 $this->getResult()->setContent( $result['return'], $count );
6264 } else {
6365 $xml = '';
64 - $page_obj = WOMProcessor::getPageObject( $articleTitle, $rid );
6566 foreach ( $objs as $id ) {
6667 if ( $id == '' ) continue;
6768 $wobj = $page_obj->getObject( $id );
@@ -76,7 +77,7 @@
7778 header ( "Content-Type: application/rdf+xml" );
7879 echo <<<OUTPUT
7980 <?xml version="1.0" encoding="UTF-8" ?>
80 -<api><womget result="Success"><return>
 81+<api><womget result="Success" revisionID="{$page_obj->getRevisionID()}"><return>
8182 {$xml}
8283 </return></womget></api>
8384 OUTPUT;
Index: trunk/extensions/WikiObjectModel/includes/apis/SRF_Xml.php
@@ -0,0 +1,44 @@
 2+<?php
 3+/**
 4+ * A query printer for xml
 5+ *
 6+ * @note AUTOLOADED
 7+ */
 8+
 9+if ( !defined( 'MEDIAWIKI' ) ) {
 10+ die( 'Not an entry point.' );
 11+}
 12+
 13+class SRFXml extends SMWResultPrinter {
 14+ protected function getResultText( $res, $outputmode ) {
 15+ $xml = '';
 16+ if ( $this->mShowHeaders != SMW_HEADERS_HIDE ) {
 17+ $xml .= '<head>' . "\n";
 18+ foreach ( $res->getPrintRequests() as $pr ) {
 19+ $xml .= "<item>{$pr->getText( $outputmode, null )}</item>\n";
 20+ }
 21+ $xml .= '</head>' . "\n";
 22+ }
 23+
 24+ $xml .= '<res>' . "\n";
 25+ // print all result rows
 26+ while ( $row = $res->getNext() ) {
 27+ $xml .= '<row>' . "\n";
 28+ $firstcol = true;
 29+ foreach ( $row as $field ) {
 30+ $xml .= '<item>' . "\n";
 31+ $growing = array();
 32+ while ( ( $object = $field->getNextObject() ) !== false ) {
 33+ $text = Sanitizer::decodeCharReferences( $object->getWikiValue() );
 34+ $growing[] = $text;
 35+ } // while...
 36+ $xml .= implode( ',', $growing );
 37+ $xml .= '</item>' . "\n";
 38+ } // foreach...
 39+ $xml .= '</row>' . "\n";
 40+ }
 41+ $xml .= '</res>' . "\n";
 42+
 43+ return $xml;
 44+ }
 45+}
\ No newline at end of file
Index: trunk/extensions/WikiObjectModel/includes/apis/WOM_OutputObjectModel.php
@@ -38,8 +38,8 @@
3939 if ( !$article->exists() )
4040 $this->dieUsage( "Article doesn't exist ($page_name)", 3 );
4141
42 - $page_obj = WOMOutputProcessor::getOutputData( $articleTitle, $rid );
4342 try {
 43+ $page_obj = WOMOutputProcessor::getOutputData( $articleTitle, $rid );
4444 $objs = WOMProcessor::getObjIdByXPath2( $page_obj, $xpath );
4545 } catch ( Exception $e ) {
4646 $err = $e->getMessage();
@@ -55,6 +55,7 @@
5656 $this->getResult()->setContent( $result['message'], $err );
5757 } else {
5858 $result['result'] = 'Success';
 59+ $result['revisionID'] = $page_obj->getRevisionID();
5960
6061 // pay attention to special xml tag, e.g., <property><value>...</value></property>
6162 $result['return'] = array();
@@ -81,7 +82,7 @@
8283 header ( "Content-Type: application/rdf+xml" );
8384 echo <<<OUTPUT
8485 <?xml version="1.0" encoding="UTF-8" ?>
85 -<api><womoutput result="Success"><return>
 86+<api><womoutput result="Success" revisionID="{$page_obj->getRevisionID()}"><return>
8687 {$xml}
8788 </return></womoutput></api>
8889 OUTPUT;
Index: trunk/extensions/WikiObjectModel/includes/apis/WOM_OutputProcessor.php
@@ -282,7 +282,10 @@
283283 foreach ( $queries as $label => $vals ) {
284284 $vals = array_unique( $vals );
285285 foreach ( $vals as $val ) {
286 - $query_res->insertObject( new WOMPropertyModel( $label, $val ) );
 286+ $qprop = new WOMPropertyModel( $label, $val );
 287+ $qprop->setObjectID( 'output' . ( $tmp_id ++ ) );
 288+ $query_res->insertObject( $qprop );
 289+ $wom->addToPageObjectSet( $qprop );
287290 }
288291 }
289292 }
@@ -310,6 +313,8 @@
311314 }
312315 }
313316
 317+ if ( wfRunHooks ( 'womGetExtraOutputObjects', array ( $wgTitle, &$wom ) ) ) {
 318+ }
314319 return $wom;
315320 }
316321 }
Index: trunk/extensions/WikiObjectModel/includes/apis/WOM_GetWikiResult.php
@@ -0,0 +1,107 @@
 2+<?php
 3+
 4+/**
 5+ * @addtogroup API
 6+ */
 7+class ApiWOMGetWikiResult extends ApiBase {
 8+
 9+ public function __construct( $main, $action ) {
 10+ parent :: __construct( $main, $action );
 11+ }
 12+
 13+ public function execute() {
 14+ global $wgUser;
 15+
 16+ $params = $this->extractRequestParams();
 17+ if ( is_null( $params['wiki'] ) )
 18+ $this->dieUsage( 'Must specify wiki text', 0 );
 19+ $wiki = $params['wiki'];
 20+ $type = $params['type'];
 21+
 22+ global $wgParser;
 23+ $popt = new ParserOptions();
 24+ $popt->setEditSection( false );
 25+ $title = Title::newFromText( '__TEMPWIKITITLE__' );
 26+ if ( strtolower( $type ) == 'ask' ) {
 27+ $wiki = "{$wiki}|format=xml";
 28+
 29+ global $wgOMIP, $smwgResultFormats, $wgAutoloadClasses;
 30+ $smwgResultFormats['xml'] = 'SRFXml';
 31+ $wgAutoloadClasses['SRFXml'] = $wgOMIP . '/includes/apis/SRF_Xml.php';
 32+
 33+ $s = $wgParser->preprocess( $wiki, $title, $popt );
 34+ $b = 0;
 35+ for ( $i = 0; $i < strlen( $s ); ++$i ) {
 36+ if ( $s { $i } == '[' ) {
 37+ ++ $b;
 38+ } elseif ( $s { $i } == ']' ) {
 39+ -- $b;
 40+ } elseif ( $s { $i } == '|' ) {
 41+ if ( $b == 0 ) break;
 42+ }
 43+ }
 44+ $rawparams = array( substr( $s, 0, $i ) );
 45+ if ( $i < strlen( $s ) ) $rawparams = array_merge( $rawparams, explode( '|', substr( $s, $i + 1 ) ) );
 46+ $result = SMWQueryProcessor::getResultFromFunctionParams( $rawparams, SMW_OUTPUT_WIKI );
 47+ } else {
 48+ $pout = $wgParser->parse( $wiki, $title, $popt );
 49+ $result = "<![CDATA[{$pout->getText()}]]>";
 50+ }
 51+
 52+ header ( "Content-Type: application/rdf+xml" );
 53+ echo <<<OUTPUT
 54+<?xml version="1.0" encoding="UTF-8" ?>
 55+<api><womwiki result="Success">
 56+<wiki><![CDATA[{$wiki}]]></wiki>
 57+<return>
 58+{$result}
 59+</return></womwiki></api>
 60+OUTPUT;
 61+ exit( 1 );
 62+ }
 63+
 64+ protected function getAllowedParams() {
 65+ $types = defined( 'SMW_VERSION' ) ? array( 'wiki', 'ask' ) : array( 'wiki' );
 66+ return array (
 67+ 'wiki' => null,
 68+ 'type' => array(
 69+ ApiBase :: PARAM_DFLT => 'wiki',
 70+ ApiBase :: PARAM_TYPE => $types
 71+ ),
 72+ );
 73+ }
 74+
 75+ protected function getParamDescription() {
 76+ $types = defined( 'SMW_VERSION' ) ? array(
 77+ 'Type to fetch wiki parse result',
 78+ 'type = wiki, get parser result of wiki text',
 79+ 'type = ask, get parser result of ask query, in xml format'
 80+ ) : array(
 81+ 'Type to fetch wiki parse result',
 82+ 'type = wiki, get parser result of wiki text',
 83+ );
 84+ return array (
 85+ 'wiki' => 'Wiki text',
 86+ 'type' => $types
 87+ );
 88+ }
 89+
 90+ protected function getDescription() {
 91+ return 'Call to get parse result of wiki';
 92+ }
 93+
 94+ protected function getExamples() {
 95+ return array (
 96+ 'api.php?action=womwiki&wiki=[[Hello]]',
 97+ 'api.php?action=womwiki&wiki=[[Category:Hello]]&type=ask'
 98+ );
 99+ }
 100+
 101+// public function mustBePosted() {
 102+// return true;
 103+// }
 104+
 105+ public function getVersion() {
 106+ return __CLASS__ . ': $Id$';
 107+ }
 108+}

Status & tagging log