Smuggli has submitted this change and it was merged.
Change subject: TopMenuBarCustomizer: Refactoring
......................................................................
TopMenuBarCustomizer: Refactoring
* Moved "NavigationSites" handling to extension TopMenuBarCustomizer pt2
* Total Makeover for extension TopMenuBarCustomizer
* "NavigationSites" also support MW messages now
* Made some doc an cc
Change-Id: Id6cf25fd83d883170c727574d5858595befdf84d
---
M Blog/Blog.class.php
M TopMenuBarCustomizer/TopMenuBarCustomizer.class.php
M TopMenuBarCustomizer/TopMenuBarCustomizer.setup.php
M TopMenuBarCustomizer/doc/Hooks.txt
A TopMenuBarCustomizer/includes/TopMenuBarCustomizerParser.php
M TopMenuBarCustomizer/resources/bluespice.TopMenuBarCustomizer.js
M TopMenuBarCustomizer/views/view.TopMenuItem.php
D TopMenuBarCustomizer/views/view.TopMenuItemMain.php
8 files changed, 458 insertions(+), 410 deletions(-)
Approvals:
Robert Vogel: Checked; Looks good to me, but someone else must approve
Smuggli: Verified; Looks good to me, approved
diff --git a/Blog/Blog.class.php b/Blog/Blog.class.php
index 7490852..bbb877a 100644
--- a/Blog/Blog.class.php
+++ b/Blog/Blog.class.php
@@ -77,7 +77,7 @@
$this->setHook( 'BSNamespaceManagerBeforeSetUsernamespaces',
'onBSNamespaceManagerBeforeSetUsernamespaces');
$this->setHook( 'BSRSSFeederGetRegisteredFeeds' );
$this->setHook( 'BeforePageDisplay' );
- $this->setHook( 'SkinTemplateOutputPageBeforeExec' );
+ $this->setHook( 'BSTopMenuBarCustomizerRegisterNavigationSites'
);
// Trackback is not fully functional in MW and thus disabled.
BsConfig::registerVar( 'MW::Blog::ShowTrackback', false,
BsConfig::LEVEL_PRIVATE|BsConfig::TYPE_BOOL );
@@ -109,23 +109,22 @@
}
/**
- * Adds entry to bs_navigation_topbar
- * @param SkinTemplate $sktemplate
- * @param BaseTemplate $tpl
- * @return boolean Always true to keep hook running
+ * Adds entry to navigation sites
+ * @global string $wgScriptPath
+ * @param array $aNavigationSites
+ * @return boolean - always true
*/
- public function onSkinTemplateOutputPageBeforeExec( &$sktemplate, &$tpl
){
+ public function onBSTopMenuBarCustomizerRegisterNavigationSites(
&$aNavigationSites ) {
global $wgScriptPath;
- $tpl->data['bs_navigation_sites'][20] = array(
+
+ $aNavigationSites[] = array(
'id' => 'nt-blog',
'href' => wfAppendQuery( $wgScriptPath.'/index.php',
array(
'action' => 'blog'
)),
- 'text' => wfMessage('bs-blog-blog')->plain()
+ 'active' => BsExtensionManager::isContextActive(
'MW::Blog::ShowBlog' ),
+ 'text' => wfMessage('bs-blog-blog')->plain(),
);
- if( BsExtensionManager::isContextActive( 'MW::Blog::ShowBlog' )
) {
- $tpl->data['bs_navigation_sites_active'] = 'nt-blog';
- }
return true;
}
diff --git a/TopMenuBarCustomizer/TopMenuBarCustomizer.class.php
b/TopMenuBarCustomizer/TopMenuBarCustomizer.class.php
index 0e7fce4..aefa6ad 100644
--- a/TopMenuBarCustomizer/TopMenuBarCustomizer.class.php
+++ b/TopMenuBarCustomizer/TopMenuBarCustomizer.class.php
@@ -22,8 +22,7 @@
* For further information visit http://www.blue-spice.org
*
* @author Patric Wirth <[email protected]>
-* @version 2.22.0
-
+* @version 2.23.0
* @package Bluespice_Extensions
* @subpackage TopMenuBarCustomizer
* @copyright Copyright (C) 2011 Hallo Welt! - Medienwerkstatt GmbH, All
rights reserved.
@@ -34,11 +33,30 @@
/**
* v1.20.0
* - MediaWiki I18N
+ * v2.23.0
+ * - Complete makeover
*/
class TopMenuBarCustomizer extends BsExtensionMW {
- private $aOldApps = array();
- private $aApps = array();
+ /**
+ *
+ * @var array
+ */
+ public static $aNavigationSiteTemplate = array(
+ 'id' => '',
+ 'href' => '',
+ 'text' => '',
+ 'active' => false,
+ 'level' => 1,
+ 'containsactive' => false,
+ 'external' => false,
+ );
+
+ /**
+ *
+ * @var array
+ */
+ private static $aNavigationSites = null;
/**
* Constructor of TopMenuBarCustomizer class
@@ -55,7 +73,7 @@
EXTINFO::STATUS => 'default',
EXTINFO::PACKAGE => 'default',
EXTINFO::URL => 'http://www.hallowelt.biz',
- EXTINFO::DEPS => array( 'bluespice' => '2.22.0' )
+ EXTINFO::DEPS => array( 'bluespice' => '2.23.0' )
);
$this->mExtensionKey = 'TopMenuBarCustomizer';
@@ -66,8 +84,9 @@
*/
public function initExt() {
//TODO: Add some error massages on article save (more than 5
entrys etc.)
- $this->setHook( 'BeforePageDisplay' );
$this->setHook( 'SkinTemplateOutputPageBeforeExec' );
+ $this->setHook( 'BeforePageDisplay' );
+ $this->setHook( 'EditFormPreloadText' );
BsConfig::registerVar('MW::TopMenuBarCustomizer::NuberOfLevels', 2,
BsConfig::LEVEL_PUBLIC|BsConfig::TYPE_INT,
'bs-topmenubarcustomizer-pref-numberoflevels' );
BsConfig::registerVar('MW::TopMenuBarCustomizer::NumberOfMainEntries', 10,
BsConfig::LEVEL_PUBLIC|BsConfig::TYPE_INT,
'bs-topmenubarcustomizer-pref-numberofmainentries', 'int' );
@@ -75,13 +94,81 @@
}
/**
- * Hook-Handler for MediaWiki 'BeforePageDisplay' hook.
- * @param OutputPage $oOutputPage
- * @param Skin $oSkin
- * @return bool
+ * Getter for the $aNavigationSites array - either from hook or
TopBarMenu title
+ * @global string $wgSitename
+ * @return array
*/
- public function onBeforePageDisplay( &$oOutputPage, &$oSkin ) {
- $oOutputPage->addModules('ext.bluespice.topmenubarcustomizer');
+ public static function getNavigationSites() {
+ if( !is_null(self::$aNavigationSites) ) return
self::$aNavigationSites;
+ self::$aNavigationSites = array();
+
+ $oTopBarMenuTitle = Title::makeTitle( NS_MEDIAWIKI,
'TopBarMenu' );
+
+ if( !is_null($oTopBarMenuTitle) && $oTopBarMenuTitle->exists()
) {
+ $sContent = BsPageContentProvider::getInstance()
+ ->getContentFromTitle( $oTopBarMenuTitle );
+
+ // force unset Applications by create an empty page
+ if( !empty($sContent) ) {
+ self::$aNavigationSites =
TopMenuBarCustomizerParser::getNavigationSites();
+ }
+ return self::$aNavigationSites;
+ }
+
+ global $wgSitename;
+ $oCurrentTitle = RequestContext::getMain()->getTitle();
+ $oMainPage = Title::newMainPage();
+
+ self::$aNavigationSites[] = array(
+ 'id' => 'wiki',
+ 'href' => $oMainPage->getFullURL(),
+ 'text' => $wgSitename,
+ 'active' => $oCurrentTitle->equals( $oMainPage ),
+ 'level' => 1,
+ 'containsactive' => false,
+ 'external' => false,
+ 'children' => array(),
+ );
+
+ wfRunHooks('BSTopMenuBarCustomizerRegisterNavigationSites',
array( &self::$aNavigationSites ));
+
+ return self::$aNavigationSites;
+ }
+
+ /**
+ * Hook-Handle for MW hook EditFormPreloadText
+ * @param string $sText
+ * @param Title $oTitle
+ * @return boolean - always true
+ */
+ public function onEditFormPreloadText($sText, $oTitle) {
+ $oTopBarMenuTitle = Title::makeTitle( NS_MEDIAWIKI,
'TopBarMenu' );
+ if( !$oTopBarMenuTitle || !$oTitle->equals($oTopBarMenuTitle) )
return true;
+
+ $aNavigationSites = self::getNavigationSites();
+ if( empty($aNavigationSites) ) {
+ return true;
+ }
+
+ $sText = TopMenuBarCustomizerParser::toWikiText(
$aNavigationSites, $sText );
+
+ return true;
+ }
+
+ /**
+ * Hook-Handle for MW hook BeforePageDisplay - Sets modules if needed
+ * @param OutputPage $out
+ * @param Skin $skin
+ * @return boolean - always true
+ */
+ public function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) {
+ $aNavigationSites = self::getNavigationSites();
+ if( empty($aNavigationSites) ) {
+ return true;
+ }
+
+ $out->addModules( 'ext.bluespice.topmenubarcustomizer' );
+ $out->addModuleStyles(
'ext.bluespice.topmenubarcustomizer.styles' );
return true;
}
@@ -92,26 +179,21 @@
* @return boolean Always true to keep hook running
*/
public function onSkinTemplateOutputPageBeforeExec( &$sktemplate, &$tpl
){
- $oTopBarMenuTitle = Title::makeTitle( NS_MEDIAWIKI,
'TopBarMenu' );
- if( is_null($oTopBarMenuTitle ) || !$oTopBarMenuTitle->exists()
) {
+ if( !isset($tpl->data['bs_navigation_sites']) ) return true;
+
+ $aNavigationSites = self::getNavigationSites();
+ if( empty($aNavigationSites) ) {
+ unset( $tpl->data['bs_navigation_sites'] );
return true;
}
- $newAppList = BsPageContentProvider::getInstance()
- ->getContentFromTitle( $oTopBarMenuTitle );
-
- // force unset Applications by create an empty page
- if( $newAppList === "" ) {
- unset($tpl->data['bs_navigation_sites']);
- return true;
- }
- $this->aOldApps = $tpl->data['bs_navigation_sites'];
- $aLines = explode( "\n", trim( $newAppList ) );
- $this->aApps = $this->parseArticleContentLines( $aLines );
+ wfRunHooks('BSTopMenuBarCustomizerBeforeRenderNavigationSites',
array( &$aNavigationSites ));
$aOut= array();
- foreach( $this->aApps as $aApp ) {
- $oMainItem = new ViewTopMenuItemMain();
+ $aOut[] = HTML::openElement( 'ul' );
+ foreach( self::getNavigationSites() as $aApp ) {
+ $aApp = array_merge(self::$aNavigationSiteTemplate,
$aApp);
+ $oMainItem = new ViewTopMenuItem();
$oMainItem->setLevel( $aApp['level'] );
$oMainItem->setName( $aApp['id'] );
$oMainItem->setLink( $aApp['href'] );
@@ -124,159 +206,10 @@
}
$aOut[] = $oMainItem->execute();
}
+ $aOut[] = HTML::closeElement( 'ul' );
$tpl->data['bs_navigation_sites'] = implode( "\n", $aOut );
return true;
- }
-
- /**
- * Returns recursively all parsed menu items (apps)
- * @param type $aLines
- * @param type $aApps
- * @param type $iPassed
- * @return Array
- */
- private function parseArticleContentLines( $aLines, $aApps = array(),
$iPassed = 0 ) {
- $iAllowedLevels =
BsConfig::get('MW::TopMenuBarCustomizer::NuberOfLevels');
- $iMaxEntrys = ( $iPassed === 0 )
- ?
BsConfig::get('MW::TopMenuBarCustomizer::NumberOfMainEntries') -1
- :
BsConfig::get('MW::TopMenuBarCustomizer::NumberOfSubEntries') -1;
-
- if ( $iAllowedLevels < 1 || $iMaxEntrys < 1 ) {
- return $aApps;
- }
-
- $iPassed++;
- $aChildLines = array();
- $i = 0;
- for ( $i; $i < count($aLines); $i++ ) {
- $aLines[$i] = trim($aLines[$i]);
- //prevents from lines without * and list starts without
parent item
- if ( strpos( $aLines[$i], '*' ) !== 0 || (strpos(
$aLines[$i], '**' ) === 0 && $i == 0)) {
- continue;
- }
-
- if ( strpos( $aLines[$i], '**' ) === 0 ) {
- if($iPassed < $iAllowedLevels) {
- $aChildLines[] = substr($aLines[$i], 1);
- }
- continue;
- }
- if ( !empty( $aChildLines ) ) {
- $iLastKey = key( array_slice( $aApps, -1, 1,
TRUE ) );
- $aApps[$iLastKey]['children'] =
$this->parseArticleContentLines( $aChildLines, array() ,$iPassed );
- foreach( $aApps[$iLastKey]['children'] as
$aChildApps ) {
- if( !$aChildApps['active'] &&
!$aChildApps['containsactive'] ) {
- continue;
- }
- $aApps[$iLastKey]['containsactive'] =
true;
- break;
- }
- $aChildLines = array();
- }
-
- if ( count($aApps) > $iMaxEntrys) {
- continue;
- }
-
- $aApp = $this->parseSingleLine( substr($aLines[$i], 1)
);
- if( empty($aApp) ) {
- continue;
- }
-
- $aApp['level'] = $iPassed;
- $aApps[] = $aApp;
- }
- //add childern to the last element
- if( !empty( $aChildLines ) ) {
- $iLastKey = key( array_slice( $aApps, -1, 1, true ) );
- $aApps[$iLastKey]['children'] =
$this->parseArticleContentLines( $aChildLines, array() ,$iPassed );
- foreach ( $aApps[$iLastKey]['children'] as $aChildApps
) {
- if ( !$aChildApps['active'] &&
!$aChildApps['containsactive'] ) {
- continue;
- }
- $aApps[$iLastKey]['containsactive'] = true;
- break;
- }
- }
-
- return $aApps;
- }
-
- /**
- * Parses a single menu item
- * @global Title $wgTitle
- * @param String $sLine
- * @return Array - Single parsed menu item (app)
- */
- private function parseSingleLine( $sLine ) {
- global $wgTitle, $wgServer, $wgScriptPath;
- $newApp = array(
- 'id' => '',
- 'href' => '',
- 'text' => '',
- 'active' => false,
- 'containsactive' => false,
- 'external' => false,
- );
-
- $aAppParts = explode( '|', trim ( $sLine ) );
- foreach( $aAppParts as $key => $val ) {
- $aAppParts[$key ] = trim( $val );
- }
- if( empty($aAppParts[0]) ) {
- return array();
- }
- $newApp['id'] = $aAppParts[0];
-
- if( !empty( $aAppParts[1] ) ) {
- $aParsedUrl = wfParseUrl( $aAppParts[1] );
- if( $aParsedUrl !== false ) {
- if(preg_match('# |\\*#',$aParsedUrl['host'])) {
- //$sParseError = $newApp; not in use
- }
- if( $aParsedUrl['scheme'] == 'http' ||
$aParsedUrl['scheme'] == 'https' ) {
- $sQuery = !empty( $aParsedUrl['query']
) ? '?'.$aParsedUrl['query'] : '';
- $newApp['href'] =
$aParsedUrl['scheme'].$aParsedUrl['delimiter'].$aParsedUrl['host'].$aParsedUrl['path'].$sQuery;
- $newApp['external'] = true;
- }
- } else if( strpos($aAppParts[1], '?') === 0 ) {
//?action=blog
- $newApp['href'] =
$wgServer.$wgScriptPath.'/'.$aAppParts[1];
- } else {
- $oTitle = Title::newFromText(
trim($aAppParts[1]) );
- if( is_null($oTitle) ) {
- //$sParseError = $newApp; not in use
- } else {
- $newApp['href'] = $oTitle->getFullURL();
- if( $oTitle->equals($wgTitle) ) {
- $newApp['active'] = true;
- }
- }
- }
- } else {
- $newApp['href'] = $wgServer.$wgScriptPath;
- }
-
- if( !empty( $aAppParts[2] ) ) {
- $newApp['text'] = $aAppParts[2];
- }
-
- //get old menu entries with the same id
- foreach($this->aOldApps as $key => $aOldApp) {
- if( $aOldApp['id'] == $newApp['id'] ) {
- if( empty($aAppParts[1]) ) {
- //no new url given - use old url
- $newApp['href'] = $aOldApp['href'];
- }
- if( empty($aAppParts[2]) ) {
- //no new display title - use old text
- $newApp['text'] = $aOldApp['text'];
- }
- break;
- }
- }
-
- return $newApp;
}
}
\ No newline at end of file
diff --git a/TopMenuBarCustomizer/TopMenuBarCustomizer.setup.php
b/TopMenuBarCustomizer/TopMenuBarCustomizer.setup.php
index e29734d..46362d6 100644
--- a/TopMenuBarCustomizer/TopMenuBarCustomizer.setup.php
+++ b/TopMenuBarCustomizer/TopMenuBarCustomizer.setup.php
@@ -1,18 +1,30 @@
<?php
-
-BsExtensionManager::registerExtension('TopMenuBarCustomizer',
BsRUNLEVEL::FULL|BsRUNLEVEL::REMOTE);
-
-$wgMessagesDirs['TopMenuBarCustomizer'] = __DIR__ . '/i18n';
-
-$wgExtensionMessagesFiles['TopMenuBarCustomizer'] = __DIR__ .
'/languages/TopMenuBarCustomizer.i18n.php';
-
-$wgResourceModules['ext.bluespice.topmenubarcustomizer'] = array(
- 'scripts' =>
'extensions/BlueSpiceExtensions/TopMenuBarCustomizer/resources/bluespice.TopMenuBarCustomizer.js',
- 'styles' =>
'extensions/BlueSpiceExtensions/TopMenuBarCustomizer/resources/bluespice.TopMenuBarCustomizer.css',
- 'position' => 'top',
- 'localBasePath' => $IP,
- 'remoteBasePath' => &$GLOBALS['wgScriptPath']
+BsExtensionManager::registerExtension(
+ 'TopMenuBarCustomizer',
+ BsRUNLEVEL::FULL|BsRUNLEVEL::REMOTE
);
-$wgAutoloadClasses['ViewTopMenuItem'] = __DIR__.'/views/view.TopMenuItem.php';
-$wgAutoloadClasses['ViewTopMenuItemMain'] =
__DIR__.'/views/view.TopMenuItemMain.php';
\ No newline at end of file
+$aResourceModuleTemplate = array(
+ 'dependencies' => 'ext.bluespice',
+ 'localBasePath' =>
"$IP/extensions/BlueSpiceExtensions/TopMenuBarCustomizer/resources",
+ 'remoteExtPath' => 'BlueSpiceExtensions/TopMenuBarCustomizer/resources'
+);
+
+$wgMessagesDirs['TopMenuBarCustomizer'] = __DIR__."/i18n";
+
+$wgExtensionMessagesFiles['TopMenuBarCustomizer'] =
__DIR__."/languages/TopMenuBarCustomizer.i18n.php";
+
+$wgAutoloadClasses['TopMenuBarCustomizerParser'] =
__DIR__."/includes/TopMenuBarCustomizerParser.php";
+$wgAutoloadClasses['ViewTopMenuItem'] = __DIR__."/views/view.TopMenuItem.php";
+
+$wgResourceModules['ext.bluespice.topmenubarcustomizer'] = array(
+ 'scripts' => 'bluespice.TopMenuBarCustomizer.js',
+ 'position' => 'top',
+) + $aResourceModuleTemplate;
+
+$wgResourceModules['ext.bluespice.topmenubarcustomizer.styles'] = array(
+ 'styles' => 'bluespice.TopMenuBarCustomizer.css',
+ 'position' => 'top',
+) + $aResourceModuleTemplate;
+
+unset($aResourceModuleTemplate);
\ No newline at end of file
diff --git a/TopMenuBarCustomizer/doc/Hooks.txt
b/TopMenuBarCustomizer/doc/Hooks.txt
index 3367792..47167d7 100644
--- a/TopMenuBarCustomizer/doc/Hooks.txt
+++ b/TopMenuBarCustomizer/doc/Hooks.txt
@@ -1,8 +1,9 @@
==TopMenuBarCustomizer.class.php==
-'BSBlueSpiceSkin:ApplicationList':
-&$aApplications.
- &$sCurrentApplicationContext:
- $wgUser:
- &$aOut:
- $this:
+If there is no MediaWiki:TopBarMenu title this array will be used to create
the navigation sites
+'BSTopMenuBarCustomizerRegisterNavigationSites':
+ &$aNavigationSites - multidimensional array which will be processed
recursively
+
+Last chance to edit params before they will be rendered
+'BSTopMenuBarCustomizerBeforeRenderNavigationSites':
+ &$aNavigationSites - multidimensional array which will be processed
recursively
\ No newline at end of file
diff --git a/TopMenuBarCustomizer/includes/TopMenuBarCustomizerParser.php
b/TopMenuBarCustomizer/includes/TopMenuBarCustomizerParser.php
new file mode 100644
index 0000000..067c46e
--- /dev/null
+++ b/TopMenuBarCustomizer/includes/TopMenuBarCustomizerParser.php
@@ -0,0 +1,272 @@
+<?php
+/**
+ * TopMenuBarCustomizerParser class for extension TopMenuBarCustomizer
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * This file is part of BlueSpice for MediaWiki
+ * For further information visit http://www.blue-spice.org
+ *
+ * @author Patric Wirth <[email protected]>
+ * @version 2.23.0
+ * @package BlueSpice_Extensions
+ * @subpackage TopMenuBarCustomizer
+ * @copyright Copyright (C) 2011 Hallo Welt! - Medienwerkstatt GmbH, All
rights reserved.
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License v2 or
later
+ * @filesource
+ */
+
+/**
+ * TopMenuBarCustomizerParser class for TopMenuBarCustomizer extension
+ * @package BlueSpice_Extensions
+ * @subpackage TopMenuBarCustomizer
+ */
+class TopMenuBarCustomizerParser {
+ private static $aNavigationSites = null;
+
+ /**
+ * Getter for $aNavigationSites array
+ * @param boolean $bForceReload
+ * @return array
+ */
+ public static function getNavigationSites( $bForceReload = false ) {
+ if( !$bForceReload && !is_null(self::$aNavigationSites) )
return self::$aNavigationSites;
+ self::$aNavigationSites = array();
+
+ $oTopBarMenuTitle = Title::makeTitle( NS_MEDIAWIKI,
'TopBarMenu' );
+ if( is_null($oTopBarMenuTitle ) || !$oTopBarMenuTitle->exists()
) {
+ return self::$aNavigationSites;
+ }
+
+ $sContent = BsPageContentProvider::getInstance()
+ ->getContentFromTitle( $oTopBarMenuTitle );
+
+ $aLines = explode( "\n", trim( $sContent ) );
+
+ $iMaxMainEntries =
BsConfig::get('MW::TopMenuBarCustomizer::NumberOfMainEntries');
+ $iMaxSubEntries =
BsConfig::get('MW::TopMenuBarCustomizer::NumberOfSubEntries');
+ $iAllowedLevels =
BsConfig::get('MW::TopMenuBarCustomizer::NuberOfLevels');
+
+ self::$aNavigationSites = self::parseArticleContentLines(
+ $aLines,
+ $iAllowedLevels,
+ $iMaxMainEntries,
+ $iMaxSubEntries
+ );
+
+ return self::$aNavigationSites;
+ }
+
+ /**
+ * Returns recursively all parsed menu items
+ * TODO: Clean up
+ * @param type $aLines
+ * @param type $aApps
+ * @param type $iPassed
+ * @return Array
+ */
+ private static function parseArticleContentLines( $aLines,
$iAllowedLevels = 2, $iMaxMainEntries = 5, $iMaxSubEntries = 20, $aApps =
array(), $iPassed = 0 ) {
+ $iMaxEntrys = ( $iPassed === 0 ) ? $iMaxMainEntries -1 :
$iMaxSubEntries -1;
+
+ if ( $iAllowedLevels < 1 || $iMaxEntrys < 1 ) {
+ return $aApps;
+ }
+
+ $iPassed++;
+ $aChildLines = array();
+ $iCount = count($aLines);
+ $i = 0;
+ for ( $i; $i < $iCount; $i++ ) {
+ $aLines[$i] = trim($aLines[$i]);
+ //prevents from lines without * and list starts without
parent item
+ if ( strpos( $aLines[$i], '*' ) !== 0 || (strpos(
$aLines[$i], '**' ) === 0 && $i == 0)) {
+ continue;
+ }
+
+ if ( strpos( $aLines[$i], '**' ) === 0 ) {
+ if($iPassed < $iAllowedLevels) {
+ $aChildLines[] = substr($aLines[$i], 1);
+ }
+ continue;
+ }
+ if ( !empty( $aChildLines ) ) {
+ $iLastKey = key( array_slice( $aApps, -1, 1,
TRUE ) );
+ $aApps[$iLastKey]['children'] =
self::parseArticleContentLines(
+ $aChildLines,
+ $iAllowedLevels,
+ $iMaxMainEntries,
+ $iMaxSubEntries,
+ array(),
+ $iPassed
+ );
+ foreach( $aApps[$iLastKey]['children'] as
$aChildApps ) {
+ if( !$aChildApps['active'] &&
!$aChildApps['containsactive'] ) {
+ continue;
+ }
+ $aApps[$iLastKey]['containsactive'] =
true;
+ break;
+ }
+ $aChildLines = array();
+ }
+
+ if ( count($aApps) > $iMaxEntrys) {
+ continue;
+ }
+
+ $aApp = self::parseSingleLine( substr($aLines[$i], 1) );
+ if( empty($aApp) ) {
+ continue;
+ }
+
+ $aApp['level'] = $iPassed;
+ $aApps[] = $aApp;
+ }
+ //add childern to the last element
+ if( !empty( $aChildLines ) ) {
+ $iLastKey = key( array_slice( $aApps, -1, 1, true ) );
+ $aApps[$iLastKey]['children'] =
self::parseArticleContentLines( $aChildLines,
+ $iAllowedLevels,
+ $iMaxMainEntries,
+ $iMaxSubEntries,
+ array(),
+ $iPassed
+ );
+ foreach ( $aApps[$iLastKey]['children'] as $aChildApps
) {
+ if ( !$aChildApps['active'] &&
!$aChildApps['containsactive'] ) {
+ continue;
+ }
+ $aApps[$iLastKey]['containsactive'] = true;
+ break;
+ }
+ }
+
+ return $aApps;
+ }
+
+ /**
+ * Parses a single menu item
+ * TODO: Clean up
+ * @global Title $wgTitle
+ * @param String $sLine
+ * @return Array - Single parsed menu item (app)
+ */
+ public static function parseSingleLine( $sLine ) {
+ global $wgTitle, $wgServer, $wgScriptPath;
+ $newApp = TopMenuBarCustomizer::$aNavigationSiteTemplate;
+
+ $aAppParts = explode( '|', trim ( $sLine ) );
+ foreach( $aAppParts as $key => $val ) {
+ $aAppParts[$key ] = trim( $val );
+ }
+ if( empty($aAppParts[0]) ) {
+ return array();
+ }
+ $newApp['id'] = $aAppParts[0];
+
+ if( !empty( $aAppParts[1] ) ) {
+ $aParsedUrl = wfParseUrl( $aAppParts[1] );
+ if( $aParsedUrl !== false ) {
+ if(preg_match('# |\\*#',$aParsedUrl['host'])) {
+ //TODO: Use status ojb on
BeforeArticleSave to detect parse errors
+ }
+ if( $aParsedUrl['scheme'] == 'http' ||
$aParsedUrl['scheme'] == 'https' ) {
+ $sQuery = !empty( $aParsedUrl['query']
) ? '?'.$aParsedUrl['query'] : '';
+ if( !isset($aParsedUrl['path']) )
$aParsedUrl['path'] = '';
+ $newApp['href'] =
$aParsedUrl['scheme'].$aParsedUrl['delimiter'].$aParsedUrl['host'].$aParsedUrl['path'].$sQuery;
+ $newApp['external'] = true;
+ }
+ } else if( strpos($aAppParts[1], '?') === 0 ) {
//?action=blog
+ $newApp['href'] =
$wgServer.$wgScriptPath.'/'.$aAppParts[1];
+ } else {
+ $oTitle = Title::newFromText(
trim($aAppParts[1]) );
+ if( is_null($oTitle) ) {
+ //TODO: Use status ojb on
BeforeArticleSave to detect parse errors
+ } else {
+ $newApp['href'] = $oTitle->getFullURL();
+ if( $oTitle->equals($wgTitle) ) {
+ $newApp['active'] = true;
+ }
+ }
+ }
+ } else {
+ $newApp['href'] = $wgServer.$wgScriptPath;
+ }
+
+ if( !empty( $aAppParts[2] ) ) {
+ $newApp['text'] = $aAppParts[2];
+ }
+
+ return $newApp;
+ }
+
+ /**
+ * Returns wikitext list from recursively processed array
+ * @global string $wgArticlePath
+ * @param array $aNavigationSites
+ * @param string $sWikiText
+ * @param string $sPrefix
+ * @return type
+ */
+ public static function toWikiText( $aNavigationSites, $sWikiText = '',
$sPrefix = '*' ) {
+ foreach( $aNavigationSites as $aNavigationSite ) {
+ $sText = $sHref = '';
+
+ if( !empty($aNavigationSite['href']) ) {
+ $sHref = '|';
+
+ if( !isset($aNavigationSite['external']) ||
!$aNavigationSite['external'] ) {
+ //extract Title from url - maybe not
100% accurate
+ global $wgArticlePath;
+ $aInternalUrl = explode(
+ substr($wgArticlePath, 0, -2),
//remove $1
+ 'A'.$aNavigationSite['href']
//Added A - url could be relative
+ );
+
+ if( !isset($aInternalUrl[1]) ) {
+ $sHref .=
$aNavigationSite['href'];
+ } else {
+ $sHref .= $aInternalUrl[1];
+ /* TODO: Remove query - not yet
needed
+ if( strpos($aInternalUrl[1],
'?') !== false ) {
+ $sHref .= substr(
+
$aInternalUrl[1],
+ 0,
+ strpos(
$aInternalUrl[1], '?')
+ );
+ } elseif(
strpos($aInternalUrl[1], '&' ) !== false) {
+ $sHref .= substr(
+
$aInternalUrl[1],
+ 0,
+ strpos(
$aInternalUrl[1], '&')
+ );
+ }*/
+ }
+ } else {
+ $sHref .= $aNavigationSite['href'];
+ }
+ if( !empty($aNavigationSite['text']) ) {
+ $sText = '|'.$aNavigationSite['text'];
+ }
+ }
+
+ $sWikiText .=
"$sPrefix{$aNavigationSite['id']}$sHref$sText\n";
+ if( empty($aNavigationSite['children']) ) continue;
+
+ $sWikiText =
self::toWikiText($aNavigationSite['children'], $sWikiText, "*$sPrefix");
+ }
+ return $sWikiText;
+ }
+}
\ No newline at end of file
diff --git a/TopMenuBarCustomizer/resources/bluespice.TopMenuBarCustomizer.js
b/TopMenuBarCustomizer/resources/bluespice.TopMenuBarCustomizer.js
index c751bb1..dc83d00 100644
--- a/TopMenuBarCustomizer/resources/bluespice.TopMenuBarCustomizer.js
+++ b/TopMenuBarCustomizer/resources/bluespice.TopMenuBarCustomizer.js
@@ -2,7 +2,6 @@
* Js for TopMenuBarCustomizer extension
*
* @author Patric Wirth <[email protected]>
-
* @package Bluespice_Extensions
* @subpackage TopMenuBarCustomizer
* @copyright Copyright (C) 2011 Hallo Welt! - Medienwerkstatt GmbH, All
rights reserved.
@@ -11,13 +10,13 @@
*/
$(document).ready(function(){
- $('.menu-item-container').hover( function(){
+ $('.menu-item-container').hover( function(){
$(this).siblings('ul.bs-apps-child').stop(true,true).slideDown('fast');
},
function(){
$(this).siblings('ul.bs-apps-child').stop(true,true).delay(100).slideUp('fast');
}
- )
+ );
$('ul.bs-apps-child').hover( function(){
$(this).stop(true,true).slideDown('fast');
@@ -25,5 +24,5 @@
function(){
$(this).stop(true,true).delay(100).slideUp('fast');
}
- )
+ );
});
\ No newline at end of file
diff --git a/TopMenuBarCustomizer/views/view.TopMenuItem.php
b/TopMenuBarCustomizer/views/view.TopMenuItem.php
index 6d3fec9..1bb7da7 100644
--- a/TopMenuBarCustomizer/views/view.TopMenuItem.php
+++ b/TopMenuBarCustomizer/views/view.TopMenuItem.php
@@ -1,6 +1,6 @@
<?php
/**
- * Renders the a sub-item of the top bar menu.
+ * Renders the a navigation item of the top bar menu.
*
* Part of BlueSpice for MediaWiki
*
@@ -14,7 +14,7 @@
*/
/**
- * This view renders sub-item.
+ * This view renders a navigation item.
* @package BlueSpice_Extensions
* @subpackage TopMenuBarCustomizer
*/
@@ -138,35 +138,48 @@
* @return string HTML output
*/
public function execute( $aParams = false ) {
- $sClass = empty($this->aChildren) ? 'menu-item-single' :
'menu-item-container';
- $sClass .= ' level-'.$this->iLevel;
- if( $this->bContainsActive) $sClass .= ' contains-active';
- if( $this->bActive) $sClass .= ' active';
+ $aClasses = array();
+
+ $aClasses[] = empty($this->aChildren) ? 'menu-item-single' :
'menu-item-container';
+ $aClasses[] = "level-$this->iLevel";
+ if( $this->bContainsActive) $aClasses[] = 'contains-active';
+ if( $this->bActive) $aClasses[] = 'active';
+
+ $sTitle = $sText = empty($this->sDisplayTitle) ? $this->sName :
$this->sDisplayTitle;
+ if( wfMessage($sTitle)->exists() ) {
+ $sTitle = $sText = wfMessage($sTitle)->plain();
+ }
global $wgExternalLinkTarget;
- $sLinkTarget = '';
- if( $this->bExternal && !empty($wgExternalLinkTarget) )
$sLinkTarget = 'target="'.$wgExternalLinkTarget.'"';
- $aOut = array();
- $aOut[] = '<li>';
- $aOut[] = ' <a href="'.$this->sLink .'" title="'.(
empty($this->sDisplayTitle) ? $this->sName : $this->sDisplayTitle ).'"
class="'.$sClass.'" '.$sLinkTarget.'>'.( empty($this->sDisplayTitle) ?
$this->sName : $this->sDisplayTitle ).'</a>';
- if( !empty($this->aChildren) ) {
- $aOut[] = $this->rederChildItems();
+ $sLinkTarget = '';
+ if( $this->bExternal && !empty($wgExternalLinkTarget) ) {
+ $sLinkTarget = 'target="'.$wgExternalLinkTarget.'"';
}
- $aOut[] = '</li>';
- return implode( "\n", $aOut);
+
+ $sOut = '';
+ $sOut .= '<li>';
+ $sOut .= "<a href='$this->sLink' title='$sTitle'
class='".implode(' ', $aClasses)."' $sLinkTarget>$sText</a>";
+ if( !empty($this->aChildren) ) {
+ $sOut .= $this->rederChildItems();
+ }
+ $sOut .= '</li>';
+ return $sOut;
}
private function rederChildItems() {
$aOut[] ='<ul class="bs-apps-child
level-'.($this->iLevel+1).'">';
foreach( $this->aChildren as $aApp ) {
+ $aApp =
array_merge(TopMenuBarCustomizer::$aNavigationSiteTemplate, $aApp);
+
$oItem = new ViewTopMenuItem();
$oItem->setLevel( $aApp['level'] );
$oItem->setName( $aApp['id'] );
$oItem->setLink( $aApp['href'] );
- $oItem->setDisplaytitle( $aApp['text'] );
$oItem->setActive( $aApp['active'] );
+ $oItem->setExternal( $aApp['external'] );
+ $oItem->setDisplaytitle( $aApp['text'] );
$oItem->setContainsActive( $aApp['containsactive'] );
if( !empty($aApp['children']) ) {
$oItem->setChildren( $aApp['children'] );
diff --git a/TopMenuBarCustomizer/views/view.TopMenuItemMain.php
b/TopMenuBarCustomizer/views/view.TopMenuItemMain.php
deleted file mode 100644
index 2cb8c38..0000000
--- a/TopMenuBarCustomizer/views/view.TopMenuItemMain.php
+++ /dev/null
@@ -1,181 +0,0 @@
-<?php
-/**
- * Renders the main (level1) item of the top bar menu.
- *
- * Part of BlueSpice for MediaWiki
- *
- * @author Patric Wirth <[email protected]>
-
- * @package BlueSpice_Extensions
- * @subpackage TopMenuBarCustomizer
- * @copyright Copyright (C) 2011 Hallo Welt! - Medienwerkstatt GmbH, All
rights reserved.
- * @license http://www.gnu.org/copyleft/gpl.html GNU Public License v2 or
later
- * @filesource
- */
-
-/**
- * This view renders the main item.
- * @package BlueSpice_Extensions
- * @subpackage TopMenuBarCustomizer
- */
-class ViewTopMenuItemMain extends ViewBaseElement {
-
- /**
- * Item level
- * @var integer
- */
- protected $iLevel = 1;
- /**
- * Name of the item
- * @var string
- */
- protected $sName = '';
- /**
- * Displayname of the item
- * @var string
- */
- protected $sDisplayTitle = '';
- /**
- * Target link
- * @var string
- */
- protected $sLink = '';
- /**
- * is this item active
- * @var boolean
- */
- protected $bActive = false;
- /**
- * is this item active
- * @var boolean
- */
- protected $bContainsActive = false;
- /**
- * is this item external
- * @var boolean
- */
- protected $bExternal = false;
- /**
- * has this item child items
- * @var array
- */
- protected $aChildren = array();
-
- /**
- * Constructor
- */
- public function __construct() {
- parent::__construct();
- }
-
- /**
- * Sets the level property
- * @param integer $iLevel
- */
- public function setLevel( $iLevel ) {
- $this->iLevel = $iLevel;
- }
-
- /**
- * Sets the name property
- * @param string $sName
- */
- public function setName( $sName ) {
- $this->sName = $sName;
- }
-
- /**
- * Sets the display title property
- * @param string $sDisplayTitle
- */
- public function setDisplaytitle( $sDisplayTitle ) {
- $this->sDisplayTitle = $sDisplayTitle;
- }
-
- /**
- * Sets the Link property
- * @param string $sLink
- */
- public function setLink( $sLink ) {
- $this->sLink = $sLink;
- }
-
- /**
- * Sets the active property
- * @param boolean $bActive
- */
- public function setActive( $bActive ) {
- $this->bActive = $bActive;
- }
-
- /**
- * Sets the contains active property
- * @param boolean $bContainsActive
- */
- public function setContainsActive( $bContainsActive ) {
- $this->bContainsActive = $bContainsActive;
- }
-
- /**
- * Sets the external property
- * @param boolean $bExternal
- */
- public function setExternal( $bExternal ) {
- $this->bExternal = $bExternal;
- }
-
- /**
- * Sets the children property
- * @param boolean $aChildren
- */
- public function setChildren( $aChildren ) {
- $this->aChildren = $aChildren;
- }
-
- /**
- * This method actually generates the output
- * @param array $aParams not used here
- * @return string HTML output
- */
- public function execute( $aParams = false ) {
- $sClass = empty($this->aChildren) ? 'menu-item-single' :
'menu-item-container';
- $sClass .= ' level-'.$this->iLevel;
- if( $this->bContainsActive) $sClass .= ' contains-active';
- if( $this->bActive) $sClass .= ' active';
-
- global $wgExternalLinkTarget;
- $sLinkTarget = '';
- if( $this->bExternal && !empty($wgExternalLinkTarget) )
$sLinkTarget = 'target="'.$wgExternalLinkTarget.'"';
-
- $aOut = array();
- $aOut[] = '<li>';
- $aOut[] = ' <a href="'.$this->sLink .'" title="'.(
empty($this->sDisplayTitle) ? $this->sName : $this->sDisplayTitle ).'"
class="'.$sClass.'" '.$sLinkTarget.'>'.( empty($this->sDisplayTitle) ?
$this->sName : $this->sDisplayTitle ).'</a>';
- if( !empty($this->aChildren) ) {
- $aOut[] = $this->rederChildItems();
- }
- $aOut[] = '</li>';
- return implode( "\n", $aOut);
- }
-
- private function rederChildItems() {
- $aOut[] ='<ul class="bs-apps-child
level-'.($this->iLevel+1).'">';
-
- foreach( $this->aChildren as $aApp ) {
- $oItem = new ViewTopMenuItem();
- $oItem->setLevel( $aApp['level'] );
- $oItem->setName( $aApp['id'] );
- $oItem->setLink( $aApp['href'] );
- $oItem->setDisplaytitle( $aApp['text'] );
- $oItem->setActive( $aApp['active'] );
- $oItem->setContainsActive( $aApp['containsactive'] );
- $oItem->setExternal( $aApp['external'] );
- if( !empty($aApp['children']) ) {
- $oItem->setChildren( $aApp['children'] );
- }
- $aOut[] = $oItem->execute();
- }
-
- $aOut[] ='</ul>';
- return implode( "\n", $aOut);
- }
-}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/148638
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id6cf25fd83d883170c727574d5858595befdf84d
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: master
Gerrit-Owner: Pwirth <[email protected]>
Gerrit-Reviewer: Mglaser <[email protected]>
Gerrit-Reviewer: Pigpen <[email protected]>
Gerrit-Reviewer: Robert Vogel <[email protected]>
Gerrit-Reviewer: Smuggli <[email protected]>
Gerrit-Reviewer: Swidmann <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits