Index: trunk/extensions/PatchOutputMobile/PatchOutputMobile.php |
— | — | @@ -17,12 +17,6 @@ |
18 | 18 | 'description' => 'patch html output for mobile' |
19 | 19 | ); |
20 | 20 | |
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 | | - |
27 | 21 | $wgExtPatchOutputMobile = new ExtPatchOutputMobile(); |
28 | 22 | |
29 | 23 | $wgHooks['OutputPageBeforeHTML'][] = array(&$wgExtPatchOutputMobile, |
— | — | @@ -30,8 +24,6 @@ |
31 | 25 | |
32 | 26 | class ExtPatchOutputMobile { |
33 | 27 | const VERSION = '0.2'; |
34 | | - |
35 | | - public static $mTable; |
36 | 28 | |
37 | 29 | private $doc; |
38 | 30 | |
— | — | @@ -70,28 +62,31 @@ |
71 | 63 | return true; |
72 | 64 | } |
73 | 65 | |
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'>↑ {$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'>↑ {$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}'>"; |
86 | 77 | |
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; |
93 | 84 | |
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 ); |
96 | 91 | |
97 | 92 | // if we had any, make sure to close the whole thing! |
98 | 93 | if (isset($GLOBALS['headings']) && $GLOBALS['headings'] > 0) { |