Jump to content

Topic on Extension talk:SectionHide

A Show/hide all sections button would be a nice feature

10
Arcane21 (talkcontribs)

As the title says, a show/hide all sections at once button would be a nice feature. Not sure where you would add it (right next to the page title or just under it towards the very right would be my first two ideas., but for pages where all someone wants to read is the very first section or wants to just see the introduction and the categories and doesn't want to have to scroll down very much, that would be a quite useful feature.

Also, while I'm not an expert on Javascript, I just tested this on MediaWiki 1.19 and it worked flawlessly, and given the rather simple hooks you've used, this extension looks very downward compatible.

Also, even if you don't want to use the Wikimedia Git Repository, it probably wouldn't hurt to put this extension on a free Github account in a downloadable zip file with the install instructions and the information needed for the MediaWiki:Common.js file.

I don't have anymore advice or suggestions at the moment, but I did want to say I believe that you are a genius, as I have long searched in vain for an extension that does what yours does, and to say I'm quite happy with it is a major understatement.

Hoggle42 (talkcontribs)

Thank you very much :)

A hide all should be quite simple to add to the parseafterparse hook function, wrapping the whole article in a <p><span><a javascript="toggle id zero">hideall</a></span></p><div id zero>[artile goes here]</div id zero>

It should be backwards compatible as far as the two hooks and various other standards go, but as I dev'd it on 1.21.1 to replace a version that no longer worked and was dev'd on 1.16 I didn't feel I could guarantee more.

I could do a zip file but found the introductory help on the gerrit site impenetrable and aimed at main code developers rather than extension writers. As I said I'm happy for anyone with more experience to transfer it to the source control system.

Once again, thank you for your endorsement! :)

Hoggle42 (talkcontribs)

hide all link added, pending changes

Arcane21 (talkcontribs)

Just tested it, feature works beautifully.

I've been testing the extension on a localhost wiki and have found it extremely responsive. It may need further tweaking on a live website environment, though given the simplicity of the code, I doubt it.

However, I am also quite pleased to report that it has no compatibility problems with the mw-collapsible class in any way. I haven't tested it with all types of collapsible code yet, but I doubt there will be conflicts.

I am also pleased to report the code is very skin agnostic, and has worked in most of the basic skins included with MediaWiki, and even several custom skins.

My only possible suggestion is to see if tweaking the show/hide all button could hide all but the first section of page, since it currently hides everything but the page title and category bar at present. I'm not sure if this will work well, but the current version hides ALL levels of section headings (including the text between the title bar and first proper section heading), which may be overkill for some people.

Hoggle42 (talkcontribs)

You'd need to insert the id zero div alongside the id 1 div to keep the text before the first heading visible. I'll have a play and make it an option in version 1.2.

Hoggle42 (talkcontribs)

done, pending changes

There's a new global variable to set how many sections you want to keep - set it to 1 to hide everything from the first heading down. I'm not sure it should be set any higher, but it seems to work in Chrome.

Arcane21 (talkcontribs)

I've been using Firefox, and it seems to be working fine for me as well.

However, could you show me exactly which lines I need to tweak to use the new variable?

Hoggle42 (talkcontribs)

in SectionHide.php - expanded instructions for localsettings.php

 * add the following line to localsettinge.php to use
 * require_once("$IP/extensions/SectionHide/SectionHide.php");
 * // Set this option to 1 to show the text before the first section when hiding all
 * // Set to X to show the top x-1 sections (use with caution - some browsers may complain)
 * $wgSectionHideShowtop = 0; //default

In SectionHideHooks.php

        public static function onParserAfterParse( &$parser, &$text, &$sstate )
                {
                global $wgSectionHideShowtop;
                // need to nest sections by levels by moving around the closing tags
                $numberofmatches = preg_match_all('#<h[2-6].*<\/h[2-6]>\n<div class="sectionblocks"#', $text, $matches, PREG_OFFSET_CAPTURE);
                $closingdivmatches = preg_match_all('#<\/div id=#', $text, $divmatches, PREG_OFFSET_CAPTURE);

                if($numberofmatches == $closingdivmatches && $numberofmatches > 1)
                        {
                        if( $wgSectionHideShowtop > $numberofmatches) $wgSectionHideShowtop = $numberofmatches; // cannot exceed the number of matches
                        $headlevel = array();

and

                        // new hide all link
                        if ( $wgSectionHideShowtop > 0 )
                                {
                                // insert a section zero opening div before the first section heading
                                $text = insertAtLoc($text, '<div class="sectionblocks" id="sectionblock0">', $matches[0][($wgSectionHideShowtop-1)][1]);
                                $text = '<p><span class="editsection visibilitytoggle">[<a href="#" onclick="toggleSectionVisibility(this, 0,'."'"
                                        .wfMsg( 'sectionhide-showall' )."','".wfMsg( 'sectionhide-hideall' )."'".')">'.wfMsg( 'sectionhide-hideall' )
                                        .'</a>]</span></p>'
                                        .$text
                                        .'</div id="sectionblock0">';
                                }
                            else
                                {
                                $text = '<p><span class="editsection visibilitytoggle">[<a href="#" onclick="toggleSectionVisibility(this, 0,'."'"
                                        .wfMsg( 'sectionhide-showall' )."','".wfMsg( 'sectionhide-hideall' )."'".')">'.wfMsg( 'sectionhide-hideall' )
                                        .'</a>]</span></p><div class="sectionblocks" id="sectionblock0">'
                                        .$text
                                        .'</div id="sectionblock0">';
                                }
                        }
                return true;
Hoggle42 (talkcontribs)
Arcane21 (talkcontribs)

....derp, now I see what you mean.

Sorry, my brain was half asleep when you informed me of the updated global variable.

Just tested the new variable, runs beautifully in Firefox (exactly how I envisioned it working too!), was planning to test it in IE and Chrome, will get back to you if I find any anomalies.

Reply to "A Show/hide all sections button would be a nice feature"