Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMListItemParser.php |
— | — | @@ -16,9 +16,9 @@ |
17 | 17 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
18 | 18 | $lastLF = ( $offset == 0 || $text { $offset - 1 } == "\n" ); |
19 | 19 | $text = substr( $text, $offset ); |
20 | | - if ( $lastLF ) { |
21 | | - $r = preg_match( '/^([\*#]+)/', $text, $m ); |
22 | | - } |
| 20 | + if ( !$lastLF ) return null; |
| 21 | + |
| 22 | + $r = preg_match( '/^([\*#]+)/', $text, $m ); |
23 | 23 | if ( $r ) { |
24 | 24 | $len = strlen( $m[0] ); |
25 | 25 | $obj = new WOMListItemModel( $m[1] ); |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMMagicWordParser.php |
— | — | @@ -13,8 +13,45 @@ |
14 | 14 | $this->m_parserId = WOM_PARSER_ID_MAGICWORD; |
15 | 15 | } |
16 | 16 | |
| 17 | + static $underscores = array( '0' => '', '1' => '' ); |
| 18 | + static $mwa = null; |
| 19 | + static function getDoubleUnderscoreRegex() { |
| 20 | + if ( WOMMagicWordParser::$mwa === null ) { |
| 21 | + WOMMagicWordParser::$mwa = MagicWord::getDoubleUnderscoreArray(); |
| 22 | + foreach ( WOMMagicWordParser::$mwa->names as $name ) { |
| 23 | + $magic = MagicWord::get( $name ); |
| 24 | + $case = intval( $magic->isCaseSensitive() ); |
| 25 | + foreach ( $magic->getSynonyms() as $i => $syn ) { |
| 26 | + $group = '(' . preg_quote( $syn, '/' ) . ')'; |
| 27 | + if ( WOMMagicWordParser::$underscores[$case] === '' ) { |
| 28 | + WOMMagicWordParser::$underscores[$case] = $group; |
| 29 | + } else { |
| 30 | + WOMMagicWordParser::$underscores[$case] .= '|' . $group; |
| 31 | + } |
| 32 | + } |
| 33 | + } |
| 34 | + if ( WOMMagicWordParser::$underscores[0] !== '' ) { |
| 35 | + WOMMagicWordParser::$underscores[0] = "/^(" . WOMMagicWordParser::$underscores[0] . ")/i"; |
| 36 | + } |
| 37 | + if ( WOMMagicWordParser::$underscores[1] !== '' ) { |
| 38 | + WOMMagicWordParser::$underscores[1] = "/^(" . WOMMagicWordParser::$underscores[1] . ")/"; |
| 39 | + } |
| 40 | + } |
| 41 | + return WOMMagicWordParser::$underscores; |
| 42 | + } |
17 | 43 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
18 | 44 | $text = substr( $text, $offset ); |
| 45 | + |
| 46 | + $regex = WOMMagicWordParser::getDoubleUnderscoreRegex(); |
| 47 | + foreach ( $regex as $reg ) { |
| 48 | + if ( $reg === '' ) continue; |
| 49 | + $r = preg_match( $reg, $text, $m ); |
| 50 | + if ( $r ) { |
| 51 | + $len = strlen( $m[0] ); |
| 52 | + $magicword = trim( $m[0] ); |
| 53 | + return array( 'len' => $len, 'obj' => new WOMMagicWordModel( $magicword, true ) ); |
| 54 | + } |
| 55 | + } |
19 | 56 | $r = preg_match( '/^\{\{([^{|}]+)\}\}/', $text, $m ); |
20 | 57 | |
21 | 58 | if ( $r ) { |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMLinkParser.php |
— | — | @@ -20,12 +20,12 @@ |
21 | 21 | if ( $r && !preg_match( '/^(?:' . wfUrlProtocols() . ')/', $m[1] ) ) { |
22 | 22 | return array( 'len' => strlen( $m[0] ), 'obj' => new WOMLinkModel( $m[1], isset( $m[3] ) ? $m[3] : '' ) ); |
23 | 23 | } |
24 | | - $r = preg_match( '/^\[((?:' . wfUrlProtocols() . ')[^ \[\]]+)(\s+([^\]]+))?\]/', $text, $m ); |
| 24 | + $r = preg_match( '/^\[((?:' . wfUrlProtocols() . ')[^ \]]+)(\s+([^\]]+))?\]/', $text, $m ); |
25 | 25 | if ( $r ) { |
26 | 26 | return array( 'len' => strlen( $m[0] ), 'obj' => new WOMLinkModel( $m[1], isset( $m[3] ) ? $m[3] : '' ) ); |
27 | 27 | } |
28 | 28 | // includes/Parser.php Parser->doMagicLinks |
29 | | - $r = preg_match( '/^(?:' . wfUrlProtocols() . ')[^][<>"\\x00-\\x20\\x7F]+/', $text, $m ); |
| 29 | + $r = preg_match( '/^(?:' . wfUrlProtocols() . ')[^][<>"|\\x00-\\x20\\x7F]+/', $text, $m ); |
30 | 30 | if ( $r ) { |
31 | 31 | return array( 'len' => strlen( $m[0] ), 'obj' => new WOMLinkModel( $m[0] ) ); |
32 | 32 | } |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMParamValueParser.php |
— | — | @@ -17,7 +17,7 @@ |
18 | 18 | if ( !( $parentObj instanceof WOMParameterModel ) ) |
19 | 19 | return null; |
20 | 20 | |
21 | | - return array( 'len' => $len, 'obj' => new WOMParamValueModel() ); |
| 21 | + return array( 'len' => 0, 'obj' => new WOMParamValueModel() ); |
22 | 22 | } |
23 | 23 | |
24 | 24 | public function isObjectClosed( $obj, $text, $offset ) { |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMHTMLTagParser.php |
— | — | @@ -24,7 +24,7 @@ |
25 | 25 | $closed = false; |
26 | 26 | if ( isset( $m[2] ) ) { |
27 | 27 | $attr = $m[2]; |
28 | | - $closed = ( $attr { strlen( $attr ) - 1 } == '/' ); |
| 28 | + $closed = ( $attr != '' && $attr { strlen( $attr ) - 1 } == '/' ); |
29 | 29 | if ( $closed ) $attr = substr( $attr, 0, strlen( $attr ) - 1 ); |
30 | 30 | while ( preg_match( '/^\s*([\w]+)\s*=\s*/', $attr, $m1 ) ) { |
31 | 31 | $attr = substr( $attr, strlen( $m1[0] ) ); |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMParameterParser.php |
— | — | @@ -37,11 +37,11 @@ |
38 | 38 | return array( 'len' => $len, 'obj' => new WOMParameterModel( $key ) ); |
39 | 39 | } |
40 | 40 | } |
41 | | - |
| 41 | + |
42 | 42 | public function getSubParserID() { |
43 | 43 | return WOM_PARSER_ID_PARAM_VALUE; |
44 | 44 | } |
45 | | - |
| 45 | + |
46 | 46 | public function isObjectClosed( $obj, $text, $offset ) { |
47 | 47 | if ( !( ( $obj instanceof WOMTemplateFieldModel ) |
48 | 48 | || ( $obj instanceof WOMParameterModel ) ) ) |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMTblCellParser.php |
— | — | @@ -13,39 +13,65 @@ |
14 | 14 | $this->m_parserId = WOM_PARSER_ID_TABLECELL; |
15 | 15 | } |
16 | 16 | |
| 17 | + private function getFirstLineChar( $text, $offset ) { |
| 18 | + for ( $i = $offset; $i >= 0; --$i ) { |
| 19 | + if ( $text { $i } == "\n" ) { |
| 20 | + $s = substr( $text, $i ); |
| 21 | + if ( preg_match( '/^\s*([!|])/', $s, $m ) ) { |
| 22 | + return $m[1]; |
| 23 | + } |
| 24 | + break; |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + return ''; |
| 29 | + } |
17 | 30 | // FIXME: what if table cell style uses parser function which contains 'return' or '|' |
18 | 31 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
19 | 32 | if ( !( $parentObj instanceof WOMTableModel ) ) return null; |
20 | 33 | |
21 | 34 | $lastLF = ( $text { $offset } == "\n" || ( $offset == 0 || $text { $offset - 1 } == "\n" ) ); |
| 35 | + // get the first char of current line |
| 36 | + $fch = $this->getFirstLineChar( $text, $offset ); |
| 37 | + if ( $fch == '' ) return null; |
| 38 | + |
22 | 39 | $text = substr( $text, $offset ); |
23 | | - |
24 | | - $r = preg_match( '/^(!!|\|\||(\s*(\|\+|\|-|[!|])))/', $text, $m ); |
| 40 | + |
| 41 | + $r = preg_match( '/^(' . ( ( $fch == '!' ) ? '!!|' : '' ) . '\|\||(\s*(\|\+|\|-|[!|])))/', $text, $m ); |
25 | 42 | if ( !$r ) return null; |
26 | 43 | |
27 | 44 | if ( isset( $m[2] ) && !$lastLF ) return null; |
28 | | - |
| 45 | + |
29 | 46 | $len = strlen( $m[0] ); |
30 | 47 | $text = substr( $text, $len ); |
31 | | - $r = preg_match( '/^[^\n|]*\|/', $text, $m1 ); |
32 | | - |
33 | | - if ( $r && preg_match( '/\{\{/', $m1[0] ) ) { |
| 48 | + $r = preg_match( '/^([^\n|]*\|)[^|]/', $text, $m1 ); |
| 49 | + if ( !$r || preg_match( '/\{\{/', $m1[1] ) ) { |
34 | 50 | // FIXME: what if matched style contains '{{', just think it is table body |
35 | | - return array( 'len' => strlen( $m[0] ), 'obj' => new WOMTableCellModel( $m[0] ) ); |
| 51 | + return array( 'len' => $len, 'obj' => new WOMTableCellModel( $m[0] ) ); |
36 | 52 | } |
37 | 53 | |
38 | | - return array( 'len' => strlen( $m[0] ) + strlen( $m1[0] ), 'obj' => new WOMTableCellModel( $m[0] . $m1[0] ) ); |
| 54 | + if ( $fch == '!' ) { |
| 55 | + $pos = strpos( $text, '!!', $len ); |
| 56 | + if ( $pos !== false && $pos < strlen( $m1[1] ) ) { |
| 57 | + return array( 'len' => $len, 'obj' => new WOMTableCellModel( $m[0] ) ); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + return array( 'len' => $len + strlen( $m1[1] ), 'obj' => new WOMTableCellModel( $m[0] . $m1[1] ) ); |
39 | 62 | } |
40 | 63 | |
41 | 64 | public function isObjectClosed( $obj, $text, $offset ) { |
42 | 65 | if ( !( $obj instanceof WOMTableCellModel ) ) return false; |
43 | | - |
| 66 | + |
| 67 | + $fch = $this->getFirstLineChar( $text, $offset ); |
| 68 | + |
44 | 69 | $lastLF = ( $text { $offset } == "\n" || ( $offset == 0 || $text { $offset - 1 } == "\n" ) ); |
45 | | - |
| 70 | + |
46 | 71 | $text = substr( $text, $offset ); |
47 | 72 | if ( strlen( $text ) == 0 ) return 0; |
48 | 73 | if ( $lastLF && preg_match( '/^(\s*[!|])/', $text ) ) return 0; |
49 | | - if ( preg_match( '/^(!!)|(\|\|)/', $text ) ) return 0; |
| 74 | + if ( $fch == '' ) return false; |
| 75 | + if ( preg_match( '/^(' . ( ( $fch == '!' ) ? '!!|':'' ) . '\|\|)/', $text ) ) return 0; |
50 | 76 | |
51 | 77 | return false; |
52 | 78 | } |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WOMSectionParser.php |
— | — | @@ -18,9 +18,9 @@ |
19 | 19 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
20 | 20 | $lastLF = ( $offset == 0 || $text { $offset - 1 } == "\n" ); |
21 | 21 | $text = substr( $text, $offset ); |
22 | | - if ( $lastLF ) { |
23 | | - $r = preg_match( '/^(={1,6})/', $text, $m ); |
24 | | - } |
| 22 | + if ( !$lastLF ) return null; |
| 23 | + |
| 24 | + $r = preg_match( '/^(={1,6})/', $text, $m ); |
25 | 25 | if ( $r ) { |
26 | 26 | $text1 = substr( $text, strlen( $m[0] ) ); |
27 | 27 | $s = explode( "\n", $text1, 2 ); |
— | — | @@ -30,9 +30,9 @@ |
31 | 31 | $len = strlen( $m[0] ) + strlen( $s[0] ) + 1/* \n */; |
32 | 32 | $level = strlen( $m[1] ) < strlen( $m1[1][0] ) ? strlen( $m[1] ) : strlen( $m1[1][0] ); |
33 | 33 | |
34 | | - $obj = new WOMSectionModel( |
| 34 | + $obj = new WOMSectionModel( trim( |
35 | 35 | substr( WOMSectionParser::$heading, 0, strlen( $m[1] ) - $level ) . |
36 | | - substr( $s[0], 0, $m1[1][1] + strlen( $m1[1][0] ) - $level ), |
| 36 | + substr( $s[0], 0, $m1[1][1] + strlen( $m1[1][0] ) - $level ) ), |
37 | 37 | $level ); |
38 | 38 | |
39 | 39 | while ( $parentObj != null && |
Index: trunk/extensions/WikiObjectModel/includes/parsers/WikiObjectModelParser.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * File holding class WikiObjectModelParser, the base for all object model parser in WOM. |
5 | | - * |
| 5 | + * |
6 | 6 | * Deal plain text only, just get next text token |
7 | 7 | * |
8 | 8 | * @author Ning |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | // /// Processing methods ///// |
36 | 36 | public function parseNext( $text, WikiObjectModelCollection $parentObj, $offset = 0 ) { |
37 | 37 | $text = substr( $text, $offset ); |
38 | | - $r = preg_match( '/^\w+/', $text, $m ); |
| 38 | + $r = preg_match( '/^[a-zA-Z0-9]+/', $text, $m ); |
39 | 39 | if ( $r ) return array( 'len' => strlen( $m[0] ), 'obj' => new WOMTextModel( $m[0] ) ); |
40 | 40 | // special case, <nowiki>, <noinclude> |
41 | 41 | $idx = stripos( $text, '<nowiki>' ); |
— | — | @@ -53,7 +53,7 @@ |
54 | 54 | return array( 'len' => 1, 'obj' => new WOMTextModel( $text { 0 } ) ); |
55 | 55 | } |
56 | 56 | |
57 | | - // E.g., |
| 57 | + // E.g., |
58 | 58 | // semantic property is extended from internal links |
59 | 59 | // parser functions is extended from templates |
60 | 60 | public function subclassOf( $parserInstance ) { |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_MagicWord.php |
— | — | @@ -5,27 +5,29 @@ |
6 | 6 | * @author Ning |
7 | 7 | * @file |
8 | 8 | * @ingroup WikiObjectModels |
9 | | - * |
| 9 | + * |
10 | 10 | */ |
11 | 11 | |
12 | 12 | class WOMMagicWordModel extends WikiObjectModel { |
13 | 13 | protected $m_magicword; |
| 14 | + protected $m_doubleUnderscore; |
14 | 15 | |
15 | | - public function __construct( $magicword ) { |
| 16 | + public function __construct( $magicword, $doubleUnderscore = false ) { |
16 | 17 | parent::__construct( WOM_TYPE_MAGICWORD ); |
17 | 18 | $this->m_magicword = $magicword; |
| 19 | + $this->m_doubleUnderscore = $doubleUnderscore; |
18 | 20 | } |
19 | 21 | |
20 | 22 | public function getMagicWord() { |
21 | 23 | return $this->m_magicword; |
22 | 24 | } |
23 | | - |
| 25 | + |
24 | 26 | public function setMagicWord( $magicword ) { |
25 | 27 | $this->m_magicword = $magicword; |
26 | 28 | } |
27 | 29 | |
28 | 30 | public function getWikiText() { |
29 | | - return "{{{$this->m_magicword}}}"; |
| 31 | + return $this->m_doubleUnderscore ? $this->m_magicword : "{{{$this->m_magicword}}}"; |
30 | 32 | } |
31 | 33 | |
32 | 34 | public function setXMLAttribute( $key, $value ) { |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Page.php |
— | — | @@ -66,16 +66,20 @@ |
67 | 67 | } |
68 | 68 | |
69 | 69 | public function appendChildObject( WikiObjectModel $obj, $id = '' ) { |
70 | | - $p = $this->m_page_objs[$id]; |
71 | | - if ( !( $p instanceof WikiObjectModelCollection ) ) { |
72 | | - return; |
| 70 | + if ( $id == '' ) { |
| 71 | + $p = $this; |
| 72 | + } else { |
| 73 | + $p = $this->m_page_objs[$id]; |
| 74 | + if ( !( $p instanceof WikiObjectModelCollection ) ) { |
| 75 | + return; |
| 76 | + } |
73 | 77 | } |
74 | 78 | $obj->setObjectID( $this->getNextId() ); |
75 | 79 | $p->insertObject( $obj ); |
76 | 80 | |
77 | 81 | $this->addToPageObjectSet( $obj ); |
78 | 82 | } |
79 | | - |
| 83 | + |
80 | 84 | public function removePageObject( $id ) { |
81 | 85 | $old_obj = $this->m_page_objs[$id]; |
82 | 86 | if ( $old_obj == null ) return; |
Index: trunk/extensions/WikiObjectModel/includes/models/WOMFactory.php |
— | — | @@ -1,9 +1,9 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * This file contains the WikiObjectModelFactory class. |
5 | | - * |
| 5 | + * |
6 | 6 | * @author Ning |
7 | | - * |
| 7 | + * |
8 | 8 | * @file |
9 | 9 | * @ingroup WikiObjectModels |
10 | 10 | */ |
— | — | @@ -12,14 +12,14 @@ |
13 | 13 | |
14 | 14 | /** |
15 | 15 | * Array of type labels indexed by type ids. Used for model type resolution. |
16 | | - * |
| 16 | + * |
17 | 17 | * @var array |
18 | 18 | */ |
19 | 19 | static private $mTypeLabels; |
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Array of class names for creating new WikiObjectModel, indexed by type id. |
23 | | - * |
| 23 | + * |
24 | 24 | * @var array of WikiObjectModel |
25 | 25 | */ |
26 | 26 | static private $mTypeClasses; |
— | — | @@ -27,9 +27,9 @@ |
28 | 28 | /** |
29 | 29 | * Create a value from a type id. If no $value is given, an empty container |
30 | 30 | * is created, the value of which can be set later on. |
31 | | - * |
| 31 | + * |
32 | 32 | * @param $typeid id string for the given type |
33 | | - * |
| 33 | + * |
34 | 34 | * @return WikiObjectModel |
35 | 35 | */ |
36 | 36 | static public function newTypeIDValue( $typeid ) { |
— | — | @@ -78,7 +78,7 @@ |
79 | 79 | /** |
80 | 80 | * A function for registering/overwriting pomtypes for WOM. Should be |
81 | 81 | * called from within the hook 'mwInitWOMTypes'. |
82 | | - * |
| 82 | + * |
83 | 83 | * @param string $id |
84 | 84 | * @param string $className |
85 | 85 | * @param mixed $label |
— | — | @@ -100,7 +100,7 @@ |
101 | 101 | * |
102 | 102 | * This method may or may not take aliases into account. For unknown |
103 | 103 | * labels, the normalised (DB-version) label is used as an ID. |
104 | | - * |
| 104 | + * |
105 | 105 | * @param string $label |
106 | 106 | */ |
107 | 107 | static public function findTypeID( $label ) { |
— | — | @@ -118,7 +118,7 @@ |
119 | 119 | * Get the translated user label for a given internal ID. If the ID does |
120 | 120 | * not have a label associated with it in the current language, the ID |
121 | 121 | * itself is transformed into a label (appropriate for user defined types). |
122 | | - * |
| 122 | + * |
123 | 123 | * @param string $id |
124 | 124 | */ |
125 | 125 | static public function findTypeLabel( $id ) { |
— | — | @@ -142,7 +142,7 @@ |
143 | 143 | * a property, and that are internal (i.e. not user defined). No labels are |
144 | 144 | * returned for internal types without user labels (e.g. the special types |
145 | 145 | * for wome special properties), and for user defined types. |
146 | | - * |
| 146 | + * |
147 | 147 | * @return array |
148 | 148 | */ |
149 | 149 | static public function getKnownTypeLabels() { |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Category.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * @author Ning |
7 | 7 | * @file |
8 | 8 | * @ingroup WikiObjectModels |
9 | | - * |
| 9 | + * |
10 | 10 | */ |
11 | 11 | |
12 | 12 | class WOMCategoryModel extends WikiObjectModel { |
— | — | @@ -13,13 +13,19 @@ |
14 | 14 | |
15 | 15 | public function __construct( $name ) { |
16 | 16 | parent::__construct( WOM_TYPE_CATEGORY ); |
17 | | - $this->m_name = $name; |
| 17 | + $title = Title::newFromText( $name, NS_CATEGORY ); |
| 18 | + if ( $title == null ) { |
| 19 | + // no idea why, just leave it |
| 20 | + $this->m_name = $name; |
| 21 | + } else { |
| 22 | + $this->m_name = $title->getText(); |
| 23 | + } |
18 | 24 | } |
19 | 25 | |
20 | 26 | public function getName() { |
21 | 27 | return $this->m_name; |
22 | 28 | } |
23 | | - |
| 29 | + |
24 | 30 | public function setName( $name ) { |
25 | 31 | $this->m_name = $name; |
26 | 32 | } |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_TmplField.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * @author Ning |
7 | 7 | * @file |
8 | 8 | * @ingroup WikiObjectModels |
9 | | - * |
| 9 | + * |
10 | 10 | */ |
11 | 11 | |
12 | 12 | class WOMTemplateFieldModel extends WOMParameterModel { |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Parameter.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * @author Ning |
7 | 7 | * @file |
8 | 8 | * @ingroup WikiObjectModels |
9 | | - * |
| 9 | + * |
10 | 10 | */ |
11 | 11 | |
12 | 12 | class WOMParameterModel extends WikiObjectModelCollection { |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_TblCell.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * @author Ning |
7 | 7 | * @file |
8 | 8 | * @ingroup WikiObjectModels |
9 | | - * |
| 9 | + * |
10 | 10 | */ |
11 | 11 | |
12 | 12 | class WOMTableCellModel extends WikiObjectModelCollection { |
— | — | @@ -21,7 +21,7 @@ |
22 | 22 | public function getPrefix() { |
23 | 23 | return $this->m_prefix; |
24 | 24 | } |
25 | | - |
| 25 | + |
26 | 26 | public function setPrefix( $prefix ) { |
27 | 27 | $this->m_prefix = $prefix; |
28 | 28 | } |
— | — | @@ -29,4 +29,20 @@ |
30 | 30 | public function getWikiText() { |
31 | 31 | return "{$this->m_prefix}" . parent::getWikiText(); |
32 | 32 | } |
| 33 | + |
| 34 | + public function setXMLAttribute( $key, $value ) { |
| 35 | + if ( $value == '' ) throw new MWException( __METHOD__ . ": value cannot be empty" ); |
| 36 | + |
| 37 | + $value = str_replace( '\n', "\n", $value ); |
| 38 | + if ( $key == 'prefix' ) { |
| 39 | + $this->m_prefix = $value; |
| 40 | + return; |
| 41 | + } |
| 42 | + throw new MWException( __METHOD__ . ": invalid key/value pair: prefix=table_cell_prefix (! / | / ||)" ); |
| 43 | + } |
| 44 | + |
| 45 | + protected function getXMLAttributes() { |
| 46 | + $prefix = str_replace( "\n", '\n', $this->m_prefix ); |
| 47 | + return "prefix=\"{$prefix}\""; |
| 48 | + } |
33 | 49 | } |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Text.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * @author Ning |
7 | 7 | * @file |
8 | 8 | * @ingroup WikiObjectModels |
9 | | - * |
| 9 | + * |
10 | 10 | */ |
11 | 11 | |
12 | 12 | class WOMTextModel extends WikiObjectModel { |
— | — | @@ -29,6 +29,6 @@ |
30 | 30 | } |
31 | 31 | |
32 | 32 | public function toXML() { |
33 | | - return htmlentities( $this->m_text ); |
| 33 | + return htmlspecialchars( $this->m_text ); |
34 | 34 | } |
35 | 35 | } |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Property.php |
— | — | @@ -5,12 +5,13 @@ |
6 | 6 | * @author Ning |
7 | 7 | * @file |
8 | 8 | * @ingroup WikiObjectModels |
9 | | - * |
| 9 | + * |
10 | 10 | */ |
11 | 11 | |
12 | 12 | class WOMPropertyModel extends WikiObjectModel { |
13 | 13 | protected $m_property; // name |
14 | 14 | protected $m_smwdatavalue; // value, caption, type |
| 15 | + protected $m_visible; |
15 | 16 | |
16 | 17 | public function __construct( $property, $value, $caption = '' ) { |
17 | 18 | parent::__construct( WOM_TYPE_PROPERTY ); |
— | — | @@ -25,6 +26,7 @@ |
26 | 27 | |
27 | 28 | $this->m_property = $property; |
28 | 29 | $this->m_smwdatavalue = $smwdatavalue; |
| 30 | + $this->m_visible = !preg_match( '/\s+/', $caption ); |
29 | 31 | } |
30 | 32 | |
31 | 33 | public function getProperty() { |
— | — | @@ -34,7 +36,7 @@ |
35 | 37 | public function setProperty( $property ) { |
36 | 38 | $this->m_property = $property; |
37 | 39 | } |
38 | | - |
| 40 | + |
39 | 41 | public function getSMWDataValue() { |
40 | 42 | return $this->m_smwdatavalue; |
41 | 43 | } |
— | — | @@ -42,12 +44,14 @@ |
43 | 45 | public function setSMWDataValue( $smwdatavalue ) { |
44 | 46 | $this->m_smwdatavalue = $smwdatavalue; |
45 | 47 | } |
46 | | - |
| 48 | + |
47 | 49 | public function getWikiText() { |
48 | 50 | $res = "[[{$this->getPropertyName()}::{$this->getPropertyValue()}"; |
49 | 51 | if ( $this->getPropertyValue() != $this->getCaption() |
50 | 52 | && $this->getCaption() != '' ) { |
51 | 53 | $res .= "|{$this->getCaption()}"; |
| 54 | + } else if ( !$this->m_visible ) { |
| 55 | + $res .= "| "; |
52 | 56 | } |
53 | 57 | $res .= "]]"; |
54 | 58 | |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Table.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * @author Ning |
7 | 7 | * @file |
8 | 8 | * @ingroup WikiObjectModels |
9 | | - * |
| 9 | + * |
10 | 10 | */ |
11 | 11 | |
12 | 12 | class WOMTableModel extends WikiObjectModelCollection { |
— | — | @@ -24,8 +24,20 @@ |
25 | 25 | public function setStyle( $style ) { |
26 | 26 | $this->m_style = $style; |
27 | 27 | } |
28 | | - |
| 28 | + |
29 | 29 | public function getWikiText() { |
30 | 30 | return "{| {$this->m_style}" . parent::getWikiText() . "\n|}"; |
31 | 31 | } |
| 32 | + |
| 33 | + public function setXMLAttribute( $key, $value ) { |
| 34 | + if ( $key == 'style' ) { |
| 35 | + $this->m_style = $value; |
| 36 | + return; |
| 37 | + } |
| 38 | + throw new MWException( __METHOD__ . ": invalid key/value pair: style=table_style" ); |
| 39 | + } |
| 40 | + |
| 41 | + protected function getXMLAttributes() { |
| 42 | + return "style=\"{$this->m_style}\""; |
| 43 | + } |
32 | 44 | } |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_ListItem.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * @author Ning |
7 | 7 | * @file |
8 | 8 | * @ingroup WikiObjectModels |
9 | | - * |
| 9 | + * |
10 | 10 | */ |
11 | 11 | |
12 | 12 | class WOMListItemModel extends WikiObjectModelCollection { |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Link.php |
— | — | @@ -5,14 +5,14 @@ |
6 | 6 | * @author Ning |
7 | 7 | * @file |
8 | 8 | * @ingroup WikiObjectModels |
9 | | - * |
| 9 | + * |
10 | 10 | */ |
11 | 11 | |
12 | 12 | class WOMLinkModel extends WikiObjectModel { |
13 | 13 | protected $m_link; |
14 | 14 | protected $m_caption; |
15 | 15 | |
16 | | - public function __construct( $link, $caption = '' ) { |
| 16 | + public function __construct( $link, $caption = null ) { |
17 | 17 | parent::__construct( WOM_TYPE_LINK ); |
18 | 18 | $this->m_link = $link; |
19 | 19 | $this->m_caption = $caption; |
— | — | @@ -31,11 +31,11 @@ |
32 | 32 | public function setLink( $link ) { |
33 | 33 | $this->m_link = $link; |
34 | 34 | } |
35 | | - |
| 35 | + |
36 | 36 | public function getCaption() { |
37 | 37 | return $this->m_caption; |
38 | 38 | } |
39 | | - |
| 39 | + |
40 | 40 | public function setCaption( $caption ) { |
41 | 41 | $this->m_caption = $caption; |
42 | 42 | } |
— | — | @@ -44,14 +44,18 @@ |
45 | 45 | if ( $this->isInline() ) { |
46 | 46 | return "[[{$this->m_link}" . ( $this->m_caption ? "|{$this->m_caption}" : "" ) . "]]"; |
47 | 47 | } else { |
48 | | - return "[{$this->m_link}" . ( $this->m_caption ? " {$this->m_caption}" : "" ) . "]"; |
| 48 | + if ( $this->m_caption === null ) { |
| 49 | + return $this->m_link; |
| 50 | + } else { |
| 51 | + return "[{$this->m_link}" . ( $this->m_caption ? " {$this->m_caption}" : "" ) . "]"; |
| 52 | + } |
49 | 53 | } |
50 | 54 | } |
51 | 55 | |
52 | 56 | protected function getXMLContent() { |
53 | 57 | return " |
54 | | -<url>{$this->m_link}</url> |
55 | | -<caption>{$this->m_caption}</caption> |
| 58 | +<url><![CDATA[{$this->m_link}]]></url> |
| 59 | +<caption><![CDATA[{$this->m_caption}]]></caption> |
56 | 60 | "; |
57 | 61 | } |
58 | 62 | } |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_ParamValue.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * @author Ning |
7 | 7 | * @file |
8 | 8 | * @ingroup WikiObjectModels |
9 | | - * |
| 9 | + * |
10 | 10 | */ |
11 | 11 | |
12 | 12 | class WOMParamValueModel extends WikiObjectModelCollection { |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_HTMLTag.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * @author Ning |
7 | 7 | * @file |
8 | 8 | * @ingroup WikiObjectModels |
9 | | - * |
| 9 | + * |
10 | 10 | */ |
11 | 11 | |
12 | 12 | class WOMHTMLTagModel extends WikiObjectModelCollection { |
— | — | @@ -21,7 +21,7 @@ |
22 | 22 | public function getName() { |
23 | 23 | return $this->m_name; |
24 | 24 | } |
25 | | - |
| 25 | + |
26 | 26 | public function setName( $name ) { |
27 | 27 | $this->m_name = $name; |
28 | 28 | } |
— | — | @@ -29,11 +29,11 @@ |
30 | 30 | public function getAttributes() { |
31 | 31 | return $this->m_attributes; |
32 | 32 | } |
33 | | - |
| 33 | + |
34 | 34 | public function setAttributes( $attrs ) { |
35 | 35 | $this->m_attributes = $attrs; |
36 | 36 | } |
37 | | - |
| 37 | + |
38 | 38 | public function getWikiText() { |
39 | 39 | return "<{$this->m_name}>" . parent::getWikiText() . "</{$this->m_name}>"; |
40 | 40 | } |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_ParserFunction.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * @author Ning |
7 | 7 | * @file |
8 | 8 | * @ingroup WikiObjectModels |
9 | | - * |
| 9 | + * |
10 | 10 | */ |
11 | 11 | class WOMParserFunctionModel extends WikiObjectModelCollection { |
12 | 12 | protected $m_function_key; |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Sentence.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * @author Ning |
7 | 7 | * @file |
8 | 8 | * @ingroup WikiObjectModels |
9 | | - * |
| 9 | + * |
10 | 10 | */ |
11 | 11 | |
12 | 12 | class WOMSentenceModel extends WikiObjectModelCollection { |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Section.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * @author Ning |
7 | 7 | * @file |
8 | 8 | * @ingroup WikiObjectModels |
9 | | - * |
| 9 | + * |
10 | 10 | */ |
11 | 11 | |
12 | 12 | class WOMSectionModel extends WikiObjectModelCollection { |
— | — | @@ -27,7 +27,7 @@ |
28 | 28 | public function setName( $name ) { |
29 | 29 | $this->m_name = $name; |
30 | 30 | } |
31 | | - |
| 31 | + |
32 | 32 | public function getLevel() { |
33 | 33 | return $this->m_level; |
34 | 34 | } |
— | — | @@ -35,9 +35,9 @@ |
36 | 36 | public function setLevel( $level ) { |
37 | 37 | $this->m_level = $level; |
38 | 38 | } |
39 | | - |
| 39 | + |
40 | 40 | public function getHeaderText() { |
41 | | -// return "\n" . |
| 41 | +// return "\n" . |
42 | 42 | return substr( WOMSectionModel::$heading, 0, $this->m_level ) . |
43 | 43 | $this->m_name . |
44 | 44 | substr( WOMSectionModel::$heading, 0, $this->m_level ) . |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | public function getWikiText() { |
49 | 49 | return $this->getHeaderText() . parent::getWikiText(); |
50 | 50 | } |
51 | | - |
| 51 | + |
52 | 52 | public function getContent() { |
53 | 53 | return parent::getWikiText(); |
54 | 54 | } |
Index: trunk/extensions/WikiObjectModel/includes/models/WOM_OM_Template.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * @author Ning |
7 | 7 | * @file |
8 | 8 | * @ingroup WikiObjectModels |
9 | | - * |
| 9 | + * |
10 | 10 | */ |
11 | 11 | |
12 | 12 | class WOMTemplateModel extends WikiObjectModelCollection { |
— | — | @@ -20,10 +20,10 @@ |
21 | 21 | |
22 | 22 | if ( $this->m_title->getNamespace() == NS_MAIN ) { |
23 | 23 | // http://www.mediawiki.org/wiki/Help:Transclusion |
24 | | - // If the source is in the Main article namespace (e.g., "Cat"), |
| 24 | + // If the source is in the Main article namespace (e.g., "Cat"), |
25 | 25 | // you must put a colon (:) in front of the name, thus: {{:Cat}} |
26 | 26 | |
27 | | - // If the source is in the Template namespace (e.g., "Template:Villagepumppages"), |
| 27 | + // If the source is in the Template namespace (e.g., "Template:Villagepumppages"), |
28 | 28 | // just use the name itself, alone, thus: {{Villagepumppages}} |
29 | 29 | if ( $this->m_name { 0 } != ':' ) { |
30 | 30 | $this->m_title = Title::makeTitleSafe( NS_TEMPLATE, $this->m_name ); |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | public function getName() { |
36 | 36 | return $this->m_name; |
37 | 37 | } |
38 | | - |
| 38 | + |
39 | 39 | public function setName( $name ) { |
40 | 40 | $this->m_name = $name; |
41 | 41 | } |
Index: trunk/extensions/WikiObjectModel/includes/WOM_Processor.php |
— | — | @@ -36,15 +36,16 @@ |
37 | 37 | WOMProcessor::setupParsers(); |
38 | 38 | } |
39 | 39 | global $wgOMModelParserMapping; |
40 | | - $id = $wgOMModelParserMapping[$obj->getTypeID()]; |
41 | | - if ( isset( WOMProcessor::$parsers[$id] ) ) { |
42 | | - $result = WOMProcessor::$parsers[$id]; |
43 | | - } else { |
44 | | - $result = WOMProcessor::$base_parser; |
| 40 | + if ( isset( $wgOMModelParserMapping[$obj->getTypeID()] ) ) { |
| 41 | + $id = $wgOMModelParserMapping[$obj->getTypeID()]; |
| 42 | + if ( isset( WOMProcessor::$parsers[$id] ) ) { |
| 43 | + wfProfileOut( $fname ); |
| 44 | + return WOMProcessor::$parsers[$id]; |
| 45 | + } |
45 | 46 | } |
46 | 47 | wfProfileOut( $fname ); |
47 | 48 | |
48 | | - return $result; |
| 49 | + return WOMProcessor::$base_parser; |
49 | 50 | } |
50 | 51 | |
51 | 52 | private static function applyObjID( WikiObjectModel $wom, WOMPageModel $root ) { |
— | — | @@ -67,7 +68,7 @@ |
68 | 69 | |
69 | 70 | $root = new WOMPageModel(); |
70 | 71 | WOMProcessor::parseNext( $text, $root, $root ); |
71 | | - WOMProcessor::parseSentences($root); |
| 72 | + WOMProcessor::parseSentences( $root ); |
72 | 73 | WOMProcessor::applyObjID( $root, $root ); |
73 | 74 | wfProfileOut( $fname ); |
74 | 75 | return $root; |
— | — | @@ -187,6 +188,11 @@ |
188 | 189 | } else { |
189 | 190 | $parserInstance2 = $parserInstance; |
190 | 191 | $result = $parserInstance->parseNext( $text, $parentObj, $offset ); |
| 192 | + if ( $result == null ) { |
| 193 | + // FIXME: just omit current char, this will not fit for Wiki parser |
| 194 | + ++ $offset; |
| 195 | + continue; |
| 196 | + } |
191 | 197 | } |
192 | 198 | |
193 | 199 | $next_obj = $result['obj']; |
— | — | @@ -204,10 +210,12 @@ |
205 | 211 | |
206 | 212 | WOMProcessor::assemble( $next_obj ); |
207 | 213 | |
208 | | - if ( $next_obj->isCollection() && !$result['closed'] ) { |
| 214 | + if ( $next_obj->isCollection() && !( isset( $result['closed'] ) && $result['closed'] ) ) { |
209 | 215 | $collection_start = $offset; |
210 | | - $d = WOMProcessor::parseNext( $text, $next_obj, $rootObj, $offset, ( $parserInstance2 == null ? null : |
211 | | - WOMProcessor::$parsers[$parserInstance2->getSubParserID()] ) ); |
| 216 | + $d = WOMProcessor::parseNext( $text, $next_obj, $rootObj, $offset, |
| 217 | + ( ( $parserInstance2 != null && isset( WOMProcessor::$parsers[$parserInstance2->getSubParserID()] ) ) ? |
| 218 | + WOMProcessor::$parsers[$parserInstance2->getSubParserID()] : |
| 219 | + null ) ); |
212 | 220 | if ( $d == 100 && $parserInstance2->isObjectClosed( $next_obj, $text, $offset ) === false ) { |
213 | 221 | // rollback |
214 | 222 | $p = WOMProcessor::getObjectParser( $parentObj ); |
— | — | @@ -491,7 +499,7 @@ |
492 | 500 | |
493 | 501 | wfProfileOut( $fname ); |
494 | 502 | } |
495 | | - |
| 503 | + |
496 | 504 | public static function appendPageObject( $object, $title, $obj_id = '', $summary = '', $revision_id = 0, $force_update = true ) { |
497 | 505 | $fname = 'WikiObjectModel::appendPageObject (WOM)'; |
498 | 506 | wfProfileIn( $fname ); |
— | — | @@ -627,7 +635,7 @@ |
628 | 636 | |
629 | 637 | wfProfileOut( $fname ); |
630 | 638 | } |
631 | | - |
| 639 | + |
632 | 640 | public static function updatePageText( $text, $title, $obj_id, $summary = '', $revision_id = 0, $force_update = true ) { |
633 | 641 | $fname = 'WikiObjectModel::updatePageText (WOM)'; |
634 | 642 | wfProfileIn( $fname ); |
Index: trunk/extensions/WikiObjectModel/includes/WOM_Setup.php |
— | — | @@ -130,9 +130,3 @@ |
131 | 131 | $wgAutoloadClasses['ApiWOMGetObjectModel'] = $wgOMIP . '/includes/apis/WOM_GetObjectModel.php'; |
132 | 132 | |
133 | 133 | |
134 | | - |
135 | | - |
136 | | -// constants for special properties |
137 | | -define( 'WOM_WF_SP_HAS_TEMPLATE', 1 ); |
138 | | -define( 'WOM_WF_SP_HAS_MULTIPLE_TEMPLATE', 2 ); |
139 | | -define( 'WOM_WF_SP_HAS_TEMPLATEFIELD_CONNECTOR', 3 ); |
Index: trunk/extensions/WikiObjectModel/includes/apis/WOM_GetObjectModel.php |
— | — | @@ -50,24 +50,38 @@ |
51 | 51 | $result['result'] = 'Success'; |
52 | 52 | |
53 | 53 | // pay attention to special xml tag, e.g., <property><value>...</value></property> |
| 54 | + $result['return'] = array(); |
54 | 55 | if ( $type == 'count' ) { |
55 | 56 | $count = 0; |
56 | 57 | foreach ( $objs as $id ) { |
57 | 58 | if ( $id == '' ) continue; |
58 | 59 | ++ $count; |
59 | 60 | } |
60 | | - $result['return'] = $count; |
| 61 | + $this->getResult()->setContent( $result['return'], $count ); |
61 | 62 | } else { |
62 | | - $result['return'] = array(); |
| 63 | + $xml = ''; |
| 64 | + $page_obj = WOMProcessor::getPageObject( $articleTitle, $rid ); |
63 | 65 | foreach ( $objs as $id ) { |
64 | 66 | if ( $id == '' ) continue; |
| 67 | + $wobj = $page_obj->getObject( $id ); |
65 | 68 | $result['return'][$id] = array(); |
66 | 69 | if ( $type == 'xml' ) { |
67 | | - $this->getResult()->setContent( $result['return'][$id], WOMProcessor::getPageObject( $articleTitle, $rid )->getObject( $id )->toXML() ); |
| 70 | + $xml .= "<{$id} xml:space=\"preserve\">{$wobj->toXML()}</{$id}>"; |
| 71 | +// $this->getResult()->setContent( $result['return'][$id], $wobj->toXML() ); |
68 | 72 | } else { |
69 | | - $this->getResult()->setContent( $result['return'][$id], WOMProcessor::getPageObject( $articleTitle, $rid )->getObject( $id )->getWikiText() ); |
| 73 | + $this->getResult()->setContent( $result['return'][$id], $wobj->getWikiText() ); |
70 | 74 | } |
71 | 75 | } |
| 76 | + if ( $type == 'xml' ) { |
| 77 | + header ( "Content-Type: application/rdf+xml" ); |
| 78 | + echo <<<OUTPUT |
| 79 | +<?xml version="1.0" encoding="UTF-8" ?> |
| 80 | +<api><womget result="Success"><return> |
| 81 | +{$xml} |
| 82 | +</return></womget></api> |
| 83 | +OUTPUT; |
| 84 | + exit( 1 ); |
| 85 | + } |
72 | 86 | } |
73 | 87 | } |
74 | 88 | $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
— | — | @@ -78,9 +92,9 @@ |
79 | 93 | 'page' => null, |
80 | 94 | 'xpath' => null, |
81 | 95 | 'type' => array( |
82 | | - ApiBase :: PARAM_DFLT => 'get', |
| 96 | + ApiBase :: PARAM_DFLT => 'wiki', |
83 | 97 | ApiBase :: PARAM_TYPE => array( |
84 | | - 'get', |
| 98 | + 'wiki', |
85 | 99 | 'count', |
86 | 100 | 'xml', |
87 | 101 | ), |
— | — | @@ -99,9 +113,9 @@ |
100 | 114 | 'xpath' => 'DOM-like xpath to locate WOM object instances (http://www.w3schools.com/xpath/xpath_syntax.asp)', |
101 | 115 | 'type' => array ( |
102 | 116 | 'Type to fetch useful wiki object data', |
103 | | - 'type = get, get specified object', |
| 117 | + 'type = wiki, get wiki text of specified object', |
104 | 118 | 'type = count, get objects count with specified xpath', |
105 | | - 'type = xml, view objects\' xml format with specified xpath, usually use with format=xml', |
| 119 | + 'type = xml, view "encoded objects\' xml" with specified xpath, usually use with format=xml', |
106 | 120 | ), |
107 | 121 | 'rid' => 'Revision id of specified page - by dafault latest updated revision (0) is used', |
108 | 122 | ); |
Index: trunk/extensions/WikiObjectModel/includes/apis/WOM_SetObjectModel.php |
— | — | @@ -19,12 +19,12 @@ |
20 | 20 | $this->dieUsage( 'Must specify xpath', 1 ); |
21 | 21 | |
22 | 22 | $page = $params['page']; |
23 | | - $type = $params['type']; |
| 23 | + $verb = $params['verb']; |
24 | 24 | $xpath = $params['xpath']; |
25 | 25 | $value = $params['value']; |
26 | 26 | $summary = $params['summary']; |
27 | 27 | $rid = $params['rid']; |
28 | | - $force_update = $params['force_update']; |
| 28 | + $force_update = ( intval( $params['force_update'] ) == 1 ); |
29 | 29 | |
30 | 30 | $articleTitle = Title::newFromText( $page ); |
31 | 31 | if ( !$articleTitle ) |
— | — | @@ -52,9 +52,9 @@ |
53 | 53 | throw new MWException( __METHOD__ . ": object does not found, xpath: {$xpath}" ); |
54 | 54 | } |
55 | 55 | |
56 | | - if ( $type == 'remove' ) { |
| 56 | + if ( $verb == 'remove' ) { |
57 | 57 | WOMProcessor::removePageObject( $articleTitle, $oid, $summary, $rid, $force_update ); |
58 | | - } else if ( $type == 'removeall' ) { |
| 58 | + } else if ( $verb == 'removeall' ) { |
59 | 59 | $wom = WOMProcessor::getPageObject( $articleTitle, $rid ); |
60 | 60 | foreach ( $objs as $id ) { |
61 | 61 | if ( $id == '' ) continue; |
— | — | @@ -76,13 +76,13 @@ |
77 | 77 | if ( is_null( $params['value'] ) ) |
78 | 78 | $this->dieUsage( 'Must specify value', 2 ); |
79 | 79 | |
80 | | - if ( $type == 'insert' ) { |
| 80 | + if ( $verb == 'insert' ) { |
81 | 81 | WOMProcessor::insertPageText( $value, $articleTitle, $oid, $summary, $rid, $force_update ); |
82 | | - } else if ( $type == 'update' ) { |
| 82 | + } else if ( $verb == 'update' ) { |
83 | 83 | WOMProcessor::updatePageText( $value, $articleTitle, $oid, $summary, $rid, $force_update ); |
84 | | - } else if ( $type == 'append' ) { |
| 84 | + } else if ( $verb == 'append' ) { |
85 | 85 | WOMProcessor::appendPageText( $value, $articleTitle, $oid, $summary, $rid, $force_update ); |
86 | | - } else if ( $type == 'attribute' ) { |
| 86 | + } else if ( $verb == 'attribute' ) { |
87 | 87 | $wom = WOMProcessor::getPageObject( $articleTitle, $rid ); |
88 | 88 | $obj = $wom->getObject( $oid ); |
89 | 89 | $kv = explode( '=', $value, 2 ); |
— | — | @@ -119,7 +119,7 @@ |
120 | 120 | protected function getAllowedParams() { |
121 | 121 | return array ( |
122 | 122 | 'page' => null, |
123 | | - 'type' => array( |
| 123 | + 'verb' => array( |
124 | 124 | ApiBase :: PARAM_DFLT => 'update', |
125 | 125 | ApiBase :: PARAM_TYPE => array( |
126 | 126 | 'update', |
— | — | @@ -141,10 +141,10 @@ |
142 | 142 | ApiBase :: PARAM_MIN => 0 |
143 | 143 | ), |
144 | 144 | 'force_update' => array( |
145 | | - ApiBase :: PARAM_DFLT => 'true', |
| 145 | + ApiBase :: PARAM_DFLT => '1', |
146 | 146 | ApiBase :: PARAM_TYPE => array( |
147 | | - 'true', |
148 | | - 'false', |
| 147 | + '1', |
| 148 | + '0', |
149 | 149 | ), |
150 | 150 | ), |
151 | 151 | ); |
— | — | @@ -153,23 +153,27 @@ |
154 | 154 | protected function getParamDescription() { |
155 | 155 | return array ( |
156 | 156 | 'page' => 'Title of the page to modify', |
157 | | - 'type' => 'Type to set to change wiki object instances', |
| 157 | + 'verb' => 'Action verb to set to change wiki object instances', |
158 | 158 | 'xpath' => array( |
159 | 159 | 'DOM-like xpath to locate WOM object instances (http://www.w3schools.com/xpath/xpath_syntax.asp)', |
160 | | - 'type = update, xpath to elements to be updated', |
161 | | - 'type = attribute, xpath to elements, the attribute will be updated', |
162 | | - 'type = insert, the element will be inserted right before the element specified by xpath', |
163 | | - 'type = append, the element will be appended right to the element children elements specified by xpath', |
164 | | - 'type = remove, xpath to element to be removed', |
165 | | - 'type = removeall, xpath to elements to be removed', |
| 160 | + 'verb = update, xpath to elements to be updated', |
| 161 | + 'verb = attribute, xpath to elements, the attribute will be updated', |
| 162 | + 'verb = insert, the element will be inserted right before the element specified by xpath', |
| 163 | + 'verb = append, the element will be appended right to the element children elements specified by xpath', |
| 164 | + 'verb = remove, xpath to element to be removed', |
| 165 | + 'verb = removeall, xpath to elements to be removed', |
166 | 166 | ), |
167 | 167 | 'value' => array( |
168 | 168 | 'Value to set', |
169 | | - 'type = attribute, attribute_name=attribute_value', |
| 169 | + 'verb = attribute, attribute_name=attribute_value', |
170 | 170 | ), |
171 | 171 | 'summary' => 'Edit summary', |
172 | 172 | 'rid' => 'Revision id of specified page - by dafault latest updated revision (0) is used', |
173 | | - 'force_update' => 'Force to update even if the revision id does not match the latest edition', |
| 173 | + 'force_update' => array( |
| 174 | + 'Force to update even if the revision id does not match the latest edition', |
| 175 | + 'force_update = 0, return "revision not match" exception if rid is not the latest one', |
| 176 | + 'force_update = 1, update anyway', |
| 177 | + ), |
174 | 178 | ); |
175 | 179 | } |
176 | 180 | |