r87262 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87261‎ | r87262 | r87263 >
Date:17:37, 2 May 2011
Author:preilly
Status:deferred (Comments)
Tags:
Comment:
Closures are a PHP 5.3 feature. MediaWiki currently requires PHP 5.2.3 or higher. Replacing anonymous function, aka closure with traditional method.
Modified paths:
  • /trunk/extensions/PatchOutputMobile/PatchOutputMobile.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PatchOutputMobile/PatchOutputMobile.php
@@ -17,12 +17,6 @@
1818 'description' => 'patch html output for mobile'
1919 );
2020
21 -// default settings
22 -ExtPatchOutputMobile::$mTable = array(
23 - 'accessed' => 'like viewed and stuff',
24 - 'information' => 'more stuff about it',
25 - 'Main Page' => 'First Page Dude');
26 -
2721 $wgExtPatchOutputMobile = new ExtPatchOutputMobile();
2822
2923 $wgHooks['OutputPageBeforeHTML'][] = array(&$wgExtPatchOutputMobile,
@@ -30,8 +24,6 @@
3125
3226 class ExtPatchOutputMobile {
3327 const VERSION = '0.2';
34 -
35 - public static $mTable;
3628
3729 private $doc;
3830
@@ -70,28 +62,31 @@
7163 return true;
7264 }
7365
74 - public function javascriptize($s) {
75 - $s = preg_replace_callback('/<h2(.*)<span class="mw-headline" [^>]*>(.+)<\/span>\w*<\/h2>/', function ($matches) {
76 - static $headings = 0;
77 - $show = "Show";
78 - $hide = "Hide";
79 - $back_to_top = "Jump Back A Section";
80 - ++$headings;
81 - // Back to top link
82 - $base = "<div class='section_anchors' id='anchor_" . intval($headings - 1) . "'><a href='#section_" . intval($headings - 1) . "' class='back_to_top'>&uarr; {$back_to_top}</a></div>";
83 - // generate the HTML we are going to inject
84 - $buttons = "<button class='section_heading show' section_id='{$headings}'>{$show}</button><button class='section_heading hide' section_id='{$headings}'>{$hide}</button>";
85 - $base .= "<h2 class='section_heading' id='section_{$headings}'{$matches[1]}{$buttons} <span>{$matches[2]}</span></h2><div class='content_block' id='content_{$headings}'>";
 66+ private function _show_hide_callback($matches) {
 67+ static $headings = 0;
 68+ $show = "Show";
 69+ $hide = "Hide";
 70+ $back_to_top = "Jump Back A Section";
 71+ ++$headings;
 72+ // Back to top link
 73+ $base = "<div class='section_anchors' id='anchor_" . intval($headings - 1) . "'><a href='#section_" . intval($headings - 1) . "' class='back_to_top'>&uarr; {$back_to_top}</a></div>";
 74+ // generate the HTML we are going to inject
 75+ $buttons = "<button class='section_heading show' section_id='{$headings}'>{$show}</button><button class='section_heading hide' section_id='{$headings}'>{$hide}</button>";
 76+ $base .= "<h2 class='section_heading' id='section_{$headings}'{$matches[1]}{$buttons} <span>{$matches[2]}</span></h2><div class='content_block' id='content_{$headings}'>";
8677
87 - if ($headings > 1) {
88 - // Close it up here
89 - $base = "</div>" . $base;
90 - }
91 -
92 - $GLOBALS['headings'] = $headings;
 78+ if ($headings > 1) {
 79+ // Close it up here
 80+ $base = "</div>" . $base;
 81+ }
 82+
 83+ $GLOBALS['headings'] = $headings;
9384
94 - return $base;
95 - }, $s);
 85+ return $base;
 86+ }
 87+
 88+ public function javascriptize($s) {
 89+ //Closures are a PHP 5.3 feature. MediaWiki currently requires PHP 5.2.3 or higher. So, using old style for now.
 90+ $s = preg_replace_callback( '/<h2(.*)<span class="mw-headline" [^>]*>(.+)<\/span>\w*<\/h2>/', array(&$this, '_show_hide_callback'), $s );
9691
9792 // if we had any, make sure to close the whole thing!
9893 if (isset($GLOBALS['headings']) && $GLOBALS['headings'] > 0) {

Comments

#Comment by Reedy (talk | contribs)   17:38, 2 May 2011

You're mixing tabs and spaces! :O

Status & tagging log