Extension talk:CustomSidebar
Comments & bug reports welcome :) --Frantik 08:46, 28 May 2009 (UTC)
TOC in sidebar
editWhy doesn't
<sidebar>__TOC__</sidebar>
work? Trying to put a Table of Contents in the sidebar.
- well even if it replaces correctly, which i doubt, the text wouldn't be in the proper format --Frantik 08:38, 17 April 2010 (UTC)
- is there a way to do such a thing using your extension? get the TOC to render in the sidebar? --two7s_clash
- not at this time --Frantik 19:54, 17 April 2010 (UTC)
<sidebar> not transcluded from templates
editI'm trying to add a custom sidebar through a template. I've put a custom sidebar (using the <sibebar> tag) in a template. However, when I include the template in a page, the custom sidebar doesn't show on that page; instead the sidebar shows up on the template page. This happens even though the <sibebar> tags appear between <includeonly> tags.
Any ideas for a fix or workaround? I'm no Wiki expert, but I'm guessing it has something to do with searching for <sibebar> tag in wgArticle->getContent() without parsing it first? ~KH
- Fixed my own problem! Preprocessing the article text solves this issue. I've managed this by initiating a parser (+ parseroptions) and replacing
$pagetext = $wgArticle->getContent();
with$pagetext = $wgParser->preprocess( $wgArticle->getContent(), $wgArticle->getTitle(), $opt );
Please add this fix or a similar solution in the next revision of this extension. ~KH- Cool thanks :) I've been meaning to release a newly updated version with many new features; I will include your changes as well. --Frantik 09:44, 7 August 2009 (UTC)
- I was able to use your suggestion to enable full template support, so thanks :) version 0.3.0 is available for download now --Frantik 22:34, 9 August 2009 (UTC)
- Cool thanks :) I've been meaning to release a newly updated version with many new features; I will include your changes as well. --Frantik 09:44, 7 August 2009 (UTC)
Adding a second bar?
editThank you for the good extension. I wonder if it would be possible to add another function to call within the skin php file, as we do with the buildsidebar built in function? I mean a "build_top_bar" function that works as your extended sidebar. Can you implement this? Generating a second bar different to manage via your extension would be really nice for me (though it has to be customized in the skin).--Federicodip 20:14, 8 August 2009 (UTC)
- I'm not quite sure I understand what you mean --Frantik 10:58, 9 August 2009 (UTC)
- It was late night and I realize now what I wrote was cryptic. I'll try to explain my project:
- I wanted to create a second bar (topbar) that I wanted to manage like the default sidebar, editing a page wihin mediawiki (mediawiki:sidebar). This was the beginning. When I saw your extension I realized that the bar could have some dynamical content. And in the example: $wgDefaultSideBarText = 'Extension talk:CustomSidebar/Sidebar' - I saw it could be possible to customize bars content for different namespaces.
- In your extension you use a hook to change the default buildSidebar function. I don't know much about building an extension, but I thought about changing a bit of your code, using part of your extension (mostly the function fnSidebarHook) without the hook, not to change buildSidebar, but to provide a new function buildTopbar() that I could call wihin my skin file. So I could use and manage a second navigation bar, dynamically based on namespaces.
- I also thought about changing the code so that I could manage namespaces bar content using only a single page mediawiki:top(ns)bar in witch rows with a * at the beginning define namespaces, and rows with two ** at the beginning are links of that namespace, but as a php noob its not so easy for me. Anyway a $wgDefaultTopBarText would work good and I could customize many foo/(top)bar. Can you help me? Can I try to change your extension and to build a new one using your code?--Federicodip 12:05, 9 August 2009 (UTC)
- I'm not sure if you can use my extension because Mediawiki generates the HTML for the sidebar after the hook is run.. so you can't just include the function in the skin --Frantik 21:16, 9 August 2009 (UTC)
- I've seen you added "... an additional sidebar" in your 3.0 release. :D
- Can you explain a bit more how it works? I mean, does it add data to sidebar or provides a brand new one? And how must I call that bar in my skin? Something like that works?:
- <?php foreach ($this->data['new_bar'] as $bar => $cont) { ?>
- You do not add anything to your skin. The extra sidebars still appear in the sidebar region of your skin. The extra features just allow you to customize sidebars based on namespace and usergroup. instead of replacing the other sidebar text, it appends it. My extension does not access the skin layer at all, it just processes text and converts it into the format that mediawiki expects for sidebars. --Frantik 14:00, 10 August 2009 (UTC)
- I'm not sure if you can use my extension because Mediawiki generates the HTML for the sidebar after the hook is run.. so you can't just include the function in the skin --Frantik 21:16, 9 August 2009 (UTC)
CSS for Custom Sidebar?
editI have created a skin with much CSS on my wiki site. I have now included this extension CustomSidebar, but I can't find out what ID or class I can use for CSS for the generated sidebar. The custom sidebar is in this div: <div class='generated-sidebar portlet' id='p-.C2.A0'>. I have tried using both this class and id in my main.css, but the custom sidebar will not use the CSS. My MediaWiki version is 1.15.1. I would very much appreciate any advice on what to do to be able to use CSS on the custom sidebar. Thank you. HelenaH 09:30, 20 November 2010 (UTC)
- Custom sidebar does not use any custom CSS or any HTML at all, so i'm not sure exactly what your problem is or how to solve it --Frantik 00:57, 21 November 2010 (UTC)
- The CSS I use is for portlet IDs like #p-navigation and #p-tb, and all my CSS is in a separate style-sheet (a .css-file). When I installed Custom sidebar the additional (custom or generated) portlet did not look like the standard portlets. For example, I did not use bullets for the lists in p-navigation and p-tb, but the generated sidebar did have bullets. So in my sidebar I had first the default navigation-portlet without bullets, then the customsidebar with bullets, and finally the toolbox without bullets. Anyway, I solved the problem by applying the CSS to a container/div that holds all of the sidebars, since I could not find out how to style them separately. So problem solved for me now. The extension works just as intended in all other ways, that's very nice. HelenaH 06:53, 21 November 2010 (UTC)
- the code in your skin file is probably in the function customBox() if you are using a skin based off one of the default skins. as far as using class='generated-sidebar portlet', that's actually TWO classes, generated-sidebar and portlet .. if you add css for generated-sidebar you're likely to get what you wanted --Frantik 15:11, 21 November 2010 (UTC)
- The CSS I use is for portlet IDs like #p-navigation and #p-tb, and all my CSS is in a separate style-sheet (a .css-file). When I installed Custom sidebar the additional (custom or generated) portlet did not look like the standard portlets. For example, I did not use bullets for the lists in p-navigation and p-tb, but the generated sidebar did have bullets. So in my sidebar I had first the default navigation-portlet without bullets, then the customsidebar with bullets, and finally the toolbox without bullets. Anyway, I solved the problem by applying the CSS to a container/div that holds all of the sidebars, since I could not find out how to style them separately. So problem solved for me now. The extension works just as intended in all other ways, that's very nice. HelenaH 06:53, 21 November 2010 (UTC)
- Custom sidebar does not use any custom CSS or any HTML at all, so i'm not sure exactly what your problem is or how to solve it --Frantik 00:57, 21 November 2010 (UTC)
Example wikis would be nice
editExample wikis would be nice. Adamtheclown 07:22, 25 December 2010 (UTC)
Seriously! This is setup for only experts to use. How does someone create a global sidebar on the right hand side like the one shown in this wiki? What files do they edit etc? (anon)
Can't get per-namespace sidebars working in 1.16
editWe have three custom namespaces - C1, C2, and C3. Localsettings.php is set up like so:
require_once("$IP/extensions/CustomSidebar/CustomSidebar.php"); $wgDefaultSideBarText = 'MediaWiki:Sidebar'; $wgDefaultSideBarNSText[NS_C1] = 'Template:C1Sidebar'; $wgDefaultSideBarNSText[NS_C1_TALK] = 'Template:C1Sidebar'; $wgDefaultSideBarNSText[NS_C2] = 'Template:C2Sidebar'; $wgDefaultSideBarNSText[NS_C2_TALK] = 'Template:C2Sidebar'; $wgDefaultSideBarNSText[NS_C3] = 'Template:C3Sidebar'; $wgDefaultSideBarNSText[NS_C3_TALK] = 'Template:C3Sidebar';
However, no changes appear to the sidebar in the Cx: pages. I've tried making the template pages with and without the <sidebar></sidebar> tags, to no avail. Suggestions? 75.72.21.98 04:41, 8 January 2011 (UTC)
- Have you defined NS_C1, etc in your default settings file? are there any error messages? does this work?
$wgDefaultSideBarText['ns'][NS_C1] = ....
--Frantik 04:48, 19 February 2011 (UTC)
I have the same problem in 1.16.1 ($wgDefaultSideBarNSText... an $wgDefaultSideBarText['ns']... doesn't work, $wgDefaultSideBarGroupText... works).
A workaround is (But as replacement, not additional Sidebar):
$wgDefaultSideBarText = 'Template:{{NAMESPACE}}Sidebar';
- The problem appears to be a typo. Using $wgDefaultSidebarNSText (note the lowercase b) works. Twisted86 19:29, 24 January 2012 (UTC)
Global Modifications
editIs there a method by which I can create a single Sidebar change that is applied globally throughout my Wiki? One might suggest applying a change to multiple namespaces, but I don't want to go through the labor of listing all of my namespaces so the Sidebar change is applied globally.
My application of this extension is essentially calling out the active user's U/N in the sidebar using the following method in Mediawiki:Sidebar -
http://mywiki.com/index.php/{{#__USERNAME}}
I have set -
$wgDefaultSideBarText = 'MediaWiki:Sidebar'
and I see my modification applied throughout the Wiki. The problem is the USERNAME magic word returns the active user's U/N correctly in the MAIN namespace, but in every other namespace it only returns the wikitext {{#__USERNAME}}. --Enterprise user 16:42, 17 February 2011 (UTC)
- I recommend not setting the default sidebar to Mediawiki:Sidebar.. try
$wgDefaultSideBarText['global'] = "Template:CustomSidebar";
- I just set up Template:CustomSidebar with
* Menu ** {{#__USERNAME}} | User Page
- and it worked as expected --Frantik 04:57, 19 February 2011 (UTC)
Additional sidebar elements for logged-in users
editThe page for this extension claims that sidebars (or sidebar elements?) can be defined based on user groups. I’m presuming that doing so for any logged-in user, one would have to:
- 1. add the line
$wgDefaultSideBarGroupText['user'] = "Template:CustomSidebarUser";
(or some other name) to Localsettings.php - 2. create the template “Template:CustomSidebarUser” (or some other name) and add the menu there.
Using the above method, however, any visitor is able to view the elements intended for logged-in users only. I’m not sure what has gone wrong here, but I should probably first ask:
- a. Can Template:CustomSidebarUser in the above example be nested as a sidebar element (e.g. on the page or in another sidebar template), or should one include two different sidebars on the same page, a regular one for any visitor and another for logged-in users?
- b. Should the template include the sidebar tags, or should the tags be added later (as in <sidebar>{{…}}</sidebar> )?
The extension is otherwise working fine for me (though I haven’t tested the other parameters, such as those for category-specific sidebars). Cavila 10:51, 18 April 2011 (UTC)
- I guess no one really knows then. If you want to add links to the sidebar for logged-in users only and this extension does not work for you either, maybe this script can help you out: User:Hoggwild5/ExtraSidebar. Cavila MW 1.17, MySQL 5.5.16, Php 5.3.8 20:06, 27 December 2011 (UTC)
- You can define the actual sidebar text in the string, as opposed to referring to a page on the wiki.. ie:
- I guess no one really knows then. If you want to add links to the sidebar for logged-in users only and this extension does not work for you either, maybe this script can help you out: User:Hoggwild5/ExtraSidebar. Cavila MW 1.17, MySQL 5.5.16, Php 5.3.8 20:06, 27 December 2011 (UTC)
$wgDefaultSideBarGroupText['user'] = " * Somepage | Sidebar link 1 * Another page | Sidebar link 2 ";
Compatibility with the Collection extension
editThis extension makes the sidebar/toolbox of the collection extension, is there a way to put it back?--Tsouchon 14:40, 26 May 2011 (UTC)
Not working on MediaWiki 1.11.2
editOn MediaWiki 1.11.2 the sidebar is always the default one. Is there any way to make it work on this old version? Thanks.
edit: Hook is from 1.14, so never mind.
set active link
editin line 198
'active' => false
replace by
'active' => ($wgTitle->getLocalURL() == $href)
Custom Sidebar for Group 'user' dont Work
editHallo, i try to set a custom sidebar for all sign in users with:
$wgDefaultSideBarGroupText['user'] = "MediaWiki:CustomSidebarUser";
but it dont works. Only the default MediaWiki:Sidebar, that ist used for anonymous user, is displayed. With all other groups (sysop, custom groups, etc) it works fine. I already tried it with:
$wgDefaultSideBarGroupText['user'] = " * Page | Name ** Page | name ";
but it dont work either.
Sys-Info MediaWiki 1.18.4 PHP 5.3.13 (cgi-fcgi)
Custom Sidebar doesn't render
editI have version 0.3.0 installed with Mediawiki 1.20.2 (and php 5.3.10). I copied the example into a test page on my wiki but nothing in the sidebar changes. Apart from loading the extension, is there anything else that needs to be configured in LocalSettings.php? I have checked Special:Version to make sure it's loaded, and also checked the php and errors logs for any problems but nothing wrong there.
I fixed this by commenting out the following line in my LocalSettings.php $wgEnableSidebarCache = true;
Having problems with the basics of setup
editHi Frantik,
Thank you for producing this extension it's exactly what I would like to achieve with my Wiki implementation. Unfortunately I'm having problems with the basics so if you or anybody else could put me straight on the what I'm doing wrong then I'd much appreciate it.
Initially I just want to change the navigation menu for all users who view an extension that I'm building. My intial reading was that with my extension being 'Special:FeedReader', I might be able to include Template:TestSidebar as follows:
$wgDefaultSideBarText = 'FeedReader:TestSidebar'
But I know that I've gotten this horribly wrong somewhere along the way.
Here's what I have:
In LocalSettings.php I have added two lines:
require_once( $IP."/extensions/CustomSidebar/CustomSidebar.php"); $wgDefaultSideBarText = "FeedReader:TestSidebar";
TestSidebar is just a page called Template:TestSidebar with the following contents:
<sidebar> * Menu ** link1|Text 1 ** link2|Text 2 </sidebar>
These are the only changes that I have made to reference the extension from within its folder.
Product Version
MediaWiki 1.17.0
PHP 5.3.3 (apache2handler)
Thanks in advance
- hi, you don't need to use the <sidebar> tags on that page. The sidebar tags are for embedding the sidebar code directly on a page (vs using $wgDefaultSidebarText) --Frantik (talk) 05:47, 26 August 2014 (UTC)
Bug with $wgDefaultSideBarText = 'Extension talk:CustomSidebar/Sidebar';
editI didn't know where you wanted posts for bugs but I discovered a bug with some Mediawiki namespace pages using:
$wgDefaultSideBarText = '{{NAMESPACE}}:{{BASEPAGENAME}}/Sidebar';
Pages in NS_MEDIAWIKI use any subpage name to show the default value of the system message. e.g MediaWiki:Uploadtext which was changed, however if you go to:-
You will see all the links to different subpage all contain the default value for the system message of Uploadtext.
Unfortunately, the preg_match
check for processing everything between <sidebar></sidebar>
is being completely ignored. Since the default text of my example system message page contains bullets (*), the contents of each * is being written as a top sidebar element. Hutchy68 (talk) 17:59, 19 February 2014 (UTC)
Adding images possible?
editdoes CustomSidebar allow displaying images in the sidebar?Gleki.arxokuna (talk) 12:54, 14 July 2014 (UTC)
- I have not tried this, but I suspect that it may not work. However, if it is only about adding images to the sidebar the PCR GUI Inserts extension may be worth a look for you. Cheers --[[kgh]] (talk) 14:16, 12 August 2014 (UTC)
Issues with MW 1.23.x
editI just tried out this extension and found that the $wgDefaultSideBarText
parameter is being ignored completely. Then using the $wgDefaultSidebarNSText
parameter, the contents of the templates gets appended to the standard sidebar added via "MediaWiki:Sidebar" and does not replace it. What I have done to get this working on a namespace basis with the current code is that I have blanked "MediaWiki:Sidebar" and defined at template to be used for every namespace. It will be great to have a fix since this is quite a popular extension with currently 175 wikis using it. I do not know what the situation is with earlier versions of MediaWiki (< MW 1.23) and I have not tested the tags provided. Cheers --[[kgh]] (talk) 14:21, 12 August 2014 (UTC)
- thanks, I will update the source code --Frantik (talk) 05:43, 26 August 2014 (UTC)
- Hi I just tested this extension and also found the
$wgDefaultSideBarText
parameter is being ignored completely. I didn't test the NSText parameter, but definitely the extension is not working right on the current version of Mediawiki (1.23.6). Christharp (talk) 17:32, 25 November 2014 (UTC)
- Hi I just tested this extension and also found the
Issues with MW 1.24
editTo fix this extension for MW 1.24+, try this substitution on approx. line 60:
global $wgLang, $wgTitle, $wgArticle, $wgDefaultSideBarText, $wgUser, $wgDefaultSideBarGroupText, $wgDefaultSidebarNSText;
$NewSideBar = false;
if (isset($wgArticle) and $wgArticle)
{
$pagetext = $wgParser->preprocess( $wgArticle->getContent(), $wgArticle->getTitle(), ParserOptions::newFromUser( $wgUser ));
becomes:
global $wgLang, $wgTitle, $wgDefaultSideBarText, $wgUser, $wgDefaultSideBarGroupText, $wgDefaultSidebarNSText;
$NewSideBar = false;
$context = RequestContext::getMain();
$wgArticle = $context->getWikiPage();
if (isset($wgArticle) and $wgArticle)
{
$pagetext = $wgParser->preprocess( ContentHandler::getContentText( $wgArticle->getContent() ), $wgArticle->getTitle(), ParserOptions::newFromUser( $wgUser ));
- This code would work except it generates an exception when you try to do a search. In other words, the sidebar is modified, but when you try to do a search you get this error message:
- MediaWiki internal error.
- Exception caught inside exception handler.
- Set $wgShowExceptionDetails = true; at the bottom of LocalSettings.php to show detailed debugging information.
- I have version 1.26.2. Everything else works fine, as far as I can tell, you just can't do searches if you try to use this feature. You can click on links, for example, but every time you try to do a search, it generates the message above. I can't find $wgShowExceptionDetails in LocalSettings.php.
Adding custom sidebar for logged in users (FIXED!)
editFor those of you trying to add a custom sidebar for members of group "user", I think I found the solution. In CustomSidebar.php
, change line 94 from:
$groups = array_reverse($wgUser->mGroups);
to:
$groups = array_reverse($wgUser->getEffectiveGroups());
Anyway, it at least worked for me.
Fix for crash on Special: pages
editRunning MW 1.25.3, enabling this extension causes crash when I try to load a Special: page, e.g., Special:Version.
I traced the probelm to a snippet of code around line 110 that throws an exception if a numeric value of < 0 ir returned by the getNamespace() method of the Title $title passed to the function factory. That apparently happens for the Special namespace.
My understanding of the code is extremely shallow, but I worked around the problem by changing the test against 0 to a test against -1. I have no idea whether this might lead to more problems, but the new snippet looks like this now...
... $ns = $title->getNamespace(); if ( $ns == NS_MEDIA ) { throw new MWException( "NS_MEDIA is a virtual namespace; use NS_FILE." ); } elseif ( $ns < -1 ) { throw new MWException( "Invalid or virtual namespace $ns given for \"$title\"." ); } ...
To solve Both problems described above Errors
editUse this code.
global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry, $wgParser, $wgUser; global $wgLang, $wgTitle, $wgArticle, $wgDefaultSideBarText, $wgUser, $wgDefaultSideBarGroupText, $wgDefaultSidebarNSText; $NewSideBar = false; $context = RequestContext::getMain(); $title = $context->getTitle(); if ($title->getNamespace() > -1) { $wgArticle = $context->getWikiPage(); if (isset($wgArticle) and $wgArticle) { $pagetext = $wgParser->preprocess( ContentHandler::getContentText($wgArticle->getContent()), $wgArticle->getTitle(), ParserOptions::newFromUser($wgUser) ); if (preg_match('%\<sidebar\>(.*)\</sidebar\>%isU', $pagetext, $matches)) { $NewSideBar = $matches[1]; } elseif (isset($wgDefaultSideBarText) and $wgDefaultSideBarText !== false) { $NewSideBar = $wgDefaultSideBarText; } }
doesn't seem to work
editI've installed the extension but it doesn't seem to work on the latest mediawiki and it says on the page it no loner works since 1.24 since there were a few changes to some variables as I understand. But the thing is I've seen the extension work like this wiki http://en.wikichip.org/wiki/Special:Version has "CustomSidebar" version 0.4.0. and this page says "0.3.0 (2009-08-09)". Is there an updated version somewhere else that they got it from? any help is much appreciated! --Billyz1010 (talk) 06:55, 26 December 2015 (UTC)
Unmaintained?
editThis doesn't work in 1.27.1 either. Is this no longer being maintained? Cardcaptor Stacey (talk) 11:51, 30 November 2016 (UTC)
- Probably yes. It still does not work in 1.31.0 :-( Ankostis (talk) 23:54, 19 September 2018 (UTC)
- This is sad since it is a pretty useful extension. Hoping that somebody takes up maintaining it. Keeping fingers crossed. --[[kgh]] (talk) 18:30, 10 November 2018 (UTC)
Menu not working
editI have this section in my sidebar menu page:
- Bollekop
- BolAlgemeen|Algemeen
- 3D:Bollekop|Bollekop
- Bollekop-Inleiding
and all that is shown are the first two, so heading and first menu item.