r113253 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113252‎ | r113253 | r113254 >
Date:17:31, 7 March 2012
Author:netbrain
Status:deferred
Tags:
Comment:
added a default visual style to extension.
added javascript logic.
moved hooks into a separate file
Modified paths:
  • /trunk/extensions/SideBarMenu/SideBarMenu.hooks.php (added) (history)
  • /trunk/extensions/SideBarMenu/SideBarMenu.php (modified) (history)
  • /trunk/extensions/SideBarMenu/css (added) (history)
  • /trunk/extensions/SideBarMenu/css/ext.sidebarmenu.css (added) (history)
  • /trunk/extensions/SideBarMenu/includes/MenuItem.php (modified) (history)
  • /trunk/extensions/SideBarMenu/js (added) (history)
  • /trunk/extensions/SideBarMenu/js/ext.sidebarmenu.js (added) (history)

Diff [purge]

Index: trunk/extensions/SideBarMenu/SideBarMenu.php
@@ -15,49 +15,42 @@
1616
1717
1818 // Specify the function that will initialize the parser function.
19 -$wgHooks['ParserFirstCallInit'][] = 'init';
 19+$wgHooks['ParserFirstCallInit'][] = 'SideBarMenuHooks::init';
2020
2121 // Specify the function that will register the magic words for the parser function.
22 -$wgHooks['LanguageGetMagic'][] = 'registerMagicWords';
 22+$wgHooks['LanguageGetMagic'][] = 'SideBarMenuHooks::registerMagicWords';
2323
 24+// Javascript variables
 25+$wgHooks['ResourceLoaderGetConfigVars'][] = 'SideBarMenuHooks::javascriptConfigVars';
 26+
2427 // Sepcify phpunit tests
25 -$wgHooks['UnitTestsList'][] = 'registerUnitTests';
 28+$wgHooks['UnitTestsList'][] = 'SideBarMenuHooks::registerUnitTests';
2629
27 -//Autoload
 30+//Autoload hooks
 31+$wgAutoloadClasses['SideBarMenuHooks'] = dirname( __FILE__ ) . '/SideBarMenu.hooks.php';
 32+
 33+//Autoload classes
2834 $wgMyExtensionIncludes = dirname(__FILE__) . '/includes';
2935 ## Special page class
3036 $wgAutoloadClasses['MenuParser'] = $wgMyExtensionIncludes . '/MenuParser.php';
3137 $wgAutoloadClasses['MenuItem'] = $wgMyExtensionIncludes . '/MenuItem.php';
3238
 39+//Resources
 40+$wgResourceModules['ext.sidebarmenu.core'] = array(
 41+ 'scripts' => array(
 42+ 'js/ext.sidebarmenu.js'
 43+ ),
 44+ 'styles' => array(
 45+ 'css/ext.sidebarmenu.css'
 46+ ),
 47+ 'dependencies' => array (
 48+ 'jquery.ui.core'
 49+ ),
 50+ 'group' => 'ext.sidebarmenu',
 51+ 'localBasePath' => dirname( __FILE__ ),
 52+ 'remoteExtPath' => 'SideBarMenu'
 53+);
3354
34 -function init(&$parser){
35 - $parser->setHook('sidebarmenu','renderFromTag');
36 - return true;
37 -}
38 -
39 -function registerMagicWords(&$magicWords, $langCode){
40 - $magicWords['sidebarmenu'] = array(0,'sidebarmenu');
41 - return true;
42 -}
43 -
44 -function renderFromTag( $input, array $args, Parser $parser, PPFrame $frame ){
45 - try{
46 - $menuHTML = MenuParser::getMenuTree($input)->toHTML();
47 - return $parser->recursiveTagParse($menuHTML,$frame);
48 - }catch(Exception $x){
49 - wfDebug("An error occured during parsing of: '$input' caught exception: $x");
50 - return "FATAL ERROR: Could not parse the following input:</br><pre>$input</pre>";
51 - }
52 -}
53 -
54 -function registerUnitTests( &$files ) {
55 - $testDir = dirname( __FILE__ ) . '/test/';
56 - $testFiles = scandir($testDir);
57 - foreach($testFiles as $testFile){
58 - $absoluteFile = $testDir . $testFile;
59 - if(is_file($absoluteFile)){
60 - $files[] = $absoluteFile;
61 - }
62 - }
63 - return true;
64 -}
 55+//default settings
 56+$wgSideBarMenuConfigShowHTML = '[show]';
 57+$wgSideBarMenuConfigHideHTML = '[hide]';
\ No newline at end of file
Index: trunk/extensions/SideBarMenu/SideBarMenu.hooks.php
@@ -0,0 +1,48 @@
 2+<?php
 3+
 4+class SideBarMenuHooks
 5+{
 6+
 7+ public static function init(&$parser){
 8+ $parser->setHook('sidebarmenu','SideBarMenuHooks::renderFromTag');
 9+ return true;
 10+ }
 11+
 12+ public static function renderFromTag( $input, array $args, Parser $parser, PPFrame $frame ){
 13+ $parser->getOutput()->addModules('ext.sidebarmenu.core');
 14+ try{
 15+ $menuHTML = '<div class="sidebar-menu-container">';
 16+ $menuHTML .= MenuParser::getMenuTree($input)->toHTML();
 17+ $menuHTML .= '</div>';
 18+ return $parser->recursiveTagParse($menuHTML,$frame);
 19+ }catch(Exception $x){
 20+ wfDebug("An error occured during parsing of: '$input' caught exception: $x");
 21+ return "FATAL ERROR: Could not parse the following input:</br><pre>$input</pre>";
 22+ }
 23+ }
 24+
 25+ public static function registerUnitTests( &$files ) {
 26+ $testDir = dirname( __FILE__ ) . '/test/';
 27+ $testFiles = scandir($testDir);
 28+ foreach($testFiles as $testFile){
 29+ $absoluteFile = $testDir . $testFile;
 30+ if(is_file($absoluteFile)){
 31+ $files[] = $absoluteFile;
 32+ }
 33+ }
 34+ return true;
 35+ }
 36+
 37+ public static function registerMagicWords(&$magicWords, $langCode){
 38+ $magicWords['sidebarmenu'] = array(0,'sidebarmenu');
 39+ return true;
 40+ }
 41+
 42+ public static function javascriptConfigVars(&$vars){
 43+ global $wgSideBarMenuConfigShowHTML,$wgSideBarMenuConfigHideHTML;
 44+ $vars['wgSideBarMenuConfigShowHTML'] = $wgSideBarMenuConfigShowHTML;
 45+ $vars['wgSideBarMenuConfigHideHTML'] = $wgSideBarMenuConfigHideHTML;
 46+ return true;
 47+ }
 48+
 49+}
Index: trunk/extensions/SideBarMenu/includes/MenuItem.php
@@ -7,6 +7,7 @@
88 private $parent = null;
99 private $text;
1010
 11+
1112 public function setExpanded($expanded)
1213 {
1314 $this->expanded = $expanded;
@@ -76,7 +77,25 @@
7778 if($this->isRoot()){
7879 $output .= $this->childrenToHTML();
7980 }else{
80 - $output .= "<li class=\"sidebar-menu-item sidebar-menu-item-".$this->getLevel().' '.($this->isExpanded() ? 'sidebar-menu-item-expanded' : 'sidebar-menu-item-collapsed')."\"><div class=\"sidebar-menu-item-text sidebar-menu-item-text-".$this->getLevel()."\">".$this->getText()."</div>";
 81+ $itemClasses[] = 'sidebar-menu-item';
 82+ $itemClasses[] = 'sidebar-menu-item-'.$this->getLevel();
 83+
 84+ if($this->hasChildren()){
 85+ $itemClasses[] = $this->isExpanded() ? 'sidebar-menu-item-expanded' : 'sidebar-menu-item-collapsed';
 86+ }
 87+
 88+ $textClasses[] = 'sidebar-menu-item-text';
 89+ $textClasses[] = 'sidebar-menu-item-text-'.$this->getLevel();
 90+
 91+ $output .= "<li class=\"".join(' ',$itemClasses)."\">";
 92+ $output .= "<div class=\"sidebar-menu-item-text-container\">";
 93+ $output .= "<span class=\"".join(' ',$textClasses)."\">".$this->getText()."</span>";
 94+
 95+ if($this->hasChildren()){
 96+ $output .= "<span class=\"sidebar-menu-item-controls\"></span>";
 97+ }
 98+
 99+ $output .= "</div>";
81100 $output .= $this->childrenToHTML();
82101 $output .= "</li>";
83102 }
@@ -87,7 +106,10 @@
88107 private function childrenToHTML()
89108 {
90109 if($this->hasChildren()){
91 - $output = "<ul class=\"sidebar-menu sidebar-menu-".$this->getLevel()."\">";
 110+ $menuClasses[] = 'sidebar-menu';
 111+ $menuClasses[] = 'sidebar-menu-'.$this->getLevel();
 112+
 113+ $output = "<ul class=\"".join(' ',$menuClasses)."\">";
92114 foreach ($this->getChildren() as $child) {
93115 $output .= $child->toHTML();
94116 }
Index: trunk/extensions/SideBarMenu/css/ext.sidebarmenu.css
@@ -0,0 +1,53 @@
 2+/* default SideBarMenu extension styling */
 3+
 4+.sidebar-menu-container{
 5+ padding: 5px;
 6+ float: left;
 7+ clear: left;
 8+}
 9+
 10+.sidebar-menu-item-collapsed .sidebar-menu{
 11+ display: none;
 12+}
 13+
 14+.sidebar-menu-0,.sidebar-menu-1{
 15+ margin: 0px !important;
 16+ padding: 0px !important;
 17+ list-style: none;
 18+}
 19+
 20+
 21+.sidebar-menu-item-1{
 22+ margin: 10px 0px;
 23+ background-color: #f2f2f2;
 24+}
 25+
 26+.sidebar-menu-item-1 > .sidebar-menu-item-text-container{
 27+ border: 1px solid #aaa;
 28+ border-bottom: 0px;
 29+ padding: 3px;
 30+}
 31+
 32+.sidebar-menu-item-2{
 33+ background-color: #f9f9f9;
 34+ border: 1px solid #aaa;
 35+ border-bottom: 0px;
 36+ padding: 3px !important;
 37+ margin-bottom: 0px !important;
 38+}
 39+
 40+.sidebar-menu-item-text-container{
 41+ position: relative;
 42+}
 43+
 44+.sidebar-menu-item-controls{
 45+ float: right;
 46+ margin-left: 5px;
 47+ color: #0645AD;
 48+ cursor: pointer;
 49+}
 50+
 51+.sidebar-menu-item-1{
 52+ border-bottom: 1px solid #aaa;
 53+}
 54+
Property changes on: trunk/extensions/SideBarMenu/css/ext.sidebarmenu.css
___________________________________________________________________
Added: svn:eol-style
155 + native *.eot = svn:mime-type=application/vnd.ms-fontobject *.gif = svn:mime-type=image/gif *.ico = svn:mime-type=image/vnd.microsoft.icon *.inc = svn:eol-style=native *.info = svn:eol-style=native *.install=svn:eol-style=native *.java = svn:eol-style=native *.jpeg = svn:mime-type=image/jpeg *.jpg = svn:mime-type=image/jpeg *.js = svn:eol-style=native *.jsp = svn:eol-style=native *.module = svn:eol-style=native *.php5 = svn:eol-style=native *.php = svn:eol-style=native *.pl = svn:eol-style=native *.pm = svn:eol-style=native *.png = svn:mime-type=image/png *.py = svn:eol-style=native *.sh = svn:eol-style=native *.sql = svn:eol-style=native *.svg = svn:mime-type=image/svg+xml *.tpl = svn:eol-style=native *.ttf = svn:mime-type=application/x-font-ttf *.txt = svn:eol-style=native *.woff = svn:mime-type=application/x-woff *.xcf = svn:mime-type=image/x-xcf Makefile = svn:eol-style=native SConscript = svn:eol-style=native SConstruct = svn:eol-style=native USERINFO = svn:eol-style=native
Index: trunk/extensions/SideBarMenu/js/ext.sidebarmenu.js
@@ -0,0 +1,6 @@
 2+$(document).ready(function(){
 3+ $('.sidebar-menu-item-controls').append(mw.config.get('wgSideBarMenuConfigShowHTML'));
 4+ $('.sidebar-menu-item-controls').click(function(){
 5+ $(this).parents('.sidebar-menu-item:first').toggleClass('sidebar-menu-item-collapsed',1500);
 6+ });
 7+});
\ No newline at end of file

Status & tagging log