r63720 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63719‎ | r63720 | r63721 >
Date:01:06, 14 March 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Stylized with Stylize.php to conform with MW's specing conventions
Modified paths:
  • /trunk/extensions/PageObjectModel/POM.php (modified) (history)
  • /trunk/extensions/PageObjectModel/POM/Comment.php (modified) (history)
  • /trunk/extensions/PageObjectModel/POM/CommentParser.php (modified) (history)
  • /trunk/extensions/PageObjectModel/POM/Element.php (modified) (history)
  • /trunk/extensions/PageObjectModel/POM/Link.php (modified) (history)
  • /trunk/extensions/PageObjectModel/POM/LinkParser.php (modified) (history)
  • /trunk/extensions/PageObjectModel/POM/Page.php (modified) (history)
  • /trunk/extensions/PageObjectModel/POM/Parser.php (modified) (history)
  • /trunk/extensions/PageObjectModel/POM/Template.php (modified) (history)
  • /trunk/extensions/PageObjectModel/POM/TemplateParameter.php (modified) (history)
  • /trunk/extensions/PageObjectModel/POM/TemplateParser.php (modified) (history)
  • /trunk/extensions/PageObjectModel/POM/TextNode.php (modified) (history)
  • /trunk/extensions/PageObjectModel/POM/Util.php (modified) (history)
  • /trunk/extensions/PageObjectModel/PageObjectModel.php (modified) (history)
  • /trunk/extensions/PageObjectModel/examples/POMVersion.php (modified) (history)
  • /trunk/extensions/PageObjectModel/tests/POMPageTest.php (modified) (history)
  • /trunk/extensions/PageObjectModel/tests/POMTemplateParserTest.php (modified) (history)
  • /trunk/extensions/PageObjectModel/tests/POMTemplateTest.php (modified) (history)
  • /trunk/extensions/PageObjectModel/tests/WrongParameterNameExceptionTest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PageObjectModel/POM.php
@@ -3,15 +3,15 @@
44 # PageObjectModel is a set of classes that allow easy manipulation of MediaWiki page source.
55 #
66
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' );
1818
Index: trunk/extensions/PageObjectModel/tests/WrongParameterNameExceptionTest.php
@@ -6,7 +6,7 @@
77 {
88 public function testWrongParameterNameExceptionMustContainMessage()
99 {
10 - $e = new WrongParameterNameException("Can't get parameter with no name");
 10+ $e = new WrongParameterNameException( "Can't get parameter with no name" );
1111 $this->assertEquals(
1212 "WrongParameterNameException: [0]: Can't get parameter with no name\n",
1313 $e->__toString()
Index: trunk/extensions/PageObjectModel/tests/POMTemplateParserTest.php
@@ -8,21 +8,21 @@
99 {
1010 $sometext = "sometext\nbefore first with spaces {{sometemplate|var1=var2}}\nbefore second {{someothertemplate}} more text at the end\n";
1111
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() );
1515
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() );
1818
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() );
2121
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() );
2424
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() );
2727 }
2828
2929 public function testTemplateParserMustPopulateTemplatesCollection()
@@ -31,29 +31,29 @@
3232 |param2 = something
3333 }} more text at the end\n";
3434
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 );
3838 }
3939
4040 public function testTemplateParserMustCorrectlyParseTemplatesWithParameters()
4141 {
4242 $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";
4343
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() );
4747
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() );
5050
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() );
5353
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() );
5656
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() );
5959 }
6060 }
Index: trunk/extensions/PageObjectModel/tests/POMTemplateTest.php
@@ -12,22 +12,22 @@
1313 public static function templateStringsProvider()
1414 {
1515 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}}' )
2222 );
2323 }
2424
2525 /**
2626 * @dataProvider templateStringsProvider
2727 */
28 - public function testTemplateMustPreserveOrderOfParameters($templatestring)
 28+ public function testTemplateMustPreserveOrderOfParameters( $templatestring )
2929 {
30 - $template = new POMTemplate($templatestring);
31 - $this->assertEquals($template->asString(), $templatestring);
 30+ $template = new POMTemplate( $templatestring );
 31+ $this->assertEquals( $template->asString(), $templatestring );
3232 }
3333
3434 # -------------------------------------------------------------------------------------------------------
@@ -39,25 +39,25 @@
4040 public static function parameterGetNameValueProvider()
4141 {
4242 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 )
5252 );
5353 }
5454
5555 /**
5656 * @dataProvider parameterGetNameValueProvider
5757 */
58 - public function testTemplateGetParameter($templatestring, $name, $value)
 58+ public function testTemplateGetParameter( $templatestring, $name, $value )
5959 {
60 - $template = new POMTemplate($templatestring);
61 - $this->assertEquals($value, $template->getParameter($name));
 60+ $template = new POMTemplate( $templatestring );
 61+ $this->assertEquals( $value, $template->getParameter( $name ) );
6262 }
6363
6464
@@ -70,136 +70,136 @@
7171 public static function parameterChangeNameValueProvider()
7272 {
7373 return array(
74 - array('{{sometemplate|a=b|b=c|numbered}}',
 74+ array( '{{sometemplate|a=b|b=c|numbered}}',
7575 1,
7676 '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}}',
7979 2,
8080 '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}}',
8383 3,
8484 '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}}',
8787 'var1',
8888 'var3',
89 - '{{sometemplate|var1=var3}}'),
90 - array('{{sometemplate|var1= var2}}',
 89+ '{{sometemplate|var1=var3}}' ),
 90+ array( '{{sometemplate|var1= var2}}',
9191 'var1',
9292 'var3',
93 - '{{sometemplate|var1= var3}}'),
94 - array('{{sometemplate|var1 =var2}}',
 93+ '{{sometemplate|var1= var3}}' ),
 94+ array( '{{sometemplate|var1 =var2}}',
9595 'var1',
9696 'var3',
97 - '{{sometemplate|var1 =var3}}'),
98 - array('{{title with spaces|var1=var2}}',
 97+ '{{sometemplate|var1 =var3}}' ),
 98+ array( '{{title with spaces|var1=var2}}',
9999 'var1',
100100 '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}}',
103103 'field name with spaces',
104104 '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}}',
107107 'var1',
108108 '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}}',
111111 'var1',
112112 '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}}',
115115 'a',
116116 '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}}',
119119 'x',
120120 'y',
121 - '{{sometemplate|a=b|b=c|numbered|x=y}}')
 121+ '{{sometemplate|a=b|b=c|numbered|x=y}}' )
122122 );
123123 }
124124
125125 /**
126126 * @dataProvider parameterChangeNameValueProvider
127127 */
128 - public function testTemplateParameterChange($orig, $index, $value, $result)
 128+ public function testTemplateParameterChange( $orig, $index, $value, $result )
129129 {
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() );
133133 }
134134
135135 # TODO add more data
136136 public static function parameterChangeSpacedNameValueProvider()
137137 {
138138 return array(
139 - array('{{sometemplate|a=b|b=c|numbered}}',
 139+ array( '{{sometemplate|a=b|b=c|numbered}}',
140140 ' 1',
141141 '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}}',
144144 ' 2 ',
145145 '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}}',
148148 '3 ',
149149 '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}}',
152152 ' var1 ',
153153 ' var3',
154 - '{{sometemplate| var1 = var3}}'),
155 - array('{{sometemplate|var1= var2}}',
 154+ '{{sometemplate| var1 = var3}}' ),
 155+ array( '{{sometemplate|var1= var2}}',
156156 ' var1 ',
157157 ' var3 ',
158 - '{{sometemplate| var1 = var3 }}'),
159 - array('{{sometemplate|var1 =var2}}',
 158+ '{{sometemplate| var1 = var3 }}' ),
 159+ array( '{{sometemplate|var1 =var2}}',
160160 ' var1 ',
161161 ' var3 ',
162 - '{{sometemplate| var1 = var3 }}'),
163 - array('{{title with spaces|var1=var2}}',
 162+ '{{sometemplate| var1 = var3 }}' ),
 163+ array( '{{title with spaces|var1=var2}}',
164164 ' var1 ',
165165 ' 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}}',
168168 'field name with spaces ',
169169 '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 }}',
172172 'var1',
173173 '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}}',
176176 'var1',
177177 '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}}',
180180 'a',
181181 '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}}',
184184 'x ',
185185 ' y',
186 - '{{sometemplate| a =b|b=c|numbered|x = y}}')
 186+ '{{sometemplate| a =b|b=c|numbered|x = y}}' )
187187 );
188188 }
189189 /**
190190 * @dataProvider parameterChangeSpacedNameValueProvider
191191 */
192 - public function testTemplateParameterChangeHonoringSpacing($orig, $index, $value, $result)
 192+ public function testTemplateParameterChangeHonoringSpacing( $orig, $index, $value, $result )
193193 {
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() );
197197 }
198198
199199 public function testParameterWithEmptyNameShouldBeIgnoredButPreserved()
200200 {
201201 $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() );
204204 }
205205
206206 /**
@@ -208,8 +208,8 @@
209209 public function testThrowExceptionOnGettingParameterByEmptyName()
210210 {
211211 $somestring = '{{tempname|name=val1}}';
212 - $template = new POMTemplate($somestring);
213 - $res = $template->getParameter(' ');
 212+ $template = new POMTemplate( $somestring );
 213+ $res = $template->getParameter( ' ' );
214214 }
215215
216216 /**
@@ -218,7 +218,7 @@
219219 public function testThrowExceptionSettingParameterByEmptyName()
220220 {
221221 $somestring = '{{tempname|name=val1}}';
222 - $template = new POMTemplate($somestring);
223 - $res = $template->setParameter(' ', 'value');
 222+ $template = new POMTemplate( $somestring );
 223+ $res = $template->setParameter( ' ', 'value' );
224224 }
225225 }
Index: trunk/extensions/PageObjectModel/tests/POMPageTest.php
@@ -8,25 +8,25 @@
99 public static function pageProvider()
1010 {
1111 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
2020 |param2 = something
21 -}} more text at the end\n")
 21+}} more text at the end\n" )
2222 );
2323 }
2424
2525 /**
2626 * @dataProvider pageProvider
2727 */
28 - public function testInputIsTheSameAsOutput($pagetext)
 28+ public function testInputIsTheSameAsOutput( $pagetext )
2929 {
30 - $page = new POMPage($pagetext);
31 - $this->assertEquals($pagetext, $page->asString());
 30+ $page = new POMPage( $pagetext );
 31+ $this->assertEquals( $pagetext, $page->asString() );
3232 }
3333 }
Index: trunk/extensions/PageObjectModel/PageObjectModel.php
@@ -5,9 +5,9 @@
66 if ( !defined( 'MEDIAWIKI' ) ) {
77 exit( 1 );
88 }
9 -require_once ("$IP/extensions/PageObjectModel/POM.php");
 9+require_once ( "$IP/extensions/PageObjectModel/POM.php" );
1010
11 -require_once ("$IP/includes/api/ApiBase.php");
 11+require_once ( "$IP/includes/api/ApiBase.php" );
1212
1313 global $wgAPIModules;
1414 $wgAPIModules['pomsettplparam'] = 'ApiPOMSetTemplateParameter';
@@ -18,24 +18,24 @@
1919 */
2020 class ApiPOMSetTemplateParameter extends ApiBase {
2121
22 - public function __construct($query, $moduleName) {
23 - parent :: __construct($query, $moduleName);
 22+ public function __construct( $query, $moduleName ) {
 23+ parent :: __construct( $query, $moduleName );
2424 }
2525
2626 public function execute() {
2727 global $wgUser;
2828
2929 $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 );
4040
4141 $page = $params['page'];
4242 $template = $params['tpl'];
@@ -46,39 +46,39 @@
4747
4848
4949 $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 );
5252
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 );
5656
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 );
6060
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] )
6464 )
6565 {
66 - $pom->templates[$template][$instance]->setParameter($parameter, $value);
 66+ $pom->templates[$template][$instance]->setParameter( $parameter, $value );
6767 }
6868 else
6969 {
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 );
7171 }
7272
73 - $success = $article->doEdit($pom->asString(), $summary);
 73+ $success = $article->doEdit( $pom->asString(), $summary );
7474
75 - $result=array();
 75+ $result = array();
7676 if ( $success ) {
77 - $result['result']='Success';
 77+ $result['result'] = 'Success';
7878 } else {
79 - $result['result']='Failure';
 79+ $result['result'] = 'Failure';
8080 }
8181
82 - $this->getResult()->addValue(null, 'pomsettplparam', $result);
 82+ $this->getResult()->addValue( null, 'pomsettplparam', $result );
8383 }
8484
8585 protected function getAllowedParams() {
@@ -135,20 +135,20 @@
136136 */
137137 class ApiPOMGetTemplateParameter extends ApiBase {
138138
139 - public function __construct($query, $moduleName) {
140 - parent :: __construct($query, $moduleName);
 139+ public function __construct( $query, $moduleName ) {
 140+ parent :: __construct( $query, $moduleName );
141141 }
142142
143143 public function execute() {
144144 global $wgUser;
145145
146146 $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 );
153153
154154 $page = $params['page'];
155155 $template = $params['tpl'];
@@ -156,28 +156,28 @@
157157 $parameter = $params['param'];
158158
159159 $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 );
162162
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 );
166166
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 );
170170
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] )
174174 )
175175 {
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 );
178178 }
179179 else
180180 {
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 );
182182 }
183183 }
184184
Index: trunk/extensions/PageObjectModel/POM/Element.php
@@ -13,17 +13,17 @@
1414 function asString() {
1515 $output = '';
1616
17 - if ($this->hide) return $output;
 17+ if ( $this->hide ) return $output;
1818
19 - foreach ($this->children as $child)
 19+ foreach ( $this->children as $child )
2020 {
21 - $output.=$child->asString();
 21+ $output .= $child->asString();
2222 }
2323
2424 return $output;
2525 }
2626
27 - function addChild(POMElement $el)
 27+ function addChild( POMElement $el )
2828 {
2929 $this->children[] = $el;
3030 }
Index: trunk/extensions/PageObjectModel/POM/LinkParser.php
@@ -7,7 +7,7 @@
88 #
99 # This function will parse all POMTextNodes in the page and add POMLink nodes if links are found
1010 #
11 - static function Parse(POMPage $page) {
 11+ static function Parse( POMPage $page ) {
1212 // this array holds shortcuts to templates
1313 $page->c['links'] = array();
1414
@@ -17,40 +17,40 @@
1818 // we'll set it to true if tree was updated
1919 $replaceoldchildrenwithnew = false;
2020
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' ) ) {
2323 $nodetext = $page->children[$n]->asString();
2424
25 - while(($open = strpos($nodetext, '[[')) !== FALSE) {
 25+ while ( ( $open = strpos( $nodetext, '[[' ) ) !== FALSE ) {
2626 $position = $open;
2727
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 );
3232
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;
3636
3737 // part before the template becomes text node
38 - $newchildren[] = new POMTextNode(substr($nodetext, 0, $open));
 38+ $newchildren[] = new POMTextNode( substr( $nodetext, 0, $open ) );
3939
4040 // 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 ) );
4242 $newchildren[] = $link;
4343 $page->c['links'][] = $link;
4444
4545 $position = $close + 2;
4646
4747 // the rest of it should be processed for more templates
48 - $nodetext = substr($nodetext, $position);
 48+ $nodetext = substr( $nodetext, $position );
4949
5050 $replaceoldchildrenwithnew = true;
5151 }
5252
53 - if (strlen($nodetext) > 0) {
54 - $newchildren[] = new POMTextNode($nodetext);
 53+ if ( strlen( $nodetext ) > 0 ) {
 54+ $newchildren[] = new POMTextNode( $nodetext );
5555
5656 $replaceoldchildrenwithnew = true;
5757 }
@@ -61,6 +61,6 @@
6262 }
6363
6464 // if tree was updated, let's replace it in the page
65 - if ($replaceoldchildrenwithnew) $page->children = $newchildren;
 65+ if ( $replaceoldchildrenwithnew ) $page->children = $newchildren;
6666 }
6767 }
Index: trunk/extensions/PageObjectModel/POM/TextNode.php
@@ -7,7 +7,7 @@
88
99 protected $nodeText = '';
1010
11 - public function POMTextNode($text)
 11+ public function POMTextNode( $text )
1212 {
1313 $this->nodeText = $text;
1414 $this->children = null; // forcefully ignore children
@@ -15,7 +15,7 @@
1616
1717 public function asString()
1818 {
19 - if ($this->hidden()) return "";
 19+ if ( $this->hidden() ) return "";
2020 return $this->nodeText;
2121 }
2222 }
Index: trunk/extensions/PageObjectModel/POM/Template.php
@@ -2,8 +2,8 @@
33 #
44 # Template class represents templates
55 #
6 -require_once('Util.php');
7 -require_once('TemplateParameter.php');
 6+require_once( 'Util.php' );
 7+require_once( 'TemplateParameter.php' );
88
99 class POMTemplate extends POMElement
1010 {
@@ -11,33 +11,33 @@
1212
1313 protected $parameters = array();
1414
15 - public function POMTemplate($text)
 15+ public function POMTemplate( $text )
1616 {
1717 $this->children = null; // forcefully ignore children
1818
1919 # 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 );
2121
2222 # Split by pipe
23 - $parts = explode('|', $text);
 23+ $parts = explode( '|', $text );
2424
2525 # 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 ) {
3131 $first_part = $splitted[0];
32 - array_unshift($parts, $splitted[1]);
 32+ array_unshift( $parts, $splitted[1] );
3333 }
3434
3535 }
3636
37 - $this->title_triple = new POMUtilTrimTriple($first_part);
 37+ $this->title_triple = new POMUtilTrimTriple( $first_part );
3838
39 - foreach ($parts as $part)
 39+ foreach ( $parts as $part )
4040 {
41 - $this->parameters[] = POMTemplateParameter::parse($part);
 41+ $this->parameters[] = POMTemplateParameter::parse( $part );
4242 }
4343 }
4444
@@ -47,68 +47,68 @@
4848 }
4949
5050 public function getParametersCount() {
51 - return count($this->parameters);
 51+ return count( $this->parameters );
5252 }
5353
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 "";
5757 $parameter = $this->parameters[$number];
58 - if (is_a($parameter, 'POMTemplateNamedParameter'))
 58+ if ( is_a( $parameter, 'POMTemplateNamedParameter' ) )
5959 return $parameter->getName();
6060 else
61 - return "";
 61+ return "";
6262 }
6363
6464 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 );
6969 }
7070
7171 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' );
7575
76 - for ($i = 0; $i < count($this->parameters); $i++) {
 76+ for ( $i = 0; $i < count( $this->parameters ); $i++ ) {
7777 $parameter = $this->parameters[$i];
78 - if ($parameter->getName() == $trimmed_name) return $i;
 78+ if ( $parameter->getName() == $trimmed_name ) return $i;
7979 }
8080 }
8181
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 "";
8585 $parameter = $this->parameters[$number];
8686 return $parameter->getValue();
8787 }
8888
89 - public function getParameter($name)
 89+ public function getParameter( $name )
9090 {
91 - $trimmed_name = trim($name);
92 - if (strlen($trimmed_name) == 0)
 91+ $trimmed_name = trim( $name );
 92+ if ( strlen( $trimmed_name ) == 0 )
9393 {
94 - throw new WrongParameterNameException('Can\'t get parameter with no name');
 94+ throw new WrongParameterNameException( 'Can\'t get parameter with no name' );
9595 }
9696
9797 $number = 1;
98 - for ($i = 0; $i < count($this->parameters); $i++)
 98+ for ( $i = 0; $i < count( $this->parameters ); $i++ )
9999 {
100100 $parameter = $this->parameters[$i];
101101
102102 # 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' ) )
104104 {
105 - if ($parameter->getName() == $trimmed_name)
 105+ if ( $parameter->getName() == $trimmed_name )
106106 {
107107 return $parameter->getValue();
108108 }
109109 }
110 - else if (is_a($parameter, 'POMTemplateNumberedParameter'))
 110+ else if ( is_a( $parameter, 'POMTemplateNumberedParameter' ) )
111111 {
112 - if ($number == $trimmed_name)
 112+ if ( $number == $trimmed_name )
113113 {
114114 return $parameter->getValue();
115115 }
@@ -119,57 +119,57 @@
120120 return null; # none matched
121121 }
122122
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" );
126126
127127 # add parameter to parameters array
128 - $this->parameters[] = new POMTemplateNamedParameter($name, $value);
 128+ $this->parameters[] = new POMTemplateNamedParameter( $name, $value );
129129 }
130130
131 - public function setParameter($name, $value,
 131+ public function setParameter( $name, $value,
132132 $ignore_name_spacing = true,
133133 $ignore_value_spacing = true,
134134 $override_name_spacing = false, # when original value exists
135135 $override_value_spacing = false # when original value exists
136136 )
137137 {
138 - $trimmed_name = trim($name);
139 - if (strlen($trimmed_name) == 0)
 138+ $trimmed_name = trim( $name );
 139+ if ( strlen( $trimmed_name ) == 0 )
140140 {
141 - throw new WrongParameterNameException("Can't set parameter with no name");
 141+ throw new WrongParameterNameException( "Can't set parameter with no name" );
142142 }
143143
144 - if ($ignore_name_spacing)
 144+ if ( $ignore_name_spacing )
145145 {
146146 $name = $trimmed_name;
147147 }
148148
149 - if ($ignore_value_spacing)
 149+ if ( $ignore_value_spacing )
150150 {
151 - $value = trim($value);
 151+ $value = trim( $value );
152152 }
153153
154154 # 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++ )
156156 {
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 )
159159 {
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 );
161161 return;
162162 }
163163 }
164164
165165 # then go through numbered parameters and see if parameter with this number exists
166166 $number = 1;
167 - for ($i = 0; $i < count($this->parameters); $i++)
 167+ for ( $i = 0; $i < count( $this->parameters ); $i++ )
168168 {
169 - if (is_a($this->parameters[$i], 'POMTemplateNumberedParameter'))
 169+ if ( is_a( $this->parameters[$i], 'POMTemplateNumberedParameter' ) )
170170 {
171 - if ($number == $trimmed_name)
 171+ if ( $number == $trimmed_name )
172172 {
173 - $this->parameters[$i]->update($value, $override_value_spacing);
 173+ $this->parameters[$i]->update( $value, $override_value_spacing );
174174 return;
175175 }
176176 $number++;
@@ -178,27 +178,27 @@
179179
180180 # now, if passed name is numeric, create numbered parameter, otherwise create named parameter
181181 # 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 )
183183 {
184 - $this->parameters[] = new POMTemplateNumberedParameter($value);
 184+ $this->parameters[] = new POMTemplateNumberedParameter( $value );
185185 }
186186 else
187187 {
188 - $this->parameters[] = new POMTemplateNamedParameter($name, $value);
 188+ $this->parameters[] = new POMTemplateNamedParameter( $name, $value );
189189 }
190190 }
191191
192192 public function asString()
193193 {
194 - if ($this->hidden()) return "";
 194+ if ( $this->hidden() ) return "";
195195
196 - $text = '{{'.$this->title_triple->toString();
 196+ $text = '{{' . $this->title_triple->toString();
197197
198 - for ($i = 0; $i < count($this->parameters); $i++)
 198+ for ( $i = 0; $i < count( $this->parameters ); $i++ )
199199 {
200200 // 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";
203203 $text .= $this->parameters[$i]->toString();
204204 }
205205
@@ -211,11 +211,11 @@
212212 class WrongParameterNameException extends Exception
213213 {
214214 // Redefine the exception so message isn't optional
215 - public function __construct($message, $code = 0) {
 215+ public function __construct( $message, $code = 0 ) {
216216 // some code
217 -
 217+
218218 // make sure everything is assigned properly
219 - parent::__construct($message, $code);
 219+ parent::__construct( $message, $code );
220220 }
221221
222222 // custom string representation of object
Index: trunk/extensions/PageObjectModel/POM/Page.php
@@ -9,20 +9,20 @@
1010
1111 var $templates; # shortcut to $c['templates'], set up if POMTemplateParser was used
1212
13 - public function POMPage($text, $parsers = array('POMCommentParser', 'POMTemplateParser', 'POMLinkParser'))
 13+ public function POMPage( $text, $parsers = array( 'POMCommentParser', 'POMTemplateParser', 'POMLinkParser' ) )
1414 {
15 - $this->addChild(new POMTextNode($text));
 15+ $this->addChild( new POMTextNode( $text ) );
1616
1717 #
1818 # Here we'll call parsers
1919 #
20 - foreach ($parsers as $parser)
 20+ foreach ( $parsers as $parser )
2121 {
2222 # 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 );
2424
2525 # 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 ) )
2727 {
2828 $this->templates = $this->c['templates'];
2929 }
Index: trunk/extensions/PageObjectModel/POM/Parser.php
@@ -10,6 +10,6 @@
1111 This is main method for parsers
1212 It takes a page as argument and processes it adding elements
1313 */
14 - static abstract function Parse(POMPage $page);
 14+ static abstract function Parse( POMPage $page );
1515 }
1616
Index: trunk/extensions/PageObjectModel/POM/TemplateParameter.php
@@ -2,37 +2,37 @@
33 #
44 # Set of classes representing various types of template parameters
55 #
6 -require_once('Util.php');
 6+require_once( 'Util.php' );
77
88 abstract class POMTemplateParameter
99 {
1010 abstract function toString();
1111
12 - static function parse($text)
 12+ static function parse( $text )
1313 {
1414
15 - $pair = explode('=', $text, 2);
 15+ $pair = explode( '=', $text, 2 );
1616
1717 # if it's a name/value pair, create POMTemplateNamedParameter, otherwise, create POMTemplateNumberedParameter
1818 # if neither can be created, return POMTemplateInvalidParameter
19 - if (count($pair) > 1)
 19+ if ( count( $pair ) > 1 )
2020 {
2121 $name = $pair[0];
2222 $value = $pair[1];
2323
24 - $name_triple = new POMUtilTrimTriple($name);
 24+ $name_triple = new POMUtilTrimTriple( $name );
2525
26 - if (strlen($name_triple->trimmed)<=0)
 26+ if ( strlen( $name_triple->trimmed ) <= 0 )
2727 {
2828 # ignore parameters with empty name
29 - return new POMTemplateInvalidParameter($text);
 29+ return new POMTemplateInvalidParameter( $text );
3030 }
3131
32 - return new POMTemplateNamedParameter($name, $value);
 32+ return new POMTemplateNamedParameter( $name, $value );
3333 }
3434 else
3535 {
36 - return new POMTemplateNumberedParameter($text);
 36+ return new POMTemplateNumberedParameter( $text );
3737 }
3838 }
3939 }
@@ -42,18 +42,18 @@
4343 private $name_triple;
4444 private $value_triple;
4545
46 - function __construct($name, $value)
 46+ function __construct( $name, $value )
4747 {
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 );
5050 }
5151
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 )
5353 {
54 - $name_triple = new POMUtilTrimTriple($name);
55 - $value_triple = new POMUtilTrimTriple($value);
 54+ $name_triple = new POMUtilTrimTriple( $name );
 55+ $value_triple = new POMUtilTrimTriple( $value );
5656
57 - if ($override_name_spacing)
 57+ if ( $override_name_spacing )
5858 {
5959 $this->name_triple = $name_triple;
6060 }
@@ -62,7 +62,7 @@
6363 $this->name_triple->trimmed = $name_triple->trimmed;
6464 }
6565
66 - if ($override_value_spacing)
 66+ if ( $override_value_spacing )
6767 {
6868 $this->value_triple = $value_triple;
6969 }
@@ -94,7 +94,7 @@
9595
9696 function toString()
9797 {
98 - return $this->name_triple->toString().'='.$this->value_triple->toString();
 98+ return $this->name_triple->toString() . '=' . $this->value_triple->toString();
9999 }
100100 }
101101
@@ -103,16 +103,16 @@
104104 {
105105 private $value_triple;
106106
107 - function __construct($value)
 107+ function __construct( $value )
108108 {
109 - $this->value_triple = new POMUtilTrimTriple($value);
 109+ $this->value_triple = new POMUtilTrimTriple( $value );
110110 }
111111
112 - function update($value, $override_value_spacing = false)
 112+ function update( $value, $override_value_spacing = false )
113113 {
114 - $value_triple = new POMUtilTrimTriple($value);
 114+ $value_triple = new POMUtilTrimTriple( $value );
115115
116 - if ($override_value_spacing)
 116+ if ( $override_value_spacing )
117117 {
118118 $this->value_triple = $value_triple;
119119 }
@@ -151,7 +151,7 @@
152152 {
153153 private $text;
154154
155 - function __construct($text)
 155+ function __construct( $text )
156156 {
157157 $this->text = $text;
158158 }
Index: trunk/extensions/PageObjectModel/POM/Link.php
@@ -2,33 +2,33 @@
33 #
44 # The Link class represents internal links of the form [[x::y|z]] (x and z being optional)
55 #
6 -require_once('Util.php');
 6+require_once( 'Util.php' );
77
88 class POMLink extends POMElement {
99 protected $destination;
1010 protected $properties = array();
1111 protected $display = null;
1212
13 - public function POMLink($text) {
 13+ public function POMLink( $text ) {
1414 $this->children = null; // forcefully ignore children
1515
1616 # 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 );
1818
1919 # 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" );
2323 }
24 - if (count($parts)==2) {
 24+ if ( count( $parts ) == 2 ) {
2525 $this->display = $parts[1];
2626 }
2727 # 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] );
3333 }
3434 }
3535 }
@@ -39,14 +39,14 @@
4040
4141 public function getProperties() {
4242 $return = array();
43 - foreach ($this->properties as $property) $return[] = $property->trimmed;
 43+ foreach ( $this->properties as $property ) $return[] = $property->trimmed;
4444 return $return;
4545 }
4646
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] );
5151 }
5252
5353 public function getDisplay() {
@@ -54,11 +54,11 @@
5555 }
5656
5757 public function asString() {
58 - if ($this->hidden()) return "";
 58+ if ( $this->hidden() ) return "";
5959 $text = '[[';
60 - foreach ($this->properties as $property) $text .= $property->toString() . '::';
 60+ foreach ( $this->properties as $property ) $text .= $property->toString() . '::';
6161 $text .= $this->destination->toString();
62 - if (!is_null($this->display)) $text .= '|' . $this->display;
 62+ if ( !is_null( $this->display ) ) $text .= '|' . $this->display;
6363 $text .= ']]';
6464 return $text;
6565 }
Index: trunk/extensions/PageObjectModel/POM/Util.php
@@ -9,15 +9,15 @@
1010 public $trimmed;
1111 public $trailing_space;
1212
13 - function POMUtilTrimTriple($text)
 13+ function POMUtilTrimTriple( $text )
1414 {
15 - $this->trimmed = trim($text);
16 - if (strlen($this->trimmed) > 0)
 15+ $this->trimmed = trim( $text );
 16+ if ( strlen( $this->trimmed ) > 0 )
1717 {
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 ) )
2020 {
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 ) );
2222 }
2323 else
2424 {
@@ -33,6 +33,6 @@
3434
3535 function toString()
3636 {
37 - return $this->leading_space.$this->trimmed.$this->trailing_space;
 37+ return $this->leading_space . $this->trimmed . $this->trailing_space;
3838 }
3939 }
Index: trunk/extensions/PageObjectModel/POM/CommentParser.php
@@ -7,7 +7,7 @@
88 #
99 # This function will parse all POMTextNodes in the page and add POMComment nodes if comments are found
1010 #
11 - static function Parse(POMPage $page) {
 11+ static function Parse( POMPage $page ) {
1212 // this array holds shortcuts to templates
1313 $page->c['comments'] = array();
1414
@@ -17,18 +17,18 @@
1818 // we'll set it to true if tree was updated
1919 $replaceoldchildrenwithnew = false;
2020
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' ) ) {
2323 $nodetext = $page->children[$n]->asString();
2424
25 - while(($open = strpos($nodetext, '<!--')) !== FALSE)
 25+ while ( ( $open = strpos( $nodetext, '<!--' ) ) !== FALSE )
2626 {
2727 $position = $open;
2828
29 - $close = strpos($nodetext, '-->', $position+4);
 29+ $close = strpos( $nodetext, '-->', $position + 4 );
3030
3131 // we didn't find end of comment but still in this loop - skipping to next chunk
32 - if ($close === FALSE) {
 32+ if ( $close === FALSE ) {
3333 $brokenchunk = TRUE;
3434 continue 2; // get to next item in for loop
3535 } else {
@@ -36,21 +36,21 @@
3737 }
3838
3939 // part before the template becomes text node
40 - $newchildren[] = new POMTextNode(substr($nodetext, 0, $open));
 40+ $newchildren[] = new POMTextNode( substr( $nodetext, 0, $open ) );
4141
4242 // 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 ) );
4444 $newchildren[] = $comment;
4545 $page->c['comments'][] = $comment;
4646
4747 // the rest of it should be processed for more comments
48 - $nodetext = substr($nodetext, $position+3);
 48+ $nodetext = substr( $nodetext, $position + 3 );
4949
5050 $replaceoldchildrenwithnew = true;
5151 }
5252
53 - if (strlen($nodetext) > 0) {
54 - $newchildren[] = new POMTextNode($nodetext);
 53+ if ( strlen( $nodetext ) > 0 ) {
 54+ $newchildren[] = new POMTextNode( $nodetext );
5555 $replaceoldchildrenwithnew = true;
5656 }
5757 } else {
@@ -60,7 +60,7 @@
6161 }
6262
6363 // if tree was updated, let's replace it in the page
64 - if ($replaceoldchildrenwithnew) {
 64+ if ( $replaceoldchildrenwithnew ) {
6565 $page->children = $newchildren;
6666 }
6767 }
Index: trunk/extensions/PageObjectModel/POM/Comment.php
@@ -7,14 +7,14 @@
88
99 protected $nodeText = '';
1010
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 );
1313 $this->nodeText = $text;
1414 $this->children = null; // forcefully ignore children
1515 }
1616
1717 public function asString() {
18 - if ($this->hidden()) return "";
 18+ if ( $this->hidden() ) return "";
1919 return '<!--' . $this->nodeText . '-->';
2020 }
2121 }
Index: trunk/extensions/PageObjectModel/POM/TemplateParser.php
@@ -3,14 +3,14 @@
44 # Template class represents templates
55 #
66
7 -define("MAX_TEMPLATE_NESTING_LEVEL", 50);
 7+define( "MAX_TEMPLATE_NESTING_LEVEL", 50 );
88
99 class POMTemplateParser extends POMParser
1010 {
1111 #
1212 # This function will parse all POMTextNodes in the page and add POMTemplate nodes if templates are found
1313 #
14 - static function Parse(POMPage $page)
 14+ static function Parse( POMPage $page )
1515 {
1616 // this array holds shortcuts to templates
1717 $page->c['templates'] = array();
@@ -21,13 +21,13 @@
2222 // we'll set it to true if tree was updated
2323 $replaceoldchildrenwithnew = false;
2424
25 - for ($n = 0; $n < sizeof($page->children); $n++)
 25+ for ( $n = 0; $n < sizeof( $page->children ); $n++ )
2626 {
27 - if (is_a($page->children[$n], 'POMTextNode'))
 27+ if ( is_a( $page->children[$n], 'POMTextNode' ) )
2828 {
2929 $nodetext = $page->children[$n]->asString();
3030
31 - while(($firstopen = strpos($nodetext, '{{')) !== FALSE)
 31+ while ( ( $firstopen = strpos( $nodetext, '{{' ) ) !== FALSE )
3232 {
3333 $position = $firstopen;
3434
@@ -36,11 +36,11 @@
3737 // by the end of this loop, $position should hold end of template
3838 do
3939 {
40 - $nextopen = strpos($nodetext, '{{', $position+2);
41 - $nextclose = strpos($nodetext, '}}', $position+2);
 40+ $nextopen = strpos( $nodetext, '{{', $position + 2 );
 41+ $nextclose = strpos( $nodetext, '}}', $position + 2 );
4242
4343 // we didn't find end of template but still in this loop - skipping to next chunk
44 - if ($nextclose === FALSE)
 44+ if ( $nextclose === FALSE )
4545 {
4646 $brokenchunk = TRUE;
4747 continue 3; // get to next item in for loop
@@ -48,7 +48,7 @@
4949
5050 // next open tag is first, balance goes up
5151 // position is updated to closest marker
52 - if ($nextopen !== FALSE && $nextopen < $nextclose)
 52+ if ( $nextopen !== FALSE && $nextopen < $nextclose )
5353 {
5454 $balance += 1;
5555 $position = $nextopen;
@@ -60,29 +60,29 @@
6161 }
6262
6363 // 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 )
6565 {
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" );
6767 }
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
6969
7070 // part before the template becomes text node
71 - $newchildren[] = new POMTextNode(substr($nodetext, 0, $firstopen));
 71+ $newchildren[] = new POMTextNode( substr( $nodetext, 0, $firstopen ) );
7272
7373 // 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 ) );
7575 $newchildren[] = $template;
7676 $page->c['templates'][$template->getTitle()][] = $template;
7777
7878 // the rest of it should be processed for more templates
79 - $nodetext = substr($nodetext, $position+2);
 79+ $nodetext = substr( $nodetext, $position + 2 );
8080
8181 $replaceoldchildrenwithnew = true;
8282 }
8383
84 - if (strlen($nodetext) > 0)
 84+ if ( strlen( $nodetext ) > 0 )
8585 {
86 - $newchildren[] = new POMTextNode($nodetext);
 86+ $newchildren[] = new POMTextNode( $nodetext );
8787
8888 $replaceoldchildrenwithnew = true;
8989 }
@@ -95,7 +95,7 @@
9696 }
9797
9898 // if tree was updated, let's replace it in the page
99 - if ($replaceoldchildrenwithnew)
 99+ if ( $replaceoldchildrenwithnew )
100100 {
101101 $page->children = $newchildren;
102102 }
Index: trunk/extensions/PageObjectModel/examples/POMVersion.php
@@ -1,15 +1,15 @@
22 <?
3 -require_once('POM.php');
 3+require_once( 'POM.php' );
44
55 # 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' ) ) );
77
88 # Check current version
9 -$ver = $pom->templates['Extension'][0]->getParameter('version');
 9+$ver = $pom->templates['Extension'][0]->getParameter( 'version' );
1010 echo "Current version: $ver\n";
1111
1212 # 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 );
1414
1515 # 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();

Status & tagging log