Index: trunk/extensions/StringFunctionsEscaped/README |
— | — | @@ -0,0 +1,185 @@ |
| 2 | +{{Extension|templatemode=
|
| 3 | +|name = StringFunctionsEscaped
|
| 4 | +|status = beta
|
| 5 | +|type1 = parser function
|
| 6 | +|type2 =
|
| 7 | +|hook1 = LanguageGetMagic
|
| 8 | +|hook2 =
|
| 9 | +|username = [[user:jpond | Jack D. Pond ]]
|
| 10 | +|author =
|
| 11 | +|description = Defines a superset of string parser functions that allow character escaping in the 'search for' and 'replace with' arguments.
|
| 12 | +|image =
|
| 13 | +|imagesize =
|
| 14 | +|version = 1.0.0
|
| 15 | +|update = 2009-09-11
|
| 16 | +|mediawiki = Tested with 1.14,1.15,1.16A, Should work with all
|
| 17 | +|php =
|
| 18 | +|license = GNU Version 2
|
| 19 | +|download =
|
| 20 | +|readme =
|
| 21 | +|changelog =
|
| 22 | +|parameters = $wgPFEnableStringFunctions
|
| 23 | +|tags =
|
| 24 | +|rights =
|
| 25 | +|example =
|
| 26 | +|compatibility =
|
| 27 | +}}
|
| 28 | +
|
| 29 | +
|
| 30 | +
|
| 31 | +==What can this extension do?==
|
| 32 | +
|
| 33 | +Wikitext allows the imbedding of certain control characters (newline, tab, etc.). These parser functions allow them to be identified and used with standard c-type escape character sequence (/n,/t, etc.).
|
| 34 | +
|
| 35 | +These can be used (among other things) to make infoblox-type templates much more WYSIWIG (see Examples) for novice/non-technical users.
|
| 36 | +
|
| 37 | +==Usage==
|
| 38 | +
|
| 39 | +These functions are all invoked exactly as their string parser functions would be (except with the '_e' appended to distinguish).
|
| 40 | +
|
| 41 | +=== pos_e: (string position)===
|
| 42 | +
|
| 43 | +<nowiki>{{#pos_e:value|key|offset}}</nowiki>
|
| 44 | +
|
| 45 | +Returns the first position of key inside the given value, or an empty string.
|
| 46 | +If offset is defined, this method will not search the first offset characters.
|
| 47 | +
|
| 48 | +See: http://php.net/manual/function.strpos.php
|
| 49 | +
|
| 50 | +=== rpos_e: (string position, reverse) ===
|
| 51 | +<nowiki>{{#rpos_e:value|key}}</nowiki>
|
| 52 | +Returns the last position of key inside the given value, or -1 if the key is not found. When using this to search for the last delimiter, add +1 to the result to retreive position after the last delimiter. This also works when the delimiter is not found, because "-1 + 1" is zero, which is the beginning of the given value.
|
| 53 | +
|
| 54 | +See: http://php.net/manual/function.strrpos.php
|
| 55 | +
|
| 56 | +=== pad_e: (pad string) ===
|
| 57 | +<nowiki>{{#pad_e:value|length|with|direction}}</nowiki>
|
| 58 | +
|
| 59 | +Returns the value padded to the certain length with the given with string.
|
| 60 | +If the with string is not given, spaces are used for padding. The direction may be specified as: 'left', 'center' or 'right'.
|
| 61 | +
|
| 62 | +See: http://php.net/manual/function.str-pad.php
|
| 63 | +
|
| 64 | +=== replace_e: (string replace) ===
|
| 65 | +
|
| 66 | +<nowiki>{{#replace_e:value|from|to}}</nowiki>
|
| 67 | +
|
| 68 | +Returns the given value with all occurences of 'from' replaced with 'to'.
|
| 69 | +
|
| 70 | +See: http://php.net/manual/function.str-replace.php
|
| 71 | +
|
| 72 | +=== explode_e: (explode string) ===
|
| 73 | +<nowiki>{{#explode_e:value|delimiter|position}}</nowiki>
|
| 74 | +
|
| 75 | +Splits the given value into pieces by the given delimiter and returns the position-th piece. Empty string is returned if there are not enough pieces.
|
| 76 | +
|
| 77 | +Note: Pieces are counted from 0.<br>
|
| 78 | +Note: A negative value can be used to count pieces from the end, instead of counting from the beginning. The last piece is at position -1.
|
| 79 | +
|
| 80 | +See: http://php.net/manual/function.explode.php
|
| 81 | +
|
| 82 | +==Download instructions==
|
| 83 | +<!-- revise these instructions if code is available via a download site -->
|
| 84 | +Please cut and paste the code found [[#Code|below]] and place it in <code>$IP/extensions/ExtensionName/ExtensionName.php</code>. ''Note: [[Manual:$IP|$IP]] stands for the root directory of your MediaWiki installation, the same directory that holds [[Manual:LocalSettings.php|LocalSettings.php]]''.
|
| 85 | +
|
| 86 | +==Installation==
|
| 87 | +String functions were integrated into [[Extension:ParserFunctions]] extension as of [[Special:Code/MediaWiki/50997|r50997]]. This revision of [[Extension:ParserFunctions]] is designed for MediaWiki 1.16, but updating to the trunk version may work on previous versions. If you are using a prior version of [[Extension:ParserFunctions]], you will also have to include [[Extension:StringFunctions]].
|
| 88 | +
|
| 89 | +Install and test [[Extension:ParserFunctions]] and (if necessary) [[Extension:StringFunctions]] prior to installing this extension.
|
| 90 | +
|
| 91 | +This extension must be included AFTER the invocation of the string parser functions.
|
| 92 | +To install this extension, add the following to [[Manual:LocalSettings.php|LocalSettings.php]]:
|
| 93 | +
|
| 94 | +=== For MediaWiki 1.15.1 and before ===
|
| 95 | +<source lang="php">
|
| 96 | +require_once("$IP/extensions/ParserFunctions/ParserFunctions.php");
|
| 97 | +require_once("$IP/extensions/StringFunctions/StringFunctions.php");
|
| 98 | +require_once("$IP/extensions/StringFunctionsEscaped/StringFunctionsEscaped.php");
|
| 99 | +</source>
|
| 100 | +
|
| 101 | +=== For MediaWiki 1.16a and after ===
|
| 102 | +<source lang="php">
|
| 103 | +require_once("$IP/extensions/ParserFunctions/ParserFunctions.php");
|
| 104 | +$wgPFEnableStringFunctions = true; // Note: this must be after ParserFunctions and before StringFunctionsEscaped
|
| 105 | +require_once("$IP/extensions/StringFunctionsEscaped/StringFunctionsEscaped.php");
|
| 106 | +</source>
|
| 107 | +==Examples==
|
| 108 | +
|
| 109 | +=== pos_e ===
|
| 110 | +
|
| 111 | +<pre>
|
| 112 | +{{#pos_e:Line 1
|
| 113 | +Line 2
|
| 114 | +Line 3|\n|7}}
|
| 115 | +
|
| 116 | +Returns:
|
| 117 | +
|
| 118 | +13
|
| 119 | +</pre>
|
| 120 | +
|
| 121 | +=== rpos_e ===
|
| 122 | +<pre>
|
| 123 | +{{#rpos_e:Line 1
|
| 124 | +Line 2
|
| 125 | +Line 3|\n}}
|
| 126 | +
|
| 127 | +Returns:
|
| 128 | +
|
| 129 | +13
|
| 130 | +</pre>
|
| 131 | +
|
| 132 | +=== pad_e ===
|
| 133 | +<pre>
|
| 134 | +~~{{#pad_e:xox|9|\n|center}}~~
|
| 135 | +
|
| 136 | +Returns:
|
| 137 | +
|
| 138 | +~~
|
| 139 | +
|
| 140 | +
|
| 141 | +xox
|
| 142 | +
|
| 143 | +
|
| 144 | +~~
|
| 145 | +</pre>
|
| 146 | +
|
| 147 | +=== replace_e ===
|
| 148 | +<pre>
|
| 149 | +{{#replace_e:Line 1
|
| 150 | +Line 2
|
| 151 | +Line 3|\n|<br>\n}}
|
| 152 | +
|
| 153 | +Returns:
|
| 154 | +
|
| 155 | +Line 1<br>
|
| 156 | +Line 2<br>
|
| 157 | +Line 3
|
| 158 | +
|
| 159 | +Which would display as:
|
| 160 | +
|
| 161 | +Line 1
|
| 162 | +Line 2
|
| 163 | +Line 3
|
| 164 | +
|
| 165 | +Rather than the unescaped:
|
| 166 | +
|
| 167 | +Line 1 Line 2 Line 3
|
| 168 | +
|
| 169 | +</pre>
|
| 170 | +
|
| 171 | +=== explode_e ===
|
| 172 | +<pre>
|
| 173 | +{{#explode_e:Line 1
|
| 174 | +Line 2
|
| 175 | +Line 3|\n|1}}
|
| 176 | +
|
| 177 | +Returns:
|
| 178 | +
|
| 179 | +Line 2
|
| 180 | +
|
| 181 | +</pre>
|
| 182 | +==See also==
|
| 183 | +
|
| 184 | +* [[Extension:ParserFunctions]]
|
| 185 | +* [[Extension:StringFunctions]]
|
| 186 | +* [[Extension:Lua]]
|
Index: trunk/extensions/StringFunctionsEscaped/StringFunctionsEscaped.php |
— | — | @@ -0,0 +1,163 @@ |
| 2 | +<?php |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) |
| 4 | + die( 'StringFunctionsEscaped::This file is a MediaWiki extension, it is not a valid entry point' ); |
| 5 | +if ( !class_exists('ExtStringFunctions',false) && |
| 6 | + !(class_exists('ParserFunctions_HookStub',false) && isset($wgPFEnableStringFunctions) && $wgPFEnableStringFunctions)) |
| 7 | + die( 'StringFunctionsEscaped::You must have extension StringFunctions or extension ParserFunctions with string functions enabled' ); |
| 8 | +/* |
| 9 | + |
| 10 | + Defines a superset of string parser functions that allow character escaping in the 'search for' and 'replace with' arguments. |
| 11 | + |
| 12 | + {{#pos_e:value|key|offset}} |
| 13 | + |
| 14 | + Returns the first position of key inside the given value, or an empty string. |
| 15 | + If offset is defined, this method will not search the first offset characters. |
| 16 | + See: http://php.net/manual/function.strpos.php |
| 17 | + |
| 18 | + {{#rpos_e:value|key}} |
| 19 | + |
| 20 | + Returns the last position of key inside the given value, or -1 if the key is |
| 21 | + not found. When using this to search for the last delimiter, add +1 to the |
| 22 | + result to retreive position after the last delimiter. This also works when |
| 23 | + the delimiter is not found, because "-1 + 1" is zero, which is the beginning |
| 24 | + of the given value. |
| 25 | + See: http://php.net/manual/function.strrpos.php |
| 26 | + |
| 27 | + {{#pad_e:value|length|with|direction}} |
| 28 | + |
| 29 | + Returns the value padded to the certain length with the given with string. |
| 30 | + If the with string is not given, spaces are used for padding. The direction |
| 31 | + may be specified as: 'left', 'center' or 'right'. |
| 32 | + See: http://php.net/manual/function.str-pad.php |
| 33 | + |
| 34 | + |
| 35 | + {{#replace_e:value|from|to}} |
| 36 | + |
| 37 | + Returns the given value with all occurences of 'from' replaced with 'to'. |
| 38 | + See: http://php.net/manual/function.str-replace.php |
| 39 | + |
| 40 | + |
| 41 | + {{#explode_e:value|delimiter|position}} |
| 42 | + |
| 43 | + Splits the given value into pieces by the given delimiter and returns the |
| 44 | + position-th piece. Empty string is returned if there are not enough pieces. |
| 45 | + Note: Pieces are counted from 0. |
| 46 | + Note: A negative value can be used to count pieces from the end, instead of |
| 47 | + counting from the beginning. The last piece is at position -1. |
| 48 | + See: http://php.net/manual/function.explode.php |
| 49 | + |
| 50 | + |
| 51 | + Copyright (c) 2009 Jack D. Pond |
| 52 | + Licensed under GNU version 2 |
| 53 | +*/ |
| 54 | + |
| 55 | +$wgExtensionCredits['parserhook'][] = array( |
| 56 | + 'path' => __FILE__, |
| 57 | + 'name' => 'StringFunctionsEscaped', |
| 58 | + 'version' => '1.0.0', // Sept 7, 2009 |
| 59 | + 'description' => 'Allows escaped characters in string functions using c-like syntax', |
| 60 | + 'descriptionmsg' => 'pfunc_desc', |
| 61 | + 'author' => array('Jack D. Pond'), |
| 62 | + 'license' => 'GNU Version 2', |
| 63 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:StringFunctionsEscaped', |
| 64 | +); |
| 65 | + |
| 66 | +$dir = dirname( __FILE__ ) . '/'; |
| 67 | +# RFU |
| 68 | +# $wgExtensionMessagesFiles['StringFunctionsEscaped'] = $dir . 'StringFunctionsEscaped.i18n.php'; |
| 69 | + |
| 70 | +$wgExtensionFunctions[] = 'wfStringFunctionsEscaped'; |
| 71 | + |
| 72 | +$wgHooks['LanguageGetMagic'][] = 'wfStringFunctionsEscapedLanguageGetMagic'; |
| 73 | + |
| 74 | +function wfStringFunctionsEscaped ( ) { |
| 75 | + global $wgParser, $wgExtStringFunctionsEscaped; |
| 76 | + |
| 77 | + $wgExtStringFunctionsEscaped = new ExtStringFunctionsEscaped ( ); |
| 78 | + |
| 79 | + $wgParser->setFunctionHook('pos_e', array(&$wgExtStringFunctionsEscaped,'runPos_e' )); |
| 80 | + $wgParser->setFunctionHook('rpos_e', array(&$wgExtStringFunctionsEscaped,'runRPos_e' )); |
| 81 | + $wgParser->setFunctionHook('pad_e', array(&$wgExtStringFunctionsEscaped,'runPad_e' )); |
| 82 | + $wgParser->setFunctionHook('replace_e', array(&$wgExtStringFunctionsEscaped,'runReplace_e' )); |
| 83 | + $wgParser->setFunctionHook('explode_e', array(&$wgExtStringFunctionsEscaped,'runExplode_e' )); |
| 84 | +} |
| 85 | + |
| 86 | +function wfStringFunctionsEscapedLanguageGetMagic( &$magicWords, $langCode = "en" ) { |
| 87 | + switch ( $langCode ) { |
| 88 | + default: |
| 89 | + $magicWords['pos_e'] = array ( 0, 'pos_e' ); |
| 90 | + $magicWords['rpos_e'] = array ( 0, 'rpos_e' ); |
| 91 | + $magicWords['pad_e'] = array ( 0, 'pad_e' ); |
| 92 | + $magicWords['replace_e'] = array ( 0, 'replace_e' ); |
| 93 | + $magicWords['explode_e'] = array ( 0, 'explode_e' ); |
| 94 | + } |
| 95 | + return true; |
| 96 | +} |
| 97 | + |
| 98 | +class ExtStringFunctionsEscaped { |
| 99 | + |
| 100 | + /** |
| 101 | + * {{#pos_e:value|key|offset}} |
| 102 | + * Note: If the needle is an empty string, single space is used instead. |
| 103 | + * Note: If the needle is not found, empty string is returned. |
| 104 | + * Note: The needle is limited to specific length. |
| 105 | + */ |
| 106 | + function runPos_e ( &$parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) { |
| 107 | + global $wgParser; |
| 108 | + list($callback,$flags) = $wgParser->mFunctionHooks['pos']; |
| 109 | + return @call_user_func_array( $callback, |
| 110 | + array_merge(array($parser),array($inStr,stripcslashes($inNeedle),$inOffset) )); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * {{#rpos_e:value|key}} |
| 115 | + * Note: If the needle is an empty string, single space is used instead. |
| 116 | + * Note: If the needle is not found, -1 is returned. |
| 117 | + * Note: The needle is limited to specific length. |
| 118 | + */ |
| 119 | + function runRPos_e( &$parser, $inStr = '', $inNeedle = '' ) { |
| 120 | + global $wgParser; |
| 121 | + list($callback,$flags) = $wgParser->mFunctionHooks['rpos']; |
| 122 | + return @call_user_func_array( $callback, |
| 123 | + array_merge(array($parser),array($inStr,stripcslashes($inNeedle)) )); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * {{#pad_e:value|length|with|direction}} |
| 128 | + * Note: Length of the resulting string is limited. |
| 129 | + */ |
| 130 | + function runPad_e( &$parser, $inStr = '', $inLen = 0, $inWith = '', $inDirection = '' ) { |
| 131 | + global $wgParser; |
| 132 | + list($callback,$flags) = $wgParser->mFunctionHooks['pad']; |
| 133 | + return @call_user_func_array( $callback, |
| 134 | + array_merge(array($parser),array($inStr, $inLen , stripcslashes($inWith), $inDirection) )); |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * {{#replace:value|from|to}} |
| 139 | + * Note: If the needle is an empty string, single space is used instead. |
| 140 | + * Note: The needle is limited to specific length. |
| 141 | + * Note: The product is limited to specific length. |
| 142 | + */ |
| 143 | + function runReplace_e( $parser, $inStr = '', $inReplaceFrom = '', $inReplaceTo = '' ) { |
| 144 | + global $wgParser; |
| 145 | + list($callback,$flags) = $wgParser->mFunctionHooks['replace']; |
| 146 | + return @call_user_func_array( $callback, |
| 147 | + array_merge(array($parser),array($inStr, stripcslashes($inReplaceFrom), stripcslashes($inReplaceTo)) )); |
| 148 | + } |
| 149 | + |
| 150 | + /** |
| 151 | + * {{#explode_e:value|delimiter|position}} |
| 152 | + * Note: Negative position can be used to specify tokens from the end. |
| 153 | + * Note: If the divider is an empty string, single space is used instead. |
| 154 | + * Note: The divider is limited to specific length. |
| 155 | + * Note: Empty string is returned, if there is not enough exploded chunks. |
| 156 | + */ |
| 157 | + function runExplode_e ( &$parser, $inStr = '', $inDiv = '', $inPos = 0 ) { |
| 158 | + global $wgParser; |
| 159 | + list($callback,$flags) = $wgParser->mFunctionHooks['explode']; |
| 160 | + return @call_user_func_array( $callback, |
| 161 | + array_merge(array($parser),array($inStr, stripcslashes($inDiv), $inPos) )); |
| 162 | + } |
| 163 | + |
| 164 | +} |
Property changes on: trunk/extensions/StringFunctionsEscaped/StringFunctionsEscaped.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 165 | + native |
Property changes on: trunk/extensions/StringFunctionsEscaped |
___________________________________________________________________ |
Added: svn:mergeinfo |
2 | 166 | Merged /branches/REL1_15/phase3/extensions/StringFunctionsEscaped:r51646 |
Index: trunk/extensions/ConditionalShowSection/README |
— | — | @@ -0,0 +1,126 @@ |
| 2 | +/*
|
| 3 | + * ConditionalShowSection MediaWiki extension
|
| 4 | + *
|
| 5 | + * @author Jean-Lou Dupont
|
| 6 | + * @package MediaWiki
|
| 7 | + * @subpackage Extensions
|
| 8 | + * @licence GNU General Public Licence 2.0
|
| 9 | + * This extension enables to conditionally show/hide a section
|
| 10 | + * of wikitext that appears between the <cshow> </cshow> tags.
|
| 11 | + *
|
| 12 | + * Add to LocalSettings.php
|
| 13 | + * with: require_once("extensions/ConditionalShowSection/ConditionalShowSection.php");
|
| 14 | + *
|
| 15 | + * HISTORY:
|
| 16 | + * 1.1: corrected bug when "ingroup" option not present, wrong results.
|
| 17 | + * 1.2: used "recursiveTagParse" to get cleaner parsing.
|
| 18 | + * 1.3: corrected error with default initialisation of userReqLogged
|
| 19 | + * 1.4: changed to using 'getEffectiveGroups' in order to have also access
|
| 20 | + * to the implicit '*' group and the default group for logged users 'user'.
|
| 21 | + * 1.5: Allow to check multiple groups - separated by ","
|
| 22 | + */
|
| 23 | +
|
| 24 | +
|
| 25 | +
|
| 26 | +{{Extension|templatemode =
|
| 27 | +|name = ConditionalShow
|
| 28 | +|status = stable
|
| 29 | +|type1 = tag
|
| 30 | +|type2 = user rights
|
| 31 | +|type3 = mywiki
|
| 32 | +|hook1 = ParserFirstCallInit
|
| 33 | +|hook2 =
|
| 34 | +|username = [[user:jldupont]]
|
| 35 | +|author =
|
| 36 | +|description = Conditionally show a wikitext section based on user group rights
|
| 37 | +|image =
|
| 38 | +|imagesize =
|
| 39 | +|version = 1.5
|
| 40 | +|update = 2009-09-10
|
| 41 | +|mediawiki = tested on 1.8.2, 1.9.3, 1.10, 1.14, 1.15, 1.16A
|
| 42 | +|php =
|
| 43 | +|license = GNU General Public Licence 2.0
|
| 44 | +|download = [http://wiki.jldupont.com/Extension:ConditionalContent http version <1.5]
|
| 45 | +|readme =
|
| 46 | +|changelog =
|
| 47 | +|parameters =
|
| 48 | +|tags = <cshow>,</cshow>
|
| 49 | +|rights =
|
| 50 | +|example =
|
| 51 | +|compatibility =
|
| 52 | +}}
|
| 53 | +
|
| 54 | +==What can this extension do?==
|
| 55 | +This extension implementes the <nowiki><cshow></nowiki> tag which conditionally shows wikitext within the tags based on user group rights and certain other parameters.
|
| 56 | +
|
| 57 | +Using the tags should be to make the user experience less confusing or more useful by only showing information relevant to the user and specific groups that user belongs to.
|
| 58 | +<div style="width: 80%; margin-left: auto; margin-right: auto; padding: 4px; border: 2px solid #FF0000; background-color: #FFDDDD; text-align: center;">
|
| 59 | +'''PLEASE NOTE!!!'''
|
| 60 | +
|
| 61 | +This tag does not protect information or instructions from being disclosed to the reader.
|
| 62 | +
|
| 63 | +The user can still see the information by editing the page or even by "view source". If you are looking to actually protect information, this is '''NOT''' the extension you want to use!
|
| 64 | +
|
| 65 | +This extension only helps you selectively show content or navigation based on groups the user belongs to.
|
| 66 | +</div>
|
| 67 | +==Note==
|
| 68 | +
|
| 69 | +This extension is not 'cache' friendly; if one requires this feature, then [[Extension:BizzWiki|BizzWiki platform]] provides a solution through [[Extension:ParserPhase2|Parser Phase 2 extension]].
|
| 70 | +
|
| 71 | +==Usage==
|
| 72 | +
|
| 73 | +Like other tags, this can be used two ways - by using the tag itself within wikitext, or by using the tag function within templates.
|
| 74 | +
|
| 75 | +If you are using it within normal wikitext, the <nowiki><cshow>. . .</cshow></nowiki> syntax suffices. If you are using it within a template, you will need to use the parser tag function as illustrated [[#Example within a Template | below]].
|
| 76 | +
|
| 77 | +===Example in Wikitext===
|
| 78 | +By default, the section of wikitext within the tags is HIDDEN unless the conditions are met - in this case the user must be logged in and belong the group 'sysops'
|
| 79 | +
|
| 80 | +<pre>
|
| 81 | +<cshow logged=1 ingroup='sysop'> This text will appear if a user with membership to 'sysop' group views this page</cshow>
|
| 82 | +</pre>
|
| 83 | +
|
| 84 | +===Example within a Template===
|
| 85 | +
|
| 86 | +If you are using this within a template or as part of a template, you need to use the <nowiki>{{##tag: . . .}}</nowiki> syntax.
|
| 87 | +
|
| 88 | +<pre>
|
| 89 | +{{#tag:cshow |
|
| 90 | +This text will appear if a user with membership to 'sysop' group views this page
|
| 91 | +| logged=1 ingroup='sysop'
|
| 92 | +}}
|
| 93 | +</pre>
|
| 94 | +
|
| 95 | +==Arguments==
|
| 96 | +
|
| 97 | +By default, the tagged section is HIDDEN unless the following conditions are met:
|
| 98 | +* Argument: logged = '1' or '0'
|
| 99 | +* Argument: ingroup = 'group XYZ' (Note, as of version 1.5, you can list multiple groups, e.g. 'sysop,approved'
|
| 100 | +
|
| 101 | +If no arguments are provided for:
|
| 102 | +logged --> assume 'don't care'
|
| 103 | +innGroup --> assume '' (no group)
|
| 104 | +
|
| 105 | +In other words, if no 'ingroup' parameter is given, then the condition 'ingroup' is never met.
|
| 106 | +
|
| 107 | +If no "logged" parameter is given, then this condition is always met.
|
| 108 | +
|
| 109 | +==Download instructions==
|
| 110 | +
|
| 111 | +The current version is available from SVN.
|
| 112 | +
|
| 113 | +Source Code and additional information can also be found at [http://bluecortex.com/index.php?title=Bluecortex:ConditionalShow].
|
| 114 | +The code should be loaded to:
|
| 115 | +
|
| 116 | +<code>$IP/extensions/ConditionalShowSection/ConditionalShowSection.php</code>. ''Note: [[Manual:$IP|$IP]] stands for the root directory of your MediaWiki installation, the same directory that holds [[Manual:LocalSettings.php|LocalSettings.php]]''.
|
| 117 | +
|
| 118 | +==Installation==
|
| 119 | +To install this extension, add the following to [[Manual:LocalSettings.php|LocalSettings.php]]:
|
| 120 | +<source lang="php">
|
| 121 | +require_once("$IP/extensions/ConditionalShowSection/ConditionalShowSection.php");
|
| 122 | +</source>
|
| 123 | +
|
| 124 | +== Other Options ==
|
| 125 | +* [[Extension:ConditionalContent]]
|
| 126 | +
|
| 127 | +[[Category:View page extensions]]
|
Index: trunk/extensions/ConditionalShowSection/ConditionalShowSection.php |
— | — | @@ -0,0 +1,100 @@ |
| 2 | +<?php |
| 3 | +/* |
| 4 | + * ConditionalShowSection MediaWiki extension |
| 5 | + * |
| 6 | + * @author Jean-Lou Dupont |
| 7 | + * @package MediaWiki |
| 8 | + * @subpackage Extensions |
| 9 | + * @licence GNU General Public Licence 2.0 |
| 10 | + * This extension enables to conditionally show/hide a section |
| 11 | + * of wikitext that appears between the <cshow> </cshow> tags. |
| 12 | + * |
| 13 | + * Add to LocalSettings.php |
| 14 | + * with: require_once("extensions/ConditionalShowSection/ConditionalShowSection.php"); |
| 15 | + * |
| 16 | + * HISTORY: |
| 17 | + * 1.1: corrected bug when "ingroup" option not present, wrong results. |
| 18 | + * 1.2: used "recursiveTagParse" to get cleaner parsing. |
| 19 | + * 1.3: corrected error with default initialisation of userReqLogged |
| 20 | + * 1.4: changed to using 'getEffectiveGroups' in order to have also access |
| 21 | + * to the implicit '*' group and the default group for logged users 'user'. |
| 22 | + * 1.5: Allow to check multiple groups - separated by "," |
| 23 | + */ |
| 24 | +$wgExtensionCredits['other'][] = array( |
| 25 | + 'name' => "ConditionalShowSection [http://www.bluecortex.com]", |
| 26 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:ConditionalShow', |
| 27 | + 'version'=> '1.5', |
| 28 | + 'author' => 'Jean-Lou Dupont [http://www.bluecortex.com]' |
| 29 | +); |
| 30 | + |
| 31 | + |
| 32 | +if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { |
| 33 | + $wgHooks['ParserFirstCallInit'][] = 'wfConditionalShowSection'; |
| 34 | +} else { // Otherwise do things the old fashioned way |
| 35 | + $wgExtensionFunctions[] = 'wfConditionalShowSection'; |
| 36 | +} |
| 37 | + |
| 38 | +function wfConditionalShowSection() { |
| 39 | + global $wgParser; |
| 40 | + $wgParser->setHook( "cshow", "ConditionalShowSection" ); |
| 41 | + return true; |
| 42 | +} |
| 43 | + |
| 44 | +function ConditionalShowSection( $input, $argv, &$parser ) { |
| 45 | + # |
| 46 | + # By default, the section is HIDDEN unless the following conditions are met: |
| 47 | + # Argument: Logged = '1' or '0' |
| 48 | + # Argument: InGroup = 'group XYZ' |
| 49 | + # |
| 50 | + # If no arguments are provided for: |
| 51 | + # - Logged --> assume 'don't care' |
| 52 | + # - InGroup --> assume '' (no group) |
| 53 | + # |
| 54 | + # In other words, if no 'ingroup' parameter is given, |
| 55 | + # then the condition 'ingroup' is never met. |
| 56 | + # |
| 57 | + # If no "logged" parameter is given, then this condition is always met. |
| 58 | + # |
| 59 | + # Examples: <cshow Logged="1" InGroup="sysop"> text to show upon conditions met </cshow> |
| 60 | + # if the user viewing the page is LOGGED and part of the SYSOP group then show the section. |
| 61 | + # |
| 62 | + # <cshow ingroup='user'> Test </cshow> |
| 63 | + # shows 'Test' if the user viewing the page is logged and by default part of the 'user' group. |
| 64 | + # |
| 65 | + global $wgUser; |
| 66 | + |
| 67 | + $userReqLogged = null; # default is "don't care" |
| 68 | + $userReqGroup = "" ; # assuming no group membership required |
| 69 | + $output = ""; # assuming the section is hidden by default. |
| 70 | + |
| 71 | + $cond1 = false; |
| 72 | + $cond2 = false; # by default, don't show the section to just anybody |
| 73 | + |
| 74 | + # Extract the parameters passed |
| 75 | + # the parser lowers the case of all the parameters passed... |
| 76 | + if (isset($argv["logged"])) |
| 77 | + { |
| 78 | + $userReqLogged = $argv["logged"]; |
| 79 | + |
| 80 | + if ($userReqLogged==="1" && ($wgUser->isLoggedIn()===true)) |
| 81 | + $cond1=true; |
| 82 | + |
| 83 | + if ($userReqLogged==="0" && ($wgUser->isLoggedIn()===false)) |
| 84 | + $cond1=true; |
| 85 | + } else $cond1=true; |
| 86 | + if (isset($argv["ingroup"])) |
| 87 | + { |
| 88 | + $userReqGroup = explode(',',$argv["ingroup"]); |
| 89 | + # which groups is the user part of? |
| 90 | + $ugroups = $wgUser->getEffectiveGroups(); // changed in v1.4 |
| 91 | + if(array_intersect($userReqGroup,$ugroups)) |
| 92 | + $cond2=true; |
| 93 | + } else $cond1=true; |
| 94 | + # if both conditions are met, then SHOW else HIDE |
| 95 | + if (($cond1===true) and ($cond2===true)){ |
| 96 | + $output=$parser->recursiveTagParse($input); |
| 97 | + } |
| 98 | + |
| 99 | + return $output; |
| 100 | +} |
| 101 | +?> |
\ No newline at end of file |
Property changes on: trunk/extensions/ConditionalShowSection/ConditionalShowSection.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 102 | + native |
Property changes on: trunk/extensions/ConditionalShowSection |
___________________________________________________________________ |
Added: svn:mergeinfo |
2 | 103 | Merged /branches/REL1_15/phase3/extensions/ConditionalShowSection:r51646 |