Netbrain has uploaded a new change for review.
https://gerrit.wikimedia.org/r/90536
Change subject: Added #subpage functionality Given the subpages A/B/C
......................................................................
Added #subpage functionality
Given the subpages A/B/C
<sidebarmenu>
</sidebarmenu>
would render a sidebarmenu with the same hierarchical structure
as the subpages equivalent to the input:
<sidebarmenu>
A
*B
**C
<sidebarmenu>
Change-Id: Ifaf87db3bd0a86aa871022d7c906050e95269720
---
M js/ext.sidebarmenu.js
M src/Hooks.php
A src/SubPageList/SubPageListExtensionInit.php
A src/SubPageList/SubPageListRenderer.php
4 files changed, 155 insertions(+), 54 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SideBarMenu
refs/changes/36/90536/1
diff --git a/js/ext.sidebarmenu.js b/js/ext.sidebarmenu.js
index c604cba..f52a97b 100644
--- a/js/ext.sidebarmenu.js
+++ b/js/ext.sidebarmenu.js
@@ -16,67 +16,70 @@
for (var id in sidebarmenu){
var container = $('#'+id);
var config = sidebarmenu[id];
- var showText = config[SBM_CONTROLS_SHOW];
- var hideText = config[SBM_CONTROLS_HIDE];
- var useAnimations = config[SBM_JS_ANIMATE];
- var minimized = config[SBM_MINIMIZED];
- if(minimized){
- container.addClass('sidebar-menu-minimized');
- container.find('.sidebar-menu-0
.sidebar-menu-item').first()
- .removeClass('sidebar-menu-item-expanded')
- .addClass('sidebar-menu-item-collapsed');
- }
+ (function(container,config){
- function initControls() {
-
container.find('.sidebar-menu-item-collapsed').children('.sidebar-menu-item-text-container').children('.sidebar-menu-item-controls').append(showText);
-
container.find('.sidebar-menu-item-expanded').children('.sidebar-menu-item-text-container').children('.sidebar-menu-item-controls').append(hideText);
- }
+ var showText = config[SBM_CONTROLS_SHOW];
+ var hideText = config[SBM_CONTROLS_HIDE];
+ var useAnimations = config[SBM_JS_ANIMATE];
+ var minimized = config[SBM_MINIMIZED];
- /*Open submenu of current page if current page is present as a
link in sidebarmenu*/
- var selfLink =
container.find('.sidebar-menu-item').find('.selflink')[0]
- if(selfLink !== undefined ){
-
$(selfLink).parents('.sidebar-menu-item-collapsed').removeClass('sidebar-menu-item-collapsed').addClass('sidebar-menu-item-expanded');
- }
-
- //initialize controls
- initControls();
-
- //initialize click actions
-
container.find('.sidebar-menu-item-controls,.sidebar-menu-item-expand-action').click(function
() {
- if(minimized && $(this)[0] ==
$('.sidebar-menu-item-controls:first')[0]){
- container.toggleClass('sidebar-menu-minimized');
+ if(minimized){
+ container.addClass('sidebar-menu-minimized');
+ container.find('.sidebar-menu-0
.sidebar-menu-item').first()
+ .removeClass('sidebar-menu-item-expanded')
+ .addClass('sidebar-menu-item-collapsed');
}
- var controls = $(this).is('.sidebar-menu-item-controls') ?
$(this) : $(this).next();
- var currentText = controls.text();
-
- if (currentText == showText) {
- controls.text(hideText);
- } else if (currentText == hideText) {
- controls.text(showText);
+ function initControls() {
+
container.find('.sidebar-menu-item-collapsed').children('.sidebar-menu-item-text-container').children('.sidebar-menu-item-controls').append(showText);
+
container.find('.sidebar-menu-item-expanded').children('.sidebar-menu-item-text-container').children('.sidebar-menu-item-controls').append(hideText);
}
- if (useAnimations) {
- //A little "ugly" hack to prevent some gui glitches.
-
$(this).parents('.sidebar-menu-item:first').toggleClass('sidebar-menu-item-collapsed
sidebar-menu-item-expanded', 250).children('.sidebar-menu').show(0, function
() {
- var _this = $(this);
- setTimeout(function () {
- _this.css('display', '')
- }, 250);
- });
- } else {
-
$(this).parents('.sidebar-menu-item:first').toggleClass('sidebar-menu-item-collapsed
sidebar-menu-item-expanded');
+ /*Open submenu of current page if current page is present
as a link in sidebarmenu*/
+ var selfLink =
container.find('.sidebar-menu-item').find('.selflink')[0]
+ if(selfLink !== undefined ){
+
$(selfLink).parents('.sidebar-menu-item-collapsed').removeClass('sidebar-menu-item-collapsed').addClass('sidebar-menu-item-expanded');
}
- });
- //must do this in javascript as serverside solution would
replace this <a href> link with escaped html characters
-
container.find('.sidebar-menu-item-expand-action').each(function(){
- $(this).html('<a href="#" onclick="return
false;">'+$(this).html()+'</a>');
- })
+ //initialize controls
+ initControls();
+
+ //initialize click actions
+
container.find('.sidebar-menu-item-controls,.sidebar-menu-item-expand-action').click(function
() {
+ if(minimized && $(this)[0] ==
$('.sidebar-menu-item-controls:first')[0]){
+ container.toggleClass('sidebar-menu-minimized');
+ }
+
+ var controls =
$(this).is('.sidebar-menu-item-controls') ? $(this) : $(this).next();
+ var currentText = controls.text();
+
+ if (currentText == showText) {
+ controls.text(hideText);
+ } else if (currentText == hideText) {
+ controls.text(showText);
+ }
+
+ if (useAnimations) {
+ //A little "ugly" hack to prevent some gui
glitches.
+
$(this).parents('.sidebar-menu-item:first').toggleClass('sidebar-menu-item-collapsed
sidebar-menu-item-expanded', 250).children('.sidebar-menu').show(0, function
() {
+ var _this = $(this);
+ setTimeout(function () {
+ _this.css('display', '')
+ }, 250);
+ });
+ } else {
+
$(this).parents('.sidebar-menu-item:first').toggleClass('sidebar-menu-item-collapsed
sidebar-menu-item-expanded');
+ }
+ });
+
+ //must do this in javascript as serverside solution would
replace this <a href> link with escaped html characters
+
container.find('.sidebar-menu-item-expand-action').each(function(){
+ $(this).html('<a href="#" onclick="return
false;">'+$(this).html()+'</a>');
+ })
+ })(container,config);
}
-
- container.show();
- }
+ $('.sidebar-menu-container').show();
+ }
});
})($,mw)
diff --git a/src/Hooks.php b/src/Hooks.php
index ddb731d..6f1c41e 100644
--- a/src/Hooks.php
+++ b/src/Hooks.php
@@ -6,11 +6,36 @@
class Hooks {
public static function init(\Parser &$parser) {
- $parser->setHook('sidebarmenu',
'SideBarMenu\Hooks::renderFromTag');
+ $parser->setHook('sidebarmenu',
'SideBarMenu\Hooks::renderSideBarMenuFromTag');
return true;
}
- public static function renderFromTag($input, array $args, \Parser
$parser, \PPFrame $frame) {
+ public static function includeSubPages(&$input) {
+ $extension = SubPageList\SubPageListExtensionInit::init();
+ $lines = explode("\n",$input);
+ for($x = 0; $x < count($lines); $x++){
+ $line = $lines[$x];
+ if(strrpos($line,'#subpage ') !== 0){
+ continue;
+ }
+ $title = explode(' ',$line)[1];
+ $title = \Title::newFromText($title);
+ if($title->exists()){
+ $subPages =
$extension->getSubPageFinder()->getSubPagesFor($title);
+ $hierarchy =
$extension->getPageHierarchyCreator()->createHierarchy($subPages);
+ $hierarchyString =
SubPageList\SubPageListRenderer::renderHierarchy($hierarchy);
+ $lines =
str_replace($line,$hierarchyString,$lines);
+ }
+ }
+ $input = implode("\n",$lines);
+ }
+
+ public static function renderSideBarMenuFromTag($input, array $args,
\Parser $parser, \PPFrame $frame) {
+ //subpages handling
+ if (defined('SPL_VERSION')) {
+ self::includeSubPages($input);
+ }
+
$parser->getOutput()->addModules('ext.sidebarmenu.core');
$input = $parser->recursiveTagParse($input,$frame);
diff --git a/src/SubPageList/SubPageListExtensionInit.php
b/src/SubPageList/SubPageListExtensionInit.php
new file mode 100644
index 0000000..fb59e6b
--- /dev/null
+++ b/src/SubPageList/SubPageListExtensionInit.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace SideBarMenu\SubPageList;
+
+use SubPageList\Extension;
+use SubPageList\Settings;
+
+/**
+ * @author: Kim Eik
+ */
+class SubPageListExtensionInit {
+
+ /**
+ * @return \SubPageList\Extension
+ */
+ public static function init(){
+
+ spl_autoload_register(function($className){
+ global $IP;
+ $dir = "$IP/extensions/SubPageList";
+ $className = ltrim( $className, '\\' );
+ $fileName = '';
+ $namespace = '';
+
+ if ( $lastNsPos = strripos( $className, '\\') ) {
+ $namespace = substr( $className, 0, $lastNsPos
);
+ $className = substr( $className, $lastNsPos + 1
);
+ $fileName = str_replace( '\\', '/', $namespace
) . '/';
+ }
+
+ $fileName .= str_replace( '_', '/', $className ) .
'.php';
+
+ $namespaceSegments = explode( '\\', $namespace );
+
+ if ( $namespaceSegments[0] === 'SubPageList' ) {
+ if ( count( $namespaceSegments ) === 1 ||
$namespaceSegments[1] !== 'Tests' ) {
+ require_once "$dir/src/$fileName";
+ }
+ }
+ },true,true);
+
+ return new Extension(Settings::newFromGlobals( $GLOBALS ) );
+ }
+}
\ No newline at end of file
diff --git a/src/SubPageList/SubPageListRenderer.php
b/src/SubPageList/SubPageListRenderer.php
new file mode 100644
index 0000000..c24d4c3
--- /dev/null
+++ b/src/SubPageList/SubPageListRenderer.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * @author: Kim Eik
+ */
+
+namespace SideBarMenu\SubPageList;
+
+class SubPageListRenderer {
+ /**
+ * @param \SubPageList\Page[] $hierarchy
+ * @param int $level
+ * @return string
+ */
+ public static function renderHierarchy($hierarchy, $level = 0){
+ $result = '';
+
+ foreach($hierarchy as $page){
+ for($i = 0; $i < $level; $i++){
+ $result .= '*';
+ }
+ $result .=
'[['.$page->getTitle()->getText().'|'.$page->getTitle()->getSubpageText()."]]\n";
+ $subPages = $page->getSubPages();
+ if(!empty($subPages)){
+ $result .=
self::renderHierarchy($subPages,$level+1);
+ }
+ }
+ return $result;
+ }
+}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/90536
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifaf87db3bd0a86aa871022d7c906050e95269720
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SideBarMenu
Gerrit-Branch: master
Gerrit-Owner: Netbrain <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits