Thread:Extension talk:Header Tabs/Hide Level 1 headings in TOC/reply

This is my solution.


 * 1) If you are NOT an expert on mediawiki/semantic read the TOC and SECTIONS related help pages. You will not find at the time I am writing the solution for your problem, but for sure (like in my case) you will end up with a better understanding of it :)
 * 2) I ended up debugging the code and here the solution.

''Considering that the best practice is not to use single "=" for sections this might be taken in consideration as change in the core mediawiki code.. (anyone reading up there?!?)''

The solution consists in changing includes/parser/Parser.php.

I left the logic for TOC creation unaltered, otherwise you will end up having problem with the header tabs excentions rendering.

The goal is to declare the Header Tab section within a proper header defined with double "=" and HIDE in the TOC the section declared with single "=".

This last part might be changed in order to show the tabs with an appropriare TOC level, but in this in my opinion/experience is useless because


 * 1) the header tab section is rendered as unique block
 * 2) the TOC links are not able to point to the appropriate headed tab.

So..

NOTES:

This change will be applied to every level 1 header defined in your WIKI!!

USAGE:


 * 1) Declare your section header as == MY SECTION ==
 * 2) Write within your section your header tab content ( = tab1 = bla bla bla = tab2 = bla2 bla2 bla2 ...
 * 3) Add in your page or  (if you are using a template for TOC)

PATCH:

edit your_wiki_path/includes/parser/Parser.php and apply the following changes in the function formatHeadings:

....  4272                 foreach ( $matches[3] as $headline ) { 4273                        $isTemplate = false; 4274                        $titleText = false; 4275                        $sectionIndex = false; 4276                        $numbering = ''; 4277                        $markerMatches = array; 4278                        if ( preg_match( "/^$markerRegex/", $headline, $markerMatches ) ) { 4279                                $serial = $markerMatches[1]; 4280                                list( $titleText, $sectionIndex ) = $this->mHeadings[$serial]; 4281                                $isTemplate = ( $titleText != $baseTitleText ); 4282                                $headline = preg_replace( "/^$markerRegex\\s*/", "", $headline ); 4283                        }   4284                         if ( $toclevel ) { 4285                                $prevlevel = $level; 4286                        }   4287                         $level = $matches[1][$headlineCount]; 4288                        if (   4289                                 ( $level > $prevlevel && $prevlevel <> 1 )   4290                                 ||   4291                                 ( $level == 1 && $prevlevel > 1 )   4292                         ) { 4293                                # Increase TOC level 4294                                $toclevel++; 4295                                $sublevelCount[$toclevel] = 0; 4296                                if ( $toclevel < $wgMaxTocLevel ) { 4297                                        $prevtoclevel = $toclevel; 4298                                        if ( $level <> 1 ) { # REMOVE THIS IF IF YOU WANT TO SHOW THE SECTION IN TOC 4299                                                $toc .= Linker::tocIndent; 4300                                        }   4301                                         $numVisible++; 4302                                }   4303                         } elseif (  $level < $prevlevel && $toclevel > 1 ) { 4304                                # Decrease TOC level, find level to jump to   4305                                 for ( $i = $toclevel; $i > 0; $i-- ) { 4306                                        if ( $levelCount[$i] == $level ) { 4307                                                # Found last matching level 4308                                                $toclevel = $i; 4309                                                break; 4310                                        } elseif ( $levelCount[$i] < $level ) { 4311                                                # Found first matching level below current level 4312                                                $toclevel = $i + 1; 4313                                                break; 4314                                        }   4315                                 }   4316                                 if ( $i == 0 ) { 4317                                        $toclevel = 1; 4318                                }   4319                                 if ( $toclevel < $wgMaxTocLevel ) { 4320                                        if ( $prevtoclevel < $wgMaxTocLevel ) { 4321                                                # Unindent only if the previous toc level was shown :p 4322                                                $toc .= Linker::tocUnindent( $prevtoclevel - $toclevel ); 4323                                                $prevtoclevel = $toclevel; 4324                                        } else { 4325                                                $toc .= Linker::tocLineEnd; 4326                                        }   4327                                 }   4328                         } elseif (  $level > $prevlevel && $prevlevel == 1 ) { 4329                                # MIK 4330                                # Decrease TOC level for headed tab 4331                                for ( $i = $toclevel-1; $i > 0; $i-- ) { 4332                                        if ( $levelCount[$i] == $level ) { 4333                                                # Found last matching level 4334                                                $toclevel = $i; 4335                                                break; 4336                                        } elseif ( $levelCount[$i] < $level ) { 4337                                                # Found first matching level below current level 4338                                                $toclevel = $i + 1; 4339                                                break; 4340                                        }   4341                                 }   4342                                 if ( $i == 0 ) { 4343                                        $toclevel = 1; 4344                                }   4345                                 if ( $toclevel < $wgMaxTocLevel ) { 4346                                        if ( $prevtoclevel < $wgMaxTocLevel ) { 4347                                                # Unindent only if the previous toc level was shown :p 4348                                                //$toc .= Linker::tocUnindent( $prevtoclevel - $toclevel ); 4349                                                $prevtoclevel = $toclevel; 4350                                        }   4351                                         //else { 4352                                        //      $toc .= Linker::tocLineEnd; 4353                                        //}   4354                                 }   4355                         } else { 4356                                # No change in level, end TOC line 4357                                if ( $toclevel < $wgMaxTocLevel ) { 4358                                        if ( $level <> 1 ) {  # REMOVE THIS IF IF YOU WANT TO SHOW THE SECTION IN TOC 4359                                                $toc .= Linker::tocLineEnd; 4360                                        }   4361                                 }   4362                         }   4363   4364                         $levelCount[$toclevel] = $level; 4365  ....   4477                         if ( $enoughToc && ( !isset( $wgMaxTocLevel ) || $toclevel < $wgMaxTocLevel ) ) { 4478                                if ( $level <> 1 ) { # REMOVE THIS IF IF YOU WANT TO SHOW THE SECTION IN TOC 4479                                        $toc .= Linker::tocLine( $anchor, $tocline,   '''4480                                                 $numbering, $toclevel, ( $isTemplate ? false : $sectionIndex ) );''' 4481                                }   4482                         }   ....   4550                 if ( $enoughToc ) { 4551                        if ( $prevtoclevel > 0 && $prevtoclevel < $wgMaxTocLevel ) { 4552                                if ( $level <> 1 ) { # REMOVE THIS IF IF YOU WANT TO SHOW THE SECTION IN TOC 4553                                        $toc .= Linker::tocUnindent( $prevtoclevel - 1 ); 4554                                }   4555                         }   4556                         $toc = Linker::tocList( $toc, $this->mOptions->getUserLangObj ); 4557                        $this->mOutput->setTOCHTML( $toc ); 4558                        $toc = self::TOC_START. $toc. self::TOC_END; 4559                }   .... ENJOY