left_delimiter = ''; $smarty->compile_dir = $wgWidgetsCompileDir; // registering custom Smarty plugins $smarty->addPluginsDir( __DIR__ . "/smarty_plugins/" ); $smarty->enableSecurity(); // These settings were for Smarty v2 - they don't seem to // have an equivalent in Smarty v3. /* $smarty->security_settings = array( 'IF_FUNCS' => array( 'is_array', 'isset', 'array', 'list', 'count', 'sizeof', 'in_array', 'true', 'false', 'null' ), 'MODIFIER_FUNCS' => array( 'validate' ) ); */ // Register the Widgets extension functions. $smarty->registerResource( 'wiki', [ [ 'WidgetRenderer', 'wiki_get_template' ], [ 'WidgetRenderer', 'wiki_get_timestamp' ], [ 'WidgetRenderer', 'wiki_get_secure' ], [ 'WidgetRenderer', 'wiki_get_trusted' ] ] ); $params = func_get_args(); // The first and second params are the parser and the widget // name - we already have both. array_shift( $params ); array_shift( $params ); $params_tree = []; foreach ( $params as $param ) { $pair = explode( '=', $param, 2 ); if ( count( $pair ) == 2 ) { $key = trim( $pair[0] ); $val = trim( $pair[1] ); } else { $key = $param; $val = true; } if ( $val == 'false' ) { $val = false; } /* If the name of the parameter has object notation a.b.c.d then we assign stuff to hash of hashes, not scalar */ $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 through all the keys but the last one. $last_key = array_pop( $keys ); foreach ( $keys as $subkey ) { // If next level of subtree doesn't exist yet, // create an empty one. if ( !array_key_exists( $subkey, $subtree ) ) { $subtree[$subkey] = []; } // move to the lower level $subtree =& $subtree[$subkey]; } // last portion of the key points to itself if ( isset( $subtree[$last_key] ) ) { // If this is already an array, push into it; // otherwise, convert into an array first. if ( !is_array( $subtree[$last_key] ) ) { $subtree[$last_key] = [ $subtree[$last_key] ]; } $subtree[$last_key][] = $val; } else { // doesn't exist yet, just setting a value $subtree[$last_key] = $val; } } $smarty->assign( $params_tree ); try { $output = $smarty->fetch( "wiki:$widgetName" ); } catch ( Exception $e ) { wfDebugLog( "Widgets", "Smarty exception while parsing '$widgetName': " . $e->getMessage() ); return '