r87337 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87336‎ | r87337 | r87338 >
Date:17:19, 3 May 2011
Author:preilly
Status:ok
Tags:
Comment:
switch to using <code>$camelCaseNames</code> for variables and <code>dash-seperated-message-keys</code>
Modified paths:
  • /trunk/extensions/PatchOutputMobile/PatchOutputMobile.i18n.php (modified) (history)
  • /trunk/extensions/PatchOutputMobile/PatchOutputMobile.php (modified) (history)
  • /trunk/extensions/PatchOutputMobile/views/layout/_footmenu_default.html.php (modified) (history)
  • /trunk/extensions/PatchOutputMobile/views/layout/_search_webkit.html.php (modified) (history)
  • /trunk/extensions/PatchOutputMobile/views/layout/application.html.php (modified) (history)
  • /trunk/extensions/PatchOutputMobile/views/notices/_donate.html.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PatchOutputMobile/PatchOutputMobile.i18n.php
@@ -2,7 +2,7 @@
33
44 $messages = array();
55 $messages['en'] = array(
6 - 'patch_output_mobile_show' => 'show',
7 - 'patch_output_mobile_hide' => 'hide',
8 - 'patch_output_mobile_back_to_top' => 'Jump Back A Section',
 6+ 'patch-output-mobile-show' => 'show',
 7+ 'patch-output-mobile-hide' => 'hide',
 8+ 'patch-output-mobile-back-to-top' => 'Jump Back A Section',
99 );
\ No newline at end of file
Index: trunk/extensions/PatchOutputMobile/views/notices/_donate.html.php
@@ -1,6 +1,6 @@
22 <?php
33
4 -$donate_html = <<<EOT
 4+$donateHtml = <<<EOT
55 <div class='mwm-message mwm-notice'>
66 Text WIKI to <a href="sms:25383">25383</a> to donate $10.
77 <br />
Index: trunk/extensions/PatchOutputMobile/views/layout/_search_webkit.html.php
@@ -1,26 +1,7 @@
22 <?php
3 -/*
4 -$search_webkit_html = <<<EOD
5 -<div id='header'>
6 - <div id='searchbox'>
7 - <img alt='W logo' id='logo' src='http://en.m.wikipedia.org/images/w.gif' />
8 - <form action='/wiki' class='search_bar' method='get'>
9 - <input id='searchField' name='search' size='27' type='search' value='' />
10 - <div id='clearButton'></div>
11 - <button id='goButton' type='submit'></button>
12 - </form>
13 - </div>
14 - <div class='nav' id='nav'>
15 - <form method="get" action="/"><button type="submit" id="homeButton">Home</button></form>
16 - <form method="get" action="/wiki/::Random"><button type="submit" id="randomButton">Random</button></form>
17 - </div>
18 -</div>
19 -EOD;
20 -*/
 3+$searchField = (!empty($_GET['search'])) ? $_GET['search'] : '';
214
22 -$search_field = (!empty($_GET['search'])) ? $_GET['search'] : '';
23 -
24 -$search_webkit_html = <<<EOD
 5+$searchWebkitHtml = <<<EOD
256 <div id='header'>
267 <div id='searchbox'>
278 <img alt='W logo' id='logo' src='http://en.m.wikipedia.org/images/w.gif' />
@@ -28,7 +9,7 @@
2910 <input type="hidden" value="Special:Search" name="title" />
3011 <input type="hidden" value="Search" name="fulltext" />
3112 <input type="hidden" value="0" name="redirs" />
32 - <input id='searchField' name='search' size='27' type='search' value='{$search_field}' />
 13+ <input id='searchField' name='search' size='27' type='search' value='{$searchField}' />
3314 <div id='clearButton'></div>
3415 <button id='goButton' type='submit'></button>
3516 </form>
Index: trunk/extensions/PatchOutputMobile/views/layout/_footmenu_default.html.php
@@ -1,12 +1,12 @@
22 <?php
33
4 -$footer_html = <<<EOD
 4+$footerHtml = <<<EOD
55 <div id='footer'>
66 <div class='nav' id='footmenu'>
77 <div class='mwm-notice'>
88 <a href="http://en.wikipedia.org/w/mobileRedirect.php?to=">View this page on regular Wikipedia</a>
99 <div id="perm">
10 - <a href="https://www.mediawiki.org/disable/???">Permanently disable mobile site</a>
 10+ <a href="https://www.mediawiki.org/disable/?">Permanently disable mobile site</a>
1111 </div>
1212 </div>
1313 </div>
Index: trunk/extensions/PatchOutputMobile/views/layout/application.html.php
@@ -1,5 +1,5 @@
22 <?php
3 -$application_html = <<<EOT
 3+$applicationHtml = <<<EOT
