Revision: 51825 Author: ialex Date: 2009-06-13 17:13:12 +0000 (Sat, 13 Jun 2009)
Log Message: ----------- * Added internationalisation file with extension's description and a message hardcoded in English * put extra namespace definition out of the extension function, otherwise it doesn't work for me (namespace protection left in the extension function) * coding style fixes Modified Paths: -------------- trunk/extensions/Widgets/Widgets.php Added Paths: ----------- trunk/extensions/Widgets/Widgets.i18n.php Added: trunk/extensions/Widgets/Widgets.i18n.php =================================================================== --- trunk/extensions/Widgets/Widgets.i18n.php (rev 0) +++ trunk/extensions/Widgets/Widgets.i18n.php 2009-06-13 17:13:12 UTC (rev 51825) @@ -0,0 +1,12 @@ +<?php +/** + * Internationalisation file for Widgets extension. + * + */ + +$messages = array(); + +$messages['en'] = array( + 'widgets-desc' => 'Allows wiki administrators to add free-form widgets to wiki by just editing pages within Widget namespace. Originally developed for [http://www.ardorado.com Ardorado.com].', + 'widgets-error' => 'Error in [[Widget:$1]]', +); Property changes on: trunk/extensions/Widgets/Widgets.i18n.php ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/extensions/Widgets/Widgets.php =================================================================== --- trunk/extensions/Widgets/Widgets.php 2009-06-13 16:09:26 UTC (rev 51824) +++ trunk/extensions/Widgets/Widgets.php 2009-06-13 17:13:12 UTC (rev 51825) @@ -14,11 +14,12 @@ $wgExtensionCredits['parserhook'][] = array( 'path' => __FILE__, - 'name' => 'Widgets', - 'description' => 'Allows wiki administrators to add free-form widgets to wiki by just editing pages within Widget namespace. Originally developed for [http://www.ardorado.com Ardorado.com]', + 'name' => 'Widgets', + 'description' => 'Allows wiki administrators to add free-form widgets to wiki by just editing pages within Widget namespace. Originally developed for [http://www.ardorado.com Ardorado.com]', + 'descriptionmsg' => 'widgets-desc', 'version' => '0.8.6', - 'author' => '[http://www.sergeychernyshev.com Sergey Chernyshev] (for [http://www.semanticcommunities.com Semantic Communities LLC.])', - 'url' => 'http://www.mediawiki.org/wiki/Extension:Widgets' + 'author' => '[http://www.sergeychernyshev.com Sergey Chernyshev] (for [http://www.semanticcommunities.com Semantic Communities LLC.])', + 'url' => 'http://www.mediawiki.org/wiki/Extension:Widgets' ); /** @@ -33,23 +34,31 @@ throw new MWException( 'Configuration error. Do not define NS_WIDGET_TALK, it is automatically set based on NS_WIDGET.' ); } +// Define new namespaces +$wgExtraNamespaces[NS_WIDGET] = 'Widget'; +$wgExtraNamespaces[NS_WIDGET_TALK] = 'Widget_talk'; + +// Support subpages only for talk pages by default +$wgNamespacesWithSubpages[NS_WIDGET_TALK] = true; + +$dir = dirname( __FILE__ ) . '/'; + // Initialize Smarty -require dirname(__FILE__)."/smarty/Smarty.class.php"; +require_once( $dir . 'smarty/Smarty.class.php' ); +$wgExtensionMessagesFile['Widgets'] = $dir . 'Widgets.i18n.php'; // Parser function registration $wgExtensionFunctions[] = 'widgetNamespacesInit'; $wgHooks['LanguageGetMagic'][] = 'widgetLanguageGetMagic'; $wgHooks['ParserFirstCallInit'][] = 'widgetParserFunctions'; -function widgetParserFunctions( &$parser ) -{ - $parser->setFunctionHook('widget', 'renderWidget'); +function widgetParserFunctions( &$parser ) { + $parser->setFunctionHook( 'widget', 'renderWidget' ); return true; } -function widgetLanguageGetMagic( &$magicWords, $langCode = "en" ) -{ +function widgetLanguageGetMagic( &$magicWords, $langCode = 'en' ) { switch ( $langCode ) { default: $magicWords['widget'] = array ( 0, 'widget' ); @@ -57,8 +66,7 @@ return true; } -function renderWidget (&$parser, $widgetName) -{ +function renderWidget ( &$parser, $widgetName ) { global $IP; $smarty = new Smarty; @@ -83,38 +91,38 @@ 'false', 'null' ), - 'MODIFIER_FUNCS' => array('validate') + 'MODIFIER_FUNCS' => array( 'validate' ) ); // register the resource name "db" - $smarty->register_resource("wiki", array("wiki_get_template", - "wiki_get_timestamp", - "wiki_get_secure", - "wiki_get_trusted")); + $smarty->register_resource( + 'wiki', + array( + 'wiki_get_template', + 'wiki_get_timestamp', + 'wiki_get_secure', + 'wiki_get_trusted' + ) + ); - $params = func_get_args(); - array_shift($params); # first one is parser - we don't need it - array_shift($params); # second one is widget name + $params = func_get_args(); + array_shift( $params ); # first one is parser - we don't need it + array_shift( $params ); # second one is widget name $params_tree = array(); - foreach ($params as $param) - { - $pair = explode('=', $param, 2); + foreach ( $params as $param ) { + $pair = explode('=', $param, 2); - if (count($pair) == 2) - { + if ( count( $pair ) == 2 ) { $key = trim($pair[0]); $val = trim($pair[1]); - } - else - { + } else { $key = $param; $val = true; } - if ($val == 'false') - { + if ( $val == 'false' ) { $val = false; } @@ -125,19 +133,17 @@ then we assign stuff to hash of hashes, not scalar */ - $keys = explode('.', $key); + $keys = explode( '.', $key ); // $subtree will be moved from top to the bottom and at the end will point to the last level $subtree =& $params_tree; // go throught all the keys but last one - $last_key = array_pop($keys); + $last_key = array_pop( $keys ); - foreach ($keys as $subkey) - { + foreach ( $keys as $subkey ) { // if next level of subtree doesn't exist yet, create an empty one - if (!array_key_exists($subkey, $subtree)) - { + if ( !array_key_exists( $subkey, $subtree ) ) { $subtree[$subkey] = array(); } @@ -146,51 +152,35 @@ } // last portion of the key points to itself - if (isset($subtree[$last_key])) - { + if ( isset( $subtree[$last_key] ) ) { // if already an array, push into it, otherwise, convert into array first - if (!is_array($subtree[$last_key])) - { - $subtree[$last_key] = array($subtree[$last_key]); + if ( !is_array( $subtree[$last_key] ) ) { + $subtree[$last_key] = array( $subtree[$last_key] ); } $subtree[$last_key][] = $val; - } - else - { + } else { // doesn't exist yet, just setting a value $subtree[$last_key] = $val; } - } + } - $smarty->assign($params_tree); + $smarty->assign( $params_tree ); - try - { - $output = $smarty->fetch("wiki:$widgetName"); + try { + $output = $smarty->fetch( "wiki:$widgetName" ); + } catch ( Exception $e ) { + wfLoadExtensionMessages( 'Widgets' ); + return '<div class=\"error\">' . wfMsgExt( 'widgets-desc', array( 'parsemag' ), $widgetName ) . '</div>'; } - catch (Exception $e) - { - return "<div class=\"error\">Error in [[Widget:$widgetName]]</div>"; - } return $parser->insertStripItem( $output, $parser->mStripState ); } function widgetNamespacesInit() { - global $wgExtraNamespaces, $wgNamespacesWithSubpages, - $wgGroupPermissions, $wgNamespaceProtection; + global $wgGroupPermissions, $wgNamespaceProtection; - // Register namespace identifiers - if (!is_array($wgExtraNamespaces)) { $wgExtraNamespaces=array(); } - $wgExtraNamespaces = $wgExtraNamespaces + array(NS_WIDGET => 'Widget', NS_WIDGET_TALK => 'Widget_talk'); - - // Support subpages only for talk pages by default - $wgNamespacesWithSubpages = $wgNamespacesWithSubpages + array( - NS_WIDGET_TALK => true - ); - - // Assign editing to 3idgeteditor group only (widgets can be dangerous so we do it here, not in LocalSettings) + // Assign editing to widgeteditor group only (widgets can be dangerous so we do it here, not in LocalSettings) $wgGroupPermissions['*']['editwidgets'] = false; $wgGroupPermissions['widgeteditor']['editwidgets'] = true; @@ -199,50 +189,40 @@ } // put these function somewhere in your application -function wiki_get_template ($widgetName, &$widgetCode, &$smarty_obj) -{ +function wiki_get_template( $widgetName, &$widgetCode, &$smarty_obj ) { $widgetTitle = Title::newFromText($widgetName, NS_WIDGET); - if ($widgetTitle && $widgetTitle->exists()) - { - $widgetArticle = new Article($widgetTitle, 0); + if ( $widgetTitle && $widgetTitle->exists() ) { + $widgetArticle = new Article( $widgetTitle, 0 ); $widgetCode = $widgetArticle->getContent(); // Remove <noinclude> sections and <includeonly> tags from form definition - $widgetCode = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $widgetCode); - $widgetCode = strtr($widgetCode, array('<includeonly>' => '', '</includeonly>' => '')); + $widgetCode = StringUtils::delimiterReplace( '<noinclude>', '</noinclude>', '', $widgetCode ); + $widgetCode = strtr( $widgetCode, array( '<includeonly>' => '', '</includeonly>' => '' ) ); return true; - } - else - { + } else { return false; } } -function wiki_get_timestamp($widgetName, &$widgetTimestamp, &$smarty_obj) -{ - $widgetTitle = Title::newFromText($widgetName, NS_WIDGET); - if ($widgetTitle && $widgetTitle->exists()) - { - $widgetArticle = new Article($widgetTitle, 0); +function wiki_get_timestamp( $widgetName, &$widgetTimestamp, &$smarty_obj ) { + $widgetTitle = Title::newFromText( $widgetName, NS_WIDGET ); + if ($widgetTitle && $widgetTitle->exists()) { + $widgetArticle = new Article( $widgetTitle, 0 ); $widgetTimestamp = $widgetArticle->getTouched(); return true; - } - else - { + } else { return false; } } -function wiki_get_secure($tpl_name, &$smarty_obj) -{ +function wiki_get_secure( $tpl_name, &$smarty_obj ) { // assume all templates are secure return true; } -function wiki_get_trusted($tpl_name, &$smarty_obj) -{ +function wiki_get_trusted( $tpl_name, &$smarty_obj ) { // not used for templates } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs