Utilisateur:Misdre/InfoTab
Apparence
Sommairement, ajouter un onglet tout là haut. Bon, tout le blabla licence auteur est dans le code. Pas les commentaires par contre. Et c'est alpha.
InfoTab.php[modifier]
<?php /* Mostly stolen from CommentPages * http://www.mediawiki.org/wiki/Extension:CommentPages * Zachary <http://www.mediawiki.org/wiki/User:Zachary>, Misdre <http://www.pokepedia.fr/index.php/Utilisateur:Misdre> * Released under the GPL */ // Check environment if ( !defined( 'MEDIAWIKI' ) ) { die( "This is not a valid entry point.\n" ); } /* Configuration */ // Credits $wgExtensionCredits['other'][] = array( 'path' => __FILE__, 'name' => 'InformationTab', 'author' => '[http://www.mediawiki.org/wiki/User:Zachary Zachary], [http://www.pokepedia.fr/index.php/Utilisateur:Misdre Misdre]', 'description' => 'Adds an "Informations" tab to each article', 'version' => '0.1a2', 'descriptionmsg' => 'informations-desc', 'url' => 'http://www.pokepedia.fr/index.php/Utilisateur:Misdre/InfoTab', ); // Internationalization $wgExtensionMessagesFiles['InfoTab'] = dirname(__FILE__) . '/InfoTab.i18n.php'; $wgHooks['SkinTemplateTabs'][] = 'wfInformationPagesSkinTemplateTabs'; function wfInformationPagesSkinTemplateTabs ( $skin, &$content_actions ) { global $wgContLang; wfLoadExtensionMessages('InfoTab'); $wgInfoTabNamespaces = array(NS_MAIN, NS_TALK); $pagename = $skin->mTitle->getText(); $namespace = $skin->mTitle->getNamespace(); $class = ''; $page = ''; $query = ''; if( !$skin->mTitle->isSubpage() && !$skin->mTitle->isTalkPage() && in_array($namespace, $wgInfoTabNamespaces) ) { $informations = Title::makeTitleSafe( $namespace, $pagename . '/Informations'); $newcontent_actions = array(); if (!$informations->exists()) { $class = 'new'; $query = array( 'action' => 'edit', 'redlink' => 1 ); if (wfMsg('infotab-preload') != '') { $query['preload'] = wfMsg('infotab-preload'); } if (wfMsg('infotab-editintro') != '') { $query['editintro'] = wfMsg('infotab-editintro'); } } else { $class = ''; } $newcontent_actions['informations'] = array( 'class' => $class, 'text' => wfMsg('nstab-informations'), 'href' => $informations->getFullURL($query), ); $insertAfter = $skin->mTitle->getNamespaceKey(); if ( isset($content_actions['article']) ) { $insertAfter = 'article'; } $content_actions = efInformationPagesArrayInsertAfter( $content_actions, $newcontent_actions, $insertAfter ); } elseif ( ($skin->mTitle->isSubpage() && in_array($namespace, $wgInfoTabNamespaces)) || ($skin->mTitle->isTalkPage() && in_array($namespace, $wgInfoTabNamespaces)) ) { $articlename = $skin->mTitle->getBaseText(); $newcontent_actions = array(); /*if($namespace == NS_TALK) { $mainarticle = Title::makeTitleSafe( $skin->mTitle->getSubjectPage()->getNamespace(), $pagename); } else { $mainarticle = Title::makeTitleSafe( $skin->mTitle->getNamespace(), $articlename); } $content_actions['article']['href'] = $mainarticle->getFullURL($query);*/ if( strcmp($skin->mTitle->getSubpageText(), 'Informations') == 0 ) { $class = 'selected '; } if($skin->mTitle->isTalkPage()) { $informations = Title::makeTitleSafe( $skin->mTitle->getSubjectPage()->getNamespace(), $articlename . '/Informations'); } else { $informations = Title::makeTitleSafe( $namespace, $articlename . '/Informations'); } if (!$informations->exists()) { $class .= 'new'; $query = array( 'action' => 'edit', 'redlink' => 1 ); if (wfMsg('infotab-preload') != '') { $query['preload'] = wfMsg('infotab-preload'); } if (wfMsg('infotab-editintro') != '') { $query['editintro'] = wfMsg('infotab-editintro'); } } else { $class .= ''; } $newcontent_actions['informations'] = array( 'class' => $class, 'text' => wfMsg('nstab-informations'), 'href' => $informations->getFullURL($query), ); $insertAfter = $skin->mTitle->getNamespaceKey(); if ( isset($content_actions['article']) ) { $insertAfter = 'article'; } $content_actions = efInformationPagesArrayInsertAfter( $content_actions, $newcontent_actions, $insertAfter ); } return true; } /** * Insert array into another array after the specified *KEY* * Stolen from GlobalFunctions.php in MW 1.16 * @param $array Array: The array. * @param $insert Array: The array to insert. * @param $after Mixed: The key to insert after */ function efInformationPagesArrayInsertAfter( $array, $insert, $after ) { // Find the offset of the element to insert after. $keys = array_keys($array); $offsetByKey = array_flip( $keys ); $offset = $offsetByKey[$after]; // Insert at the specified offset $before = array_slice( $array, 0, $offset + 1, true ); $after = array_slice( $array, $offset + 1, count($array)-$offset, true ); $output = $before + $insert + $after; return $output; }
InfoTab.i18n.php[modifier]
<?php /** * Internationalisation file for extension InfoTab. */ $messages['en'] = array( 'informations-desc' => 'Adds a link to informations about the current page (main namespace only)', // 'informations-tab' => 'Informations', 'infotab-editintro' => '', 'infotab-preload' => '', 'nstab-informations' => 'Informations', ); $messages['fr'] = array( 'informations-desc' => 'Ajoute un lien blablabla', // 'informations-tab' => 'Informations', 'infotab-editintro' => '', 'infotab-preload' => '', 'nstab-informations' => 'Informations', );