Index: trunk/extensions/HideNamespace.php |
— | — | @@ -0,0 +1,129 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Extension HideNamespace - Hides namespace in the header and title when a page is in specified namespace |
| 6 | + * or when the {{#hidens:}} parser function is called. |
| 7 | + * |
| 8 | + * @package MediaWiki |
| 9 | + * @subpackage Extensions |
| 10 | + * @author Matěj Grabovský (mgrabovsky.github.com) |
| 11 | + * @copyright © 2010, Matěj Grabovský |
| 12 | + * @licence GNU General Public Licence 2.0 or later |
| 13 | + */ |
| 14 | + |
| 15 | +if( !defined('MEDIAWIKI') ) { |
| 16 | + echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" ); |
| 17 | + die(); |
| 18 | +} |
| 19 | + |
| 20 | +$wgExtensionMessagesFiles['HideNamespace'] = dirname(__FILE__) . '/HideNamespace.i18n.php'; |
| 21 | +$wgExtensionMessagesFiles['HideNamespaceMagic'] = dirname(__FILE__) . '/HideNamespace.i18n.magic.php'; |
| 22 | + |
| 23 | +$wgExtensionFunctions[] = 'wfHideNamespaceSetup'; |
| 24 | +$wgExtensionCredits['other'][] = array( |
| 25 | + 'path' => __FILE__, |
| 26 | + 'name' => "HideNamespace", |
| 27 | + 'description' => "Hides namespace in the header and title when a page is in specified namespace or when the <code><nowiki>{{#hidens:}}</nowiki></code> parser function is called.", |
| 28 | + 'descriptionmsg' => "hidens-desc", |
| 29 | + 'version' => "1.3", |
| 30 | + 'author' => "Matěj Grabovský", |
| 31 | + 'url' => "http://www.mediawiki.org/wiki/Extension:HideNamespace", |
| 32 | +); |
| 33 | + |
| 34 | +function wfHideNamespaceSetup() { |
| 35 | + global $wgParser, $wgHooks; |
| 36 | + |
| 37 | + $extHidensObj = new ExtensionHideNamespace; |
| 38 | + |
| 39 | + // Register hooks |
| 40 | + $wgHooks['ArticleViewHeader'][] = array( $extHidensObj, 'onArticleViewHeader' ); |
| 41 | + $wgHooks['BeforePageDisplay'][] = array( $extHidensObj, 'onBeforePageDisplay' ); |
| 42 | + |
| 43 | + // If we support ParserFirstCallInit, hook our function to register PF hooks with it |
| 44 | + if( defined('MW_SUPPORTS_PARSERFIRSTCALLINIT') ) { |
| 45 | + $wgHooks['ParserFirstCallInit'][] = array( $extHidensObj, 'RegisterParser' ); |
| 46 | + |
| 47 | + // Else manualy unstub Parser and call our function |
| 48 | + } else { |
| 49 | + if( class_exists( 'StubObject' ) && !StubObject::isRealObject( $wgParser ) ) { |
| 50 | + $wgParser->_unstub(); |
| 51 | + } |
| 52 | + $extHidensObj->RegisterParser( $wgParser ); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +class ExtensionHideNamespace { |
| 57 | + private static $namespace, $namespaceL10n; |
| 58 | + private static $forceHide = false, $forceShow = false; |
| 59 | + |
| 60 | + /** |
| 61 | + * Register our parser functions. |
| 62 | + */ |
| 63 | + function RegisterParser( &$parser ) { |
| 64 | + $parser->setFunctionHook( 'hidens', array( $this, 'hideNs' ) ); |
| 65 | + $parser->setFunctionHook( 'showns', array( $this, 'showNs' ) ); |
| 66 | + |
| 67 | + return true; |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Callback for our parser function {{#hidens:}}. |
| 72 | + * Force to hide the namespace. |
| 73 | + */ |
| 74 | + function hideNs( &$parser ) { |
| 75 | + self::$forceHide = true; |
| 76 | + |
| 77 | + return ''; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Callback for our parser function {{#showns:}}. |
| 82 | + * Force to show the namespace. |
| 83 | + */ |
| 84 | + function showNs( &$parser ) { |
| 85 | + self::$forceShow = true; |
| 86 | + |
| 87 | + return ''; |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Callback for the ArticleViewHeader hook. |
| 92 | + * Saves namespace identifier and localized namespace name to the $namespace and $namespaceL10n variables. |
| 93 | + */ |
| 94 | + function onArticleViewHeader( $article, $outputDone, $enableParserCcache ) { |
| 95 | + self::$namespace = $article->mTitle->mNamespace; |
| 96 | + |
| 97 | + if( self::$namespace === NS_MAIN ) { |
| 98 | + self::$namespaceL10n = ''; |
| 99 | + } else { |
| 100 | + self::$namespaceL10n = substr( $article->mTitle->getPrefixedText(), 0, strpos($article->mTitle->getPrefixedText(),':') ); |
| 101 | + } |
| 102 | + |
| 103 | + return true; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Callback for the OutputPageBeforeHTML hook. |
| 108 | + * "Hides" the namespace in the header and in title. |
| 109 | + */ |
| 110 | + function onBeforePageDisplay( &$out, $skin ) { |
| 111 | + if( self::$namespace === NS_MAIN ) |
| 112 | + return true; |
| 113 | + |
| 114 | + global $wgHideNsNamespaces; |
| 115 | + |
| 116 | + // Hide the namespace if: |
| 117 | + // * The page's namespace is contained in the $wgHideNsNamespaces array |
| 118 | + // or |
| 119 | + // * The {{#hidens:}} function was called |
| 120 | + // BUT *not* when the {{#showns:}} function was called |
| 121 | + |
| 122 | + if( ( (isset($wgHideNsNamespaces) && in_array(self::$namespace, $wgHideNsNamespaces)) || self::$forceHide ) && |
| 123 | + !self::$forceShow ) |
| 124 | + { |
| 125 | + $out->setPageTitle( substr( $out->getPageTitle(), strlen(self::$namespaceL10n)+1 ) ); |
| 126 | + } |
| 127 | + |
| 128 | + return true; |
| 129 | + } |
| 130 | +} |
Property changes on: trunk/extensions/HideNamespace.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 131 | + native |
Index: trunk/extensions/HideNamespace.i18n.magic.php |
— | — | @@ -0,0 +1,11 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +$magicWords = array(); |
| 5 | + |
| 6 | +/** |
| 7 | + * English |
| 8 | + */ |
| 9 | +$magicWords['en'] = array( |
| 10 | + 'hidens' => array( 0, 'hidens' ), |
| 11 | + 'showns' => array( 0, 'showns' ), |
| 12 | +); |
Property changes on: trunk/extensions/HideNamespace.i18n.magic.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 13 | + native |
Index: trunk/extensions/HideNamespace.i18n.php |
— | — | @@ -0,0 +1,39 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Internationalisation for extension HideNamespace. |
| 6 | + * |
| 7 | + * @package MediaWiki |
| 8 | + * @subpackage Extensions |
| 9 | + */ |
| 10 | + |
| 11 | +$messages = array(); |
| 12 | + |
| 13 | +/** English |
| 14 | + * @author Matěj Grabovský |
| 15 | + */ |
| 16 | +$messages['en'] = array( |
| 17 | + 'hidens-desc' => 'Hides namespace in the header and title when a page is in specified namespace or when the <code><nowiki>{{#hidens:}}</nowiki></code> parser function is called.', |
| 18 | +); |
| 19 | + |
| 20 | +/** Message documentation (Message documentation) |
| 21 | + * @author Matěj Grabovský |
| 22 | + */ |
| 23 | +$messages['qqq'] = array( |
| 24 | + 'hidens-desc' => 'Short description of the extension. Shown in [[Special:Version]].', |
| 25 | +); |
| 26 | + |
| 27 | +/** Czech (Česky) |
| 28 | + * @author Matěj Grabovský |
| 29 | + */ |
| 30 | +$messages['cs'] = array( |
| 31 | + 'hidens-desc' => 'Skryje jmenný prostor v nadpisu a titulku, když je stránka ve specifikovaném jmenném prostoru nebo když je zavolána funkce parseru <code><nowiki>{{#hidens:}}</nowiki></code>.', |
| 32 | +); |
| 33 | + |
| 34 | +/** German (Deutsch) |
| 35 | + * @author Jork Leiterer |
| 36 | + * @author kghbln |
| 37 | + */ |
| 38 | +$messages['de'] = array( |
| 39 | + 'hidens-desc' => 'Versteckt die Bezeichnung des Namensraums in Header und Titel einer Seite, sofern sie sich in einem nicht anzuzeigenden Namensraum befindet, oder wenn die <code><nowiki>{{#hidens:}}</nowiki></code> Parser-Funktion genutzt wird.', |
| 40 | +); |
Property changes on: trunk/extensions/HideNamespace.i18n.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 41 | + native |