r80750 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80749‎ | r80750 | r80751 >
Date:16:14, 22 January 2011
Author:dantman
Status:deferred
Tags:
Comment:
Add optional support for <metadesc> and {{#description2: methods of manually controlling the description.
Modified paths:
  • /trunk/extensions/Description2/Description2.i18n.magic.php (added) (history)
  • /trunk/extensions/Description2/Description2.php (modified) (history)

Diff [purge]

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
119 + native
Index: trunk/extensions/Description2/Description2.php
@@ -28,7 +28,7 @@
2929 $wgExtensionCredits['other'][] = array(
3030 'path' => __FILE__,
3131 'name' => 'Description2',
32 - 'version' => '0.1.1',
 32+ 'version' => '0.2',
3333 'author' => 'Daniel Friesen',
3434 'url' => 'http://www.mediawiki.org/wiki/Extension:Description2',
3535 'descriptionmsg' => 'description2-desc',
@@ -36,7 +36,17 @@
3737
3838 $dir = dirname( __FILE__ );
3939 $wgExtensionMessagesFiles['Description2'] = $dir . '/Description2.i18n.php';
 40+$wgExtensionMessagesFiles['Description2Magic'] = $dir . '/Description2.i18n.magic.php';
4041
 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+
4151 $wgHooks['ParserAfterTidy'][] = 'egDescription2ParserAfterTidy';
4252 function egDescription2ParserAfterTidy( &$parser, &$text ) {
4353 global $wgContLang;
@@ -56,14 +66,37 @@
5767 }
5868
5969 if ( $desc ) {
60 - $pOut = $parser->getOutput();
61 - $pOut->setProperty("description", $desc);
62 - $pOut->addOutputHook("setdescription");
 70+ efDescription2SetDescription( $parser, $desc );
6371 }
6472
6573 return true;
6674 }
6775
 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+
68101 $wgParserOutputHooks['setdescription'] = 'egDescription2ParserOutputSetDescription';
69102 function egDescription2ParserOutputSetDescription( $out, $parserOutput, $data ) {
70103 // Export the description from the main parser output into the OutputPage
@@ -77,3 +110,7 @@
78111 return true;
79112 }
80113
 114+
 115+## Configuration
 116+$wgEnableMetaDescriptionFunctions = false;
 117+

Status & tagging log