mediawiki-l-boun...@lists.wikimedia.org schrieb am 24.11.2010 12:02:59: > Hello! > > I want to add navigation tabs linking to sub-pages at the top of > *articles* (i.e., pages in the main name-space). In particular, I'd > like to add a "Bib" tab, which would link to <Article>/Bibliography, > and a "Links" tab, which would link to <Article>/Links. > > The DynamicTabs extension > (http://www.mediawiki.org/wiki/Extension:DynamicTabs) doesn't appear > to provide this functionality---I specifically want tabs that link to > sub-pages of the current article, not to a page of the same base name > in another name-space. (Also, DynamicTabs apparently doesn't work for > the Vector skin.)
I am currently writing an extension for this purpose. It's still pre-alpha but it works on my current installation. The advantage over DynamicTabs is that it works with both, monobook based and the new vector skin. Feel free to copy from the code, the license is the GPL. The following variables can be used in LocalSettings.php: //Identifier of Namespaces for which additional tabs shall be generated $wgAddNsTabs[] = $wgExtraNamespaces[NS_A]; $wgAddNsTabs[] = $wgExtraNamespaces[NS_E]; $wgAddNsTabs[] = $wgExtraNamespaces[NS_S]; //Tab for talk page will be removed if this is set to true $wgAddNsTabsRemoveTalkPage = true; //Option for getting debug output from the plugin. 1-3 available. 1 will show //errors only, 2 will show errors and warnings, 3+ will show full debug info //Default: 0 $wgAddNsTabsDebug = 3; //Specifying the debug file $wgDebugLogGroups["AddNsTabs"] = "/tmp/Mediawiki-AddNsTabs-debug.log" ; //Of course you need this: require_once("$IP/extensions/AddNsTabs/AddNsTabs.php"); This is the AddNsTabs.php file: -----------------begin-of-file------------------ <?php $wgHooks['SkinTemplateNavigation'][] = 'AddNsTabs_VectorMode'; //Register function (called from VectorTemplate based skins) $wgHooks['SkinTemplateTabs'][] = 'AddNsTabs_StdMode'; //Register function (called from SkinTemplate based skins) $wgExtensionCredits['other'][] = array( 'name' => 'AddNsTabs', 'version' => '0.0.2', 'author' => 'Arnd Muenzebrock', //'url' => 'http://www.mediawiki.org/wiki/Extension:AddNsTabs', //This does not exist yet 'description' => 'Adds tabs for additional Namespaces', ); //constants for error reporting define("ERROR", 1); define("WARNING", 2); define("INFO", 3); function AddNsTabs_VectorMode( &$skin_object, &$links ) { global $wgAddNsTabs; global $wgAddNsTabsRemoveTalkPage; printDebug("AddNsTabs started in VectorTemplate-mode", INFO); if ( $wgAddNsTabsRemoveTalkPage ) { //Remove Tab for talk page printDebug("Removing tab for talk-page", INFO); // Generate XML IDs from namespace name (borrowed from Vector.php) $subjectId = $skin_object->getTitle()->getNamespaceKey( '' ); if ( $subjectId == 'main' ) { $talkId = 'talk'; } else { $talkId = "{$subjectId}_talk"; } unset( $links['namespaces'][$talkId] ); } foreach ($wgAddNsTabs as $AddNamespace) { $AddNamespace = trim($AddNamespace); printDebug("Processing Namespace: " . $AddNamespace, INFO); if ($skin_object->getTitle()->getNsText() == $AddNamespace) { //if this namespace from the $wgAddNsTabs is actually shown //replace tab with link to Main-Namespace printDebug("Replacing add. tab for " . $AddNamespace . " with tab for main namespace", INFO); $AddNamespace = 'main'; $AddNamespaceWikilink = $skin_object->getTitle()->newFromText( ':' . $skin_object->getTitle()->getText() ); } else { //Generate a wikilink to a page with the current page title in the currently processed namespace $AddNamespaceWikilink = $skin_object->getTitle()->newFromText( $AddNamespace . ':' . $skin_object->getTitle()->getText() ); } printDebug("Corresponding Wikilink: ". $AddNamespaceWikilink, INFO); //Insert this into the $links-array $links['namespaces'][$AddNamespace] = $skin_object->tabAction( $AddNamespaceWikilink, 'vector-namespace-' . $AddNamespace, false, '', true ); //The following is of no effect at the moment. We set it anyway for possible future use in SkinVector::execute() $links['namespace'][$AddNamespace]['context'] = $AddNamespace; } return true; } function AddNsTabs_StdMode( &$skin_object, &$content_actions ) { global $wgAddNsTabs; global $wgAddNsTabsRemoveTalkPage; printDebug("AddNsTabs started in QuickTemplate-mode (standard-mode)", INFO); if ( $wgAddNsTabsRemoveTalkPage ) { //Remove Tab for talk page printDebug("Removing tab for talk-page", INFO); unset( $content_actions['talk'] ); } foreach($wgAddNsTabs as $AddNamespace) {//Loop array of Namespaces $AddNamespace = trim($AddNamespace); printDebug("Processing Namespace: " . $AddNamespace, INFO); if ($skin_object->getTitle()->getNsText() == $AddNamespace) { //if this namespace from the $wgAddNsTabs is actually shown //replace tab with link to Main-Namespace printDebug("Replacing add. tab for " . $AddNamespace . " with tab for main namespace", INFO); $AddNamespace = 'main'; $page = Title::newFromText( ':' . $skin_object->mTitle->getText()); } else { $page = Title::newFromText( $AddNamespace . ':' . $skin_object->mTitle->getText()); } $href = $page->getLocalUrl(); printDebug("Corresponding URL: ". $href, INFO); $content_actions[strtolower($AddNamespace)] = Array( 'class' => ($AddNamespace == $skin_object->getTitle()->getNsText()?'selected':''), 'text' => $AddNamespace, 'href' => $href, ); } return true; } /** * The following is thankfully borrowed from the LDAP-Authentication plugin * http://www.mediawiki.org/wiki/Extension:LDAP_Authentication */ /** * Prints debugging information. $debugText is what you want to print, $debugVal * is the level at which you want to print the information. * * @param string $debugText * @param string $debugVal * */ function printDebug( $debugText, $debugVal, $debugArr = null ) { global $wgAddNsTabsDebug; if ( isset( $debugArr ) ) { if ( $wgAddNsTabsDebug >= $debugVal ) { $text = $debugText . " " . implode( "::", $debugArr ); wfDebugLog( 'AddNsTabs', $text, false ); } } else { if ( $wgAddNsTabsDebug >= $debugVal ) { wfDebugLog( 'AddNsTabs', $debugText, false ); } } } -----------------end-of-file------------------- I want to improve this and make it more flexible so that it also fits to your needs. But as I'm doing it in my (rare) spare time, I can't promise you a date for this. Also, this is my first extension, so the code and function calls to other mediawiki classes might look clumsy to experienced mediawiki hackers; any hints on this are appreciated. > The MediaWiki FAQ (http://www.mediawiki.org/wiki/Manual:FAQ) provides > an example that creates a navigation tab linking to the main page, but > I can't figure out how to alter it to link to a sub-page of the > current article---and *only* for articles, as well. > > Any ideas? (Ideally, the solution would be skin- and JavaScript-independent.) > > Cheers, > Tom. HTH, Arnd _______________________________________________ MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-l