Index: trunk/extensions/PageObjectModel/POM.php |
— | — | @@ -3,15 +3,15 @@ |
4 | 4 | # PageObjectModel is a set of classes that allow easy manipulation of MediaWiki page source. |
5 | 5 | # |
6 | 6 | |
7 | | -require_once('POM/Element.php'); |
8 | | -require_once('POM/Page.php'); |
9 | | -require_once('POM/Parser.php'); |
10 | | -require_once('POM/CommentParser.php'); |
11 | | -require_once('POM/Comment.php'); |
12 | | -require_once('POM/LinkParser.php'); |
13 | | -require_once('POM/Link.php'); |
14 | | -require_once('POM/TemplateParser.php'); |
15 | | -require_once('POM/Template.php'); |
16 | | -require_once('POM/TemplateCollection.php'); |
17 | | -require_once('POM/TextNode.php'); |
| 7 | +require_once( 'POM/Element.php' ); |
| 8 | +require_once( 'POM/Page.php' ); |
| 9 | +require_once( 'POM/Parser.php' ); |
| 10 | +require_once( 'POM/CommentParser.php' ); |
| 11 | +require_once( 'POM/Comment.php' ); |
| 12 | +require_once( 'POM/LinkParser.php' ); |
| 13 | +require_once( 'POM/Link.php' ); |
| 14 | +require_once( 'POM/TemplateParser.php' ); |
| 15 | +require_once( 'POM/Template.php' ); |
| 16 | +require_once( 'POM/TemplateCollection.php' ); |
| 17 | +require_once( 'POM/TextNode.php' ); |
18 | 18 | |
Index: trunk/extensions/PageObjectModel/tests/WrongParameterNameExceptionTest.php |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | { |
8 | 8 | public function testWrongParameterNameExceptionMustContainMessage() |
9 | 9 | { |
10 | | - $e = new WrongParameterNameException("Can't get parameter with no name"); |
| 10 | + $e = new WrongParameterNameException( "Can't get parameter with no name" ); |
11 | 11 | $this->assertEquals( |
12 | 12 | "WrongParameterNameException: [0]: Can't get parameter with no name\n", |
13 | 13 | $e->__toString() |
Index: trunk/extensions/PageObjectModel/tests/POMTemplateParserTest.php |
— | — | @@ -8,21 +8,21 @@ |
9 | 9 | { |
10 | 10 | $sometext = "sometext\nbefore first with spaces {{sometemplate|var1=var2}}\nbefore second {{someothertemplate}} more text at the end\n"; |
11 | 11 | |
12 | | - $page = new POMPage($sometext); |
13 | | - $this->assertTrue(is_a($page->children[0], 'POMTextNode')); |
14 | | - $this->assertEquals("sometext\nbefore first with spaces ", $page->children[0]->asString()); |
| 12 | + $page = new POMPage( $sometext ); |
| 13 | + $this->assertTrue( is_a( $page->children[0], 'POMTextNode' ) ); |
| 14 | + $this->assertEquals( "sometext\nbefore first with spaces ", $page->children[0]->asString() ); |
15 | 15 | |
16 | | - $this->assertTrue(is_a($page->children[1], 'POMTemplate')); |
17 | | - $this->assertEquals('{{sometemplate|var1=var2}}', $page->children[1]->asString()); |
| 16 | + $this->assertTrue( is_a( $page->children[1], 'POMTemplate' ) ); |
| 17 | + $this->assertEquals( '{{sometemplate|var1=var2}}', $page->children[1]->asString() ); |
18 | 18 | |
19 | | - $this->assertTrue(is_a($page->children[2], 'POMTextNode')); |
20 | | - $this->assertEquals("\nbefore second ", $page->children[2]->asString()); |
| 19 | + $this->assertTrue( is_a( $page->children[2], 'POMTextNode' ) ); |
| 20 | + $this->assertEquals( "\nbefore second ", $page->children[2]->asString() ); |
21 | 21 | |
22 | | - $this->assertTrue(is_a($page->children[3], 'POMTemplate')); |
23 | | - $this->assertEquals('{{someothertemplate}}', $page->children[3]->asString()); |
| 22 | + $this->assertTrue( is_a( $page->children[3], 'POMTemplate' ) ); |
| 23 | + $this->assertEquals( '{{someothertemplate}}', $page->children[3]->asString() ); |
24 | 24 | |
25 | | - $this->assertTrue(is_a($page->children[4], 'POMTextNode')); |
26 | | - $this->assertEquals(" more text at the end\n", $page->children[4]->asString()); |
| 25 | + $this->assertTrue( is_a( $page->children[4], 'POMTextNode' ) ); |
| 26 | + $this->assertEquals( " more text at the end\n", $page->children[4]->asString() ); |
27 | 27 | } |
28 | 28 | |
29 | 29 | public function testTemplateParserMustPopulateTemplatesCollection() |
— | — | @@ -31,29 +31,29 @@ |
32 | 32 | |param2 = something |
33 | 33 | }} more text at the end\n"; |
34 | 34 | |
35 | | - $page = new POMPage($sometext); |
36 | | - $this->assertEquals(count($page->c['templates']['sometemplate']), 1); |
37 | | - $this->assertEquals(count($page->c['templates']['someothertemplate']), 2); |
| 35 | + $page = new POMPage( $sometext ); |
| 36 | + $this->assertEquals( count( $page->c['templates']['sometemplate'] ), 1 ); |
| 37 | + $this->assertEquals( count( $page->c['templates']['someothertemplate'] ), 2 ); |
38 | 38 | } |
39 | 39 | |
40 | 40 | public function testTemplateParserMustCorrectlyParseTemplatesWithParameters() |
41 | 41 | { |
42 | 42 | $sometext = "sometext\nbefore first with spaces {{sometemplate|var1=val1 {{subtemplate|subvar1=subval2}} val1 continue|var2=val2}}\nbefore second {{someothertemplate}} more text at the end\n"; |
43 | 43 | |
44 | | - $page = new POMPage($sometext); |
45 | | - $this->assertTrue(is_a($page->children[0], 'POMTextNode')); |
46 | | - $this->assertEquals("sometext\nbefore first with spaces ", $page->children[0]->asString()); |
| 44 | + $page = new POMPage( $sometext ); |
| 45 | + $this->assertTrue( is_a( $page->children[0], 'POMTextNode' ) ); |
| 46 | + $this->assertEquals( "sometext\nbefore first with spaces ", $page->children[0]->asString() ); |
47 | 47 | |
48 | | - $this->assertTrue(is_a($page->children[1], 'POMTemplate')); |
49 | | - $this->assertEquals('{{sometemplate|var1=val1 {{subtemplate|subvar1=subval2}} val1 continue|var2=val2}}', $page->children[1]->asString()); |
| 48 | + $this->assertTrue( is_a( $page->children[1], 'POMTemplate' ) ); |
| 49 | + $this->assertEquals( '{{sometemplate|var1=val1 {{subtemplate|subvar1=subval2}} val1 continue|var2=val2}}', $page->children[1]->asString() ); |
50 | 50 | |
51 | | - $this->assertTrue(is_a($page->children[2], 'POMTextNode')); |
52 | | - $this->assertEquals("\nbefore second ", $page->children[2]->asString()); |
| 51 | + $this->assertTrue( is_a( $page->children[2], 'POMTextNode' ) ); |
| 52 | + $this->assertEquals( "\nbefore second ", $page->children[2]->asString() ); |
53 | 53 | |
54 | | - $this->assertTrue(is_a($page->children[3], 'POMTemplate')); |
55 | | - $this->assertEquals('{{someothertemplate}}', $page->children[3]->asString()); |
| 54 | + $this->assertTrue( is_a( $page->children[3], 'POMTemplate' ) ); |
| 55 | + $this->assertEquals( '{{someothertemplate}}', $page->children[3]->asString() ); |
56 | 56 | |
57 | | - $this->assertTrue(is_a($page->children[4], 'POMTextNode')); |
58 | | - $this->assertEquals(" more text at the end\n", $page->children[4]->asString()); |
| 57 | + $this->assertTrue( is_a( $page->children[4], 'POMTextNode' ) ); |
| 58 | + $this->assertEquals( " more text at the end\n", $page->children[4]->asString() ); |
59 | 59 | } |
60 | 60 | } |
Index: trunk/extensions/PageObjectModel/tests/POMTemplateTest.php |
— | — | @@ -12,22 +12,22 @@ |
13 | 13 | public static function templateStringsProvider() |
14 | 14 | { |
15 | 15 | return array( |
16 | | - array('{{sometemplate|var1=var2}}'), |
17 | | - array('{{title with spaces|var1=var2}}'), |
18 | | - array('{{sometemplate| field name with spaces=var2}}'), |
19 | | - array('{{sometemplate|var1=value with spaces}}'), |
20 | | - array('{{sometemplate|1234|var1=value with spaces}}'), |
21 | | - array('{{sometemplate|a=b|b=c|numbered}}') |
| 16 | + array( '{{sometemplate|var1=var2}}' ), |
| 17 | + array( '{{title with spaces|var1=var2}}' ), |
| 18 | + array( '{{sometemplate| field name with spaces=var2}}' ), |
| 19 | + array( '{{sometemplate|var1=value with spaces}}' ), |
| 20 | + array( '{{sometemplate|1234|var1=value with spaces}}' ), |
| 21 | + array( '{{sometemplate|a=b|b=c|numbered}}' ) |
22 | 22 | ); |
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @dataProvider templateStringsProvider |
27 | 27 | */ |
28 | | - public function testTemplateMustPreserveOrderOfParameters($templatestring) |
| 28 | + public function testTemplateMustPreserveOrderOfParameters( $templatestring ) |
29 | 29 | { |
30 | | - $template = new POMTemplate($templatestring); |
31 | | - $this->assertEquals($template->asString(), $templatestring); |
| 30 | + $template = new POMTemplate( $templatestring ); |
| 31 | + $this->assertEquals( $template->asString(), $templatestring ); |
32 | 32 | } |
33 | 33 | |
34 | 34 | # ------------------------------------------------------------------------------------------------------- |
— | — | @@ -39,25 +39,25 @@ |
40 | 40 | public static function parameterGetNameValueProvider() |
41 | 41 | { |
42 | 42 | return array( |
43 | | - array('{{sometemplate|var1=var2}}', 'var1', 'var2'), |
44 | | - array('{{title with spaces|var1=var2}}', 'var1', 'var2'), |
45 | | - array('{{sometemplate| field name with spaces=var2}}', 'field name with spaces', 'var2'), |
46 | | - array('{{sometemplate|var1=value with spaces}}', 'var1', 'value with spaces'), |
47 | | - array('{{sometemplate|1234|var1=value with spaces}}', 'var1', 'value with spaces'), |
48 | | - array('{{sometemplate|a=b|b=c|numbered}}', 'a', 'b'), |
49 | | - array('{{sometemplate|a=b|b=c|numbered}}', 'b', 'c'), |
50 | | - array('{{sometemplate|a=b|b=c|numbered}}', 1, 'numbered'), |
51 | | - array('{{sometemplate|var1=var2}}', 'noexistent', null) |
| 43 | + array( '{{sometemplate|var1=var2}}', 'var1', 'var2' ), |
| 44 | + array( '{{title with spaces|var1=var2}}', 'var1', 'var2' ), |
| 45 | + array( '{{sometemplate| field name with spaces=var2}}', 'field name with spaces', 'var2' ), |
| 46 | + array( '{{sometemplate|var1=value with spaces}}', 'var1', 'value with spaces' ), |
| 47 | + array( '{{sometemplate|1234|var1=value with spaces}}', 'var1', 'value with spaces' ), |
| 48 | + array( '{{sometemplate|a=b|b=c|numbered}}', 'a', 'b' ), |
| 49 | + array( '{{sometemplate|a=b|b=c|numbered}}', 'b', 'c' ), |
| 50 | + array( '{{sometemplate|a=b|b=c|numbered}}', 1, 'numbered' ), |
| 51 | + array( '{{sometemplate|var1=var2}}', 'noexistent', null ) |
52 | 52 | ); |
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * @dataProvider parameterGetNameValueProvider |
57 | 57 | */ |
58 | | - public function testTemplateGetParameter($templatestring, $name, $value) |
| 58 | + public function testTemplateGetParameter( $templatestring, $name, $value ) |
59 | 59 | { |
60 | | - $template = new POMTemplate($templatestring); |
61 | | - $this->assertEquals($value, $template->getParameter($name)); |
| 60 | + $template = new POMTemplate( $templatestring ); |
| 61 | + $this->assertEquals( $value, $template->getParameter( $name ) ); |
62 | 62 | } |
63 | 63 | |
64 | 64 | |
— | — | @@ -70,136 +70,136 @@ |
71 | 71 | public static function parameterChangeNameValueProvider() |
72 | 72 | { |
73 | 73 | return array( |
74 | | - array('{{sometemplate|a=b|b=c|numbered}}', |
| 74 | + array( '{{sometemplate|a=b|b=c|numbered}}', |
75 | 75 | 1, |
76 | 76 | 'renumbered', |
77 | | - '{{sometemplate|a=b|b=c|renumbered}}'), |
78 | | - array('{{sometemplate|a=b|b=c|numbered 1|numbered 2}}', |
| 77 | + '{{sometemplate|a=b|b=c|renumbered}}' ), |
| 78 | + array( '{{sometemplate|a=b|b=c|numbered 1|numbered 2}}', |
79 | 79 | 2, |
80 | 80 | 'renumbered 2', |
81 | | - '{{sometemplate|a=b|b=c|numbered 1|renumbered 2}}'), |
82 | | - array('{{sometemplate|a=b|b=c|numbered 1|numbered 2}}', |
| 81 | + '{{sometemplate|a=b|b=c|numbered 1|renumbered 2}}' ), |
| 82 | + array( '{{sometemplate|a=b|b=c|numbered 1|numbered 2}}', |
83 | 83 | 3, |
84 | 84 | 'new numbered', |
85 | | - '{{sometemplate|a=b|b=c|numbered 1|numbered 2|new numbered}}'), |
86 | | - array('{{sometemplate|var1=var2}}', |
| 85 | + '{{sometemplate|a=b|b=c|numbered 1|numbered 2|new numbered}}' ), |
| 86 | + array( '{{sometemplate|var1=var2}}', |
87 | 87 | 'var1', |
88 | 88 | 'var3', |
89 | | - '{{sometemplate|var1=var3}}'), |
90 | | - array('{{sometemplate|var1= var2}}', |
| 89 | + '{{sometemplate|var1=var3}}' ), |
| 90 | + array( '{{sometemplate|var1= var2}}', |
91 | 91 | 'var1', |
92 | 92 | 'var3', |
93 | | - '{{sometemplate|var1= var3}}'), |
94 | | - array('{{sometemplate|var1 =var2}}', |
| 93 | + '{{sometemplate|var1= var3}}' ), |
| 94 | + array( '{{sometemplate|var1 =var2}}', |
95 | 95 | 'var1', |
96 | 96 | 'var3', |
97 | | - '{{sometemplate|var1 =var3}}'), |
98 | | - array('{{title with spaces|var1=var2}}', |
| 97 | + '{{sometemplate|var1 =var3}}' ), |
| 98 | + array( '{{title with spaces|var1=var2}}', |
99 | 99 | 'var1', |
100 | 100 | 'var3', |
101 | | - '{{title with spaces|var1=var3}}'), |
102 | | - array('{{sometemplate| field name with spaces=var2}}', |
| 101 | + '{{title with spaces|var1=var3}}' ), |
| 102 | + array( '{{sometemplate| field name with spaces=var2}}', |
103 | 103 | 'field name with spaces', |
104 | 104 | 'var3', |
105 | | - '{{sometemplate| field name with spaces=var3}}'), |
106 | | - array('{{sometemplate|var1=value with spaces}}', |
| 105 | + '{{sometemplate| field name with spaces=var3}}' ), |
| 106 | + array( '{{sometemplate|var1=value with spaces}}', |
107 | 107 | 'var1', |
108 | 108 | 'value with spaces 2', |
109 | | - '{{sometemplate|var1=value with spaces 2}}'), |
110 | | - array('{{sometemplate|1234|var1=value with spaces}}', |
| 109 | + '{{sometemplate|var1=value with spaces 2}}' ), |
| 110 | + array( '{{sometemplate|1234|var1=value with spaces}}', |
111 | 111 | 'var1', |
112 | 112 | 'value with spaces 2', |
113 | | - '{{sometemplate|1234|var1=value with spaces 2}}'), |
114 | | - array('{{sometemplate|a=b|b=c|numbered}}', |
| 113 | + '{{sometemplate|1234|var1=value with spaces 2}}' ), |
| 114 | + array( '{{sometemplate|a=b|b=c|numbered}}', |
115 | 115 | 'a', |
116 | 116 | 'd', |
117 | | - '{{sometemplate|a=d|b=c|numbered}}'), |
118 | | - array('{{sometemplate|a=b|b=c|numbered}}', |
| 117 | + '{{sometemplate|a=d|b=c|numbered}}' ), |
| 118 | + array( '{{sometemplate|a=b|b=c|numbered}}', |
119 | 119 | 'x', |
120 | 120 | 'y', |
121 | | - '{{sometemplate|a=b|b=c|numbered|x=y}}') |
| 121 | + '{{sometemplate|a=b|b=c|numbered|x=y}}' ) |
122 | 122 | ); |
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | 126 | * @dataProvider parameterChangeNameValueProvider |
127 | 127 | */ |
128 | | - public function testTemplateParameterChange($orig, $index, $value, $result) |
| 128 | + public function testTemplateParameterChange( $orig, $index, $value, $result ) |
129 | 129 | { |
130 | | - $template = new POMTemplate($orig); |
131 | | - $template->setParameter($index, $value); |
132 | | - $this->assertEquals($result, $template->asString()); |
| 130 | + $template = new POMTemplate( $orig ); |
| 131 | + $template->setParameter( $index, $value ); |
| 132 | + $this->assertEquals( $result, $template->asString() ); |
133 | 133 | } |
134 | 134 | |
135 | 135 | # TODO add more data |
136 | 136 | public static function parameterChangeSpacedNameValueProvider() |
137 | 137 | { |
138 | 138 | return array( |
139 | | - array('{{sometemplate|a=b|b=c|numbered}}', |
| 139 | + array( '{{sometemplate|a=b|b=c|numbered}}', |
140 | 140 | ' 1', |
141 | 141 | 'renumbered', |
142 | | - '{{sometemplate|a=b|b=c|renumbered}}'), |
143 | | - array('{{sometemplate|a=b|b=c|numbered 1|numbered 2}}', |
| 142 | + '{{sometemplate|a=b|b=c|renumbered}}' ), |
| 143 | + array( '{{sometemplate|a=b|b=c|numbered 1|numbered 2}}', |
144 | 144 | ' 2 ', |
145 | 145 | 'renumbered 2', |
146 | | - '{{sometemplate|a=b|b=c|numbered 1|renumbered 2}}'), |
147 | | - array('{{sometemplate|a=b|b=c|numbered 1|numbered 2}}', |
| 146 | + '{{sometemplate|a=b|b=c|numbered 1|renumbered 2}}' ), |
| 147 | + array( '{{sometemplate|a=b|b=c|numbered 1|numbered 2}}', |
148 | 148 | '3 ', |
149 | 149 | 'new numbered', |
150 | | - '{{sometemplate|a=b|b=c|numbered 1|numbered 2|new numbered}}'), |
151 | | - array('{{sometemplate|var1=var2}}', |
| 150 | + '{{sometemplate|a=b|b=c|numbered 1|numbered 2|new numbered}}' ), |
| 151 | + array( '{{sometemplate|var1=var2}}', |
152 | 152 | ' var1 ', |
153 | 153 | ' var3', |
154 | | - '{{sometemplate| var1 = var3}}'), |
155 | | - array('{{sometemplate|var1= var2}}', |
| 154 | + '{{sometemplate| var1 = var3}}' ), |
| 155 | + array( '{{sometemplate|var1= var2}}', |
156 | 156 | ' var1 ', |
157 | 157 | ' var3 ', |
158 | | - '{{sometemplate| var1 = var3 }}'), |
159 | | - array('{{sometemplate|var1 =var2}}', |
| 158 | + '{{sometemplate| var1 = var3 }}' ), |
| 159 | + array( '{{sometemplate|var1 =var2}}', |
160 | 160 | ' var1 ', |
161 | 161 | ' var3 ', |
162 | | - '{{sometemplate| var1 = var3 }}'), |
163 | | - array('{{title with spaces|var1=var2}}', |
| 162 | + '{{sometemplate| var1 = var3 }}' ), |
| 163 | + array( '{{title with spaces|var1=var2}}', |
164 | 164 | ' var1 ', |
165 | 165 | ' var3 ', |
166 | | - '{{title with spaces| var1 = var3 }}'), |
167 | | - array('{{sometemplate| field name with spaces=var2}}', |
| 166 | + '{{title with spaces| var1 = var3 }}' ), |
| 167 | + array( '{{sometemplate| field name with spaces=var2}}', |
168 | 168 | 'field name with spaces ', |
169 | 169 | 'var3 ', |
170 | | - '{{sometemplate|field name with spaces =var3 }}'), |
171 | | - array('{{sometemplate| var1 = value with spaces }}', |
| 170 | + '{{sometemplate|field name with spaces =var3 }}' ), |
| 171 | + array( '{{sometemplate| var1 = value with spaces }}', |
172 | 172 | 'var1', |
173 | 173 | 'value with spaces 2', |
174 | | - '{{sometemplate|var1=value with spaces 2}}'), |
175 | | - array('{{sometemplate|1234|var1= value with spaces}}', |
| 174 | + '{{sometemplate|var1=value with spaces 2}}' ), |
| 175 | + array( '{{sometemplate|1234|var1= value with spaces}}', |
176 | 176 | 'var1', |
177 | 177 | 'value with spaces 2', |
178 | | - '{{sometemplate|1234|var1=value with spaces 2}}'), |
179 | | - array('{{sometemplate|a =b | b = c|numbered}}', |
| 178 | + '{{sometemplate|1234|var1=value with spaces 2}}' ), |
| 179 | + array( '{{sometemplate|a =b | b = c|numbered}}', |
180 | 180 | 'a', |
181 | 181 | 'd', |
182 | | - '{{sometemplate|a=d| b = c|numbered}}'), |
183 | | - array('{{sometemplate| a =b|b=c|numbered}}', |
| 182 | + '{{sometemplate|a=d| b = c|numbered}}' ), |
| 183 | + array( '{{sometemplate| a =b|b=c|numbered}}', |
184 | 184 | 'x ', |
185 | 185 | ' y', |
186 | | - '{{sometemplate| a =b|b=c|numbered|x = y}}') |
| 186 | + '{{sometemplate| a =b|b=c|numbered|x = y}}' ) |
187 | 187 | ); |
188 | 188 | } |
189 | 189 | /** |
190 | 190 | * @dataProvider parameterChangeSpacedNameValueProvider |
191 | 191 | */ |
192 | | - public function testTemplateParameterChangeHonoringSpacing($orig, $index, $value, $result) |
| 192 | + public function testTemplateParameterChangeHonoringSpacing( $orig, $index, $value, $result ) |
193 | 193 | { |
194 | | - $template = new POMTemplate($orig); |
195 | | - $template->setParameter($index, $value, false, false, true, true); |
196 | | - $this->assertEquals($result, $template->asString()); |
| 194 | + $template = new POMTemplate( $orig ); |
| 195 | + $template->setParameter( $index, $value, false, false, true, true ); |
| 196 | + $this->assertEquals( $result, $template->asString() ); |
197 | 197 | } |
198 | 198 | |
199 | 199 | public function testParameterWithEmptyNameShouldBeIgnoredButPreserved() |
200 | 200 | { |
201 | 201 | $somestring = '{{tempname|name=val1|=val2}}'; |
202 | | - $template = new POMTemplate($somestring); |
203 | | - $this->assertEquals($somestring, $template->asString()); |
| 202 | + $template = new POMTemplate( $somestring ); |
| 203 | + $this->assertEquals( $somestring, $template->asString() ); |
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
— | — | @@ -208,8 +208,8 @@ |
209 | 209 | public function testThrowExceptionOnGettingParameterByEmptyName() |
210 | 210 | { |
211 | 211 | $somestring = '{{tempname|name=val1}}'; |
212 | | - $template = new POMTemplate($somestring); |
213 | | - $res = $template->getParameter(' '); |
| 212 | + $template = new POMTemplate( $somestring ); |
| 213 | + $res = $template->getParameter( ' ' ); |
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
— | — | @@ -218,7 +218,7 @@ |
219 | 219 | public function testThrowExceptionSettingParameterByEmptyName() |
220 | 220 | { |
221 | 221 | $somestring = '{{tempname|name=val1}}'; |
222 | | - $template = new POMTemplate($somestring); |
223 | | - $res = $template->setParameter(' ', 'value'); |
| 222 | + $template = new POMTemplate( $somestring ); |
| 223 | + $res = $template->setParameter( ' ', 'value' ); |
224 | 224 | } |
225 | 225 | } |
Index: trunk/extensions/PageObjectModel/tests/POMPageTest.php |
— | — | @@ -8,25 +8,25 @@ |
9 | 9 | public static function pageProvider() |
10 | 10 | { |
11 | 11 | return array( |
12 | | - array('{{sometemplate|var1=var2}}'), |
13 | | - array('{{title with spaces|var1=var2}}'), |
14 | | - array('{{sometemplate| field name with spaces=var2}}'), |
15 | | - array('{{sometemplate|var1=value with spaces}}'), |
16 | | - array('{{sometemplate|1234|var1=value with spaces}}'), |
17 | | - array('{{sometemplate|a=b|b=c|numbered}}'), |
18 | | - array('{{sometemplate|a={{othertemplate|x=y}}|b=c|numbered}}'), |
19 | | - array("sometext\nbefore first with spaces {{sometemplate |var1=var2}}\nbefore second {{ someothertemplate|param1 = 0}} plus another {{someothertemplate |
| 12 | + array( '{{sometemplate|var1=var2}}' ), |
| 13 | + array( '{{title with spaces|var1=var2}}' ), |
| 14 | + array( '{{sometemplate| field name with spaces=var2}}' ), |
| 15 | + array( '{{sometemplate|var1=value with spaces}}' ), |
| 16 | + array( '{{sometemplate|1234|var1=value with spaces}}' ), |
| 17 | + array( '{{sometemplate|a=b|b=c|numbered}}' ), |
| 18 | + array( '{{sometemplate|a={{othertemplate|x=y}}|b=c|numbered}}' ), |
| 19 | + array( "sometext\nbefore first with spaces {{sometemplate |var1=var2}}\nbefore second {{ someothertemplate|param1 = 0}} plus another {{someothertemplate |
20 | 20 | |param2 = something |
21 | | -}} more text at the end\n") |
| 21 | +}} more text at the end\n" ) |
22 | 22 | ); |
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @dataProvider pageProvider |
27 | 27 | */ |
28 | | - public function testInputIsTheSameAsOutput($pagetext) |
| 28 | + public function testInputIsTheSameAsOutput( $pagetext ) |
29 | 29 | { |
30 | | - $page = new POMPage($pagetext); |
31 | | - $this->assertEquals($pagetext, $page->asString()); |
| 30 | + $page = new POMPage( $pagetext ); |
| 31 | + $this->assertEquals( $pagetext, $page->asString() ); |
32 | 32 | } |
33 | 33 | } |
Index: trunk/extensions/PageObjectModel/PageObjectModel.php |
— | — | @@ -5,9 +5,9 @@ |
6 | 6 | if ( !defined( 'MEDIAWIKI' ) ) { |
7 | 7 | exit( 1 ); |
8 | 8 | } |
9 | | -require_once ("$IP/extensions/PageObjectModel/POM.php"); |
| 9 | +require_once ( "$IP/extensions/PageObjectModel/POM.php" ); |
10 | 10 | |
11 | | -require_once ("$IP/includes/api/ApiBase.php"); |
| 11 | +require_once ( "$IP/includes/api/ApiBase.php" ); |
12 | 12 | |
13 | 13 | global $wgAPIModules; |
14 | 14 | $wgAPIModules['pomsettplparam'] = 'ApiPOMSetTemplateParameter'; |
— | — | @@ -18,24 +18,24 @@ |
19 | 19 | */ |
20 | 20 | class ApiPOMSetTemplateParameter extends ApiBase { |
21 | 21 | |
22 | | - public function __construct($query, $moduleName) { |
23 | | - parent :: __construct($query, $moduleName); |
| 22 | + public function __construct( $query, $moduleName ) { |
| 23 | + parent :: __construct( $query, $moduleName ); |
24 | 24 | } |
25 | 25 | |
26 | 26 | public function execute() { |
27 | 27 | global $wgUser; |
28 | 28 | |
29 | 29 | $params = $this->extractRequestParams(); |
30 | | - if (is_null($params['page'])) |
31 | | - $this->dieUsage('Must specify page title', 0); |
32 | | - if (is_null($params['tpl'])) |
33 | | - $this->dieUsage('Must specify template name', 1); |
34 | | - if (is_null($params['param'])) |
35 | | - $this->dieUsage('Must specify parameter name', 2); |
36 | | - if (is_null($params['value'])) |
37 | | - $this->dieUsage('Must specify value', 3); |
38 | | - if (is_null($params['summary'])) |
39 | | - $this->dieUsage('Must specify edit summary', 4); |
| 30 | + if ( is_null( $params['page'] ) ) |
| 31 | + $this->dieUsage( 'Must specify page title', 0 ); |
| 32 | + if ( is_null( $params['tpl'] ) ) |
| 33 | + $this->dieUsage( 'Must specify template name', 1 ); |
| 34 | + if ( is_null( $params['param'] ) ) |
| 35 | + $this->dieUsage( 'Must specify parameter name', 2 ); |
| 36 | + if ( is_null( $params['value'] ) ) |
| 37 | + $this->dieUsage( 'Must specify value', 3 ); |
| 38 | + if ( is_null( $params['summary'] ) ) |
| 39 | + $this->dieUsage( 'Must specify edit summary', 4 ); |
40 | 40 | |
41 | 41 | $page = $params['page']; |
42 | 42 | $template = $params['tpl']; |
— | — | @@ -46,39 +46,39 @@ |
47 | 47 | |
48 | 48 | |
49 | 49 | $articleTitle = Title::newFromText( $page ); |
50 | | - if (!$articleTitle) |
51 | | - $this->dieUsage("Can't create title object ($page)", 5); |
| 50 | + if ( !$articleTitle ) |
| 51 | + $this->dieUsage( "Can't create title object ($page)", 5 ); |
52 | 52 | |
53 | | - $errors = $articleTitle->getUserPermissionsErrors('edit', $wgUser); |
54 | | - if(!empty($errors)) |
55 | | - $this->dieUsage(wfMsg($errors[0][0], $errors[0][1]), 8); |
| 53 | + $errors = $articleTitle->getUserPermissionsErrors( 'edit', $wgUser ); |
| 54 | + if ( !empty( $errors ) ) |
| 55 | + $this->dieUsage( wfMsg( $errors[0][0], $errors[0][1] ), 8 ); |
56 | 56 | |
57 | | - $article = new Article($articleTitle); |
58 | | - if (!$article->exists()) |
59 | | - $this->dieUsage("Article doesn't exist ($page)", 6); |
| 57 | + $article = new Article( $articleTitle ); |
| 58 | + if ( !$article->exists() ) |
| 59 | + $this->dieUsage( "Article doesn't exist ($page)", 6 ); |
60 | 60 | |
61 | | - $pom = new POMPage($article->getContent()); |
62 | | - if (array_key_exists($template, $pom->templates) |
63 | | - && array_key_exists($instance, $pom->templates[$template]) |
| 61 | + $pom = new POMPage( $article->getContent() ); |
| 62 | + if ( array_key_exists( $template, $pom->templates ) |
| 63 | + && array_key_exists( $instance, $pom->templates[$template] ) |
64 | 64 | ) |
65 | 65 | { |
66 | | - $pom->templates[$template][$instance]->setParameter($parameter, $value); |
| 66 | + $pom->templates[$template][$instance]->setParameter( $parameter, $value ); |
67 | 67 | } |
68 | 68 | else |
69 | 69 | { |
70 | | - $this->dieUsage("This template ($template, instance #$instance) with this parameter ($parameter) doesn't exist within this page ($page)", 7); |
| 70 | + $this->dieUsage( "This template ($template, instance #$instance) with this parameter ($parameter) doesn't exist within this page ($page)", 7 ); |
71 | 71 | } |
72 | 72 | |
73 | | - $success = $article->doEdit($pom->asString(), $summary); |
| 73 | + $success = $article->doEdit( $pom->asString(), $summary ); |
74 | 74 | |
75 | | - $result=array(); |
| 75 | + $result = array(); |
76 | 76 | if ( $success ) { |
77 | | - $result['result']='Success'; |
| 77 | + $result['result'] = 'Success'; |
78 | 78 | } else { |
79 | | - $result['result']='Failure'; |
| 79 | + $result['result'] = 'Failure'; |
80 | 80 | } |
81 | 81 | |
82 | | - $this->getResult()->addValue(null, 'pomsettplparam', $result); |
| 82 | + $this->getResult()->addValue( null, 'pomsettplparam', $result ); |
83 | 83 | } |
84 | 84 | |
85 | 85 | protected function getAllowedParams() { |
— | — | @@ -135,20 +135,20 @@ |
136 | 136 | */ |
137 | 137 | class ApiPOMGetTemplateParameter extends ApiBase { |
138 | 138 | |
139 | | - public function __construct($query, $moduleName) { |
140 | | - parent :: __construct($query, $moduleName); |
| 139 | + public function __construct( $query, $moduleName ) { |
| 140 | + parent :: __construct( $query, $moduleName ); |
141 | 141 | } |
142 | 142 | |
143 | 143 | public function execute() { |
144 | 144 | global $wgUser; |
145 | 145 | |
146 | 146 | $params = $this->extractRequestParams(); |
147 | | - if (is_null($params['page'])) |
148 | | - $this->dieUsage('Must specify page title', 0); |
149 | | - if (is_null($params['tpl'])) |
150 | | - $this->dieUsage('Must specify template name', 1); |
151 | | - if (is_null($params['param'])) |
152 | | - $this->dieUsage('Must specify parameter name', 2); |
| 147 | + if ( is_null( $params['page'] ) ) |
| 148 | + $this->dieUsage( 'Must specify page title', 0 ); |
| 149 | + if ( is_null( $params['tpl'] ) ) |
| 150 | + $this->dieUsage( 'Must specify template name', 1 ); |
| 151 | + if ( is_null( $params['param'] ) ) |
| 152 | + $this->dieUsage( 'Must specify parameter name', 2 ); |
153 | 153 | |
154 | 154 | $page = $params['page']; |
155 | 155 | $template = $params['tpl']; |
— | — | @@ -156,28 +156,28 @@ |
157 | 157 | $parameter = $params['param']; |
158 | 158 | |
159 | 159 | $articleTitle = Title::newFromText( $page ); |
160 | | - if (!$articleTitle) |
161 | | - $this->dieUsage("Can't create title object ($page)", 5); |
| 160 | + if ( !$articleTitle ) |
| 161 | + $this->dieUsage( "Can't create title object ($page)", 5 ); |
162 | 162 | |
163 | | - $errors = $articleTitle->getUserPermissionsErrors('read', $wgUser); |
164 | | - if(!empty($errors)) |
165 | | - $this->dieUsage(wfMsg($errors[0][0], $errors[0][1]), 8); |
| 163 | + $errors = $articleTitle->getUserPermissionsErrors( 'read', $wgUser ); |
| 164 | + if ( !empty( $errors ) ) |
| 165 | + $this->dieUsage( wfMsg( $errors[0][0], $errors[0][1] ), 8 ); |
166 | 166 | |
167 | | - $article = new Article($articleTitle); |
168 | | - if (!$article->exists()) |
169 | | - $this->dieUsage("Article doesn't exist ($page)", 6); |
| 167 | + $article = new Article( $articleTitle ); |
| 168 | + if ( !$article->exists() ) |
| 169 | + $this->dieUsage( "Article doesn't exist ($page)", 6 ); |
170 | 170 | |
171 | | - $pom = new POMPage($article->getContent()); |
172 | | - if (array_key_exists($template, $pom->templates) |
173 | | - && array_key_exists($instance, $pom->templates[$template]) |
| 171 | + $pom = new POMPage( $article->getContent() ); |
| 172 | + if ( array_key_exists( $template, $pom->templates ) |
| 173 | + && array_key_exists( $instance, $pom->templates[$template] ) |
174 | 174 | ) |
175 | 175 | { |
176 | | - $result['value'] = $pom->templates[$template][$instance]->getParameter($parameter); |
177 | | - $this->getResult()->addValue(null, 'pomgettplparam', $result); |
| 176 | + $result['value'] = $pom->templates[$template][$instance]->getParameter( $parameter ); |
| 177 | + $this->getResult()->addValue( null, 'pomgettplparam', $result ); |
178 | 178 | } |
179 | 179 | else |
180 | 180 | { |
181 | | - $this->dieUsage("This template ($template, instance #$instance) with this parameter ($parameter) doesn't exist within this page ($page)", 7); |
| 181 | + $this->dieUsage( "This template ($template, instance #$instance) with this parameter ($parameter) doesn't exist within this page ($page)", 7 ); |
182 | 182 | } |
183 | 183 | } |
184 | 184 | |
Index: trunk/extensions/PageObjectModel/POM/Element.php |
— | — | @@ -13,17 +13,17 @@ |
14 | 14 | function asString() { |
15 | 15 | $output = ''; |
16 | 16 | |
17 | | - if ($this->hide) return $output; |
| 17 | + if ( $this->hide ) return $output; |
18 | 18 | |
19 | | - foreach ($this->children as $child) |
| 19 | + foreach ( $this->children as $child ) |
20 | 20 | { |
21 | | - $output.=$child->asString(); |
| 21 | + $output .= $child->asString(); |
22 | 22 | } |
23 | 23 | |
24 | 24 | return $output; |
25 | 25 | } |
26 | 26 | |
27 | | - function addChild(POMElement $el) |
| 27 | + function addChild( POMElement $el ) |
28 | 28 | { |
29 | 29 | $this->children[] = $el; |
30 | 30 | } |
Index: trunk/extensions/PageObjectModel/POM/LinkParser.php |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | # |
9 | 9 | # This function will parse all POMTextNodes in the page and add POMLink nodes if links are found |
10 | 10 | # |
11 | | - static function Parse(POMPage $page) { |
| 11 | + static function Parse( POMPage $page ) { |
12 | 12 | // this array holds shortcuts to templates |
13 | 13 | $page->c['links'] = array(); |
14 | 14 | |
— | — | @@ -17,40 +17,40 @@ |
18 | 18 | // we'll set it to true if tree was updated |
19 | 19 | $replaceoldchildrenwithnew = false; |
20 | 20 | |
21 | | - for ($n = 0; $n < sizeof($page->children); $n++) { |
22 | | - if (is_a($page->children[$n], 'POMTextNode')) { |
| 21 | + for ( $n = 0; $n < sizeof( $page->children ); $n++ ) { |
| 22 | + if ( is_a( $page->children[$n], 'POMTextNode' ) ) { |
23 | 23 | $nodetext = $page->children[$n]->asString(); |
24 | 24 | |
25 | | - while(($open = strpos($nodetext, '[[')) !== FALSE) { |
| 25 | + while ( ( $open = strpos( $nodetext, '[[' ) ) !== FALSE ) { |
26 | 26 | $position = $open; |
27 | 27 | |
28 | | - $nextopen = strpos($nodetext, '[[', $position+2); |
29 | | - $pipe = strpos($nodetext, '|', $position+2); |
30 | | - $nextpipe = strpos($nodetext, '|', $pipe+1); |
31 | | - $close = strpos($nodetext, ']]', $position+2); |
| 28 | + $nextopen = strpos( $nodetext, '[[', $position + 2 ); |
| 29 | + $pipe = strpos( $nodetext, '|', $position + 2 ); |
| 30 | + $nextpipe = strpos( $nodetext, '|', $pipe + 1 ); |
| 31 | + $close = strpos( $nodetext, ']]', $position + 2 ); |
32 | 32 | |
33 | | - if (FALSE === $close) break; # some markup confuses this poor parser, and thus it ignores the rest of this node |
34 | | - if (!(FALSE === $nextpipe) && ($nextpipe < $close)) break; |
35 | | - if (!(FALSE === $nextopen) && ($nextopen < $close)) break; |
| 33 | + if ( FALSE === $close ) break; # some markup confuses this poor parser, and thus it ignores the rest of this node |
| 34 | + if ( !( FALSE === $nextpipe ) && ( $nextpipe < $close ) ) break; |
| 35 | + if ( !( FALSE === $nextopen ) && ( $nextopen < $close ) ) break; |
36 | 36 | |
37 | 37 | // part before the template becomes text node |
38 | | - $newchildren[] = new POMTextNode(substr($nodetext, 0, $open)); |
| 38 | + $newchildren[] = new POMTextNode( substr( $nodetext, 0, $open ) ); |
39 | 39 | |
40 | 40 | // part between opening [[ and closing ]] becomes link |
41 | | - $link = new POMLink(substr($nodetext, $open, $close+2-$open)); |
| 41 | + $link = new POMLink( substr( $nodetext, $open, $close + 2 - $open ) ); |
42 | 42 | $newchildren[] = $link; |
43 | 43 | $page->c['links'][] = $link; |
44 | 44 | |
45 | 45 | $position = $close + 2; |
46 | 46 | |
47 | 47 | // the rest of it should be processed for more templates |
48 | | - $nodetext = substr($nodetext, $position); |
| 48 | + $nodetext = substr( $nodetext, $position ); |
49 | 49 | |
50 | 50 | $replaceoldchildrenwithnew = true; |
51 | 51 | } |
52 | 52 | |
53 | | - if (strlen($nodetext) > 0) { |
54 | | - $newchildren[] = new POMTextNode($nodetext); |
| 53 | + if ( strlen( $nodetext ) > 0 ) { |
| 54 | + $newchildren[] = new POMTextNode( $nodetext ); |
55 | 55 | |
56 | 56 | $replaceoldchildrenwithnew = true; |
57 | 57 | } |
— | — | @@ -61,6 +61,6 @@ |
62 | 62 | } |
63 | 63 | |
64 | 64 | // if tree was updated, let's replace it in the page |
65 | | - if ($replaceoldchildrenwithnew) $page->children = $newchildren; |
| 65 | + if ( $replaceoldchildrenwithnew ) $page->children = $newchildren; |
66 | 66 | } |
67 | 67 | } |
Index: trunk/extensions/PageObjectModel/POM/TextNode.php |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | |
9 | 9 | protected $nodeText = ''; |
10 | 10 | |
11 | | - public function POMTextNode($text) |
| 11 | + public function POMTextNode( $text ) |
12 | 12 | { |
13 | 13 | $this->nodeText = $text; |
14 | 14 | $this->children = null; // forcefully ignore children |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | |
17 | 17 | public function asString() |
18 | 18 | { |
19 | | - if ($this->hidden()) return ""; |
| 19 | + if ( $this->hidden() ) return ""; |
20 | 20 | return $this->nodeText; |
21 | 21 | } |
22 | 22 | } |
Index: trunk/extensions/PageObjectModel/POM/Template.php |
— | — | @@ -2,8 +2,8 @@ |
3 | 3 | # |
4 | 4 | # Template class represents templates |
5 | 5 | # |
6 | | -require_once('Util.php'); |
7 | | -require_once('TemplateParameter.php'); |
| 6 | +require_once( 'Util.php' ); |
| 7 | +require_once( 'TemplateParameter.php' ); |
8 | 8 | |
9 | 9 | class POMTemplate extends POMElement |
10 | 10 | { |
— | — | @@ -11,33 +11,33 @@ |
12 | 12 | |
13 | 13 | protected $parameters = array(); |
14 | 14 | |
15 | | - public function POMTemplate($text) |
| 15 | + public function POMTemplate( $text ) |
16 | 16 | { |
17 | 17 | $this->children = null; // forcefully ignore children |
18 | 18 | |
19 | 19 | # Remove curly braces at the beginning and at the end |
20 | | - $text = substr($text, 2, strlen($text) - 4); |
| 20 | + $text = substr( $text, 2, strlen( $text ) - 4 ); |
21 | 21 | |
22 | 22 | # Split by pipe |
23 | | - $parts = explode('|', $text); |
| 23 | + $parts = explode( '|', $text ); |
24 | 24 | |
25 | 25 | # Check if this is a function call in the form #name: |
26 | | - $first_part = array_shift($parts); |
27 | | - if (strpos(trim($first_part), "#")==0) |
28 | | - if (strpos($first_part, ":")!==False) { |
29 | | - $splitted = explode(':', $first_part, 2); |
30 | | - if (count($splitted) == 2) { |
| 26 | + $first_part = array_shift( $parts ); |
| 27 | + if ( strpos( trim( $first_part ), "#" ) == 0 ) |
| 28 | + if ( strpos( $first_part, ":" ) !== False ) { |
| 29 | + $splitted = explode( ':', $first_part, 2 ); |
| 30 | + if ( count( $splitted ) == 2 ) { |
31 | 31 | $first_part = $splitted[0]; |
32 | | - array_unshift($parts, $splitted[1]); |
| 32 | + array_unshift( $parts, $splitted[1] ); |
33 | 33 | } |
34 | 34 | |
35 | 35 | } |
36 | 36 | |
37 | | - $this->title_triple = new POMUtilTrimTriple($first_part); |
| 37 | + $this->title_triple = new POMUtilTrimTriple( $first_part ); |
38 | 38 | |
39 | | - foreach ($parts as $part) |
| 39 | + foreach ( $parts as $part ) |
40 | 40 | { |
41 | | - $this->parameters[] = POMTemplateParameter::parse($part); |
| 41 | + $this->parameters[] = POMTemplateParameter::parse( $part ); |
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
— | — | @@ -47,68 +47,68 @@ |
48 | 48 | } |
49 | 49 | |
50 | 50 | public function getParametersCount() { |
51 | | - return count($this->parameters); |
| 51 | + return count( $this->parameters ); |
52 | 52 | } |
53 | 53 | |
54 | | - public function getParameterName($number) { |
55 | | - if ($number < 0) return ""; |
56 | | - if ($number > count($this->parameters)-1) return ""; |
| 54 | + public function getParameterName( $number ) { |
| 55 | + if ( $number < 0 ) return ""; |
| 56 | + if ( $number > count( $this->parameters ) - 1 ) return ""; |
57 | 57 | $parameter = $this->parameters[$number]; |
58 | | - if (is_a($parameter, 'POMTemplateNamedParameter')) |
| 58 | + if ( is_a( $parameter, 'POMTemplateNamedParameter' ) ) |
59 | 59 | return $parameter->getName(); |
60 | 60 | else |
61 | | - return ""; |
| 61 | + return ""; |
62 | 62 | } |
63 | 63 | |
64 | 64 | public function removeParameterByNumber( $number ) { |
65 | | - if ($number < 0) return; |
66 | | - if ($number > count($this->parameters)-1) return; |
67 | | - unset($this->parameters[$number]); |
68 | | - $this->parameters = array_values($this->parameters); |
| 65 | + if ( $number < 0 ) return; |
| 66 | + if ( $number > count( $this->parameters ) - 1 ) return; |
| 67 | + unset( $this->parameters[$number] ); |
| 68 | + $this->parameters = array_values( $this->parameters ); |
69 | 69 | } |
70 | 70 | |
71 | 71 | public function getNumberByName( $name ) { |
72 | | - $trimmed_name = trim($name); |
73 | | - if (strlen($trimmed_name) == 0) |
74 | | - throw new WrongParameterNameException('Can\'t get parameter with no name'); |
| 72 | + $trimmed_name = trim( $name ); |
| 73 | + if ( strlen( $trimmed_name ) == 0 ) |
| 74 | + throw new WrongParameterNameException( 'Can\'t get parameter with no name' ); |
75 | 75 | |
76 | | - for ($i = 0; $i < count($this->parameters); $i++) { |
| 76 | + for ( $i = 0; $i < count( $this->parameters ); $i++ ) { |
77 | 77 | $parameter = $this->parameters[$i]; |
78 | | - if ($parameter->getName() == $trimmed_name) return $i; |
| 78 | + if ( $parameter->getName() == $trimmed_name ) return $i; |
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | | - public function getParameterByNumber($number) { |
83 | | - if ($number < 0) return ""; |
84 | | - if ($number > count($this->parameters)-1) return ""; |
| 82 | + public function getParameterByNumber( $number ) { |
| 83 | + if ( $number < 0 ) return ""; |
| 84 | + if ( $number > count( $this->parameters ) - 1 ) return ""; |
85 | 85 | $parameter = $this->parameters[$number]; |
86 | 86 | return $parameter->getValue(); |
87 | 87 | } |
88 | 88 | |
89 | | - public function getParameter($name) |
| 89 | + public function getParameter( $name ) |
90 | 90 | { |
91 | | - $trimmed_name = trim($name); |
92 | | - if (strlen($trimmed_name) == 0) |
| 91 | + $trimmed_name = trim( $name ); |
| 92 | + if ( strlen( $trimmed_name ) == 0 ) |
93 | 93 | { |
94 | | - throw new WrongParameterNameException('Can\'t get parameter with no name'); |
| 94 | + throw new WrongParameterNameException( 'Can\'t get parameter with no name' ); |
95 | 95 | } |
96 | 96 | |
97 | 97 | $number = 1; |
98 | | - for ($i = 0; $i < count($this->parameters); $i++) |
| 98 | + for ( $i = 0; $i < count( $this->parameters ); $i++ ) |
99 | 99 | { |
100 | 100 | $parameter = $this->parameters[$i]; |
101 | 101 | |
102 | 102 | # checking this in runtime to make sure we cover all post-parsing updates to the list |
103 | | - if (is_a($parameter, 'POMTemplateNamedParameter')) |
| 103 | + if ( is_a( $parameter, 'POMTemplateNamedParameter' ) ) |
104 | 104 | { |
105 | | - if ($parameter->getName() == $trimmed_name) |
| 105 | + if ( $parameter->getName() == $trimmed_name ) |
106 | 106 | { |
107 | 107 | return $parameter->getValue(); |
108 | 108 | } |
109 | 109 | } |
110 | | - else if (is_a($parameter, 'POMTemplateNumberedParameter')) |
| 110 | + else if ( is_a( $parameter, 'POMTemplateNumberedParameter' ) ) |
111 | 111 | { |
112 | | - if ($number == $trimmed_name) |
| 112 | + if ( $number == $trimmed_name ) |
113 | 113 | { |
114 | 114 | return $parameter->getValue(); |
115 | 115 | } |
— | — | @@ -119,57 +119,57 @@ |
120 | 120 | return null; # none matched |
121 | 121 | } |
122 | 122 | |
123 | | - public function addParameter($name, $value) { |
124 | | - if (strlen(trim($name)) == 0) |
125 | | - throw new WrongParameterNameException("Can't set parameter with no name"); |
| 123 | + public function addParameter( $name, $value ) { |
| 124 | + if ( strlen( trim( $name ) ) == 0 ) |
| 125 | + throw new WrongParameterNameException( "Can't set parameter with no name" ); |
126 | 126 | |
127 | 127 | # add parameter to parameters array |
128 | | - $this->parameters[] = new POMTemplateNamedParameter($name, $value); |
| 128 | + $this->parameters[] = new POMTemplateNamedParameter( $name, $value ); |
129 | 129 | } |
130 | 130 | |
131 | | - public function setParameter($name, $value, |
| 131 | + public function setParameter( $name, $value, |
132 | 132 | $ignore_name_spacing = true, |
133 | 133 | $ignore_value_spacing = true, |
134 | 134 | $override_name_spacing = false, # when original value exists |
135 | 135 | $override_value_spacing = false # when original value exists |
136 | 136 | ) |
137 | 137 | { |
138 | | - $trimmed_name = trim($name); |
139 | | - if (strlen($trimmed_name) == 0) |
| 138 | + $trimmed_name = trim( $name ); |
| 139 | + if ( strlen( $trimmed_name ) == 0 ) |
140 | 140 | { |
141 | | - throw new WrongParameterNameException("Can't set parameter with no name"); |
| 141 | + throw new WrongParameterNameException( "Can't set parameter with no name" ); |
142 | 142 | } |
143 | 143 | |
144 | | - if ($ignore_name_spacing) |
| 144 | + if ( $ignore_name_spacing ) |
145 | 145 | { |
146 | 146 | $name = $trimmed_name; |
147 | 147 | } |
148 | 148 | |
149 | | - if ($ignore_value_spacing) |
| 149 | + if ( $ignore_value_spacing ) |
150 | 150 | { |
151 | | - $value = trim($value); |
| 151 | + $value = trim( $value ); |
152 | 152 | } |
153 | 153 | |
154 | 154 | # first go through named parameters and see if name matches |
155 | | - for ($i = 0; $i < count($this->parameters); $i++) |
| 155 | + for ( $i = 0; $i < count( $this->parameters ); $i++ ) |
156 | 156 | { |
157 | | - if (is_a($this->parameters[$i], 'POMTemplateNamedParameter') && |
158 | | - $this->parameters[$i]->getName() == $trimmed_name) |
| 157 | + if ( is_a( $this->parameters[$i], 'POMTemplateNamedParameter' ) && |
| 158 | + $this->parameters[$i]->getName() == $trimmed_name ) |
159 | 159 | { |
160 | | - $this->parameters[$i]->update($name, $value, $override_name_spacing, $override_value_spacing); |
| 160 | + $this->parameters[$i]->update( $name, $value, $override_name_spacing, $override_value_spacing ); |
161 | 161 | return; |
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
165 | 165 | # then go through numbered parameters and see if parameter with this number exists |
166 | 166 | $number = 1; |
167 | | - for ($i = 0; $i < count($this->parameters); $i++) |
| 167 | + for ( $i = 0; $i < count( $this->parameters ); $i++ ) |
168 | 168 | { |
169 | | - if (is_a($this->parameters[$i], 'POMTemplateNumberedParameter')) |
| 169 | + if ( is_a( $this->parameters[$i], 'POMTemplateNumberedParameter' ) ) |
170 | 170 | { |
171 | | - if ($number == $trimmed_name) |
| 171 | + if ( $number == $trimmed_name ) |
172 | 172 | { |
173 | | - $this->parameters[$i]->update($value, $override_value_spacing); |
| 173 | + $this->parameters[$i]->update( $value, $override_value_spacing ); |
174 | 174 | return; |
175 | 175 | } |
176 | 176 | $number++; |
— | — | @@ -178,27 +178,27 @@ |
179 | 179 | |
180 | 180 | # now, if passed name is numeric, create numbered parameter, otherwise create named parameter |
181 | 181 | # add parameter to parameters array |
182 | | - if (is_numeric($trimmed_name) && ((int)$trimmed_name) == $trimmed_name) |
| 182 | + if ( is_numeric( $trimmed_name ) && ( (int)$trimmed_name ) == $trimmed_name ) |
183 | 183 | { |
184 | | - $this->parameters[] = new POMTemplateNumberedParameter($value); |
| 184 | + $this->parameters[] = new POMTemplateNumberedParameter( $value ); |
185 | 185 | } |
186 | 186 | else |
187 | 187 | { |
188 | | - $this->parameters[] = new POMTemplateNamedParameter($name, $value); |
| 188 | + $this->parameters[] = new POMTemplateNamedParameter( $name, $value ); |
189 | 189 | } |
190 | 190 | } |
191 | 191 | |
192 | 192 | public function asString() |
193 | 193 | { |
194 | | - if ($this->hidden()) return ""; |
| 194 | + if ( $this->hidden() ) return ""; |
195 | 195 | |
196 | | - $text = '{{'.$this->title_triple->toString(); |
| 196 | + $text = '{{' . $this->title_triple->toString(); |
197 | 197 | |
198 | | - for ($i = 0; $i < count($this->parameters); $i++) |
| 198 | + for ( $i = 0; $i < count( $this->parameters ); $i++ ) |
199 | 199 | { |
200 | 200 | // if a function, then the first sep is a :, otherwise | |
201 | | - $text .= (($i==0) && (substr($this->getTitle(),0,1)=='#')) ? ':' : '|'; |
202 | | - #echo "\n[$i]: ".var_export($this->parameters)."\n\n-----------------------------------\n"; |
| 201 | + $text .= ( ( $i == 0 ) && ( substr( $this->getTitle(), 0, 1 ) == '#' ) ) ? ':' : '|'; |
| 202 | + # echo "\n[$i]: ".var_export($this->parameters)."\n\n-----------------------------------\n"; |
203 | 203 | $text .= $this->parameters[$i]->toString(); |
204 | 204 | } |
205 | 205 | |
— | — | @@ -211,11 +211,11 @@ |
212 | 212 | class WrongParameterNameException extends Exception |
213 | 213 | { |
214 | 214 | // Redefine the exception so message isn't optional |
215 | | - public function __construct($message, $code = 0) { |
| 215 | + public function __construct( $message, $code = 0 ) { |
216 | 216 | // some code |
217 | | - |
| 217 | + |
218 | 218 | // make sure everything is assigned properly |
219 | | - parent::__construct($message, $code); |
| 219 | + parent::__construct( $message, $code ); |
220 | 220 | } |
221 | 221 | |
222 | 222 | // custom string representation of object |
Index: trunk/extensions/PageObjectModel/POM/Page.php |
— | — | @@ -9,20 +9,20 @@ |
10 | 10 | |
11 | 11 | var $templates; # shortcut to $c['templates'], set up if POMTemplateParser was used |
12 | 12 | |
13 | | - public function POMPage($text, $parsers = array('POMCommentParser', 'POMTemplateParser', 'POMLinkParser')) |
| 13 | + public function POMPage( $text, $parsers = array( 'POMCommentParser', 'POMTemplateParser', 'POMLinkParser' ) ) |
14 | 14 | { |
15 | | - $this->addChild(new POMTextNode($text)); |
| 15 | + $this->addChild( new POMTextNode( $text ) ); |
16 | 16 | |
17 | 17 | # |
18 | 18 | # Here we'll call parsers |
19 | 19 | # |
20 | | - foreach ($parsers as $parser) |
| 20 | + foreach ( $parsers as $parser ) |
21 | 21 | { |
22 | 22 | # workign around no class variables in PHP pre 5.3.0 |
23 | | - call_user_func(array($parser, 'Parse'), $this); |
| 23 | + call_user_func( array( $parser, 'Parse' ), $this ); |
24 | 24 | |
25 | 25 | # let's try to add $this->templates |
26 | | - if ($parser == 'POMTemplateParser' && array_key_exists('templates', $this->c)) |
| 26 | + if ( $parser == 'POMTemplateParser' && array_key_exists( 'templates', $this->c ) ) |
27 | 27 | { |
28 | 28 | $this->templates = $this->c['templates']; |
29 | 29 | } |
Index: trunk/extensions/PageObjectModel/POM/Parser.php |
— | — | @@ -10,6 +10,6 @@ |
11 | 11 | This is main method for parsers |
12 | 12 | It takes a page as argument and processes it adding elements |
13 | 13 | */ |
14 | | - static abstract function Parse(POMPage $page); |
| 14 | + static abstract function Parse( POMPage $page ); |
15 | 15 | } |
16 | 16 | |
Index: trunk/extensions/PageObjectModel/POM/TemplateParameter.php |
— | — | @@ -2,37 +2,37 @@ |
3 | 3 | # |
4 | 4 | # Set of classes representing various types of template parameters |
5 | 5 | # |
6 | | -require_once('Util.php'); |
| 6 | +require_once( 'Util.php' ); |
7 | 7 | |
8 | 8 | abstract class POMTemplateParameter |
9 | 9 | { |
10 | 10 | abstract function toString(); |
11 | 11 | |
12 | | - static function parse($text) |
| 12 | + static function parse( $text ) |
13 | 13 | { |
14 | 14 | |
15 | | - $pair = explode('=', $text, 2); |
| 15 | + $pair = explode( '=', $text, 2 ); |
16 | 16 | |
17 | 17 | # if it's a name/value pair, create POMTemplateNamedParameter, otherwise, create POMTemplateNumberedParameter |
18 | 18 | # if neither can be created, return POMTemplateInvalidParameter |
19 | | - if (count($pair) > 1) |
| 19 | + if ( count( $pair ) > 1 ) |
20 | 20 | { |
21 | 21 | $name = $pair[0]; |
22 | 22 | $value = $pair[1]; |
23 | 23 | |
24 | | - $name_triple = new POMUtilTrimTriple($name); |
| 24 | + $name_triple = new POMUtilTrimTriple( $name ); |
25 | 25 | |
26 | | - if (strlen($name_triple->trimmed)<=0) |
| 26 | + if ( strlen( $name_triple->trimmed ) <= 0 ) |
27 | 27 | { |
28 | 28 | # ignore parameters with empty name |
29 | | - return new POMTemplateInvalidParameter($text); |
| 29 | + return new POMTemplateInvalidParameter( $text ); |
30 | 30 | } |
31 | 31 | |
32 | | - return new POMTemplateNamedParameter($name, $value); |
| 32 | + return new POMTemplateNamedParameter( $name, $value ); |
33 | 33 | } |
34 | 34 | else |
35 | 35 | { |
36 | | - return new POMTemplateNumberedParameter($text); |
| 36 | + return new POMTemplateNumberedParameter( $text ); |
37 | 37 | } |
38 | 38 | } |
39 | 39 | } |
— | — | @@ -42,18 +42,18 @@ |
43 | 43 | private $name_triple; |
44 | 44 | private $value_triple; |
45 | 45 | |
46 | | - function __construct($name, $value) |
| 46 | + function __construct( $name, $value ) |
47 | 47 | { |
48 | | - $this->name_triple = new POMUtilTrimTriple($name); |
49 | | - $this->value_triple = new POMUtilTrimTriple($value); |
| 48 | + $this->name_triple = new POMUtilTrimTriple( $name ); |
| 49 | + $this->value_triple = new POMUtilTrimTriple( $value ); |
50 | 50 | } |
51 | 51 | |
52 | | - function update($name, $value, $override_name_spacing = false, $override_value_spacing = false) |
| 52 | + function update( $name, $value, $override_name_spacing = false, $override_value_spacing = false ) |
53 | 53 | { |
54 | | - $name_triple = new POMUtilTrimTriple($name); |
55 | | - $value_triple = new POMUtilTrimTriple($value); |
| 54 | + $name_triple = new POMUtilTrimTriple( $name ); |
| 55 | + $value_triple = new POMUtilTrimTriple( $value ); |
56 | 56 | |
57 | | - if ($override_name_spacing) |
| 57 | + if ( $override_name_spacing ) |
58 | 58 | { |
59 | 59 | $this->name_triple = $name_triple; |
60 | 60 | } |
— | — | @@ -62,7 +62,7 @@ |
63 | 63 | $this->name_triple->trimmed = $name_triple->trimmed; |
64 | 64 | } |
65 | 65 | |
66 | | - if ($override_value_spacing) |
| 66 | + if ( $override_value_spacing ) |
67 | 67 | { |
68 | 68 | $this->value_triple = $value_triple; |
69 | 69 | } |
— | — | @@ -94,7 +94,7 @@ |
95 | 95 | |
96 | 96 | function toString() |
97 | 97 | { |
98 | | - return $this->name_triple->toString().'='.$this->value_triple->toString(); |
| 98 | + return $this->name_triple->toString() . '=' . $this->value_triple->toString(); |
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
— | — | @@ -103,16 +103,16 @@ |
104 | 104 | { |
105 | 105 | private $value_triple; |
106 | 106 | |
107 | | - function __construct($value) |
| 107 | + function __construct( $value ) |
108 | 108 | { |
109 | | - $this->value_triple = new POMUtilTrimTriple($value); |
| 109 | + $this->value_triple = new POMUtilTrimTriple( $value ); |
110 | 110 | } |
111 | 111 | |
112 | | - function update($value, $override_value_spacing = false) |
| 112 | + function update( $value, $override_value_spacing = false ) |
113 | 113 | { |
114 | | - $value_triple = new POMUtilTrimTriple($value); |
| 114 | + $value_triple = new POMUtilTrimTriple( $value ); |
115 | 115 | |
116 | | - if ($override_value_spacing) |
| 116 | + if ( $override_value_spacing ) |
117 | 117 | { |
118 | 118 | $this->value_triple = $value_triple; |
119 | 119 | } |
— | — | @@ -151,7 +151,7 @@ |
152 | 152 | { |
153 | 153 | private $text; |
154 | 154 | |
155 | | - function __construct($text) |
| 155 | + function __construct( $text ) |
156 | 156 | { |
157 | 157 | $this->text = $text; |
158 | 158 | } |
Index: trunk/extensions/PageObjectModel/POM/Link.php |
— | — | @@ -2,33 +2,33 @@ |
3 | 3 | # |
4 | 4 | # The Link class represents internal links of the form [[x::y|z]] (x and z being optional) |
5 | 5 | # |
6 | | -require_once('Util.php'); |
| 6 | +require_once( 'Util.php' ); |
7 | 7 | |
8 | 8 | class POMLink extends POMElement { |
9 | 9 | protected $destination; |
10 | 10 | protected $properties = array(); |
11 | 11 | protected $display = null; |
12 | 12 | |
13 | | - public function POMLink($text) { |
| 13 | + public function POMLink( $text ) { |
14 | 14 | $this->children = null; // forcefully ignore children |
15 | 15 | |
16 | 16 | # Remove braces at the beginning and at the end |
17 | | - $text = substr($text, 2, strlen($text) - 4); |
| 17 | + $text = substr( $text, 2, strlen( $text ) - 4 ); |
18 | 18 | |
19 | 19 | # Split by pipe |
20 | | - $parts = explode('|', $text); |
21 | | - if (count($parts)>2) { |
22 | | - die("[ERROR] Parsing a link with more than one pipe character: [[" . $text . "]]\n"); |
| 20 | + $parts = explode( '|', $text ); |
| 21 | + if ( count( $parts ) > 2 ) { |
| 22 | + die( "[ERROR] Parsing a link with more than one pipe character: [[" . $text . "]]\n" ); |
23 | 23 | } |
24 | | - if (count($parts)==2) { |
| 24 | + if ( count( $parts ) == 2 ) { |
25 | 25 | $this->display = $parts[1]; |
26 | 26 | } |
27 | 27 | # Split first part by :: |
28 | | - $moreparts = explode("::", $parts[0]); |
29 | | - $this->destination = new POMUtilTrimTriple($moreparts[count($moreparts)-1]); |
30 | | - if (count($moreparts)>1) { |
31 | | - for ($i = 0; $i < count($moreparts)-1; $i++) { |
32 | | - $this->properties[] = new POMUtilTrimTriple($moreparts[$i]); |
| 28 | + $moreparts = explode( "::", $parts[0] ); |
| 29 | + $this->destination = new POMUtilTrimTriple( $moreparts[count( $moreparts ) - 1] ); |
| 30 | + if ( count( $moreparts ) > 1 ) { |
| 31 | + for ( $i = 0; $i < count( $moreparts ) - 1; $i++ ) { |
| 32 | + $this->properties[] = new POMUtilTrimTriple( $moreparts[$i] ); |
33 | 33 | } |
34 | 34 | } |
35 | 35 | } |
— | — | @@ -39,14 +39,14 @@ |
40 | 40 | |
41 | 41 | public function getProperties() { |
42 | 42 | $return = array(); |
43 | | - foreach ($this->properties as $property) $return[] = $property->trimmed; |
| 43 | + foreach ( $this->properties as $property ) $return[] = $property->trimmed; |
44 | 44 | return $return; |
45 | 45 | } |
46 | 46 | |
47 | | - public function removePropertyByNumber($i) { |
48 | | - if ($i < 0) return; |
49 | | - if ($i >= count($this->properties)) return; |
50 | | - unset($this->properties[$i]); |
| 47 | + public function removePropertyByNumber( $i ) { |
| 48 | + if ( $i < 0 ) return; |
| 49 | + if ( $i >= count( $this->properties ) ) return; |
| 50 | + unset( $this->properties[$i] ); |
51 | 51 | } |
52 | 52 | |
53 | 53 | public function getDisplay() { |
— | — | @@ -54,11 +54,11 @@ |
55 | 55 | } |
56 | 56 | |
57 | 57 | public function asString() { |
58 | | - if ($this->hidden()) return ""; |
| 58 | + if ( $this->hidden() ) return ""; |
59 | 59 | $text = '[['; |
60 | | - foreach ($this->properties as $property) $text .= $property->toString() . '::'; |
| 60 | + foreach ( $this->properties as $property ) $text .= $property->toString() . '::'; |
61 | 61 | $text .= $this->destination->toString(); |
62 | | - if (!is_null($this->display)) $text .= '|' . $this->display; |
| 62 | + if ( !is_null( $this->display ) ) $text .= '|' . $this->display; |
63 | 63 | $text .= ']]'; |
64 | 64 | return $text; |
65 | 65 | } |
Index: trunk/extensions/PageObjectModel/POM/Util.php |
— | — | @@ -9,15 +9,15 @@ |
10 | 10 | public $trimmed; |
11 | 11 | public $trailing_space; |
12 | 12 | |
13 | | - function POMUtilTrimTriple($text) |
| 13 | + function POMUtilTrimTriple( $text ) |
14 | 14 | { |
15 | | - $this->trimmed = trim($text); |
16 | | - if (strlen($this->trimmed) > 0) |
| 15 | + $this->trimmed = trim( $text ); |
| 16 | + if ( strlen( $this->trimmed ) > 0 ) |
17 | 17 | { |
18 | | - $this->leading_space = substr($text, 0, strpos($text, $this->trimmed)); |
19 | | - if (strpos($text, $this->trimmed) + strlen($this->trimmed) < strlen($text)) |
| 18 | + $this->leading_space = substr( $text, 0, strpos( $text, $this->trimmed ) ); |
| 19 | + if ( strpos( $text, $this->trimmed ) + strlen( $this->trimmed ) < strlen( $text ) ) |
20 | 20 | { |
21 | | - $this->trailing_space = substr($text, strpos($text, $this->trimmed) + strlen($this->trimmed)); |
| 21 | + $this->trailing_space = substr( $text, strpos( $text, $this->trimmed ) + strlen( $this->trimmed ) ); |
22 | 22 | } |
23 | 23 | else |
24 | 24 | { |
— | — | @@ -33,6 +33,6 @@ |
34 | 34 | |
35 | 35 | function toString() |
36 | 36 | { |
37 | | - return $this->leading_space.$this->trimmed.$this->trailing_space; |
| 37 | + return $this->leading_space . $this->trimmed . $this->trailing_space; |
38 | 38 | } |
39 | 39 | } |
Index: trunk/extensions/PageObjectModel/POM/CommentParser.php |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | # |
9 | 9 | # This function will parse all POMTextNodes in the page and add POMComment nodes if comments are found |
10 | 10 | # |
11 | | - static function Parse(POMPage $page) { |
| 11 | + static function Parse( POMPage $page ) { |
12 | 12 | // this array holds shortcuts to templates |
13 | 13 | $page->c['comments'] = array(); |
14 | 14 | |
— | — | @@ -17,18 +17,18 @@ |
18 | 18 | // we'll set it to true if tree was updated |
19 | 19 | $replaceoldchildrenwithnew = false; |
20 | 20 | |
21 | | - for ($n = 0; $n < sizeof($page->children); $n++) { |
22 | | - if (is_a($page->children[$n], 'POMTextNode')) { |
| 21 | + for ( $n = 0; $n < sizeof( $page->children ); $n++ ) { |
| 22 | + if ( is_a( $page->children[$n], 'POMTextNode' ) ) { |
23 | 23 | $nodetext = $page->children[$n]->asString(); |
24 | 24 | |
25 | | - while(($open = strpos($nodetext, '<!--')) !== FALSE) |
| 25 | + while ( ( $open = strpos( $nodetext, '<!--' ) ) !== FALSE ) |
26 | 26 | { |
27 | 27 | $position = $open; |
28 | 28 | |
29 | | - $close = strpos($nodetext, '-->', $position+4); |
| 29 | + $close = strpos( $nodetext, '-->', $position + 4 ); |
30 | 30 | |
31 | 31 | // we didn't find end of comment but still in this loop - skipping to next chunk |
32 | | - if ($close === FALSE) { |
| 32 | + if ( $close === FALSE ) { |
33 | 33 | $brokenchunk = TRUE; |
34 | 34 | continue 2; // get to next item in for loop |
35 | 35 | } else { |
— | — | @@ -36,21 +36,21 @@ |
37 | 37 | } |
38 | 38 | |
39 | 39 | // part before the template becomes text node |
40 | | - $newchildren[] = new POMTextNode(substr($nodetext, 0, $open)); |
| 40 | + $newchildren[] = new POMTextNode( substr( $nodetext, 0, $open ) ); |
41 | 41 | |
42 | 42 | // part between opening <!-- and closing --> becomes comment |
43 | | - $comment = new POMComment(substr($nodetext, $open, $position+3-$open)); |
| 43 | + $comment = new POMComment( substr( $nodetext, $open, $position + 3 - $open ) ); |
44 | 44 | $newchildren[] = $comment; |
45 | 45 | $page->c['comments'][] = $comment; |
46 | 46 | |
47 | 47 | // the rest of it should be processed for more comments |
48 | | - $nodetext = substr($nodetext, $position+3); |
| 48 | + $nodetext = substr( $nodetext, $position + 3 ); |
49 | 49 | |
50 | 50 | $replaceoldchildrenwithnew = true; |
51 | 51 | } |
52 | 52 | |
53 | | - if (strlen($nodetext) > 0) { |
54 | | - $newchildren[] = new POMTextNode($nodetext); |
| 53 | + if ( strlen( $nodetext ) > 0 ) { |
| 54 | + $newchildren[] = new POMTextNode( $nodetext ); |
55 | 55 | $replaceoldchildrenwithnew = true; |
56 | 56 | } |
57 | 57 | } else { |
— | — | @@ -60,7 +60,7 @@ |
61 | 61 | } |
62 | 62 | |
63 | 63 | // if tree was updated, let's replace it in the page |
64 | | - if ($replaceoldchildrenwithnew) { |
| 64 | + if ( $replaceoldchildrenwithnew ) { |
65 | 65 | $page->children = $newchildren; |
66 | 66 | } |
67 | 67 | } |
Index: trunk/extensions/PageObjectModel/POM/Comment.php |
— | — | @@ -7,14 +7,14 @@ |
8 | 8 | |
9 | 9 | protected $nodeText = ''; |
10 | 10 | |
11 | | - public function POMComment($text) { |
12 | | - $text = substr($text, 4, strlen($text) - 7); |
| 11 | + public function POMComment( $text ) { |
| 12 | + $text = substr( $text, 4, strlen( $text ) - 7 ); |
13 | 13 | $this->nodeText = $text; |
14 | 14 | $this->children = null; // forcefully ignore children |
15 | 15 | } |
16 | 16 | |
17 | 17 | public function asString() { |
18 | | - if ($this->hidden()) return ""; |
| 18 | + if ( $this->hidden() ) return ""; |
19 | 19 | return '<!--' . $this->nodeText . '-->'; |
20 | 20 | } |
21 | 21 | } |
Index: trunk/extensions/PageObjectModel/POM/TemplateParser.php |
— | — | @@ -3,14 +3,14 @@ |
4 | 4 | # Template class represents templates |
5 | 5 | # |
6 | 6 | |
7 | | -define("MAX_TEMPLATE_NESTING_LEVEL", 50); |
| 7 | +define( "MAX_TEMPLATE_NESTING_LEVEL", 50 ); |
8 | 8 | |
9 | 9 | class POMTemplateParser extends POMParser |
10 | 10 | { |
11 | 11 | # |
12 | 12 | # This function will parse all POMTextNodes in the page and add POMTemplate nodes if templates are found |
13 | 13 | # |
14 | | - static function Parse(POMPage $page) |
| 14 | + static function Parse( POMPage $page ) |
15 | 15 | { |
16 | 16 | // this array holds shortcuts to templates |
17 | 17 | $page->c['templates'] = array(); |
— | — | @@ -21,13 +21,13 @@ |
22 | 22 | // we'll set it to true if tree was updated |
23 | 23 | $replaceoldchildrenwithnew = false; |
24 | 24 | |
25 | | - for ($n = 0; $n < sizeof($page->children); $n++) |
| 25 | + for ( $n = 0; $n < sizeof( $page->children ); $n++ ) |
26 | 26 | { |
27 | | - if (is_a($page->children[$n], 'POMTextNode')) |
| 27 | + if ( is_a( $page->children[$n], 'POMTextNode' ) ) |
28 | 28 | { |
29 | 29 | $nodetext = $page->children[$n]->asString(); |
30 | 30 | |
31 | | - while(($firstopen = strpos($nodetext, '{{')) !== FALSE) |
| 31 | + while ( ( $firstopen = strpos( $nodetext, '{{' ) ) !== FALSE ) |
32 | 32 | { |
33 | 33 | $position = $firstopen; |
34 | 34 | |
— | — | @@ -36,11 +36,11 @@ |
37 | 37 | // by the end of this loop, $position should hold end of template |
38 | 38 | do |
39 | 39 | { |
40 | | - $nextopen = strpos($nodetext, '{{', $position+2); |
41 | | - $nextclose = strpos($nodetext, '}}', $position+2); |
| 40 | + $nextopen = strpos( $nodetext, '{{', $position + 2 ); |
| 41 | + $nextclose = strpos( $nodetext, '}}', $position + 2 ); |
42 | 42 | |
43 | 43 | // we didn't find end of template but still in this loop - skipping to next chunk |
44 | | - if ($nextclose === FALSE) |
| 44 | + if ( $nextclose === FALSE ) |
45 | 45 | { |
46 | 46 | $brokenchunk = TRUE; |
47 | 47 | continue 3; // get to next item in for loop |
— | — | @@ -48,7 +48,7 @@ |
49 | 49 | |
50 | 50 | // next open tag is first, balance goes up |
51 | 51 | // position is updated to closest marker |
52 | | - if ($nextopen !== FALSE && $nextopen < $nextclose) |
| 52 | + if ( $nextopen !== FALSE && $nextopen < $nextclose ) |
53 | 53 | { |
54 | 54 | $balance += 1; |
55 | 55 | $position = $nextopen; |
— | — | @@ -60,29 +60,29 @@ |
61 | 61 | } |
62 | 62 | |
63 | 63 | // In case something is wrong and we recursed too deep, die. |
64 | | - if ($balance > MAX_TEMPLATE_NESTING_LEVEL) |
| 64 | + if ( $balance > MAX_TEMPLATE_NESTING_LEVEL ) |
65 | 65 | { |
66 | | - die('[ERROR] Reached maximum template nesting level of '.MAX_TEMPLATE_NESTING_LEVEL.". Something is probably wrong with POM, please report this problem to developers.\n"); |
| 66 | + die( '[ERROR] Reached maximum template nesting level of ' . MAX_TEMPLATE_NESTING_LEVEL . ". Something is probably wrong with POM, please report this problem to developers.\n" ); |
67 | 67 | } |
68 | | - } while ($balance > 0); // we'll be done with the loop only when found matching chunk |
| 68 | + } while ( $balance > 0 ); // we'll be done with the loop only when found matching chunk |
69 | 69 | |
70 | 70 | // part before the template becomes text node |
71 | | - $newchildren[] = new POMTextNode(substr($nodetext, 0, $firstopen)); |
| 71 | + $newchildren[] = new POMTextNode( substr( $nodetext, 0, $firstopen ) ); |
72 | 72 | |
73 | 73 | // part between opening {{ and closing }} becomes template |
74 | | - $template = new POMTemplate(substr($nodetext, $firstopen, $position+2-$firstopen)); |
| 74 | + $template = new POMTemplate( substr( $nodetext, $firstopen, $position + 2 - $firstopen ) ); |
75 | 75 | $newchildren[] = $template; |
76 | 76 | $page->c['templates'][$template->getTitle()][] = $template; |
77 | 77 | |
78 | 78 | // the rest of it should be processed for more templates |
79 | | - $nodetext = substr($nodetext, $position+2); |
| 79 | + $nodetext = substr( $nodetext, $position + 2 ); |
80 | 80 | |
81 | 81 | $replaceoldchildrenwithnew = true; |
82 | 82 | } |
83 | 83 | |
84 | | - if (strlen($nodetext) > 0) |
| 84 | + if ( strlen( $nodetext ) > 0 ) |
85 | 85 | { |
86 | | - $newchildren[] = new POMTextNode($nodetext); |
| 86 | + $newchildren[] = new POMTextNode( $nodetext ); |
87 | 87 | |
88 | 88 | $replaceoldchildrenwithnew = true; |
89 | 89 | } |
— | — | @@ -95,7 +95,7 @@ |
96 | 96 | } |
97 | 97 | |
98 | 98 | // if tree was updated, let's replace it in the page |
99 | | - if ($replaceoldchildrenwithnew) |
| 99 | + if ( $replaceoldchildrenwithnew ) |
100 | 100 | { |
101 | 101 | $page->children = $newchildren; |
102 | 102 | } |
Index: trunk/extensions/PageObjectModel/examples/POMVersion.php |
— | — | @@ -1,15 +1,15 @@ |
2 | 2 | <? |
3 | | -require_once('POM.php'); |
| 3 | +require_once( 'POM.php' ); |
4 | 4 | |
5 | 5 | # Get document from MediaWiki server |
6 | | -$pom = new POMPage(join(file('http://www.mediawiki.org/w/index.php?title=Extension:Page_Object_Model&action=raw'))); |
| 6 | +$pom = new POMPage( join( file( 'http://www.mediawiki.org/w/index.php?title=Extension:Page_Object_Model&action=raw' ) ) ); |
7 | 7 | |
8 | 8 | # Check current version |
9 | | -$ver = $pom->templates['Extension'][0]->getParameter('version'); |
| 9 | +$ver = $pom->templates['Extension'][0]->getParameter( 'version' ); |
10 | 10 | echo "Current version: $ver\n"; |
11 | 11 | |
12 | 12 | # Increase version number by fraction |
13 | | -$pom->templates['Extension'][0]->setParameter('version', $ver + 0.1); |
| 13 | +$pom->templates['Extension'][0]->setParameter( 'version', $ver + 0.1 ); |
14 | 14 | |
15 | 15 | # Do whatever you want with result (we'll just display it) |
16 | | -echo "Document with increased version:\n".$pom->asString(); |
| 16 | +echo "Document with increased version:\n" . $pom->asString(); |