Extension:TopOfPage

From MediaWiki.org
Jump to: navigation, search
Wikimedia-logo-meta.png

This page was moved from MetaWiki.
It probably requires cleanup – please feel free to help out. In addition, some links on the page may be red; respective pages might be found at Meta. Remove this template once cleanup is complete.

I often found the TopOFPage tag missing in large documents. This made me look at the Wiki's code and led me to Linker.php.
I found the code where the [edit] link is created. I knew this was the place where I should get the code.

This code goes after line 784:

 /** @todo document */
function editSectionLinkForOther( $title, $section ) {
global $wgRequest;
global $wgContLang;

$title = Title::newFromText($title);
$editurl = '&section='.$section;
$url = $this->makeKnownLink($title->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
$topurl = $this->makeKnownLink($title->getPrefixedText()."#top","TopOfPage");

if( $wgContLang->isRTL() ) {
$farside = 'left';
$nearside = 'right';
} else {
$farside = 'right';
$nearside = 'left';
}
return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$topurl."]</div><div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";

}

/** @todo document */
function editSectionLink( $nt, $section ) {
global $wgContLang;

$editurl = '&section='.$section;
$url = $this->makeKnownLink($nt->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
$topurl = $this->makeKnownLink($nt->getPrefixedText()."#top","TopOfPage");

if( $wgContLang->isRTL() ) {
$farside = 'left';
$nearside = 'right';
} else {
$farside = 'right';
$nearside = 'left';
}
return "<div style=\"float:$farside;\">[".$topurl."]</div>"."<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
}


There are some basic Wiki functions that I had to understand before I could get this to work.
Especially $this->makeKnownLink. This function creates a link where you specify:

  • The pagename (in this case requested by $nt->getPrefixedText())
  • The name of the link


In this case, I requested $nt->getPrefixedText() and added #top to the link.
This results in the following syntax: $nt->getPrefixedText()."#top"

All the rest is clear I think :) Have fun adding it. It can be really useful for a wiki with large documents :)


Template:Uncat

Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox