Hack: Editing headers in MediaWiki Template.

Have you ever tried to put headers in MediaWiki and tried to edit them from page view? You might have been forwarded to template edit section instead of section edit. If you want to go to section edit section rather than template edit section then this small hack is for you.

here are the steps you have to perform:

1. open includes/Parser.php file from MediaWiki installed directory.

2. find the following line inside the formatHadings function.

# give headline the correct <h#> tag
if( $showEditLink && ( !$istemplate || $templatetitle !== “” ) ) {
if( $istemplate )
$editlink = $sk->editSectionLinkForOther($templatetitle, $templatesection);
else
$editlink = $sk->editSectionLink($this->mTitle, $sectionCount+1, $headline_hint);
} else {
$editlink = ”;
}
$head[$headlineCount] = $sk->makeHeadline( $level, $matches[‘attrib’][$headlineCount], $anchor, $headline, $editlink );

$headlineCount++;
if( !$istemplate )
$sectionCount++;

and replace with

if( $showEditLink && ( !$istemplate || $templatetitle !== “” ) ) {
$editlink = $sk->editSectionLink($this->mTitle, $sectionCount+1, $headline_hint);
} else {
$editlink = ”;
}
$head[$headlineCount] = $sk->makeHeadline( $level, $matches[‘attrib’][$headlineCount], $anchor, $headline, $editlink );

$headlineCount++;
$sectionCount++;

3. now save the file and test the feature.

you are all done to use this hack…

3 thoughts on “Hack: Editing headers in MediaWiki Template.

  1. Greg says:

    Is there any way to make this hack also jump down to the section when you click edit?

    Maybe I’m doing something wrong… It allows me to click edit, but it seems to edit the whole page instead of the section.

    Thanks.

  2. Calle says:

    Hi, I looked in mediawiki 1.17 Parser.php and it has changed in the area you patched. Could you have a look and update this hack if possible ?
    thanks.
    Philippe, France

Leave a Reply

Your email address will not be published. Required fields are marked *