Index: trunk/extensions/WikiObjectModel/WikiObjectModel.php |
— | — | @@ -6,26 +6,17 @@ |
7 | 7 | */ |
8 | 8 | if ( !defined( 'MEDIAWIKI' ) ) die; |
9 | 9 | |
10 | | -define( 'WOM_VERSION', '1.0.1 alpha' ); |
| 10 | +define( 'WOM_VERSION', '1.0.2 alpha' ); |
11 | 11 | |
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 | | - |
21 | 12 | $wgOMIP = $IP . '/extensions/WikiObjectModel'; |
22 | 13 | $wgOMScriptPath = $wgScriptPath . '/extensions/WikiObjectModel'; |
23 | 14 | |
24 | | -$wgExtensionFunctions[] = 'smwfOMInitLanguage'; |
| 15 | +$wgExtensionFunctions[] = 'wfWOMSetupExtension'; |
25 | 16 | $wgExtensionMessagesFiles['WikiObjectModel'] = $wgOMIP . '/languages/Messages.php'; |
26 | 17 | |
27 | 18 | require_once( $wgOMIP . '/includes/WOM_Setup.php' ); |
28 | 19 | |
29 | | -function smwfOMInitLanguageObject( $langcode, $fallback = null ) { |
| 20 | +function wfWOMInitLanguageObject( $langcode, $fallback = null ) { |
30 | 21 | global $wgOMIP; |
31 | 22 | |
32 | 23 | $langClass = 'WOMLanguage' . str_replace( '-', '_', ucfirst( $langcode ) ); |
— | — | @@ -45,10 +36,34 @@ |
46 | 37 | return new $langClass(); |
47 | 38 | } |
48 | 39 | |
49 | | -function smwfOMInitLanguage() { |
| 40 | +function wfWOMInitLanguage() { |
50 | 41 | global $wgLanguageCode, $wgLang; |
51 | 42 | global $wgOMContLang, $wgOMLang; |
52 | 43 | |
53 | | - $wgOMContLang = smwfOMInitLanguageObject( $wgLanguageCode ); |
54 | | - $wgOMLang = smwfOMInitLanguageObject( $wgLang->getCode(), $wgOMContLang ); |
| 44 | + $wgOMContLang = wfWOMInitLanguageObject( $wgLanguageCode ); |
| 45 | + $wgOMLang = wfWOMInitLanguageObject( $wgLang->getCode(), $wgOMContLang ); |
55 | 46 | } |
| 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 @@ |
14 | 14 | $this->m_parserId = WOM_PARSER_ID_LISTITEM; |
15 | 15 | } |
16 | 16 | |
| 17 | + public function getValidModelTypes() { |
| 18 | + return array( WOM_TYPE_LISTITEM ); |
| 19 | + } |
| 20 | + |
17 | 21 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
18 | 22 | $lastLF = ( $offset == 0 || $text { $offset - 1 } == "\n" ); |
19 | 23 | $text = substr( $text, $offset ); |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMLinkParser.php |
— | — | @@ -13,6 +13,10 @@ |
14 | 14 | $this->m_parserId = WOM_PARSER_ID_LINK; |
15 | 15 | } |
16 | 16 | |
| 17 | + public function getValidModelTypes() { |
| 18 | + return array( WOM_TYPE_LINK ); |
| 19 | + } |
| 20 | + |
17 | 21 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
18 | 22 | $text = substr( $text, $offset ); |
19 | 23 | |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMParamValueParser.php |
— | — | @@ -13,6 +13,10 @@ |
14 | 14 | $this->m_parserId = WOM_PARSER_ID_PARAM_VALUE; |
15 | 15 | } |
16 | 16 | |
| 17 | + public function getValidModelTypes() { |
| 18 | + return array( WOM_TYPE_PARAM_VALUE ); |
| 19 | + } |
| 20 | + |
17 | 21 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
18 | 22 | if ( !( ( $parentObj instanceof WOMParameterModel ) |
19 | 23 | || ( $parentObj instanceof WOMTemplateFieldHolderModel ) ) ) |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMHTMLTagParser.php |
— | — | @@ -13,6 +13,10 @@ |
14 | 14 | $this->m_parserId = WOM_PARSER_ID_HTMLTAG; |
15 | 15 | } |
16 | 16 | |
| 17 | + public function getValidModelTypes() { |
| 18 | + return array( WOM_TYPE_HTMLTAG ); |
| 19 | + } |
| 20 | + |
17 | 21 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
18 | 22 | $text = substr( $text, $offset ); |
19 | 23 | // 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 @@ |
14 | 14 | $this->m_parserId = WOM_PARSER_ID_PARSERFUNCTION; |
15 | 15 | } |
16 | 16 | |
| 17 | + public function getValidModelTypes() { |
| 18 | + return array( WOM_TYPE_PARSERFUNCTION ); |
| 19 | + } |
| 20 | + |
17 | 21 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
18 | 22 | $text = substr( $text, $offset ); |
19 | 23 | $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 @@ |
16 | 16 | $this->m_parserId = WOM_PARSER_ID_SECTION; |
17 | 17 | } |
18 | 18 | |
| 19 | + public function getValidModelTypes() { |
| 20 | + return array( WOM_TYPE_SECTION ); |
| 21 | + } |
| 22 | + |
19 | 23 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
20 | 24 | $lastLF = ( $offset == 0 || $text { $offset - 1 } == "\n" ); |
21 | 25 | $text = substr( $text, $offset ); |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMTemplateParser.php |
— | — | @@ -13,6 +13,10 @@ |
14 | 14 | $this->m_parserId = WOM_PARSER_ID_TEMPLATE; |
15 | 15 | } |
16 | 16 | |
| 17 | + public function getValidModelTypes() { |
| 18 | + return array( WOM_TYPE_TEMPLATE ); |
| 19 | + } |
| 20 | + |
17 | 21 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
18 | 22 | $text = substr( $text, $offset ); |
19 | 23 | $r = preg_match( '/^(\{\{([^{|}]+))([|}])/', $text, $m ); |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMMagicWordParser.php |
— | — | @@ -13,6 +13,10 @@ |
14 | 14 | $this->m_parserId = WOM_PARSER_ID_MAGICWORD; |
15 | 15 | } |
16 | 16 | |
| 17 | + public function getValidModelTypes() { |
| 18 | + return array( WOM_TYPE_MAGICWORD ); |
| 19 | + } |
| 20 | + |
17 | 21 | static $underscores = array( '0' => '', '1' => '' ); |
18 | 22 | static $mwa = null; |
19 | 23 | static function getDoubleUnderscoreRegex() { |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMTemplateFieldHolderParser.php |
— | — | @@ -13,6 +13,10 @@ |
14 | 14 | $this->m_parserId = WOM_PARSER_ID_TEMPLATE_FIELD_HOLDER; |
15 | 15 | } |
16 | 16 | |
| 17 | + public function getValidModelTypes() { |
| 18 | + return array( WOM_TYPE_TMPL_FIELD_HOLDER ); |
| 19 | + } |
| 20 | + |
17 | 21 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
18 | 22 | $text = substr( $text, $offset ); |
19 | 23 | $r = preg_match( '/^(\{\{\{([^{|}]+))([|}])/', $text, $m ); |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMCategoryParser.php |
— | — | @@ -13,6 +13,10 @@ |
14 | 14 | $this->m_parserId = WOM_PARSER_ID_CATEGORY; |
15 | 15 | } |
16 | 16 | |
| 17 | + public function getValidModelTypes() { |
| 18 | + return array( WOM_TYPE_CATEGORY ); |
| 19 | + } |
| 20 | + |
17 | 21 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
18 | 22 | $text = substr( $text, $offset ); |
19 | 23 | 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 @@ |
14 | 14 | $this->m_parserId = WOM_PARSER_ID_PARAMETER; |
15 | 15 | } |
16 | 16 | |
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 ); |
39 | 19 | } |
40 | 20 | |
41 | 21 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
— | — | @@ -44,8 +24,12 @@ |
45 | 25 | |
46 | 26 | $text = substr( $text, $offset ); |
47 | 27 | |
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 | + } |
50 | 34 | |
51 | 35 | $r = preg_match( '/^([^=|}]*)(\||=|\}|$)/', $text, $m ); |
52 | 36 | if ( !$r ) return null; |
— | — | @@ -67,18 +51,26 @@ |
68 | 52 | } |
69 | 53 | |
70 | 54 | 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 | + } |
74 | 59 | |
75 | 60 | return WOM_PARSER_ID_PARAM_VALUE; |
76 | 61 | } |
77 | 62 | |
78 | 63 | 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 ) ) ) |
83 | 75 | return false; |
84 | 76 | |
85 | 77 | if ( ( strlen( $text ) >= $offset + 1 ) && $text { $offset } == '|' ) { |
— | — | @@ -86,7 +78,10 @@ |
87 | 79 | } |
88 | 80 | $parentClose = WOMProcessor::getObjectParser( $obj->getParent() ) |
89 | 81 | ->isObjectClosed( $obj->getParent(), $text, $offset ); |
90 | | - if ( $parentClose !== false ) return 0; |
| 82 | + if ( $parentClose !== false ) { |
| 83 | + $obj->setPipe( false ); |
| 84 | + return 0; |
| 85 | + } |
91 | 86 | |
92 | 87 | return false; |
93 | 88 | } |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMPropertyValueParser.php |
— | — | @@ -13,6 +13,10 @@ |
14 | 14 | $this->m_parserId = WOM_PARSER_ID_PROPERTY_VALUE; |
15 | 15 | } |
16 | 16 | |
| 17 | + public function getValidModelTypes() { |
| 18 | + return array( WOM_TYPE_NESTPROPERTYVAL ); |
| 19 | + } |
| 20 | + |
17 | 21 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
18 | 22 | if ( !( $parentObj instanceof WOMNestPropertyModel ) ) |
19 | 23 | return null; |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMTblCellParser.php |
— | — | @@ -13,6 +13,10 @@ |
14 | 14 | $this->m_parserId = WOM_PARSER_ID_TABLECELL; |
15 | 15 | } |
16 | 16 | |
| 17 | + public function getValidModelTypes() { |
| 18 | + return array( WOM_TYPE_TBL_CELL ); |
| 19 | + } |
| 20 | + |
17 | 21 | private function getFirstLineChar( $text, $offset ) { |
18 | 22 | for ( $i = $offset; $i >= 0; --$i ) { |
19 | 23 | if ( $text { $i } == "\n" ) { |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMPropertyParser.php |
— | — | @@ -14,6 +14,10 @@ |
15 | 15 | $this->m_parserId = WOM_PARSER_ID_PROPERTY; |
16 | 16 | } |
17 | 17 | |
| 18 | + public function getValidModelTypes() { |
| 19 | + return array( WOM_TYPE_PROPERTY, WOM_TYPE_NESTPROPERTY ); |
| 20 | + } |
| 21 | + |
18 | 22 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
19 | 23 | if ( !defined( 'SMW_VERSION' ) ) { |
20 | 24 | return null; |
— | — | @@ -21,6 +25,26 @@ |
22 | 26 | |
23 | 27 | $text = substr( $text, $offset ); |
24 | 28 | |
| 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 | + } |
25 | 49 | // copied from SemanticMediaWiki, includes/SMW_ParserExtensions.php |
26 | 50 | // not deal with <nowiki>, could be bug here. SMW has the same bug |
27 | 51 | // E.g., [[text::this <nowiki> is ]] </nowiki> not good]] |
— | — | @@ -45,24 +69,6 @@ |
46 | 70 | // } |
47 | 71 | $r = preg_match( $semanticLinkPattern, $text, $m ); |
48 | 72 | 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 | | - |
67 | 73 | return array( 'len' => strlen( $m[0] ), 'obj' => new WOMPropertyModel( $m[1], $m[2], isset( $m[3] ) ? $m[3] : '' ) ); |
68 | 74 | } |
69 | 75 | return null; |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMTableParser.php |
— | — | @@ -13,6 +13,10 @@ |
14 | 14 | $this->m_parserId = WOM_PARSER_ID_TABLE; |
15 | 15 | } |
16 | 16 | |
| 17 | + public function getValidModelTypes() { |
| 18 | + return array( WOM_TYPE_TABLE ); |
| 19 | + } |
| 20 | + |
17 | 21 | // FIXME: what if table style uses parser function which contains 'return' |
18 | 22 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
19 | 23 | $text = substr( $text, $offset ); |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WikiObjectModelParser.php |
— | — | @@ -53,6 +53,10 @@ |
54 | 54 | return array( 'len' => 1, 'obj' => new WOMTextModel( $text { 0 } ) ); |
55 | 55 | } |
56 | 56 | |
| 57 | + public function getValidModelTypes() { |
| 58 | + return array( WOM_TYPE_TEXT ); |
| 59 | + } |
| 60 | + |
57 | 61 | // E.g., |
58 | 62 | // semantic property is extended from internal links |
59 | 63 | // parser functions is extended from templates |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Parameter.php |
— | — | @@ -10,20 +10,26 @@ |
11 | 11 | |
12 | 12 | class WOMParameterModel extends WikiObjectModelCollection { |
13 | 13 | protected $m_key; |
| 14 | + protected $m_pipe; |
14 | 15 | |
15 | 16 | public function __construct( $key = '' ) { |
16 | 17 | parent::__construct( WOM_TYPE_PARAMETER ); |
17 | 18 | $this->m_key = $key; |
| 19 | + $this->m_pipe = true; |
18 | 20 | } |
19 | 21 | |
20 | 22 | public function getKey() { |
21 | 23 | return $this->m_key; |
22 | 24 | } |
23 | 25 | |
| 26 | + public function setPipe( $pipe ) { |
| 27 | + $this->m_pipe = $pipe; |
| 28 | + } |
| 29 | + |
24 | 30 | public function getWikiText() { |
25 | 31 | return ( $this->m_key == '' ? "" : ( $this->m_key . '=' ) ) . |
26 | 32 | $this->getValueText() . |
27 | | - '|'; |
| 33 | + ( $this->m_pipe ? '|' : '' ); |
28 | 34 | } |
29 | 35 | |
30 | 36 | public function getValueText() { |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Property.php |
— | — | @@ -72,7 +72,11 @@ |
73 | 73 | } |
74 | 74 | |
75 | 75 | 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}"; |
77 | 81 | if ( $this->getPropertyValue() != $this->getCaption() |
78 | 82 | && $this->getCaption() != '' ) { |
79 | 83 | $res .= "|{$this->getCaption()}"; |
— | — | @@ -89,7 +93,7 @@ |
90 | 94 | } |
91 | 95 | |
92 | 96 | 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() ); |
94 | 98 | } |
95 | 99 | |
96 | 100 | public function getCaption() { |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_HTMLTag.php |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | return $this->m_name; |
24 | 24 | } |
25 | 25 | |
26 | | - public function setName( $name ) { |
| 26 | + public function setTagName( $name ) { |
27 | 27 | $this->m_name = $name; |
28 | 28 | } |
29 | 29 | |
— | — | @@ -37,6 +37,7 @@ |
38 | 38 | $v = preg_replace( '/^[\'"](.*)[\'"]$/', '$1', $v ); |
39 | 39 | if ( $attr == $a ) return $v; |
40 | 40 | } |
| 41 | + return null; |
41 | 42 | } |
42 | 43 | |
43 | 44 | public function setAttributes( $attrs ) { |
— | — | @@ -62,14 +63,14 @@ |
63 | 64 | public function setXMLAttribute( $key, $value ) { |
64 | 65 | if ( $value == '' ) throw new MWException( __METHOD__ . ": value cannot be empty" ); |
65 | 66 | |
66 | | - if ( $key == 'name' ) { |
| 67 | + if ( $key == 'tag' ) { |
67 | 68 | $this->m_name = $value; |
68 | 69 | } else { |
69 | | - throw new MWException( __METHOD__ . ": invalid key/value pair: name=html_tag_name" ); |
| 70 | + $attrs[$key] = $value; |
70 | 71 | } |
71 | 72 | } |
72 | 73 | protected function getXMLAttributes() { |
73 | | - $ret = 'name="' . self::xml_entities( $this->m_name ) . '"'; |
| 74 | + $ret = 'tag="' . self::xml_entities( $this->m_name ) . '"'; |
74 | 75 | foreach ( $this->m_attrs as $a => $v ) { |
75 | 76 | $v = preg_replace( '/^"(.*)"$/', '$1', $v ); |
76 | 77 | 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 @@ |
15 | 15 | private static $isParsersRegistered = false; |
16 | 16 | private static $parsers = array(); |
17 | 17 | private static $base_parser; |
| 18 | + private static $modelParserMapping = array(); |
18 | 19 | |
| 20 | + public static $parserFuncParsers = array(); |
| 21 | + |
19 | 22 | private static function setupParsers() { |
20 | 23 | if ( self::$isParsersRegistered ) return; |
21 | 24 | |
— | — | @@ -22,9 +25,33 @@ |
23 | 26 | foreach ( $wgOMParsers as $p ) { |
24 | 27 | $parser = new $p(); |
25 | 28 | self::$parsers[$parser->getParserID()] = $parser; |
| 29 | + foreach ( $parser->getValidModelTypes() as $type ) { |
| 30 | + self::$modelParserMapping[$type] = $parser->getParserID(); |
| 31 | + } |
26 | 32 | } |
27 | 33 | self::$base_parser = self::$parsers[WOM_PARSER_ID_TEXT]; |
28 | 34 | |
| 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 | + |
29 | 56 | self::$isParsersRegistered = true; |
30 | 57 | } |
31 | 58 | |
— | — | @@ -35,9 +62,8 @@ |
36 | 63 | if ( !self::$isParsersRegistered ) { |
37 | 64 | self::setupParsers(); |
38 | 65 | } |
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()]; |
42 | 68 | if ( isset( self::$parsers[$id] ) ) { |
43 | 69 | wfProfileOut( $fname ); |
44 | 70 | return self::$parsers[$id]; |
— | — | @@ -119,7 +145,10 @@ |
120 | 146 | if ( $obj->getTypeID() == WOM_TYPE_HTMLTAG ) { |
121 | 147 | // special case, html tag |
122 | 148 | } 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 | + } |
124 | 153 | } |
125 | 154 | $new_objs[] = $obj; |
126 | 155 | } |
— | — | @@ -180,7 +209,10 @@ |
181 | 210 | if ( $obj->getTypeID() == WOM_TYPE_HTMLTAG ) { |
182 | 211 | // special case, html tag |
183 | 212 | } 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 | + } |
185 | 217 | } |
186 | 218 | $new_objs[] = $obj; |
187 | 219 | } |
— | — | @@ -230,7 +262,9 @@ |
231 | 263 | foreach ( self::$parsers as $parser ) { |
232 | 264 | $parser_res = $parser->parseNext( $text, $parentObj, $offset ); |
233 | 265 | 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 | + |
235 | 269 | $parserInstance = $parser; |
236 | 270 | $result = $parser_res; |
237 | 271 | } |
Index: trunk/extensions/WikiObjectModel/includes/WOM_Setup.php |
— | — | @@ -14,8 +14,6 @@ |
15 | 15 | $wgAutoloadClasses['WOMTemplateModel'] = $wgOMIP . '/includes/models/WOM_OM_Template.php'; |
16 | 16 | $wgAutoloadClasses['WOMParserFunctionModel'] = $wgOMIP . '/includes/models/WOM_OM_ParserFunction.php'; |
17 | 17 | $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'; |
20 | 18 | $wgAutoloadClasses['WOMParamValueModel'] = $wgOMIP . '/includes/models/WOM_OM_ParamValue.php'; |
21 | 19 | $wgAutoloadClasses['WOMTemplateFieldModel'] = $wgOMIP . '/includes/models/WOM_OM_TmplField.php'; |
22 | 20 | $wgAutoloadClasses['WOMPropertyModel'] = $wgOMIP . '/includes/models/WOM_OM_Property.php'; |
— | — | @@ -32,6 +30,7 @@ |
33 | 31 | $wgAutoloadClasses['WOMMagicWordModel'] = $wgOMIP . '/includes/models/WOM_OM_MagicWord.php'; |
34 | 32 | $wgAutoloadClasses['WOMHTMLTagModel'] = $wgOMIP . '/includes/models/WOM_OM_HTMLTag.php'; |
35 | 33 | $wgAutoloadClasses['WOMTemplateFieldHolderModel'] = $wgOMIP . '/includes/models/WOM_OM_TmplFieldHolder.php'; |
| 34 | +$wgAutoloadClasses['WOMRedirectModel'] = $wgOMIP . '/includes/models/WOM_OM_Redirect.php'; |
36 | 35 | |
37 | 36 | // Definitions |
38 | 37 | define( 'WOM_TYPE_PAGE' , 'page' ); |
— | — | @@ -45,8 +44,6 @@ |
46 | 45 | define( 'WOM_TYPE_TEMPLATE' , 'template' ); |
47 | 46 | define( 'WOM_TYPE_PARSERFUNCTION' , 'parser_function' ); |
48 | 47 | define( 'WOM_TYPE_PARAMETER' , 'parameter' ); |
49 | | -define( 'WOM_TYPE_QUERYSTRING' , 'querystring' ); |
50 | | -define( 'WOM_TYPE_QUERYPRINTOUT' , 'printout' ); |
51 | 48 | define( 'WOM_TYPE_PARAM_VALUE' , 'value' ); |
52 | 49 | define( 'WOM_TYPE_TMPL_FIELD' , 'template_field' ); |
53 | 50 | define( 'WOM_TYPE_SENTENCE' , 'sentence' ); |
— | — | @@ -57,6 +54,7 @@ |
58 | 55 | define( 'WOM_TYPE_MAGICWORD' , 'magicword' ); |
59 | 56 | define( 'WOM_TYPE_HTMLTAG' , 'html' ); |
60 | 57 | define( 'WOM_TYPE_TMPL_FIELD_HOLDER', 'template_field_holder' ); |
| 58 | +define( 'WOM_TYPE_REDIRECT' , 'redirect' ); |
61 | 59 | |
62 | 60 | // POM Parser |
63 | 61 | $wgAutoloadClasses['WikiObjectModelParser'] = $wgOMIP . '/includes/parsers/WikiObjectModelParser.php'; |
— | — | @@ -76,6 +74,7 @@ |
77 | 75 | $wgAutoloadClasses['WOMMagicWordParser'] = $wgOMIP . '/includes/parsers/WOMMagicWordParser.php'; |
78 | 76 | $wgAutoloadClasses['WOMHTMLTagParser'] = $wgOMIP . '/includes/parsers/WOMHTMLTagParser.php'; |
79 | 77 | $wgAutoloadClasses['WOMTemplateFieldHolderParser'] = $wgOMIP . '/includes/parsers/WOMTemplateFieldHolderParser.php'; |
| 78 | +$wgAutoloadClasses['WOMRedirectParser'] = $wgOMIP . '/includes/parsers/WOMRedirectParser.php'; |
80 | 79 | |
81 | 80 | // Definitions |
82 | 81 | define( 'WOM_PARSER_ID_CATEGORY' , 'category' ); |
— | — | @@ -94,6 +93,7 @@ |
95 | 94 | define( 'WOM_PARSER_ID_MAGICWORD' , 'magicword' ); |
96 | 95 | define( 'WOM_PARSER_ID_HTMLTAG' , 'html' ); |
97 | 96 | define( 'WOM_PARSER_ID_TEMPLATE_FIELD_HOLDER', 'template_field_holder' ); |
| 97 | +define( 'WOM_PARSER_ID_REDIRECT' , 'redirect' ); |
98 | 98 | |
99 | 99 | global $wgOMParsers, $wgOMModelParserMapping; |
100 | 100 | $wgOMParsers = array( |
— | — | @@ -113,29 +113,21 @@ |
114 | 114 | 'WOMMagicWordParser', |
115 | 115 | 'WOMHTMLTagParser', |
116 | 116 | 'WOMTemplateFieldHolderParser', |
| 117 | + 'WOMRedirectParser', |
117 | 118 | ); |
118 | 119 | |
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', |
140 | 132 | ); |
141 | 133 | |
142 | 134 | global $wgOMSentenceObjectTypes; |
— | — | @@ -164,4 +156,5 @@ |
165 | 157 | $wgAutoloadClasses['ApiWOMQuery'] = $wgOMIP . '/includes/apis/WOM_Query.php'; |
166 | 158 | $wgAPIModules['womoutput'] = 'ApiWOMOutputObjectModel'; |
167 | 159 | $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 @@ |
34 | 34 | $this->dieUsage( "Article doesn't exist ($page_name)", 3 ); |
35 | 35 | |
36 | 36 | try { |
37 | | - $objs = WOMProcessor::getObjIdByXPath( $articleTitle, $xpath, $rid ); |
| 37 | + $page_obj = WOMProcessor::getPageObject( $articleTitle, $rid ); |
| 38 | + $objs = WOMProcessor::getObjIdByXPath2( $page_obj, $xpath ); |
38 | 39 | } catch ( Exception $e ) { |
39 | 40 | $err = $e->getMessage(); |
40 | 41 | } |
— | — | @@ -48,6 +49,7 @@ |
49 | 50 | $this->getResult()->setContent( $result['message'], $err ); |
50 | 51 | } else { |
51 | 52 | $result['result'] = 'Success'; |
| 53 | + $result['revisionID'] = $page_obj->getRevisionID(); |
52 | 54 | |
53 | 55 | // pay attention to special xml tag, e.g., <property><value>...</value></property> |
54 | 56 | $result['return'] = array(); |
— | — | @@ -60,7 +62,6 @@ |
61 | 63 | $this->getResult()->setContent( $result['return'], $count ); |
62 | 64 | } else { |
63 | 65 | $xml = ''; |
64 | | - $page_obj = WOMProcessor::getPageObject( $articleTitle, $rid ); |
65 | 66 | foreach ( $objs as $id ) { |
66 | 67 | if ( $id == '' ) continue; |
67 | 68 | $wobj = $page_obj->getObject( $id ); |
— | — | @@ -76,7 +77,7 @@ |
77 | 78 | header ( "Content-Type: application/rdf+xml" ); |
78 | 79 | echo <<<OUTPUT |
79 | 80 | <?xml version="1.0" encoding="UTF-8" ?> |
80 | | -<api><womget result="Success"><return> |
| 81 | +<api><womget result="Success" revisionID="{$page_obj->getRevisionID()}"><return> |
81 | 82 | {$xml} |
82 | 83 | </return></womget></api> |
83 | 84 | 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 @@ |
39 | 39 | if ( !$article->exists() ) |
40 | 40 | $this->dieUsage( "Article doesn't exist ($page_name)", 3 ); |
41 | 41 | |
42 | | - $page_obj = WOMOutputProcessor::getOutputData( $articleTitle, $rid ); |
43 | 42 | try { |
| 43 | + $page_obj = WOMOutputProcessor::getOutputData( $articleTitle, $rid ); |
44 | 44 | $objs = WOMProcessor::getObjIdByXPath2( $page_obj, $xpath ); |
45 | 45 | } catch ( Exception $e ) { |
46 | 46 | $err = $e->getMessage(); |
— | — | @@ -55,6 +55,7 @@ |
56 | 56 | $this->getResult()->setContent( $result['message'], $err ); |
57 | 57 | } else { |
58 | 58 | $result['result'] = 'Success'; |
| 59 | + $result['revisionID'] = $page_obj->getRevisionID(); |
59 | 60 | |
60 | 61 | // pay attention to special xml tag, e.g., <property><value>...</value></property> |
61 | 62 | $result['return'] = array(); |
— | — | @@ -81,7 +82,7 @@ |
82 | 83 | header ( "Content-Type: application/rdf+xml" ); |
83 | 84 | echo <<<OUTPUT |
84 | 85 | <?xml version="1.0" encoding="UTF-8" ?> |
85 | | -<api><womoutput result="Success"><return> |
| 86 | +<api><womoutput result="Success" revisionID="{$page_obj->getRevisionID()}"><return> |
86 | 87 | {$xml} |
87 | 88 | </return></womoutput></api> |
88 | 89 | OUTPUT; |
Index: trunk/extensions/WikiObjectModel/includes/apis/WOM_OutputProcessor.php |
— | — | @@ -282,7 +282,10 @@ |
283 | 283 | foreach ( $queries as $label => $vals ) { |
284 | 284 | $vals = array_unique( $vals ); |
285 | 285 | 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 ); |
287 | 290 | } |
288 | 291 | } |
289 | 292 | } |
— | — | @@ -310,6 +313,8 @@ |
311 | 314 | } |
312 | 315 | } |
313 | 316 | |
| 317 | + if ( wfRunHooks ( 'womGetExtraOutputObjects', array ( $wgTitle, &$wom ) ) ) { |
| 318 | + } |
314 | 319 | return $wom; |
315 | 320 | } |
316 | 321 | } |
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 | +}
|