Index: tags/extensions/Widgets/REL_0_8_2/Widgets.php |
— | — | @@ -0,0 +1,213 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * |
| 5 | + * {{#widget:<WidgetName>|<name1>=<value1>|<name2>=<value2>}} |
| 6 | + * |
| 7 | + * @author Sergey Chernyshev |
| 8 | + * @version $Id: Widgets.php 15 2008-06-25 21:22:40Z sergey.chernyshev $ |
| 9 | + */ |
| 10 | + |
| 11 | +$wgExtensionCredits['parserhook'][] = array( |
| 12 | + 'name' => 'Widgets', |
| 13 | + '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]', |
| 14 | + 'version' => '0.8.2', |
| 15 | + 'author' => '[http://www.sergeychernyshev.com Sergey Chernyshev] (for [http://www.semanticcommunities.com Semantic Communities LLC.])', |
| 16 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:Widgets' |
| 17 | +); |
| 18 | + |
| 19 | +// Initialize Smarty |
| 20 | + |
| 21 | +require "$IP/extensions/Widgets/smarty/Smarty.class.php"; |
| 22 | + |
| 23 | +// Parser function registration |
| 24 | +$wgExtensionFunctions[] = 'widgetParserFunctions'; |
| 25 | +$wgHooks['LanguageGetMagic'][] = 'widgetLanguageGetMagic'; |
| 26 | + |
| 27 | +// Init Widget namespaces |
| 28 | +widgetNamespacesInit(); |
| 29 | + |
| 30 | +function widgetParserFunctions() |
| 31 | +{ |
| 32 | + global $wgParser; |
| 33 | + $wgParser->setFunctionHook('widget', 'renderWidget'); |
| 34 | +} |
| 35 | + |
| 36 | +function widgetLanguageGetMagic( &$magicWords, $langCode = "en" ) |
| 37 | +{ |
| 38 | + switch ( $langCode ) { |
| 39 | + default: |
| 40 | + $magicWords['widget'] = array ( 0, 'widget' ); |
| 41 | + } |
| 42 | + return true; |
| 43 | +} |
| 44 | + |
| 45 | +function renderWidget (&$parser, $widgetName) |
| 46 | +{ |
| 47 | + global $IP; |
| 48 | + |
| 49 | + $smarty = new Smarty; |
| 50 | + $smarty->left_delimiter = '<!--{'; |
| 51 | + $smarty->right_delimiter = '}-->'; |
| 52 | + $smarty->compile_dir = "$IP/extensions/Widgets/compiled_templates/"; |
| 53 | + $smarty->security = true; |
| 54 | + $smarty->security_settings = array( |
| 55 | + 'IF_FUNCS' => array('is_array', 'isset', 'array', 'list', 'count', 'sizeof', 'in_array', 'true', 'false', 'null') |
| 56 | + ); |
| 57 | + |
| 58 | + // register the resource name "db" |
| 59 | + $smarty->register_resource("wiki", array("wiki_get_template", |
| 60 | + "wiki_get_timestamp", |
| 61 | + "wiki_get_secure", |
| 62 | + "wiki_get_trusted")); |
| 63 | + |
| 64 | + $params = func_get_args(); |
| 65 | + array_shift($params); # first one is parser - we don't need it |
| 66 | + array_shift($params); # second one is widget name |
| 67 | + |
| 68 | + $params_tree = array(); |
| 69 | + |
| 70 | + foreach ($params as $param) |
| 71 | + { |
| 72 | + $pair = explode('=', $param, 2); |
| 73 | + |
| 74 | + if (count($pair) == 2) |
| 75 | + { |
| 76 | + $key = trim($pair[0]); |
| 77 | + $val = trim($pair[1]); |
| 78 | + |
| 79 | + /* If the name of the parameter has object notation |
| 80 | + |
| 81 | + a.b.c.d |
| 82 | + |
| 83 | + then we assign stuff to hash of hashes, not scalar |
| 84 | + |
| 85 | + */ |
| 86 | + $keys = explode('.', $key); |
| 87 | + |
| 88 | + // $subtree will be moved from top to the bottom and at the end will point to the last level |
| 89 | + $subtree =& $params_tree; |
| 90 | + |
| 91 | + // go throught all the keys but last one |
| 92 | + $last_key = array_pop($keys); |
| 93 | + |
| 94 | + foreach ($keys as $subkey) |
| 95 | + { |
| 96 | + // if next level of subtree doesn't exist yet, create an empty one |
| 97 | + if (!array_key_exists($subkey, $subtree)) |
| 98 | + { |
| 99 | + $subtree[$subkey] = array(); |
| 100 | + } |
| 101 | + |
| 102 | + // move to the lower level |
| 103 | + $subtree =& $subtree[$subkey]; |
| 104 | + } |
| 105 | + |
| 106 | + // last portion of the key points to itself |
| 107 | + if (isset($subtree[$last_key])) |
| 108 | + { |
| 109 | + // if already an array, push into it, otherwise, convert into array first |
| 110 | + if (!is_array($subtree[$last_key])) |
| 111 | + { |
| 112 | + $subtree[$last_key] = array($subtree[$last_key]); |
| 113 | + } |
| 114 | + |
| 115 | + $subtree[$last_key][] = $val; |
| 116 | + } |
| 117 | + else |
| 118 | + { |
| 119 | + // doesn't exist yet, just setting a value |
| 120 | + $subtree[$last_key] = $val; |
| 121 | + } |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + $smarty->assign($params_tree); |
| 126 | + |
| 127 | + try |
| 128 | + { |
| 129 | + $output = $smarty->fetch("wiki:$widgetName"); |
| 130 | + } |
| 131 | + catch (Exception $e) |
| 132 | + { |
| 133 | + return "<div class=\"error\">Error in [[Widget:$widgetName]]</div>"; |
| 134 | + } |
| 135 | + |
| 136 | + return $parser->insertStripItem( $output, $parser->mStripState ); |
| 137 | +} |
| 138 | + |
| 139 | +function widgetNamespacesInit() { |
| 140 | + global $widgetNamespaceIndex, $wgExtraNamespaces, $wgNamespacesWithSubpages, |
| 141 | + $wgGroupPermissions, $wgNamespaceProtection; |
| 142 | + |
| 143 | + if (!isset($widgetNamespaceIndex)) { |
| 144 | + $widgetNamespaceIndex = 274; |
| 145 | + } |
| 146 | + |
| 147 | + define('NS_WIDGET', $widgetNamespaceIndex); |
| 148 | + define('NS_WIDGET_TALK', $widgetNamespaceIndex+1); |
| 149 | + |
| 150 | + // Register namespace identifiers |
| 151 | + if (!is_array($wgExtraNamespaces)) { $wgExtraNamespaces=array(); } |
| 152 | + $wgExtraNamespaces = $wgExtraNamespaces + array(NS_WIDGET => 'Widget', NS_WIDGET_TALK => 'Widget_talk'); |
| 153 | + |
| 154 | + // Support subpages only for talk pages by default |
| 155 | + $wgNamespacesWithSubpages = $wgNamespacesWithSubpages + array( |
| 156 | + NS_WIDGET_TALK => true |
| 157 | + ); |
| 158 | + |
| 159 | + // Assign editing to 3idgeteditor group only (widgets can be dangerous so we do it here, not in LocalSettings) |
| 160 | + $wgGroupPermissions['*']['editwidgets'] = false; |
| 161 | + $wgGroupPermissions['widgeteditor']['editwidgets'] = true; |
| 162 | + |
| 163 | + // Setting required namespace permission rights |
| 164 | + $wgNamespaceProtection[NS_WIDGET] = array( 'editwidgets' ); |
| 165 | +} |
| 166 | + |
| 167 | +// put these function somewhere in your application |
| 168 | +function wiki_get_template ($widgetName, &$widgetCode, &$smarty_obj) |
| 169 | +{ |
| 170 | + $widgetTitle = Title::newFromText($widgetName, NS_WIDGET); |
| 171 | + if ($widgetTitle && $widgetTitle->exists()) |
| 172 | + { |
| 173 | + $widgetArticle = new Article($widgetTitle, 0); |
| 174 | + $widgetCode = $widgetArticle->getContent(); |
| 175 | + |
| 176 | + // Remove <noinclude> sections and <includeonly> tags from form definition |
| 177 | + $widgetCode = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $widgetCode); |
| 178 | + $widgetCode = strtr($widgetCode, array('<includeonly>' => '', '</includeonly>' => '')); |
| 179 | + |
| 180 | + return true; |
| 181 | + } |
| 182 | + else |
| 183 | + { |
| 184 | + return false; |
| 185 | + } |
| 186 | +} |
| 187 | + |
| 188 | +function wiki_get_timestamp($widgetName, &$widgetTimestamp, &$smarty_obj) |
| 189 | +{ |
| 190 | + $widgetTitle = Title::newFromText($widgetName, NS_WIDGET); |
| 191 | + if ($widgetTitle && $widgetTitle->exists()) |
| 192 | + { |
| 193 | + $widgetArticle = new Article($widgetTitle, 0); |
| 194 | + $widgetTimestamp = $widgetArticle->getTouched(); |
| 195 | + |
| 196 | + return true; |
| 197 | + } |
| 198 | + else |
| 199 | + { |
| 200 | + return false; |
| 201 | + } |
| 202 | +} |
| 203 | + |
| 204 | +function wiki_get_secure($tpl_name, &$smarty_obj) |
| 205 | +{ |
| 206 | + // assume all templates are secure |
| 207 | + return true; |
| 208 | +} |
| 209 | + |
| 210 | +function wiki_get_trusted($tpl_name, &$smarty_obj) |
| 211 | +{ |
| 212 | + // not used for templates |
| 213 | +} |
| 214 | + |
Property changes on: tags/extensions/Widgets/REL_0_8_2/Widgets.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 215 | + native |
Index: tags/extensions/Widgets/REL_0_8_2/Makefile |
— | — | @@ -0,0 +1,31 @@ |
| 2 | +all: |
| 3 | + |
| 4 | +rel: release |
| 5 | +release: |
| 6 | +ifndef v |
| 7 | + # Must specify version as 'v' param |
| 8 | + # |
| 9 | + # make rel v=1.1.1 |
| 10 | + # |
| 11 | +else |
| 12 | + # |
| 13 | + # Tagging it with release tag |
| 14 | + # |
| 15 | + svn copy . svn+ssh://sergeychernyshev@svn.wikimedia.org/svnroot/mediawiki/tags/extensions/Widgets/REL_${subst .,_,${v}}/ |
| 16 | + # |
| 17 | + # Creating release tarball and zip |
| 18 | + # |
| 19 | + svn export . Widgets |
| 20 | + svn export smarty Widgets/smarty |
| 21 | + # Not including Makefile into the package since it's not doing anything but release packaging |
| 22 | + rm Widgets/Makefile |
| 23 | + tar -c Widgets -zf Widgets_${v}.tgz |
| 24 | + zip -r Widgets_${v}.zip Widgets |
| 25 | + rm -rf Widgets |
| 26 | + |
| 27 | + # |
| 28 | + # Copying tarball and zip to destination |
| 29 | + # |
| 30 | + mv Widgets_${v}.tgz ${dest} |
| 31 | + mv Widgets_${v}.zip ${dest} |
| 32 | +endif |
Property changes on: tags/extensions/Widgets/REL_0_8_2/Makefile |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 33 | + native |
Property changes on: tags/extensions/Widgets/REL_0_8_2 |
___________________________________________________________________ |
Name: svn:externals |
2 | 34 | + smarty http://smarty-php.googlecode.com/svn/tags/Smarty_2_6_18/libs/ |