Index: trunk/extensions/Description2/Description2.i18n.magic.php |
— | — | @@ -0,0 +1,17 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Magic word internationalisation for Description2 extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +$magicWords = array(); |
| 11 | + |
| 12 | +/** English |
| 13 | + * @author Daniel Friesen |
| 14 | + */ |
| 15 | +$magicWords['en'] = array( |
| 16 | + 'description2' => array( 0, 'description2' ), |
| 17 | +); |
| 18 | + |
Property changes on: trunk/extensions/Description2/Description2.i18n.magic.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 19 | + native |
Index: trunk/extensions/Description2/Description2.php |
— | — | @@ -28,7 +28,7 @@ |
29 | 29 | $wgExtensionCredits['other'][] = array( |
30 | 30 | 'path' => __FILE__, |
31 | 31 | 'name' => 'Description2', |
32 | | - 'version' => '0.1.1', |
| 32 | + 'version' => '0.2', |
33 | 33 | 'author' => 'Daniel Friesen', |
34 | 34 | 'url' => 'http://www.mediawiki.org/wiki/Extension:Description2', |
35 | 35 | 'descriptionmsg' => 'description2-desc', |
— | — | @@ -36,7 +36,17 @@ |
37 | 37 | |
38 | 38 | $dir = dirname( __FILE__ ); |
39 | 39 | $wgExtensionMessagesFiles['Description2'] = $dir . '/Description2.i18n.php'; |
| 40 | +$wgExtensionMessagesFiles['Description2Magic'] = $dir . '/Description2.i18n.magic.php'; |
40 | 41 | |
| 42 | +function efDescription2SetDescription( $parser, $desc ) { |
| 43 | + $pOut = $parser->getOutput(); |
| 44 | + if ( $pOut->getProperty("description") !== false ) { |
| 45 | + return; |
| 46 | + } |
| 47 | + $pOut->setProperty("description", $desc); |
| 48 | + $pOut->addOutputHook("setdescription"); |
| 49 | +} |
| 50 | + |
41 | 51 | $wgHooks['ParserAfterTidy'][] = 'egDescription2ParserAfterTidy'; |
42 | 52 | function egDescription2ParserAfterTidy( &$parser, &$text ) { |
43 | 53 | global $wgContLang; |
— | — | @@ -56,14 +66,37 @@ |
57 | 67 | } |
58 | 68 | |
59 | 69 | if ( $desc ) { |
60 | | - $pOut = $parser->getOutput(); |
61 | | - $pOut->setProperty("description", $desc); |
62 | | - $pOut->addOutputHook("setdescription"); |
| 70 | + efDescription2SetDescription( $parser, $desc ); |
63 | 71 | } |
64 | 72 | |
65 | 73 | return true; |
66 | 74 | } |
67 | 75 | |
| 76 | +$wgHooks['ParserFirstCallInit'][] = array( 'efDescription2RegisterParser' ); |
| 77 | +function efDescription2RegisterParser( &$parser ) { |
| 78 | + global $wgEnableMetaDescriptionFunctions; |
| 79 | + if ( !$wgEnableMetaDescriptionFunctions ) { |
| 80 | + // Functions and tags are disabled |
| 81 | + return true; |
| 82 | + } |
| 83 | + $parser->setFunctionHook( 'description2', 'efDescription2Function', Parser::SFH_OBJECT_ARGS ); |
| 84 | + $parser->setFunctionTagHook( 'metadesc', 'efDescription2Tag', Parser::SFH_OBJECT_ARGS ); |
| 85 | + return true; |
| 86 | +} |
| 87 | + |
| 88 | +function efDescription2Function( $parser, $frame, $args ) { |
| 89 | + $desc = isset( $args[0] ) ? $frame->expand( $args[0] ) : ''; |
| 90 | + efDescription2SetDescription( $parser, $desc ); |
| 91 | + return ''; |
| 92 | +} |
| 93 | +function efDescription2Tag( $parser, $frame, $content, $attributes ) { |
| 94 | + $desc = (isset( $content ) ? $content : (isset($attributes["content"]) ? $attributes["content"] : null)); |
| 95 | + if ( isset($desc) ) { |
| 96 | + efDescription2SetDescription( $parser, $desc ); |
| 97 | + } |
| 98 | + return ''; |
| 99 | +} |
| 100 | + |
68 | 101 | $wgParserOutputHooks['setdescription'] = 'egDescription2ParserOutputSetDescription'; |
69 | 102 | function egDescription2ParserOutputSetDescription( $out, $parserOutput, $data ) { |
70 | 103 | // Export the description from the main parser output into the OutputPage |
— | — | @@ -77,3 +110,7 @@ |
78 | 111 | return true; |
79 | 112 | } |
80 | 113 | |
| 114 | + |
| 115 | +## Configuration |
| 116 | +$wgEnableMetaDescriptionFunctions = false; |
| 117 | + |