44 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
55 <html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
66 <head>
@@ -22,12 +22,12 @@
2323 <script type="text/javascript" language="javascript" SRC="http://en.m.wikipedia.org/javascripts/application.js"></script>
2424 </head>
2525 <body>
26 - {$search_webkit_html}
 26+ {$searchWebkitHtml}
2727 <div class='show' id='content_wrapper'>
28 - {$donate_html}
29 - {$content_html}
 28+ {$donateHtml}
 29+ {$contentHtml}
3030 </div>
31 - {$footer_html}
 31+ {$footerHtml}
3232 </body>
3333 </html>
3434 EOT;
Index: trunk/extensions/PatchOutputMobile/PatchOutputMobile.php
@@ -18,7 +18,7 @@
1919 'url' => 'http://www.mediawiki.org/wiki/Extension:PatchOutputMobile',
2020 );
2121
22 -$dir = dirname(__FILE__) . '/';
 22+$dir = dirname(__FILE__) . DIRECTORY_SEPARATOR;
2323 $wgExtensionMessagesFiles['PatchOutputMobile'] = $dir . 'PatchOutputMobile.i18n.php';
2424
2525 $wgExtPatchOutputMobile = new ExtPatchOutputMobile();
@@ -27,28 +27,28 @@
2828 'onOutputPageBeforeHTML' );
2929
3030 class ExtPatchOutputMobile {
31 - const VERSION = '0.2.4';
 31+ const VERSION = '0.2.6';
3232
3333 private $doc;
3434
3535 public static $messages = array();
3636
37 - public $items_to_remove = array(
38 - '#contentSub', # redirection notice
39 - 'div.messagebox', # cleanup data
40 - '#siteNotice', # site notice
41 - '#siteSub', # "From Wikipedia..."
42 - '#jump-to-nav', # jump-to-nav
43 - 'div.editsection', # edit blocks
44 - 'div.infobox', # Infoboxes in the article
45 - 'table.toc', # table of contents
46 - '#catlinks', # category links
47 - 'div.stub', # stub warnings
48 - 'table.metadata', # ugly metadata
 37+ public $itemsToRemove = array(
 38+ '#contentSub', # redirection notice
 39+ 'div.messagebox', # cleanup data
 40+ '#siteNotice', # site notice
 41+ '#siteSub', # "From Wikipedia..."
 42+ '#jump-to-nav', # jump-to-nav
 43+ 'div.editsection', # edit blocks
 44+ 'div.infobox', # Infoboxes in the article
 45+ 'table.toc', # table of contents
 46+ '#catlinks', # category links
 47+ 'div.stub', # stub warnings
 48+ 'table.metadata', # ugly metadata
4949 'form',
5050 'div.sister-project',
5151 'script',
52 - 'div.magnify', # stupid magnify thing
 52+ 'div.magnify', # stupid magnify thing
5353 '.editsection',
5454 'span.t',
5555 'sup[style*="help"]',
@@ -68,9 +68,9 @@
6969 public function onOutputPageBeforeHTML( &$out, &$text ) {
7070 // Need to stash the results of the "wfMsg" call before the Output Buffering handler
7171 // because at this point the database connection is shut down, etc.
72 - ExtPatchOutputMobile::$messages['patch_output_mobile_show'] = wfMsg('patch_output_mobile_show');
73 - ExtPatchOutputMobile::$messages['patch_output_mobile_hide'] = wfMsg('patch_output_mobile_hide');
74 - ExtPatchOutputMobile::$messages['patch_output_mobile_back_to_top'] = wfMsg('patch_output_mobile_back_to_top');
 72+ ExtPatchOutputMobile::$messages['patch-output-mobile-show'] = wfMsg( 'patch-output-mobile-show' );
 73+ ExtPatchOutputMobile::$messages['patch-output-mobile-hide'] = wfMsg( 'patch-output-mobile-hide' );
 74+ ExtPatchOutputMobile::$messages['patch-output-mobile-back-to-top'] = wfMsg( 'patch-output-mobile-back-to-top' );
7575
7676 ob_start( array( $this, 'parse' ) );
7777 return true;
@@ -78,14 +78,14 @@
7979
8080 private function showHideCallback( $matches ) {
8181 static $headings = 0;
82 - $show = ExtPatchOutputMobile::$messages['patch_output_mobile_show'];
83 - $hide = ExtPatchOutputMobile::$messages['patch_output_mobile_hide'];
84 - $back_to_top = ExtPatchOutputMobile::$messages['patch_output_mobile_back_to_top'];
 82+ $show = ExtPatchOutputMobile::$messages['patch-output-mobile-show'];
 83+ $hide = ExtPatchOutputMobile::$messages['patch-output-mobile-hide'];
 84+ $backToTop = ExtPatchOutputMobile::$messages['patch-output-mobile-back-to-top'];
8585 ++$headings;
8686 // Back to top link
8787 $base = "<div class='section_anchors' id='anchor_" . intval( $headings - 1 ) .
8888 "'><a href='#section_" . intval( $headings - 1 ) .
89 - "' class='back_to_top'>&uarr; {$back_to_top}</a></div>";
 89+ "' class='back_to_top'>&uarr; {$backToTop}</a></div>";
9090 // generate the HTML we are going to inject
9191 $buttons = "<button class='section_heading show' section_id='{$headings}'>{$show}</button><button class='section_heading hide' section_id='{$headings}'>{$hide}</button>";
9292 $base .= "<h2 class='section_heading' id='section_{$headings}'{$matches[1]}{$buttons} <span>{$matches[2]}</span></h2><div class='content_block' id='content_{$headings}'>";
@@ -127,16 +127,16 @@
128128 }
129129
130130 private function parseItemsToRemove() {
131 - $item_to_remove_records = array();
 131+ $itemToRemoveRecords = array();
132132
133 - foreach ( $this->items_to_remove as $item_to_remove ) {
 133+ foreach ( $this->itemsToRemove as $itemToRemove ) {
134134 $type = '';
135 - $raw_name = '';
136 - CssDetection::detectIdCssOrTag( $item_to_remove, $type, $raw_name );
137 - $item_to_remove_records[$type][] = $raw_name;
 135+ $rawName = '';
 136+ CssDetection::detectIdCssOrTag( $itemToRemove, $type, $rawName );
 137+ $itemToRemoveRecords[$type][] = $rawName;
138138 }
139139
140 - return $item_to_remove_records;
 140+ return $itemToRemoveRecords;
141141 }
142142
143143 public function DOMParse( $html ) {
@@ -146,12 +146,12 @@
147147 $this->doc->preserveWhiteSpace = false;
148148 $this->doc->strictErrorChecking = false;
149149
150 - $item_to_remove_records = $this->parseItemsToRemove();
 150+ $itemToRemoveRecords = $this->parseItemsToRemove();
151151
152 - $title_node = $this->doc->getElementsByTagName( 'title' );
 152+ $titleNode = $this->doc->getElementsByTagName( 'title' );
153153
154 - if ( $title_node->length > 0 ) {
155 - $title = $title_node->item( 0 )->nodeValue;
 154+ if ( $titleNode->length > 0 ) {
 155+ $title = $titleNode->item( 0 )->nodeValue;
156156 }
157157
158158 // Tags
@@ -163,12 +163,12 @@
164164 // For example:
165165
166166 $domElemsToRemove = array();
167 - foreach ( $item_to_remove_records['TAG'] as $tag_to_remove ) {
168 - $tag_to_remove_nodes = $this->doc->getElementsByTagName( $tag_to_remove );
 167+ foreach ( $itemToRemoveRecords['TAG'] as $tagToRemove ) {
 168+ $tagToRemoveNodes = $this->doc->getElementsByTagName( $tagToRemove );
169169
170 - foreach( $tag_to_remove_nodes as $tag_to_remove_node ) {
171 - if ( $tag_to_remove_node ) {
172 - $domElemsToRemove[] = $tag_to_remove_node;
 170+ foreach( $tagToRemoveNodes as $tagToRemoveNode ) {
 171+ if ( $tagToRemoveNode ) {
 172+ $domElemsToRemove[] = $tagToRemoveNode;
173173 }
174174 }
175175 }
@@ -178,55 +178,55 @@
179179 }
180180
181181 // Elements with named IDs
182 - foreach ( $item_to_remove_records['ID'] as $item_to_remove ) {
183 - $item_to_remove_node = $this->doc->getElementById( $item_to_remove );
184 - if ( $item_to_remove_node ) {
185 - $removed_item_to_remove = $item_to_remove_node->parentNode->removeChild( $item_to_remove_node );
 182+ foreach ( $itemToRemoveRecords['ID'] as $itemToRemove ) {
 183+ $itemToRemoveNode = $this->doc->getElementById( $itemToRemove );
 184+ if ( $itemToRemoveNode ) {
 185+ $removedItemToRemove = $itemToRemoveNode->parentNode->removeChild( $itemToRemoveNode );
186186 }
187187 }
188188
189189 // CSS Classes
190190 $xpath = new DOMXpath( $this->doc );
191 - foreach ( $item_to_remove_records['CLASS'] as $class_to_remove ) {
192 - $elements = $xpath->query( '//*[@class="' . $class_to_remove . '"]' );
 191+ foreach ( $itemToRemoveRecords['CLASS'] as $classToRemove ) {
 192+ $elements = $xpath->query( '//*[@class="' . $classToRemove . '"]' );
193193
194194 foreach( $elements as $element ) {
195 - $removed_element = $element->parentNode->removeChild( $element );
 195+ $removedElement = $element->parentNode->removeChild( $element );
196196 }
197197 }
198198
199199 // Tags with CSS Classes
200 - foreach ( $item_to_remove_records['TAG_CLASS'] as $class_to_remove ) {
201 - $parts = explode( '.', $class_to_remove );
 200+ foreach ( $itemToRemoveRecords['TAG_CLASS'] as $classToRemove ) {
 201+ $parts = explode( '.', $classToRemove );
202202
203203 $elements = $xpath->query(
204204 '//' . $parts[0] . '[@class="' . $parts[1] . '"]'
205205 );
206206
207207 foreach( $elements as $element ) {
208 - $removed_element = $element->parentNode->removeChild( $element );
 208+ $removedElement = $element->parentNode->removeChild( $element );
209209 }
210210 }
211211
212212 // Handle red links with action equal to edit
213 - $redlinks = $xpath->query( '//a[@class="new"]' );
214 - foreach( $redlinks as $redlink ) {
 213+ $redLinks = $xpath->query( '//a[@class="new"]' );
 214+ foreach( $redLinks as $redLink ) {
215215 //PHP Bug #36795 — Inappropriate "unterminated entity reference"
216 - $spannode = $this->doc->createElement( "span", str_replace( "&", "&amp;", $redlink->nodeValue ) );
 216+ $spanNode = $this->doc->createElement( "span", str_replace( "&", "&amp;", $redLink->nodeValue ) );
217217
218 - if ( $redlink->hasAttributes() ) {
219 - $attributes = $redlink->attributes;
 218+ if ( $redLink->hasAttributes() ) {
 219+ $attributes = $redLink->attributes;
220220 foreach ( $attributes as $i => $attribute ) {
221 - $spannode->setAttribute( $attribute->name, $attribute->value );
 221+ $spanNode->setAttribute( $attribute->name, $attribute->value );
222222 }
223223 }
224224
225 - $redlink->parentNode->replaceChild( $spannode, $redlink );
 225+ $redLink->parentNode->replaceChild( $spanNode, $redLink );
226226 }
227227
228228 $content = $this->doc->getElementById( 'content' );
229229
230 - $content_html = $this->doc->saveXML( $content, LIBXML_NOEMPTYTAG );
 230+ $contentHtml = $this->doc->saveXML( $content, LIBXML_NOEMPTYTAG );
231231
232232 if ( empty( $title ) ) {
233233 $title = 'Wikipedia';
@@ -237,32 +237,32 @@
238238 require( 'views/layout/_footmenu_default.html.php' );
239239 require( 'views/layout/application.html.php' );
240240
241 - return ( strlen( $content_html ) > 4000 ) ? $this->javascriptize( $application_html ) : $application_html; //$content_html;
 241+ return ( strlen( $contentHtml ) > 4000 ) ? $this->javascriptize( $applicationHtml ) : $applicationHtml;
242242 }
243243 }
244244
245245 class CssDetection {
246246
247 - public static function detectIdCssOrTag( $snippet, &$type, &$raw_name ) {
 247+ public static function detectIdCssOrTag( $snippet, &$type, &$rawName ) {
248248 $output = '';
249249
250250 if ( strpos( $snippet, '.' ) === 0 ) {
251251 $output = 'Class found: ';
252252 $type = 'CLASS';
253 - $raw_name = substr( $snippet, 1 );
 253+ $rawName = substr( $snippet, 1 );
254254 }
255255
256256 if ( strpos( $snippet, '#' ) === 0 ) {
257257 $output = 'ID found: ';
258258 $type = 'ID';
259 - $raw_name = substr( $snippet, 1 );
 259+ $rawName = substr( $snippet, 1 );
260260 }
261261
262262 if ( strpos( $snippet, '.' ) !== 0 &&
263263 strpos( $snippet, '.' ) !== false ) {
264264 $output = 'Tag with Class found: ';
265265 $type = 'TAG_CLASS';
266 - $raw_name = $snippet;
 266+ $rawName = $snippet;
267267 }
268268
269269 if ( strpos( $snippet, '.' ) === false &&
@@ -271,13 +271,13 @@
272272 strpos( $snippet, ']' ) === false ) {
273273 $output = 'Tag found: ';
274274 $type = 'TAG';
275 - $raw_name = $snippet;
 275+ $rawName = $snippet;
276276 }
277277
278278 if ( empty( $output ) ) {
279279 $output = 'Unknown HTML snippet found: ';
280280 $type = 'UNKNOWN';
281 - $raw_name = $snippet;
 281+ $rawName = $snippet;
282282 }
283283
284284 return $output;

Status & tagging log