Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMTemplateFieldHolderParser.php |
— | — | @@ -1,44 +1,44 @@ |
2 | | -<?php
|
3 | | -/**
|
4 | | - * @author Ning
|
5 | | - *
|
6 | | - * @file
|
7 | | - * @ingroup WikiObjectModels
|
8 | | - */
|
9 | | -
|
10 | | -class WOMTemplateFieldHolderParser extends WikiObjectModelParser {
|
11 | | -
|
12 | | - public function __construct() {
|
13 | | - parent::__construct();
|
14 | | - $this->m_parserId = WOM_PARSER_ID_TEMPLATE_FIELD_HOLDER;
|
15 | | - }
|
16 | | -
|
17 | | - public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) {
|
18 | | - $text = substr( $text, $offset );
|
19 | | - $r = preg_match( '/^(\{\{\{([^{|}]+))([|}])/', $text, $m );
|
20 | | -
|
21 | | - if ( $r ) {
|
22 | | - if ( !preg_match( '/[^' . Title::legalChars() . ']/', trim( $m[2] ) ) )
|
23 | | -// if(!preg_match(Title::getTitleInvalidRegex(), trim($m[2])))
|
24 | | - return array( 'len' => ( $m[3] == '|' ) ? strlen( $m[0] ) : strlen( $m[1] ), 'obj' => new WOMTemplateFieldHolderModel( trim( $m[2] ) ) );
|
25 | | - }
|
26 | | - return null;
|
27 | | - }
|
28 | | -
|
29 | | - public function getSubParserID() {
|
30 | | - return WOM_PARSER_ID_PARAM_VALUE;
|
31 | | - }
|
32 | | -
|
33 | | - public function isObjectClosed( $obj, $text, $offset ) {
|
34 | | - if ( !$obj instanceof WOMTemplateFieldHolderModel ) return false;
|
35 | | -
|
36 | | - if ( ( strlen( $text ) >= $offset + 3 )
|
37 | | - && $text { $offset } == '}'
|
38 | | - && $text { $offset + 1 } == '}'
|
39 | | - && $text { $offset + 2 } == '}' ) {
|
40 | | - return 3;
|
41 | | - }
|
42 | | -
|
43 | | - return false;
|
44 | | - }
|
45 | | -}
|
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @author Ning |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup WikiObjectModels |
| 8 | + */ |
| 9 | + |
| 10 | +class WOMTemplateFieldHolderParser extends WikiObjectModelParser { |
| 11 | + |
| 12 | + public function __construct() { |
| 13 | + parent::__construct(); |
| 14 | + $this->m_parserId = WOM_PARSER_ID_TEMPLATE_FIELD_HOLDER; |
| 15 | + } |
| 16 | + |
| 17 | + public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
| 18 | + $text = substr( $text, $offset ); |
| 19 | + $r = preg_match( '/^(\{\{\{([^{|}]+))([|}])/', $text, $m ); |
| 20 | + |
| 21 | + if ( $r ) { |
| 22 | + if ( !preg_match( '/[^' . Title::legalChars() . ']/', trim( $m[2] ) ) ) |
| 23 | +// if(!preg_match(Title::getTitleInvalidRegex(), trim($m[2]))) |
| 24 | + return array( 'len' => ( $m[3] == '|' ) ? strlen( $m[0] ) : strlen( $m[1] ), 'obj' => new WOMTemplateFieldHolderModel( trim( $m[2] ) ) ); |
| 25 | + } |
| 26 | + return null; |
| 27 | + } |
| 28 | + |
| 29 | + public function getSubParserID() { |
| 30 | + return WOM_PARSER_ID_PARAM_VALUE; |
| 31 | + } |
| 32 | + |
| 33 | + public function isObjectClosed( $obj, $text, $offset ) { |
| 34 | + if ( !$obj instanceof WOMTemplateFieldHolderModel ) return false; |
| 35 | + |
| 36 | + if ( ( strlen( $text ) >= $offset + 3 ) |
| 37 | + && $text { $offset } == '}' |
| 38 | + && $text { $offset + 1 } == '}' |
| 39 | + && $text { $offset + 2 } == '}' ) { |
| 40 | + return 3; |
| 41 | + } |
| 42 | + |
| 43 | + return false; |
| 44 | + } |
| 45 | +} |
Property changes on: trunk/extensions/WikiObjectModel/includes/parsers/WOMTemplateFieldHolderParser.php |
___________________________________________________________________ |
Added: svn:eol-style |
46 | 46 | + native |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_TmplFieldHolder.php |
— | — | @@ -1,44 +1,44 @@ |
2 | | -<?php
|
3 | | -/**
|
4 | | - * This model implements Template Field Holder models.
|
5 | | - *
|
6 | | - * @author Ning
|
7 | | - * @file
|
8 | | - * @ingroup WikiObjectModels
|
9 | | - *
|
10 | | - */
|
11 | | -
|
12 | | -class WOMTemplateFieldHolderModel extends WikiObjectModelCollection {
|
13 | | - protected $m_key;
|
14 | | -
|
15 | | - public function __construct( $key ) {
|
16 | | - parent::__construct( WOM_TYPE_TMPL_FIELD_HOLDER );
|
17 | | - $this->m_key = $key;
|
18 | | - }
|
19 | | -
|
20 | | - public function getKey() {
|
21 | | - return $this->m_key;
|
22 | | - }
|
23 | | -
|
24 | | - public function getWikiText() {
|
25 | | - return "{{{{$this->m_key}|{$this->getValueText()}}}}";
|
26 | | - }
|
27 | | -
|
28 | | - public function getValueText() {
|
29 | | - return parent::getWikiText();
|
30 | | - }
|
31 | | -
|
32 | | - public function setXMLAttribute( $key, $value ) {
|
33 | | - if ( $value == '' ) throw new MWException( __METHOD__ . ": value cannot be empty" );
|
34 | | -
|
35 | | - if ( $key == 'name' ) {
|
36 | | - $this->m_key = $value;
|
37 | | - } else {
|
38 | | - throw new MWException( __METHOD__ . ": invalid key/value pair: name|value_if_blank" );
|
39 | | - }
|
40 | | - }
|
41 | | -
|
42 | | - protected function getXMLAttributes() {
|
43 | | - return 'name="' . self::xml_entities( $this->m_key ) . '"';
|
44 | | - }
|
45 | | -}
|
| 2 | +<?php |
| 3 | +/** |
| 4 | + * This model implements Template Field Holder models. |
| 5 | + * |
| 6 | + * @author Ning |
| 7 | + * @file |
| 8 | + * @ingroup WikiObjectModels |
| 9 | + * |
| 10 | + */ |
| 11 | + |
| 12 | +class WOMTemplateFieldHolderModel extends WikiObjectModelCollection { |
| 13 | + protected $m_key; |
| 14 | + |
| 15 | + public function __construct( $key ) { |
| 16 | + parent::__construct( WOM_TYPE_TMPL_FIELD_HOLDER ); |
| 17 | + $this->m_key = $key; |
| 18 | + } |
| 19 | + |
| 20 | + public function getKey() { |
| 21 | + return $this->m_key; |
| 22 | + } |
| 23 | + |
| 24 | + public function getWikiText() { |
| 25 | + return "{{{{$this->m_key}|{$this->getValueText()}}}}"; |
| 26 | + } |
| 27 | + |
| 28 | + public function getValueText() { |
| 29 | + return parent::getWikiText(); |
| 30 | + } |
| 31 | + |
| 32 | + public function setXMLAttribute( $key, $value ) { |
| 33 | + if ( $value == '' ) throw new MWException( __METHOD__ . ": value cannot be empty" ); |
| 34 | + |
| 35 | + if ( $key == 'name' ) { |
| 36 | + $this->m_key = $value; |
| 37 | + } else { |
| 38 | + throw new MWException( __METHOD__ . ": invalid key/value pair: name|value_if_blank" ); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + protected function getXMLAttributes() { |
| 43 | + return 'name="' . self::xml_entities( $this->m_key ) . '"'; |
| 44 | + } |
| 45 | +} |
Property changes on: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_TmplFieldHolder.php |
___________________________________________________________________ |
Added: svn:eol-style |
46 | 46 | + native |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Paragraph.php |
— | — | @@ -1,25 +1,25 @@ |
2 | | -<?php
|
3 | | -/**
|
4 | | - * This model implements Paragraph models.
|
5 | | - *
|
6 | | - * @author Ning
|
7 | | - * @file
|
8 | | - * @ingroup WikiObjectModels
|
9 | | - *
|
10 | | - */
|
11 | | -
|
12 | | -class WOMParagraphModel extends WikiObjectModelCollection {
|
13 | | -
|
14 | | - public function __construct() {
|
15 | | - parent::__construct( WOM_TYPE_PARAGRAPH );
|
16 | | - }
|
17 | | -
|
18 | | - public function getWikiText() {
|
19 | | - $pre = $this->getPreviousObject();
|
20 | | - return ( ( $pre != null && ( $pre->getTypeID() == WOM_TYPE_PARAGRAPH ) ) ? "\n\n" : '' ) . $this->getValueText();
|
21 | | - }
|
22 | | -
|
23 | | - public function getValueText() {
|
24 | | - return parent::getWikiText();
|
25 | | - }
|
26 | | -}
|
| 2 | +<?php |
| 3 | +/** |
| 4 | + * This model implements Paragraph models. |
| 5 | + * |
| 6 | + * @author Ning |
| 7 | + * @file |
| 8 | + * @ingroup WikiObjectModels |
| 9 | + * |
| 10 | + */ |
| 11 | + |
| 12 | +class WOMParagraphModel extends WikiObjectModelCollection { |
| 13 | + |
| 14 | + public function __construct() { |
| 15 | + parent::__construct( WOM_TYPE_PARAGRAPH ); |
| 16 | + } |
| 17 | + |
| 18 | + public function getWikiText() { |
| 19 | + $pre = $this->getPreviousObject(); |
| 20 | + return ( ( $pre != null && ( $pre->getTypeID() == WOM_TYPE_PARAGRAPH ) ) ? "\n\n" : '' ) . $this->getValueText(); |
| 21 | + } |
| 22 | + |
| 23 | + public function getValueText() { |
| 24 | + return parent::getWikiText(); |
| 25 | + } |
| 26 | +} |
Property changes on: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Paragraph.php |
___________________________________________________________________ |
Added: svn:eol-style |
27 | 27 | + native |
Index: trunk/extensions/WikiObjectModel/includes/apis/WOM_OutputObjectModel.php |
— | — | @@ -1,139 +1,139 @@ |
2 | | -<?php
|
3 | | -
|
4 | | -global $wgOMIP;
|
5 | | -require_once( $wgOMIP . '/includes/apis/WOM_OutputProcessor.php' );
|
6 | | -
|
7 | | -/**
|
8 | | - * @addtogroup API
|
9 | | - */
|
10 | | -class ApiWOMOutputObjectModel extends ApiBase {
|
11 | | -
|
12 | | - public function __construct( $main, $action ) {
|
13 | | - parent :: __construct( $main, $action );
|
14 | | - }
|
15 | | -
|
16 | | - public function execute() {
|
17 | | - global $wgUser;
|
18 | | -
|
19 | | - $params = $this->extractRequestParams();
|
20 | | - if ( is_null( $params['title'] ) )
|
21 | | - $this->dieUsage( 'Must specify page title', 0 );
|
22 | | - if ( is_null( $params['xpath'] ) )
|
23 | | - $this->dieUsage( 'Must specify xpath', 1 );
|
24 | | -
|
25 | | - $page_name = $params['title'];
|
26 | | - $xpath = $params['xpath'];
|
27 | | - $type = $params['type'];
|
28 | | - $rid = $params['rid'];
|
29 | | -
|
30 | | -
|
31 | | - $articleTitle = Title::newFromText( $page_name );
|
32 | | - if ( !$articleTitle )
|
33 | | - $this->dieUsage( "Can't create title object ($page_name)", 2 );
|
34 | | -
|
35 | | - $article = new Article( $articleTitle );
|
36 | | - if ( !$article->exists() )
|
37 | | - $this->dieUsage( "Article doesn't exist ($page_name)", 3 );
|
38 | | -
|
39 | | - $page_obj = WOMOutputProcessor::getOutputData( $articleTitle, $rid );
|
40 | | - try {
|
41 | | - $objs = WOMProcessor::getObjIdByXPath2( $page_obj, $xpath );
|
42 | | - } catch ( Exception $e ) {
|
43 | | - $err = $e->getMessage();
|
44 | | - }
|
45 | | -
|
46 | | - $result = array();
|
47 | | -
|
48 | | - if ( isset( $err ) ) {
|
49 | | - $result = array(
|
50 | | - 'result' => 'Failure',
|
51 | | - 'message' => array(),
|
52 | | - );
|
53 | | - $this->getResult()->setContent( $result['message'], $err );
|
54 | | - } else {
|
55 | | - $result['result'] = 'Success';
|
56 | | -
|
57 | | - // pay attention to special xml tag, e.g., <property><value>...</value></property>
|
58 | | - $result['return'] = array();
|
59 | | - if ( $type == 'count' ) {
|
60 | | - $count = 0;
|
61 | | - foreach ( $objs as $id ) {
|
62 | | - if ( $id == '' ) continue;
|
63 | | - ++ $count;
|
64 | | - }
|
65 | | - $this->getResult()->setContent( $result['return'], $count );
|
66 | | - } else {
|
67 | | - $xml = '';
|
68 | | - foreach ( $objs as $id ) {
|
69 | | - if ( $id == '' ) continue;
|
70 | | - $wobj = $page_obj->getObject( $id );
|
71 | | - $result['return'][$id] = array();
|
72 | | - if ( $type == 'xml' ) {
|
73 | | - $xml .= "<{$id} xml:space=\"preserve\">{$wobj->toXML()}</{$id}>";
|
74 | | - } else {
|
75 | | - $this->getResult()->setContent( $result['return'][$id], $wobj->getWikiText() );
|
76 | | - }
|
77 | | - }
|
78 | | - if ( $type == 'xml' ) {
|
79 | | - header ( "Content-Type: application/rdf+xml" );
|
80 | | - echo <<<OUTPUT
|
81 | | -<?xml version="1.0" encoding="UTF-8" ?>
|
82 | | -<api><womoutput result="Success"><return>
|
83 | | -{$xml}
|
84 | | -</return></womoutput></api>
|
85 | | -OUTPUT;
|
86 | | - exit( 1 );
|
87 | | - }
|
88 | | - }
|
89 | | - }
|
90 | | - $this->getResult()->addValue( null, $this->getModuleName(), $result );
|
91 | | - }
|
92 | | -
|
93 | | - protected function getAllowedParams() {
|
94 | | - return array (
|
95 | | - 'title' => null,
|
96 | | - 'xpath' => null,
|
97 | | - 'type' => array(
|
98 | | - ApiBase :: PARAM_DFLT => 'wiki',
|
99 | | - ApiBase :: PARAM_TYPE => array(
|
100 | | - 'wiki',
|
101 | | - 'count',
|
102 | | - 'xml',
|
103 | | - ),
|
104 | | - ),
|
105 | | - 'rid' => array (
|
106 | | - ApiBase :: PARAM_TYPE => 'integer',
|
107 | | - ApiBase :: PARAM_DFLT => 0,
|
108 | | - ApiBase :: PARAM_MIN => 0
|
109 | | - ),
|
110 | | - );
|
111 | | - }
|
112 | | -
|
113 | | - protected function getParamDescription() {
|
114 | | - return array (
|
115 | | - 'title' => 'Title of the page to modify',
|
116 | | - 'xpath' => 'DOM-like xpath to locate WOM object instances (http://www.w3schools.com/xpath/xpath_syntax.asp)',
|
117 | | - 'type' => array (
|
118 | | - 'Type to fetch useful wiki object data',
|
119 | | - 'type = wiki, get wiki text of specified object',
|
120 | | - 'type = count, get objects count with specified xpath',
|
121 | | - 'type = xml, view "encoded objects\' xml" with specified xpath, usually use with format=xml',
|
122 | | - ),
|
123 | | - 'rid' => 'Revision id of specified page - by dafault latest updated revision (0) is used',
|
124 | | - );
|
125 | | - }
|
126 | | -
|
127 | | - protected function getDescription() {
|
128 | | - return 'Call to get object values to Wiki Object Model';
|
129 | | - }
|
130 | | -
|
131 | | - protected function getExamples() {
|
132 | | - return array (
|
133 | | - 'api.php?action=womoutput&title=Somepage&xpath=//template[@name=SomeTempate]/template_field[@key=templateparam]'
|
134 | | - );
|
135 | | - }
|
136 | | -
|
137 | | - public function getVersion() {
|
138 | | - return __CLASS__ . ': $Id$';
|
139 | | - }
|
140 | | -}
|
| 2 | +<?php |
| 3 | + |
| 4 | +global $wgOMIP; |
| 5 | +require_once( $wgOMIP . '/includes/apis/WOM_OutputProcessor.php' ); |
| 6 | + |
| 7 | +/** |
| 8 | + * @addtogroup API |
| 9 | + */ |
| 10 | +class ApiWOMOutputObjectModel extends ApiBase { |
| 11 | + |
| 12 | + public function __construct( $main, $action ) { |
| 13 | + parent :: __construct( $main, $action ); |
| 14 | + } |
| 15 | + |
| 16 | + public function execute() { |
| 17 | + global $wgUser; |
| 18 | + |
| 19 | + $params = $this->extractRequestParams(); |
| 20 | + if ( is_null( $params['title'] ) ) |
| 21 | + $this->dieUsage( 'Must specify page title', 0 ); |
| 22 | + if ( is_null( $params['xpath'] ) ) |
| 23 | + $this->dieUsage( 'Must specify xpath', 1 ); |
| 24 | + |
| 25 | + $page_name = $params['title']; |
| 26 | + $xpath = $params['xpath']; |
| 27 | + $type = $params['type']; |
| 28 | + $rid = $params['rid']; |
| 29 | + |
| 30 | + |
| 31 | + $articleTitle = Title::newFromText( $page_name ); |
| 32 | + if ( !$articleTitle ) |
| 33 | + $this->dieUsage( "Can't create title object ($page_name)", 2 ); |
| 34 | + |
| 35 | + $article = new Article( $articleTitle ); |
| 36 | + if ( !$article->exists() ) |
| 37 | + $this->dieUsage( "Article doesn't exist ($page_name)", 3 ); |
| 38 | + |
| 39 | + $page_obj = WOMOutputProcessor::getOutputData( $articleTitle, $rid ); |
| 40 | + try { |
| 41 | + $objs = WOMProcessor::getObjIdByXPath2( $page_obj, $xpath ); |
| 42 | + } catch ( Exception $e ) { |
| 43 | + $err = $e->getMessage(); |
| 44 | + } |
| 45 | + |
| 46 | + $result = array(); |
| 47 | + |
| 48 | + if ( isset( $err ) ) { |
| 49 | + $result = array( |
| 50 | + 'result' => 'Failure', |
| 51 | + 'message' => array(), |
| 52 | + ); |
| 53 | + $this->getResult()->setContent( $result['message'], $err ); |
| 54 | + } else { |
| 55 | + $result['result'] = 'Success'; |
| 56 | + |
| 57 | + // pay attention to special xml tag, e.g., <property><value>...</value></property> |
| 58 | + $result['return'] = array(); |
| 59 | + if ( $type == 'count' ) { |
| 60 | + $count = 0; |
| 61 | + foreach ( $objs as $id ) { |
| 62 | + if ( $id == '' ) continue; |
| 63 | + ++ $count; |
| 64 | + } |
| 65 | + $this->getResult()->setContent( $result['return'], $count ); |
| 66 | + } else { |
| 67 | + $xml = ''; |
| 68 | + foreach ( $objs as $id ) { |
| 69 | + if ( $id == '' ) continue; |
| 70 | + $wobj = $page_obj->getObject( $id ); |
| 71 | + $result['return'][$id] = array(); |
| 72 | + if ( $type == 'xml' ) { |
| 73 | + $xml .= "<{$id} xml:space=\"preserve\">{$wobj->toXML()}</{$id}>"; |
| 74 | + } else { |
| 75 | + $this->getResult()->setContent( $result['return'][$id], $wobj->getWikiText() ); |
| 76 | + } |
| 77 | + } |
| 78 | + if ( $type == 'xml' ) { |
| 79 | + header ( "Content-Type: application/rdf+xml" ); |
| 80 | + echo <<<OUTPUT |
| 81 | +<?xml version="1.0" encoding="UTF-8" ?> |
| 82 | +<api><womoutput result="Success"><return> |
| 83 | +{$xml} |
| 84 | +</return></womoutput></api> |
| 85 | +OUTPUT; |
| 86 | + exit( 1 ); |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
| 91 | + } |
| 92 | + |
| 93 | + protected function getAllowedParams() { |
| 94 | + return array ( |
| 95 | + 'title' => null, |
| 96 | + 'xpath' => null, |
| 97 | + 'type' => array( |
| 98 | + ApiBase :: PARAM_DFLT => 'wiki', |
| 99 | + ApiBase :: PARAM_TYPE => array( |
| 100 | + 'wiki', |
| 101 | + 'count', |
| 102 | + 'xml', |
| 103 | + ), |
| 104 | + ), |
| 105 | + 'rid' => array ( |
| 106 | + ApiBase :: PARAM_TYPE => 'integer', |
| 107 | + ApiBase :: PARAM_DFLT => 0, |
| 108 | + ApiBase :: PARAM_MIN => 0 |
| 109 | + ), |
| 110 | + ); |
| 111 | + } |
| 112 | + |
| 113 | + protected function getParamDescription() { |
| 114 | + return array ( |
| 115 | + 'title' => 'Title of the page to modify', |
| 116 | + 'xpath' => 'DOM-like xpath to locate WOM object instances (http://www.w3schools.com/xpath/xpath_syntax.asp)', |
| 117 | + 'type' => array ( |
| 118 | + 'Type to fetch useful wiki object data', |
| 119 | + 'type = wiki, get wiki text of specified object', |
| 120 | + 'type = count, get objects count with specified xpath', |
| 121 | + 'type = xml, view "encoded objects\' xml" with specified xpath, usually use with format=xml', |
| 122 | + ), |
| 123 | + 'rid' => 'Revision id of specified page - by dafault latest updated revision (0) is used', |
| 124 | + ); |
| 125 | + } |
| 126 | + |
| 127 | + protected function getDescription() { |
| 128 | + return 'Call to get object values to Wiki Object Model'; |
| 129 | + } |
| 130 | + |
| 131 | + protected function getExamples() { |
| 132 | + return array ( |
| 133 | + 'api.php?action=womoutput&title=Somepage&xpath=//template[@name=SomeTempate]/template_field[@key=templateparam]' |
| 134 | + ); |
| 135 | + } |
| 136 | + |
| 137 | + public function getVersion() { |
| 138 | + return __CLASS__ . ': $Id$'; |
| 139 | + } |
| 140 | +} |
Property changes on: trunk/extensions/WikiObjectModel/includes/apis/WOM_OutputObjectModel.php |
___________________________________________________________________ |
Added: svn:eol-style |
141 | 141 | + native |
Index: trunk/extensions/WikiObjectModel/includes/apis/WOM_OM_QueryResult.php |
— | — | @@ -1,16 +1,16 @@ |
2 | | -<?php
|
3 | | -/**
|
4 | | - * This model implements Query result models.
|
5 | | - *
|
6 | | - * @author Ning
|
7 | | - * @file
|
8 | | - * @ingroup WikiObjectModels
|
9 | | - *
|
10 | | - */
|
11 | | -
|
12 | | -class WOMQueryResult extends WikiObjectModelCollection {
|
13 | | -
|
14 | | - public function __construct() {
|
15 | | - parent::__construct( 'q_result' );
|
16 | | - }
|
17 | | -}
|
| 2 | +<?php |
| 3 | +/** |
| 4 | + * This model implements Query result models. |
| 5 | + * |
| 6 | + * @author Ning |
| 7 | + * @file |
| 8 | + * @ingroup WikiObjectModels |
| 9 | + * |
| 10 | + */ |
| 11 | + |
| 12 | +class WOMQueryResult extends WikiObjectModelCollection { |
| 13 | + |
| 14 | + public function __construct() { |
| 15 | + parent::__construct( 'q_result' ); |
| 16 | + } |
| 17 | +} |
Property changes on: trunk/extensions/WikiObjectModel/includes/apis/WOM_OM_QueryResult.php |
___________________________________________________________________ |
Added: svn:eol-style |
18 | 18 | + native |
Index: trunk/extensions/WikiObjectModel/includes/apis/WOM_OutputProcessor.php |
— | — | @@ -1,298 +1,298 @@ |
2 | | -<?php
|
3 | | -if ( !defined( 'MEDIAWIKI' ) ) die;
|
4 | | -
|
5 | | -global $wgHooks, $wgParser;
|
6 | | -if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
|
7 | | - $wgHooks['ParserFirstCallInit'][] = 'WOMOutputProcessor::smwgWTregisterParserFunctions';
|
8 | | -} else {
|
9 | | - if ( class_exists( 'StubObject' ) && !StubObject::isRealObject( $wgParser ) ) {
|
10 | | - $wgParser->_unstub();
|
11 | | - }
|
12 | | - WOMOutputProcessor::smwgWTregisterParserFunctions( $wgParser );
|
13 | | -}
|
14 | | -
|
15 | | -global $wgOMOutputHookedParserFunctions;
|
16 | | -$wgOMOutputHookedParserFunctions = array(
|
17 | | - 'ask',
|
18 | | - 'sparql',
|
19 | | -);
|
20 | | -
|
21 | | -global $wgOMIP;
|
22 | | -require_once( $wgOMIP . '/includes/apis/WOM_OM_QueryResult.php' );
|
23 | | -
|
24 | | -class WOMOutputProcessor {
|
25 | | - static function smwfProcessSPARQLQueryParserFunctionGTP( &$parser ) {
|
26 | | - global $smwgWebserviceEndpoint;
|
27 | | - if ( !isset( $smwgWebserviceEndpoint ) ) return '';
|
28 | | -
|
29 | | - global $smwgIQRunningNumber;
|
30 | | - $smwgIQRunningNumber++;
|
31 | | - $params = func_get_args();
|
32 | | - array_shift( $params ); // we already know the $parser ...
|
33 | | -
|
34 | | - SMWSPARQLQueryProcessor::processFunctionParams( $params, $querystring, $params, $printouts );
|
35 | | - $query = SMWSPARQLQueryProcessor::createQuery( $querystring, $params, SMWQueryProcessor::INLINE_QUERY, '', $printouts );
|
36 | | -
|
37 | | - if ( !( ( $query->querymode == SMWQuery::MODE_INSTANCES ) || ( $query->querymode == SMWQuery::MODE_NONE ) ) ) {
|
38 | | - return '';
|
39 | | - }
|
40 | | - self::prequery( $params, $printouts, $label, $wom_id );
|
41 | | -
|
42 | | - // source from SMWHalo, SMW_SPARQLQueryProcessor.php
|
43 | | -
|
44 | | - // Query routing allows extensions to provide alternative stores as data sources
|
45 | | - // The while feature is experimental and is not properly integrated with most of SMW's architecture. For instance, some query printers just fetch their own store.
|
46 | | - // / TODO: case-insensitive
|
47 | | - global $smwgQuerySources;
|
48 | | -
|
49 | | - $query->params = $params; // this is a hack
|
50 | | -
|
51 | | - if ( array_key_exists( "source", $params ) && array_key_exists( $params["source"], $smwgQuerySources ) ) {
|
52 | | - $store = new $smwgQuerySources[$params["source"]]();
|
53 | | - } else {
|
54 | | - $store = smwfGetStore(); // default store
|
55 | | - }
|
56 | | -
|
57 | | - $res = $store->getQueryResult( $query );
|
58 | | -
|
59 | | - if ( !is_array( $res ) ) {
|
60 | | - $qResults['tsc'] = $res;
|
61 | | - } else {
|
62 | | - $qResults = $res;
|
63 | | - }
|
64 | | -
|
65 | | - foreach ( $qResults as $source => $res ) {
|
66 | | - while ( $row = $res->getNext() ) {
|
67 | | - $firstcol = true;
|
68 | | - foreach ( $row as $field ) {
|
69 | | - $object = $field->getNextObject();
|
70 | | - $text = $object->getWikiValue();
|
71 | | - self::$queryProps[$wom_id][$label][] = $text;
|
72 | | -
|
73 | | - // get the first column only
|
74 | | - break;
|
75 | | - }
|
76 | | - }
|
77 | | - }
|
78 | | -
|
79 | | - return '';
|
80 | | - }
|
81 | | - private static function prequery( &$params, $printouts, &$label, &$wom_id ) {
|
82 | | - if ( isset( $params['mainlabel'] ) ) {
|
83 | | - $label = $params['mainlabel'];
|
84 | | - if ( $label == '-' ) {
|
85 | | - $pr = $printouts[0];
|
86 | | - $label = $pr->getLabel();
|
87 | | - }
|
88 | | - } else {
|
89 | | - $label = '{Query #' . self::$queryId . '}';
|
90 | | - self::$queryId ++;
|
91 | | - }
|
92 | | -
|
93 | | - if ( !isset( $params['limit'] ) ) {
|
94 | | - $params['limit'] = 20; // limit to 20 result by default
|
95 | | - }
|
96 | | - $wom_id = '';
|
97 | | - if ( isset( $params['wom_id'] ) ) {
|
98 | | - $wom_id = $params['wom_id'];
|
99 | | - }
|
100 | | - }
|
101 | | - static function smwfProcessInlineQueryParserFunctionGTP( &$parser ) {
|
102 | | - global $smwgQEnabled, $smwgIQRunningNumber;
|
103 | | - if ( $smwgQEnabled ) {
|
104 | | - $smwgIQRunningNumber++;
|
105 | | - $rawparams = func_get_args();
|
106 | | - array_shift( $rawparams ); // we already know the $parser ...
|
107 | | -
|
108 | | - SMWQueryProcessor::processFunctionParams( $rawparams, &$querystring, &$params, &$printouts );
|
109 | | - self::prequery( $params, $printouts, $label, $wom_id );
|
110 | | -
|
111 | | - $query = SMWQueryProcessor::createQuery(
|
112 | | - $querystring,
|
113 | | - $params,
|
114 | | - SMWQueryProcessor::INLINE_QUERY,
|
115 | | - SMW_OUTPUT_WIKI,
|
116 | | - $printouts
|
117 | | - );
|
118 | | - $res = smwfGetStore()->getQueryResult( $query );
|
119 | | -
|
120 | | - while ( $row = $res->getNext() ) {
|
121 | | - $firstcol = true;
|
122 | | - foreach ( $row as $field ) {
|
123 | | - $object = $field->getNextObject();
|
124 | | - $text = $object->getWikiValue();
|
125 | | - self::$queryProps[$wom_id][$label][] = $text;
|
126 | | -
|
127 | | - // get the first column only
|
128 | | - break;
|
129 | | - }
|
130 | | - }
|
131 | | - }
|
132 | | - return '';
|
133 | | - }
|
134 | | -
|
135 | | - static function smwgWTregisterParserFunctions( &$parser ) {
|
136 | | - global $wgWOMOutputHooked;
|
137 | | - if ( $wgWOMOutputHooked === true ) {
|
138 | | - if ( defined( 'SMW_VERSION' ) ) {
|
139 | | - $parser->setFunctionHook( 'ask', 'WOMOutputProcessor::smwfProcessInlineQueryParserFunctionGTP' );
|
140 | | - }
|
141 | | - if ( defined( 'SMW_HALO_VERSION' ) ) {
|
142 | | - $parser->setFunctionHook( 'sparql', 'WOMOutputProcessor::smwfProcessSPARQLQueryParserFunctionGTP' );
|
143 | | - }
|
144 | | - }
|
145 | | - return true; // always return true, in order not to stop MW's hook processing!
|
146 | | - }
|
147 | | -
|
148 | | - private static function removeSubWOMIds( WikiObjectModelCollection $parent ) {
|
149 | | - foreach ( $parent->getObjects() as $wobj ) {
|
150 | | - $wobj->setObjectID( '' );
|
151 | | - if ( $wobj instanceof WikiObjectModelCollection ) {
|
152 | | - self::removeSubWOMIds( $wobj );
|
153 | | - }
|
154 | | - }
|
155 | | - }
|
156 | | -
|
157 | | - static $queryProps = null;
|
158 | | - static $queryId = 0;
|
159 | | - static function getOutputData( $title, $rid = 0 ) {
|
160 | | - // normal page
|
161 | | - global $wgTitle, $wgUser;
|
162 | | - $wgTitle = $title;
|
163 | | - $revision = Revision::newFromTitle( $title, $rid );
|
164 | | - if ( $revision === NULL ) {
|
165 | | - throw new MWException( __METHOD__ . ": Page not exist '{$page_name} ({$rid})'" );
|
166 | | - }
|
167 | | - $text = $revision->getText();
|
168 | | - $wom = WOMProcessor::parseToWOM( $text );
|
169 | | -
|
170 | | - global $wgOMOutputHookedParserFunctions;
|
171 | | - $pfs = $wom->getObjectsByTypeID( WOM_TYPE_PARSERFUNCTION );
|
172 | | - foreach ( $pfs as $id => $obj ) {
|
173 | | - self::removeSubWOMIds( $obj );
|
174 | | - foreach ( $wgOMOutputHookedParserFunctions as $function_key ) {
|
175 | | - if ( $obj->getFunctionKey() == $function_key ) {
|
176 | | - // add wom id to parser function, with specified parameter 'wom_id'
|
177 | | - $param = new WOMParameterModel( 'wom_id' );
|
178 | | - $pv = new WOMParamValueModel();
|
179 | | - $param->insertObject( $pv );
|
180 | | - $pv->insertObject( new WOMTextModel( $id ) );
|
181 | | - $obj->insertObject( $param );
|
182 | | - }
|
183 | | - }
|
184 | | - }
|
185 | | - // FIXME: template values may have object ids
|
186 | | - $tmpls = $wom->getObjectsByTypeID( WOM_TYPE_TEMPLATE );
|
187 | | - foreach ( $tmpls as $id => $obj ) {
|
188 | | - self::removeSubWOMIds( $obj );
|
189 | | - }
|
190 | | -
|
191 | | - global $wgParser, $wgOut, $wgWOMOutputHooked;
|
192 | | - $wgWOMOutputHooked = true;
|
193 | | - $options = ParserOptions::newFromUser( $wgUser );
|
194 | | -
|
195 | | - self::$queryProps = array();
|
196 | | - self::$queryId = 1;
|
197 | | - $wgParser->parse( $wom->getWikiText(), $title, $options );
|
198 | | -
|
199 | | - $output = SMWParseData::getSMWdata( $wgParser );
|
200 | | -
|
201 | | - if ( !isset( $output ) ) {
|
202 | | - $semdata = smwfGetStore()->getSemanticData( $title );
|
203 | | - } else {
|
204 | | - $semdata = $output;
|
205 | | - }
|
206 | | -
|
207 | | - $tmp_id = 0;
|
208 | | - // fill in semantic properties
|
209 | | - $properties = array();
|
210 | | - foreach ( $semdata->getProperties() as $property ) {
|
211 | | - if ( !$property->isShown() ) { // showing this is not desired, hide
|
212 | | - continue;
|
213 | | - } elseif ( $property->isUserDefined() ) { // user defined property
|
214 | | - $property->setCaption( preg_replace( '/[ ]/u', ' ', $property->getWikiValue(), 2 ) );
|
215 | | - // / NOTE: the preg_replace is a slight hack to ensure that the left column does not get too narrow
|
216 | | - $properties[$property->getWikiValue()] = array();
|
217 | | - } elseif ( $property->isVisible() ) { // predefined property
|
218 | | - $properties[$property->getWikiValue()] = array();
|
219 | | - } else { // predefined, internal property
|
220 | | - continue;
|
221 | | - }
|
222 | | -
|
223 | | - $propvalues = $semdata->getPropertyValues( $property );
|
224 | | - foreach ( $propvalues as $propvalue ) {
|
225 | | - $properties[$property->getWikiValue()][$propvalue->getWikiValue()] = false;
|
226 | | - }
|
227 | | - }
|
228 | | - $props = $wom->getObjectsByTypeID( WOM_TYPE_PROPERTY );
|
229 | | - foreach ( $props as $prop ) {
|
230 | | - $id = $prop->getObjectID();
|
231 | | - if ( $id == '' ) continue;
|
232 | | - $name = $prop->getPropertyName();
|
233 | | - $value = $prop->getPropertyValue();
|
234 | | - if ( !isset( $properties[$name][$value] ) ) {
|
235 | | - // remove category not match to output
|
236 | | - $wom->removePageObject( $id );
|
237 | | - } else {
|
238 | | - $properties[$name][$value] = true;
|
239 | | - }
|
240 | | - }
|
241 | | - foreach ( $properties as $name => $values ) {
|
242 | | - foreach ( $values as $val => $flag ) {
|
243 | | - if ( $flag !== true ) {
|
244 | | - $p = new WOMPropertyModel( $name, $val );
|
245 | | - $p->setObjectID( 'output' . ( $tmp_id ++ ) );
|
246 | | - $wom->insertObject( $p );
|
247 | | - $wom->addToPageObjectSet( $p );
|
248 | | - }
|
249 | | - }
|
250 | | - }
|
251 | | -
|
252 | | - // fill in ask query results
|
253 | | - foreach ( self::$queryProps as $wom_id => $queries ) {
|
254 | | - $query_res = new WOMQueryResult();
|
255 | | - if ( $wom_id != '' ) {
|
256 | | - $parent = $wom->getObject( $wom_id );
|
257 | | - } else {
|
258 | | - $parent = new WOMParserFunctionModel( 'ask' );
|
259 | | - $parent->setObjectID( 'output' . ( $tmp_id ++ ) );
|
260 | | - $wom->insertObject( $parent );
|
261 | | - $wom->addToPageObjectSet( $parent );
|
262 | | - }
|
263 | | - $parent->insertObject( $query_res );
|
264 | | - $query_res->setObjectID( 'output' . ( $tmp_id ++ ) );
|
265 | | - $wom->addToPageObjectSet( $query_res );
|
266 | | - foreach ( $queries as $label => $vals ) {
|
267 | | - $vals = array_unique( $vals );
|
268 | | - foreach ( $vals as $val ) {
|
269 | | - $query_res->insertObject( new WOMPropertyModel( $label, $val ) );
|
270 | | - }
|
271 | | - }
|
272 | | - }
|
273 | | -
|
274 | | - // fill in categories
|
275 | | - $categories = $title->getParentCategories();
|
276 | | - $cates = $wom->getObjectsByTypeID( WOM_TYPE_CATEGORY );
|
277 | | - foreach ( $cates as $cate ) {
|
278 | | - $id = $cate->getObjectID();
|
279 | | - if ( $id == '' ) continue;
|
280 | | - $name = Title::newFromText( $cate->getName(), NS_CATEGORY )->getFullText();
|
281 | | - if ( !isset( $categories[$name] ) ) {
|
282 | | - // remove category not match to output
|
283 | | - $wom->removePageObject( $id );
|
284 | | - } else {
|
285 | | - $categories[$name] = true;
|
286 | | - }
|
287 | | - }
|
288 | | - foreach ( $categories as $cate => $flag ) {
|
289 | | - if ( $flag !== true ) {
|
290 | | - $c = new WOMCategoryModel( Title::newFromText( $cate )->getText() );
|
291 | | - $c->setObjectID( 'output' . ( $tmp_id ++ ) );
|
292 | | - $wom->insertObject( $c );
|
293 | | - $wom->addToPageObjectSet( $c );
|
294 | | - }
|
295 | | - }
|
296 | | -
|
297 | | - return $wom;
|
298 | | - }
|
299 | | -}
|
| 2 | +<?php |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) die; |
| 4 | + |
| 5 | +global $wgHooks, $wgParser; |
| 6 | +if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { |
| 7 | + $wgHooks['ParserFirstCallInit'][] = 'WOMOutputProcessor::smwgWTregisterParserFunctions'; |
| 8 | +} else { |
| 9 | + if ( class_exists( 'StubObject' ) && !StubObject::isRealObject( $wgParser ) ) { |
| 10 | + $wgParser->_unstub(); |
| 11 | + } |
| 12 | + WOMOutputProcessor::smwgWTregisterParserFunctions( $wgParser ); |
| 13 | +} |
| 14 | + |
| 15 | +global $wgOMOutputHookedParserFunctions; |
| 16 | +$wgOMOutputHookedParserFunctions = array( |
| 17 | + 'ask', |
| 18 | + 'sparql', |
| 19 | +); |
| 20 | + |
| 21 | +global $wgOMIP; |
| 22 | +require_once( $wgOMIP . '/includes/apis/WOM_OM_QueryResult.php' ); |
| 23 | + |
| 24 | +class WOMOutputProcessor { |
| 25 | + static function smwfProcessSPARQLQueryParserFunctionGTP( &$parser ) { |
| 26 | + global $smwgWebserviceEndpoint; |
| 27 | + if ( !isset( $smwgWebserviceEndpoint ) ) return ''; |
| 28 | + |
| 29 | + global $smwgIQRunningNumber; |
| 30 | + $smwgIQRunningNumber++; |
| 31 | + $params = func_get_args(); |
| 32 | + array_shift( $params ); // we already know the $parser ... |
| 33 | + |
| 34 | + SMWSPARQLQueryProcessor::processFunctionParams( $params, $querystring, $params, $printouts ); |
| 35 | + $query = SMWSPARQLQueryProcessor::createQuery( $querystring, $params, SMWQueryProcessor::INLINE_QUERY, '', $printouts ); |
| 36 | + |
| 37 | + if ( !( ( $query->querymode == SMWQuery::MODE_INSTANCES ) || ( $query->querymode == SMWQuery::MODE_NONE ) ) ) { |
| 38 | + return ''; |
| 39 | + } |
| 40 | + self::prequery( $params, $printouts, $label, $wom_id ); |
| 41 | + |
| 42 | + // source from SMWHalo, SMW_SPARQLQueryProcessor.php |
| 43 | + |
| 44 | + // Query routing allows extensions to provide alternative stores as data sources |
| 45 | + // The while feature is experimental and is not properly integrated with most of SMW's architecture. For instance, some query printers just fetch their own store. |
| 46 | + // / TODO: case-insensitive |
| 47 | + global $smwgQuerySources; |
| 48 | + |
| 49 | + $query->params = $params; // this is a hack |
| 50 | + |
| 51 | + if ( array_key_exists( "source", $params ) && array_key_exists( $params["source"], $smwgQuerySources ) ) { |
| 52 | + $store = new $smwgQuerySources[$params["source"]](); |
| 53 | + } else { |
| 54 | + $store = smwfGetStore(); // default store |
| 55 | + } |
| 56 | + |
| 57 | + $res = $store->getQueryResult( $query ); |
| 58 | + |
| 59 | + if ( !is_array( $res ) ) { |
| 60 | + $qResults['tsc'] = $res; |
| 61 | + } else { |
| 62 | + $qResults = $res; |
| 63 | + } |
| 64 | + |
| 65 | + foreach ( $qResults as $source => $res ) { |
| 66 | + while ( $row = $res->getNext() ) { |
| 67 | + $firstcol = true; |
| 68 | + foreach ( $row as $field ) { |
| 69 | + $object = $field->getNextObject(); |
| 70 | + $text = $object->getWikiValue(); |
| 71 | + self::$queryProps[$wom_id][$label][] = $text; |
| 72 | + |
| 73 | + // get the first column only |
| 74 | + break; |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + return ''; |
| 80 | + } |
| 81 | + private static function prequery( &$params, $printouts, &$label, &$wom_id ) { |
| 82 | + if ( isset( $params['mainlabel'] ) ) { |
| 83 | + $label = $params['mainlabel']; |
| 84 | + if ( $label == '-' ) { |
| 85 | + $pr = $printouts[0]; |
| 86 | + $label = $pr->getLabel(); |
| 87 | + } |
| 88 | + } else { |
| 89 | + $label = '{Query #' . self::$queryId . '}'; |
| 90 | + self::$queryId ++; |
| 91 | + } |
| 92 | + |
| 93 | + if ( !isset( $params['limit'] ) ) { |
| 94 | + $params['limit'] = 20; // limit to 20 result by default |
| 95 | + } |
| 96 | + $wom_id = ''; |
| 97 | + if ( isset( $params['wom_id'] ) ) { |
| 98 | + $wom_id = $params['wom_id']; |
| 99 | + } |
| 100 | + } |
| 101 | + static function smwfProcessInlineQueryParserFunctionGTP( &$parser ) { |
| 102 | + global $smwgQEnabled, $smwgIQRunningNumber; |
| 103 | + if ( $smwgQEnabled ) { |
| 104 | + $smwgIQRunningNumber++; |
| 105 | + $rawparams = func_get_args(); |
| 106 | + array_shift( $rawparams ); // we already know the $parser ... |
| 107 | + |
| 108 | + SMWQueryProcessor::processFunctionParams( $rawparams, &$querystring, &$params, &$printouts ); |
| 109 | + self::prequery( $params, $printouts, $label, $wom_id ); |
| 110 | + |
| 111 | + $query = SMWQueryProcessor::createQuery( |
| 112 | + $querystring, |
| 113 | + $params, |
| 114 | + SMWQueryProcessor::INLINE_QUERY, |
| 115 | + SMW_OUTPUT_WIKI, |
| 116 | + $printouts |
| 117 | + ); |
| 118 | + $res = smwfGetStore()->getQueryResult( $query ); |
| 119 | + |
| 120 | + while ( $row = $res->getNext() ) { |
| 121 | + $firstcol = true; |
| 122 | + foreach ( $row as $field ) { |
| 123 | + $object = $field->getNextObject(); |
| 124 | + $text = $object->getWikiValue(); |
| 125 | + self::$queryProps[$wom_id][$label][] = $text; |
| 126 | + |
| 127 | + // get the first column only |
| 128 | + break; |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + return ''; |
| 133 | + } |
| 134 | + |
| 135 | + static function smwgWTregisterParserFunctions( &$parser ) { |
| 136 | + global $wgWOMOutputHooked; |
| 137 | + if ( $wgWOMOutputHooked === true ) { |
| 138 | + if ( defined( 'SMW_VERSION' ) ) { |
| 139 | + $parser->setFunctionHook( 'ask', 'WOMOutputProcessor::smwfProcessInlineQueryParserFunctionGTP' ); |
| 140 | + } |
| 141 | + if ( defined( 'SMW_HALO_VERSION' ) ) { |
| 142 | + $parser->setFunctionHook( 'sparql', 'WOMOutputProcessor::smwfProcessSPARQLQueryParserFunctionGTP' ); |
| 143 | + } |
| 144 | + } |
| 145 | + return true; // always return true, in order not to stop MW's hook processing! |
| 146 | + } |
| 147 | + |
| 148 | + private static function removeSubWOMIds( WikiObjectModelCollection $parent ) { |
| 149 | + foreach ( $parent->getObjects() as $wobj ) { |
| 150 | + $wobj->setObjectID( '' ); |
| 151 | + if ( $wobj instanceof WikiObjectModelCollection ) { |
| 152 | + self::removeSubWOMIds( $wobj ); |
| 153 | + } |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + static $queryProps = null; |
| 158 | + static $queryId = 0; |
| 159 | + static function getOutputData( $title, $rid = 0 ) { |
| 160 | + // normal page |
| 161 | + global $wgTitle, $wgUser; |
| 162 | + $wgTitle = $title; |
| 163 | + $revision = Revision::newFromTitle( $title, $rid ); |
| 164 | + if ( $revision === NULL ) { |
| 165 | + throw new MWException( __METHOD__ . ": Page not exist '{$page_name} ({$rid})'" ); |
| 166 | + } |
| 167 | + $text = $revision->getText(); |
| 168 | + $wom = WOMProcessor::parseToWOM( $text ); |
| 169 | + |
| 170 | + global $wgOMOutputHookedParserFunctions; |
| 171 | + $pfs = $wom->getObjectsByTypeID( WOM_TYPE_PARSERFUNCTION ); |
| 172 | + foreach ( $pfs as $id => $obj ) { |
| 173 | + self::removeSubWOMIds( $obj ); |
| 174 | + foreach ( $wgOMOutputHookedParserFunctions as $function_key ) { |
| 175 | + if ( $obj->getFunctionKey() == $function_key ) { |
| 176 | + // add wom id to parser function, with specified parameter 'wom_id' |
| 177 | + $param = new WOMParameterModel( 'wom_id' ); |
| 178 | + $pv = new WOMParamValueModel(); |
| 179 | + $param->insertObject( $pv ); |
| 180 | + $pv->insertObject( new WOMTextModel( $id ) ); |
| 181 | + $obj->insertObject( $param ); |
| 182 | + } |
| 183 | + } |
| 184 | + } |
| 185 | + // FIXME: template values may have object ids |
| 186 | + $tmpls = $wom->getObjectsByTypeID( WOM_TYPE_TEMPLATE ); |
| 187 | + foreach ( $tmpls as $id => $obj ) { |
| 188 | + self::removeSubWOMIds( $obj ); |
| 189 | + } |
| 190 | + |
| 191 | + global $wgParser, $wgOut, $wgWOMOutputHooked; |
| 192 | + $wgWOMOutputHooked = true; |
| 193 | + $options = ParserOptions::newFromUser( $wgUser ); |
| 194 | + |
| 195 | + self::$queryProps = array(); |
| 196 | + self::$queryId = 1; |
| 197 | + $wgParser->parse( $wom->getWikiText(), $title, $options ); |
| 198 | + |
| 199 | + $output = SMWParseData::getSMWdata( $wgParser ); |
| 200 | + |
| 201 | + if ( !isset( $output ) ) { |
| 202 | + $semdata = smwfGetStore()->getSemanticData( $title ); |
| 203 | + } else { |
| 204 | + $semdata = $output; |
| 205 | + } |
| 206 | + |
| 207 | + $tmp_id = 0; |
| 208 | + // fill in semantic properties |
| 209 | + $properties = array(); |
| 210 | + foreach ( $semdata->getProperties() as $property ) { |
| 211 | + if ( !$property->isShown() ) { // showing this is not desired, hide |
| 212 | + continue; |
| 213 | + } elseif ( $property->isUserDefined() ) { // user defined property |
| 214 | + $property->setCaption( preg_replace( '/[ ]/u', ' ', $property->getWikiValue(), 2 ) ); |
| 215 | + // / NOTE: the preg_replace is a slight hack to ensure that the left column does not get too narrow |
| 216 | + $properties[$property->getWikiValue()] = array(); |
| 217 | + } elseif ( $property->isVisible() ) { // predefined property |
| 218 | + $properties[$property->getWikiValue()] = array(); |
| 219 | + } else { // predefined, internal property |
| 220 | + continue; |
| 221 | + } |
| 222 | + |
| 223 | + $propvalues = $semdata->getPropertyValues( $property ); |
| 224 | + foreach ( $propvalues as $propvalue ) { |
| 225 | + $properties[$property->getWikiValue()][$propvalue->getWikiValue()] = false; |
| 226 | + } |
| 227 | + } |
| 228 | + $props = $wom->getObjectsByTypeID( WOM_TYPE_PROPERTY ); |
| 229 | + foreach ( $props as $prop ) { |
| 230 | + $id = $prop->getObjectID(); |
| 231 | + if ( $id == '' ) continue; |
| 232 | + $name = $prop->getPropertyName(); |
| 233 | + $value = $prop->getPropertyValue(); |
| 234 | + if ( !isset( $properties[$name][$value] ) ) { |
| 235 | + // remove category not match to output |
| 236 | + $wom->removePageObject( $id ); |
| 237 | + } else { |
| 238 | + $properties[$name][$value] = true; |
| 239 | + } |
| 240 | + } |
| 241 | + foreach ( $properties as $name => $values ) { |
| 242 | + foreach ( $values as $val => $flag ) { |
| 243 | + if ( $flag !== true ) { |
| 244 | + $p = new WOMPropertyModel( $name, $val ); |
| 245 | + $p->setObjectID( 'output' . ( $tmp_id ++ ) ); |
| 246 | + $wom->insertObject( $p ); |
| 247 | + $wom->addToPageObjectSet( $p ); |
| 248 | + } |
| 249 | + } |
| 250 | + } |
| 251 | + |
| 252 | + // fill in ask query results |
| 253 | + foreach ( self::$queryProps as $wom_id => $queries ) { |
| 254 | + $query_res = new WOMQueryResult(); |
| 255 | + if ( $wom_id != '' ) { |
| 256 | + $parent = $wom->getObject( $wom_id ); |
| 257 | + } else { |
| 258 | + $parent = new WOMParserFunctionModel( 'ask' ); |
| 259 | + $parent->setObjectID( 'output' . ( $tmp_id ++ ) ); |
| 260 | + $wom->insertObject( $parent ); |
| 261 | + $wom->addToPageObjectSet( $parent ); |
| 262 | + } |
| 263 | + $parent->insertObject( $query_res ); |
| 264 | + $query_res->setObjectID( 'output' . ( $tmp_id ++ ) ); |
| 265 | + $wom->addToPageObjectSet( $query_res ); |
| 266 | + foreach ( $queries as $label => $vals ) { |
| 267 | + $vals = array_unique( $vals ); |
| 268 | + foreach ( $vals as $val ) { |
| 269 | + $query_res->insertObject( new WOMPropertyModel( $label, $val ) ); |
| 270 | + } |
| 271 | + } |
| 272 | + } |
| 273 | + |
| 274 | + // fill in categories |
| 275 | + $categories = $title->getParentCategories(); |
| 276 | + $cates = $wom->getObjectsByTypeID( WOM_TYPE_CATEGORY ); |
| 277 | + foreach ( $cates as $cate ) { |
| 278 | + $id = $cate->getObjectID(); |
| 279 | + if ( $id == '' ) continue; |
| 280 | + $name = Title::newFromText( $cate->getName(), NS_CATEGORY )->getFullText(); |
| 281 | + if ( !isset( $categories[$name] ) ) { |
| 282 | + // remove category not match to output |
| 283 | + $wom->removePageObject( $id ); |
| 284 | + } else { |
| 285 | + $categories[$name] = true; |
| 286 | + } |
| 287 | + } |
| 288 | + foreach ( $categories as $cate => $flag ) { |
| 289 | + if ( $flag !== true ) { |
| 290 | + $c = new WOMCategoryModel( Title::newFromText( $cate )->getText() ); |
| 291 | + $c->setObjectID( 'output' . ( $tmp_id ++ ) ); |
| 292 | + $wom->insertObject( $c ); |
| 293 | + $wom->addToPageObjectSet( $c ); |
| 294 | + } |
| 295 | + } |
| 296 | + |
| 297 | + return $wom; |
| 298 | + } |
| 299 | +} |
Property changes on: trunk/extensions/WikiObjectModel/includes/apis/WOM_OutputProcessor.php |
___________________________________________________________________ |
Added: svn:eol-style |
300 | 300 | + native |
Index: trunk/extensions/WikiObjectModel/includes/apis/WOM_Query.php |
— | — | @@ -1,154 +1,154 @@ |
2 | | -<?php
|
3 | | -
|
4 | | -/**
|
5 | | - * @addtogroup API
|
6 | | - */
|
7 | | -class ApiWOMQuery extends ApiBase {
|
8 | | -
|
9 | | - public function __construct( $main, $action ) {
|
10 | | - parent :: __construct( $main, $action );
|
11 | | - }
|
12 | | -
|
13 | | - // given the 'key', return the result set of 'xpath' or wiki object id set
|
14 | | - // e.g., key=hello, world&action=womquery,
|
15 | | - // returns <match><id>1</id><type>text</type><start>20</start><end>30</end></match>
|
16 | | - // in wiki object id="1", the text part of WOM node, char index start at 20 and end at 30
|
17 | | - // for the paragraph instance, it will return id1, id2, id 3
|
18 | | - // given the 'key', specify the returning object type, same result set to the previous api
|
19 | | - // e.g., key=hello, world&action=womquery&return=sentence/paragraph/property value/template value/section...
|
20 | | - // for the paragraph instance,
|
21 | | - // return=sentence, it will return id3
|
22 | | - // return=paragraph, it will return id1, id2
|
23 | | - // given the 'key' and returning type, specify the context of required object, same return
|
24 | | - // e.g., key=hello, world&action=womquery&return=sentence&xpath=/page/section[3]
|
25 | | - // for the paragraph instance,
|
26 | | - // return=paragraph, xpath=sentence/.., it will return id2
|
27 | | -
|
28 | | - public function execute() {
|
29 | | - global $wgUser;
|
30 | | -
|
31 | | - $params = $this->extractRequestParams();
|
32 | | - if ( is_null( $params['title'] ) )
|
33 | | - $this->dieUsage( 'Must specify page title', 0 );
|
34 | | - if ( is_null( $params['key'] ) )
|
35 | | - $this->dieUsage( 'Must specify key', 1 );
|
36 | | -
|
37 | | - $page_name = $params['title'];
|
38 | | - $key = $params['key'];
|
39 | | - $rid = $params['rid'];
|
40 | | - $type = $params['type'];
|
41 | | - $xpath = $params['xpath'];
|
42 | | -
|
43 | | - $articleTitle = Title::newFromText( $page_name );
|
44 | | - if ( !$articleTitle )
|
45 | | - $this->dieUsage( "Can't create title object ($page_name)", 2 );
|
46 | | -
|
47 | | - $article = new Article( $articleTitle );
|
48 | | - if ( !$article->exists() )
|
49 | | - $this->dieUsage( "Article doesn't exist ($page_name)", 3 );
|
50 | | -
|
51 | | - if ( !$xpath ) {
|
52 | | - $xpath = '/';
|
53 | | - }
|
54 | | - try {
|
55 | | - $objs = WOMProcessor::getObjIdByXPath( $articleTitle, $xpath, $rid );
|
56 | | - } catch ( Exception $e ) {
|
57 | | - $err = $e->getMessage();
|
58 | | - }
|
59 | | -
|
60 | | - $result = array();
|
61 | | -
|
62 | | - if ( isset( $err ) ) {
|
63 | | - $result = array(
|
64 | | - 'result' => 'Failure',
|
65 | | - 'message' => array(),
|
66 | | - );
|
67 | | - $this->getResult()->setContent( $result['message'], $err );
|
68 | | - } else {
|
69 | | - $result['result'] = 'Success';
|
70 | | -
|
71 | | - // pay attention to special xml tag, e.g., <property><value>...</value></property>
|
72 | | - $result['return'] = array();
|
73 | | - if ( $type == 'count' ) {
|
74 | | - $count = 0;
|
75 | | - foreach ( $objs as $id ) {
|
76 | | - if ( $id == '' ) continue;
|
77 | | - ++ $count;
|
78 | | - }
|
79 | | - $this->getResult()->setContent( $result['return'], $count );
|
80 | | - } else {
|
81 | | - $xml = '';
|
82 | | - $page_obj = WOMProcessor::getPageObject( $articleTitle, $rid );
|
83 | | - foreach ( $objs as $id ) {
|
84 | | - if ( $id == '' ) continue;
|
85 | | - $wobj = $page_obj->getObject( $id );
|
86 | | - $result['return'][$id] = array();
|
87 | | - if ( $type == 'xml' ) {
|
88 | | - $xml .= "<{$id} xml:space=\"preserve\">{$wobj->toXML()}</{$id}>";
|
89 | | -// $this->getResult()->setContent( $result['return'][$id], $wobj->toXML() );
|
90 | | - } else {
|
91 | | - $this->getResult()->setContent( $result['return'][$id], $wobj->getWikiText() );
|
92 | | - }
|
93 | | - }
|
94 | | - if ( $type == 'xml' ) {
|
95 | | - header ( "Content-Type: application/rdf+xml" );
|
96 | | - echo <<<OUTPUT
|
97 | | -<?xml version="1.0" encoding="UTF-8" ?>
|
98 | | -<api><womquery result="Success"><return>
|
99 | | -{$xml}
|
100 | | -</return></womquery></api>
|
101 | | -OUTPUT;
|
102 | | - exit( 1 );
|
103 | | - }
|
104 | | - }
|
105 | | - }
|
106 | | - $this->getResult()->addValue( null, $this->getModuleName(), $result );
|
107 | | - }
|
108 | | -
|
109 | | - protected function getAllowedParams() {
|
110 | | - return array (
|
111 | | - 'title' => null,
|
112 | | - 'key' => null,
|
113 | | - 'xpath' => null,
|
114 | | - 'type' => array(
|
115 | | - ApiBase :: PARAM_DFLT => WOM_TYPE_SENTENCE,
|
116 | | - ApiBase :: PARAM_TYPE => array(
|
117 | | - WOM_TYPE_SECTION,
|
118 | | - WOM_TYPE_PARAGRAPH,
|
119 | | - WOM_TYPE_SENTENCE,
|
120 | | - ),
|
121 | | - ),
|
122 | | - 'rid' => array (
|
123 | | - ApiBase :: PARAM_TYPE => 'integer',
|
124 | | - ApiBase :: PARAM_DFLT => 0,
|
125 | | - ApiBase :: PARAM_MIN => 0
|
126 | | - ),
|
127 | | - );
|
128 | | - }
|
129 | | -
|
130 | | - protected function getParamDescription() {
|
131 | | - return array (
|
132 | | - 'title' => 'Title of the page to modify',
|
133 | | - 'key' => 'query key',
|
134 | | - 'xpath' => 'DOM-like xpath to locate WOM object instances (http://www.w3schools.com/xpath/xpath_syntax.asp)',
|
135 | | - 'type' => array (
|
136 | | - 'Object type to fetch useful wiki object data',
|
137 | | - ),
|
138 | | - 'rid' => 'Revision id of specified page - by dafault latest updated revision (0) is used',
|
139 | | - );
|
140 | | - }
|
141 | | -
|
142 | | - protected function getDescription() {
|
143 | | - return 'Call to get objects to Wiki Object Model';
|
144 | | - }
|
145 | | -
|
146 | | - protected function getExamples() {
|
147 | | - return array (
|
148 | | - 'api.php?action=womquery&title=Somepage&key=hello,world'
|
149 | | - );
|
150 | | - }
|
151 | | -
|
152 | | - public function getVersion() {
|
153 | | - return __CLASS__ . ': $Id$';
|
154 | | - }
|
155 | | -}
|
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * @addtogroup API |
| 6 | + */ |
| 7 | +class ApiWOMQuery extends ApiBase { |
| 8 | + |
| 9 | + public function __construct( $main, $action ) { |
| 10 | + parent :: __construct( $main, $action ); |
| 11 | + } |
| 12 | + |
| 13 | + // given the 'key', return the result set of 'xpath' or wiki object id set |
| 14 | + // e.g., key=hello, world&action=womquery, |
| 15 | + // returns <match><id>1</id><type>text</type><start>20</start><end>30</end></match> |
| 16 | + // in wiki object id="1", the text part of WOM node, char index start at 20 and end at 30 |
| 17 | + // for the paragraph instance, it will return id1, id2, id 3 |
| 18 | + // given the 'key', specify the returning object type, same result set to the previous api |
| 19 | + // e.g., key=hello, world&action=womquery&return=sentence/paragraph/property value/template value/section... |
| 20 | + // for the paragraph instance, |
| 21 | + // return=sentence, it will return id3 |
| 22 | + // return=paragraph, it will return id1, id2 |
| 23 | + // given the 'key' and returning type, specify the context of required object, same return |
| 24 | + // e.g., key=hello, world&action=womquery&return=sentence&xpath=/page/section[3] |
| 25 | + // for the paragraph instance, |
| 26 | + // return=paragraph, xpath=sentence/.., it will return id2 |
| 27 | + |
| 28 | + public function execute() { |
| 29 | + global $wgUser; |
| 30 | + |
| 31 | + $params = $this->extractRequestParams(); |
| 32 | + if ( is_null( $params['title'] ) ) |
| 33 | + $this->dieUsage( 'Must specify page title', 0 ); |
| 34 | + if ( is_null( $params['key'] ) ) |
| 35 | + $this->dieUsage( 'Must specify key', 1 ); |
| 36 | + |
| 37 | + $page_name = $params['title']; |
| 38 | + $key = $params['key']; |
| 39 | + $rid = $params['rid']; |
| 40 | + $type = $params['type']; |
| 41 | + $xpath = $params['xpath']; |
| 42 | + |
| 43 | + $articleTitle = Title::newFromText( $page_name ); |
| 44 | + if ( !$articleTitle ) |
| 45 | + $this->dieUsage( "Can't create title object ($page_name)", 2 ); |
| 46 | + |
| 47 | + $article = new Article( $articleTitle ); |
| 48 | + if ( !$article->exists() ) |
| 49 | + $this->dieUsage( "Article doesn't exist ($page_name)", 3 ); |
| 50 | + |
| 51 | + if ( !$xpath ) { |
| 52 | + $xpath = '/'; |
| 53 | + } |
| 54 | + try { |
| 55 | + $objs = WOMProcessor::getObjIdByXPath( $articleTitle, $xpath, $rid ); |
| 56 | + } catch ( Exception $e ) { |
| 57 | + $err = $e->getMessage(); |
| 58 | + } |
| 59 | + |
| 60 | + $result = array(); |
| 61 | + |
| 62 | + if ( isset( $err ) ) { |
| 63 | + $result = array( |
| 64 | + 'result' => 'Failure', |
| 65 | + 'message' => array(), |
| 66 | + ); |
| 67 | + $this->getResult()->setContent( $result['message'], $err ); |
| 68 | + } else { |
| 69 | + $result['result'] = 'Success'; |
| 70 | + |
| 71 | + // pay attention to special xml tag, e.g., <property><value>...</value></property> |
| 72 | + $result['return'] = array(); |
| 73 | + if ( $type == 'count' ) { |
| 74 | + $count = 0; |
| 75 | + foreach ( $objs as $id ) { |
| 76 | + if ( $id == '' ) continue; |
| 77 | + ++ $count; |
| 78 | + } |
| 79 | + $this->getResult()->setContent( $result['return'], $count ); |
| 80 | + } else { |
| 81 | + $xml = ''; |
| 82 | + $page_obj = WOMProcessor::getPageObject( $articleTitle, $rid ); |
| 83 | + foreach ( $objs as $id ) { |
| 84 | + if ( $id == '' ) continue; |
| 85 | + $wobj = $page_obj->getObject( $id ); |
| 86 | + $result['return'][$id] = array(); |
| 87 | + if ( $type == 'xml' ) { |
| 88 | + $xml .= "<{$id} xml:space=\"preserve\">{$wobj->toXML()}</{$id}>"; |
| 89 | +// $this->getResult()->setContent( $result['return'][$id], $wobj->toXML() ); |
| 90 | + } else { |
| 91 | + $this->getResult()->setContent( $result['return'][$id], $wobj->getWikiText() ); |
| 92 | + } |
| 93 | + } |
| 94 | + if ( $type == 'xml' ) { |
| 95 | + header ( "Content-Type: application/rdf+xml" ); |
| 96 | + echo <<<OUTPUT |
| 97 | +<?xml version="1.0" encoding="UTF-8" ?> |
| 98 | +<api><womquery result="Success"><return> |
| 99 | +{$xml} |
| 100 | +</return></womquery></api> |
| 101 | +OUTPUT; |
| 102 | + exit( 1 ); |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
| 107 | + } |
| 108 | + |
| 109 | + protected function getAllowedParams() { |
| 110 | + return array ( |
| 111 | + 'title' => null, |
| 112 | + 'key' => null, |
| 113 | + 'xpath' => null, |
| 114 | + 'type' => array( |
| 115 | + ApiBase :: PARAM_DFLT => WOM_TYPE_SENTENCE, |
| 116 | + ApiBase :: PARAM_TYPE => array( |
| 117 | + WOM_TYPE_SECTION, |
| 118 | + WOM_TYPE_PARAGRAPH, |
| 119 | + WOM_TYPE_SENTENCE, |
| 120 | + ), |
| 121 | + ), |
| 122 | + 'rid' => array ( |
| 123 | + ApiBase :: PARAM_TYPE => 'integer', |
| 124 | + ApiBase :: PARAM_DFLT => 0, |
| 125 | + ApiBase :: PARAM_MIN => 0 |
| 126 | + ), |
| 127 | + ); |
| 128 | + } |
| 129 | + |
| 130 | + protected function getParamDescription() { |
| 131 | + return array ( |
| 132 | + 'title' => 'Title of the page to modify', |
| 133 | + 'key' => 'query key', |
| 134 | + 'xpath' => 'DOM-like xpath to locate WOM object instances (http://www.w3schools.com/xpath/xpath_syntax.asp)', |
| 135 | + 'type' => array ( |
| 136 | + 'Object type to fetch useful wiki object data', |
| 137 | + ), |
| 138 | + 'rid' => 'Revision id of specified page - by dafault latest updated revision (0) is used', |
| 139 | + ); |
| 140 | + } |
| 141 | + |
| 142 | + protected function getDescription() { |
| 143 | + return 'Call to get objects to Wiki Object Model'; |
| 144 | + } |
| 145 | + |
| 146 | + protected function getExamples() { |
| 147 | + return array ( |
| 148 | + 'api.php?action=womquery&title=Somepage&key=hello,world' |
| 149 | + ); |
| 150 | + } |
| 151 | + |
| 152 | + public function getVersion() { |
| 153 | + return __CLASS__ . ': $Id$'; |
| 154 | + } |
| 155 | +} |
Property changes on: trunk/extensions/WikiObjectModel/includes/apis/WOM_Query.php |
___________________________________________________________________ |
Added: svn:eol-style |
156 | 156 | + native |
Index: trunk/extensions/RegexFun/RELEASE-NOTES |
— | — | @@ -1,9 +1,9 @@ |
2 | | - Changelog:
|
3 | | - ==========
|
4 | | - * Nov. xx, 2011 -- Version 1.0 (initial release).
|
5 | | - Introduces the following parser functions defined within 'ExtRegexFun' class:
|
6 | | - - #regex
|
7 | | - - #regexsearch
|
8 | | - - #regexall
|
9 | | - - #regex_var
|
| 2 | + Changelog: |
| 3 | + ========== |
| 4 | + * Nov. xx, 2011 -- Version 1.0 (initial release). |
| 5 | + Introduces the following parser functions defined within 'ExtRegexFun' class: |
| 6 | + - #regex |
| 7 | + - #regexsearch |
| 8 | + - #regexall |
| 9 | + - #regex_var |
10 | 10 | - #regexquote |
\ No newline at end of file |
Property changes on: trunk/extensions/RegexFun/RELEASE-NOTES |
___________________________________________________________________ |
Added: svn:eol-style |
11 | 11 | + native |
Index: trunk/extensions/RegexFun/README |
— | — | @@ -1,40 +1,40 @@ |
2 | | -== About ==
|
3 | | -
|
4 | | -''Regex Fun'' is a MediaWiki extension by Daniel Werner which adds parser functions for performing regular expression
|
5 | | -searches and replacements.
|
6 | | -The '#regex' parser function is inspired by RegexParserFunctions from Jim R. Wilson and mostly compatible with it.
|
7 | | -RegexParserFunctions has some design flaws and missing functionality that should be filled by this extension.
|
8 | | -
|
9 | | -''Regex Fun'' defines the following parser functions within your wiki:
|
10 | | -
|
11 | | - - #regex: Search or replace with help of php preg regular expression. Returns first match in search mode.
|
12 | | - Use of the 'e' modifier behind the expression will be filtered and eliminated from the pattern!
|
13 | | - - #regexsearch: Same as 'regex' with the difference that in replacement mode if no match could be found, an empty
|
14 | | - string '' will be returned instead of the unaltered original.
|
15 | | - - #regexall: Searches the whole string for as many matches as possible and returns them separated by a separator.
|
16 | | - - #regex_var: Allows to access references of the last used 'regex' or 'regexsearch' function.
|
17 | | - - #regexquote: Runs php function 'preg_quote' on a string to use user-input savelly in regex functions. In case the
|
18 | | - first character is a character with special meaning in MW, it will be replaced with its hexadecimal
|
19 | | - notation e.g. '\x23' instead of '#'. This will prevent from things going terribly wrong when using
|
20 | | - user input within a regular expression.
|
21 | | -
|
22 | | -* Website: http://www.mediawiki.org/wiki/Extension:Regex_Fun
|
23 | | -* Author: Daniel Werner < danweetz@web.de >
|
24 | | -
|
25 | | -
|
26 | | -== Installation ==
|
27 | | -
|
28 | | -Once you have downloaded the code, place the 'RegexFun' directory within your
|
29 | | -MediaWiki 'extensions' directory. Then add the following code to your
|
30 | | -[[Manual:LocalSettings.php|LocalSettings.php]] file:
|
31 | | -
|
32 | | - # RegexFun
|
33 | | - require_once( "$IP/extensions/RegexFun/RegexFun.php" );
|
34 | | -
|
35 | | -
|
36 | | -== Contributing ==
|
37 | | -
|
38 | | -If you have bug reports or requests, please add them to the ''Regex Fun'' Talk page [0].
|
39 | | -You can also send them to Daniel Werner < danweetz@web.de >
|
40 | | -
|
| 2 | +== About == |
| 3 | + |
| 4 | +''Regex Fun'' is a MediaWiki extension by Daniel Werner which adds parser functions for performing regular expression |
| 5 | +searches and replacements. |
| 6 | +The '#regex' parser function is inspired by RegexParserFunctions from Jim R. Wilson and mostly compatible with it. |
| 7 | +RegexParserFunctions has some design flaws and missing functionality that should be filled by this extension. |
| 8 | + |
| 9 | +''Regex Fun'' defines the following parser functions within your wiki: |
| 10 | + |
| 11 | + - #regex: Search or replace with help of php preg regular expression. Returns first match in search mode. |
| 12 | + Use of the 'e' modifier behind the expression will be filtered and eliminated from the pattern! |
| 13 | + - #regexsearch: Same as 'regex' with the difference that in replacement mode if no match could be found, an empty |
| 14 | + string '' will be returned instead of the unaltered original. |
| 15 | + - #regexall: Searches the whole string for as many matches as possible and returns them separated by a separator. |
| 16 | + - #regex_var: Allows to access references of the last used 'regex' or 'regexsearch' function. |
| 17 | + - #regexquote: Runs php function 'preg_quote' on a string to use user-input savelly in regex functions. In case the |
| 18 | + first character is a character with special meaning in MW, it will be replaced with its hexadecimal |
| 19 | + notation e.g. '\x23' instead of '#'. This will prevent from things going terribly wrong when using |
| 20 | + user input within a regular expression. |
| 21 | + |
| 22 | +* Website: http://www.mediawiki.org/wiki/Extension:Regex_Fun |
| 23 | +* Author: Daniel Werner < danweetz@web.de > |
| 24 | + |
| 25 | + |
| 26 | +== Installation == |
| 27 | + |
| 28 | +Once you have downloaded the code, place the 'RegexFun' directory within your |
| 29 | +MediaWiki 'extensions' directory. Then add the following code to your |
| 30 | +[[Manual:LocalSettings.php|LocalSettings.php]] file: |
| 31 | + |
| 32 | + # RegexFun |
| 33 | + require_once( "$IP/extensions/RegexFun/RegexFun.php" ); |
| 34 | + |
| 35 | + |
| 36 | +== Contributing == |
| 37 | + |
| 38 | +If you have bug reports or requests, please add them to the ''Regex Fun'' Talk page [0]. |
| 39 | +You can also send them to Daniel Werner < danweetz@web.de > |
| 40 | + |
41 | 41 | [0] http://www.mediawiki.org/w/index.php?title=Extension_talk:Regex_Fun |
\ No newline at end of file |
Property changes on: trunk/extensions/RegexFun/README |
___________________________________________________________________ |
Added: svn:eol-style |
42 | 42 | + native |