Index: trunk/extensions/CreditTab/README |
— | — | @@ -0,0 +1,8 @@ |
| 2 | +Options |
| 3 | +Default the Tab only shows up in ContentNamespace |
| 4 | + |
| 5 | +Show in all Namespaces |
| 6 | +$wgCreditTabNamespaces=true; |
| 7 | + |
| 8 | +Show in certain Namespaces, example: |
| 9 | +$wgCreditTabNamespaces=array(0,14); |
Index: trunk/extensions/CreditTab/CreditTab.i18n.php |
— | — | @@ -0,0 +1,24 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Messages file for the InputBox extension |
| 6 | + * |
| 7 | + * @addtogroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +/** |
| 11 | + * Get all extension messages |
| 12 | + * |
| 13 | + * @return array |
| 14 | + */ |
| 15 | +$messages = array(); |
| 16 | + |
| 17 | +$messages['en'] = array( |
| 18 | + 'credits-desc' => 'Adds a link to Credits', |
| 19 | + 'credits-tab' => 'Credits', |
| 20 | +); |
| 21 | + |
| 22 | +$messages['de'] = array( |
| 23 | + 'credits-desc' => 'Fügt Link zu Autoren hinzu', |
| 24 | + 'credits-tab' => 'Autoren', |
| 25 | +); |
\ No newline at end of file |
Index: trunk/extensions/CreditTab/CreditTab.php |
— | — | @@ -0,0 +1,109 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | +* @addtogroup Extensions |
| 5 | +*/ |
| 6 | +// Check environment |
| 7 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 8 | + echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" ); |
| 9 | + die( -1 ); |
| 10 | +} |
| 11 | + |
| 12 | +/* Configuration */ |
| 13 | + |
| 14 | +// Credits |
| 15 | +$wgExtensionCredits['other'][] = array( |
| 16 | + 'path' => __FILE__, |
| 17 | + 'name' => 'CreditTab', |
| 18 | + 'author' => '[http://www.dasch-tour.de DaSch]', |
| 19 | + 'description' => 'Adds a link to Credits', |
| 20 | + 'version' => '1.2.0', |
| 21 | + 'descriptionmsg' => 'credits-desc', |
| 22 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:CreditTab', |
| 23 | +); |
| 24 | +$dir = dirname( __FILE__ ) . '/'; |
| 25 | + |
| 26 | +// Internationalization |
| 27 | +$wgExtensionMessagesFiles['CreditTab'] = $dir . 'CreditTab.i18n.php'; |
| 28 | + |
| 29 | +$wgHooks['ParserBeforeTidy'][] = 'addAuthorHeadLink'; |
| 30 | +$wgHooks['SkinTemplateNavigation'][] = 'displayTab'; |
| 31 | + |
| 32 | +function addAuthorHeadLink ( &$parser, &$text ) { |
| 33 | + global $wgTitle; |
| 34 | + $parser->mOutput->addHeadItem('<link rel="author" type="text/html" title="' . wfMsg('credits-tab') . '" href="' . $wgTitle->getLocalURL( 'action=credits' ) . '" />'); |
| 35 | + return true; |
| 36 | +} |
| 37 | +function displayTab( $obj, &$links ) { |
| 38 | + // the old '$content_actions' array is thankfully just a |
| 39 | + // sub-array of this one |
| 40 | + $views_links = $links['views']; |
| 41 | + showCredits( $obj, $views_links ); |
| 42 | + $links['views'] = $views_links; |
| 43 | + return true; |
| 44 | + } |
| 45 | +function showCredits( $obj, &$content_actions ) { |
| 46 | + global $wgRequest, $wgCreditTabNamespaces; |
| 47 | + if ( method_exists ( $obj, 'getTitle' ) ) { |
| 48 | + $title = $obj->getTitle(); |
| 49 | + } else { |
| 50 | + $title = $obj->mTitle; |
| 51 | + } |
| 52 | + wfLoadExtensionMessages('CreditTab'); |
| 53 | + $ctNamespace = $title->getNamespace(); |
| 54 | + $ctInsert=false; |
| 55 | + if (count($wgCreditTabNamespaces)>0) { |
| 56 | + if (in_array($ctNamespace, $wgCreditTabNamespaces)) { |
| 57 | + $ctInsert=true; |
| 58 | + } |
| 59 | + if (is_bool($wgCreditTabNamespaces)) { |
| 60 | + $ctInsert=$wgCreditTabNamespaces; |
| 61 | + } |
| 62 | + } |
| 63 | + else { |
| 64 | + if ($title->isContentPage()) { |
| 65 | + $ctInsert=true; |
| 66 | + } |
| 67 | + else { |
| 68 | + $ctInsert=false; |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + $class_name = ( $wgRequest->getVal( 'action' ) == 'credits' ) ? 'selected' : ''; |
| 73 | + if( $title->exists() && $ctInsert) { |
| 74 | + $credit_tab = array( |
| 75 | + 'class' => $class_name, |
| 76 | + 'text' => wfMsg('credits-tab'), |
| 77 | + 'href' => $title->getLocalURL( 'action=credits' ), |
| 78 | + ); |
| 79 | + // find the location of the 'edit' tab, and add |
| 80 | + // 'edit with form' right before it. |
| 81 | + // this is a "key-safe" splice - it preserves |
| 82 | + // both the keys and the values of the array, |
| 83 | + // by editing them separately and then |
| 84 | + // rebuilding the array. |
| 85 | + // based on the example at |
| 86 | + // http://us2.php.net/manual/en/function.array-splice.php#31234 |
| 87 | + $tab_keys = array_keys( $content_actions ); |
| 88 | + $tab_values = array_values( $content_actions ); |
| 89 | + $edit_tab_location = array_search('history', $tab_keys); |
| 90 | + $edit_tab_location++; |
| 91 | + // If there's no 'edit' tab, look for the 'view source' tab |
| 92 | + // instead. |
| 93 | + if ( $edit_tab_location == null ) { |
| 94 | + $edit_tab_location = array_search( 'viewsource', $tab_keys ); |
| 95 | + } |
| 96 | + |
| 97 | + // This should rarely happen, but if there was no edit *or* |
| 98 | + // view source tab, set the location index to -1, so the |
| 99 | + // tab shows up near the end. |
| 100 | + if ( $edit_tab_location == null ) { |
| 101 | + $edit_tab_location = - 1; |
| 102 | + } |
| 103 | + array_splice($tab_keys, $edit_tab_location, 0, 'credits'); |
| 104 | + array_splice($tab_values, $edit_tab_location, 0, array($credit_tab)); |
| 105 | + $content_actions = array(); |
| 106 | + for ($i = 0; $i < count($tab_keys); $i++) |
| 107 | + $content_actions[$tab_keys[$i]] = $tab_values[$i]; |
| 108 | + } |
| 109 | + return true; |
| 110 | +} |