Index: trunk/extensions/Translate/groups/mediawiki-defines.txt |
— | — | @@ -195,6 +195,8 @@ |
196 | 196 | Community Voice |
197 | 197 | aliasfile = CommunityVoice/CommunityVoice.alias.php |
198 | 198 | |
| 199 | +Conditional Show Section |
| 200 | + |
199 | 201 | Configure |
200 | 202 | aliasfile = Configure/Configure.alias.php |
201 | 203 | optional = configure-section-html, configure-section-ajax |
Index: trunk/extensions/ConditionalShowSection/ConditionalShowSection.php |
— | — | @@ -1,16 +1,16 @@ |
2 | 2 | <?php |
3 | | -/* |
| 3 | +/** |
4 | 4 | * ConditionalShowSection MediaWiki extension |
5 | 5 | * |
6 | 6 | * @author Jean-Lou Dupont |
7 | 7 | * @package MediaWiki |
8 | 8 | * @subpackage Extensions |
9 | | - * @licence GNU General Public Licence 2.0 |
| 9 | + * @license GNU General Public Licence 2.0 |
10 | 10 | * This extension enables to conditionally show/hide a section |
11 | 11 | * of wikitext that appears between the <cshow> </cshow> tags. |
12 | 12 | * |
13 | 13 | * Add to LocalSettings.php |
14 | | - * with: require_once("extensions/ConditionalShowSection/ConditionalShowSection.php"); |
| 14 | + * with: require_once( "$IP/extensions/conditionalshowsection/conditionalshowsection.php" ); |
15 | 15 | * |
16 | 16 | * HISTORY: |
17 | 17 | * 1.1: corrected bug when "ingroup" option not present, wrong results. |
— | — | @@ -20,14 +20,18 @@ |
21 | 21 | * to the implicit '*' group and the default group for logged users 'user'. |
22 | 22 | * 1.5: Allow to check multiple groups - separated by "," |
23 | 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]' |
| 24 | +$wgExtensionCredits['parserhook'][] = array( |
| 25 | + 'path' => __FILE__, |
| 26 | + 'name' => 'ConditionalShowSection', |
| 27 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:ConditionalShow', |
| 28 | + 'version' => '1.5', |
| 29 | + 'author' => '[http://www.bluecortex.com Jean-Lou Dupont]', |
| 30 | + 'descriptionmsg' => 'conditionalshowsection-desc', |
29 | 31 | ); |
30 | | - |
31 | 32 | |
| 33 | +$dir = dirname( __FILE__ ) . '/'; |
| 34 | +$wgExtensionMessagesFiles['ConditionalShowSection'] = $dir . 'ConditionalShowSection.i18n.php'; |
| 35 | + |
32 | 36 | if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { |
33 | 37 | $wgHooks['ParserFirstCallInit'][] = 'wfConditionalShowSection'; |
34 | 38 | } else { // Otherwise do things the old fashioned way |
— | — | @@ -39,62 +43,61 @@ |
40 | 44 | $wgParser->setHook( "cshow", "ConditionalShowSection" ); |
41 | 45 | return true; |
42 | 46 | } |
43 | | - |
| 47 | + |
44 | 48 | 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 | 49 | # |
| 50 | + # By default, the section is HIDDEN unless the following conditions are met: |
| 51 | + # Argument: Logged = '1' or '0' |
| 52 | + # Argument: InGroup = 'group XYZ' |
| 53 | + # |
| 54 | + # If no arguments are provided for: |
| 55 | + # - Logged --> assume 'don't care' |
| 56 | + # - InGroup --> assume '' (no group) |
| 57 | + # |
54 | 58 | # In other words, if no 'ingroup' parameter is given, |
55 | 59 | # then the condition 'ingroup' is never met. |
56 | | - # |
| 60 | + # |
57 | 61 | # 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 | # |
| 63 | + # Examples: <cshow Logged="1" InGroup="sysop"> text to show upon conditions met </cshow> |
| 64 | + # if the user viewing the page is LOGGED and part of the SYSOP group then show the section. |
| 65 | + # |
62 | 66 | # <cshow ingroup='user'> Test </cshow> |
63 | 67 | # shows 'Test' if the user viewing the page is logged and by default part of the 'user' group. |
64 | | - # |
| 68 | + # |
65 | 69 | global $wgUser; |
66 | | - |
| 70 | + |
67 | 71 | $userReqLogged = null; # default is "don't care" |
68 | 72 | $userReqGroup = "" ; # assuming no group membership required |
69 | 73 | $output = ""; # assuming the section is hidden by default. |
70 | 74 | |
71 | | - $cond1 = false; |
72 | | - $cond2 = false; # by default, don't show the section to just anybody |
73 | | - |
| 75 | + $cond1 = false; |
| 76 | + $cond2 = false; # by default, don't show the section to just anybody |
| 77 | + |
74 | 78 | # Extract the parameters passed |
75 | 79 | # the parser lowers the case of all the parameters passed... |
76 | | - if (isset($argv["logged"])) |
| 80 | + if ( isset( $argv["logged"] ) ) |
77 | 81 | { |
78 | 82 | $userReqLogged = $argv["logged"]; |
| 83 | + |
| 84 | + if ( $userReqLogged === "1" && ( $wgUser->isLoggedIn() === true ) ) |
| 85 | + $cond1 = true; |
79 | 86 | |
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 | + if ( $userReqLogged === "0" && ( $wgUser->isLoggedIn() === false ) ) |
| 88 | + $cond1 = true; |
| 89 | + } else $cond1 = true; |
| 90 | + if ( isset( $argv["ingroup"] ) ) |
87 | 91 | { |
88 | | - $userReqGroup = explode(',',$argv["ingroup"]); |
| 92 | + $userReqGroup = explode( ',', $argv["ingroup"] ); |
89 | 93 | # which groups is the user part of? |
90 | 94 | $ugroups = $wgUser->getEffectiveGroups(); // changed in v1.4 |
91 | | - if(array_intersect($userReqGroup,$ugroups)) |
92 | | - $cond2=true; |
93 | | - } else $cond1=true; |
| 95 | + if ( array_intersect( $userReqGroup, $ugroups ) ) |
| 96 | + $cond2 = true; |
| 97 | + } else $cond1 = true; |
94 | 98 | # if both conditions are met, then SHOW else HIDE |
95 | | - if (($cond1===true) and ($cond2===true)){ |
96 | | - $output=$parser->recursiveTagParse($input); |
| 99 | + if ( ( $cond1 === true ) and ( $cond2 === true ) ) { |
| 100 | + $output = $parser->recursiveTagParse( $input ); |
97 | 101 | } |
98 | | - |
| 102 | + |
99 | 103 | return $output; |
100 | | -} |
101 | | -?> |
\ No newline at end of file |
| 104 | +} |
\ No newline at end of file |
Index: trunk/extensions/ConditionalShowSection/ConditionalShowSection.i18n.php |
— | — | @@ -0,0 +1,17 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalization for ConditionalShowSection extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +$messages = array(); |
| 11 | + |
| 12 | +/** English |
| 13 | + * @author Jean-Lou Dupont |
| 14 | + */ |
| 15 | +$messages['en'] = array( |
| 16 | + 'conditionalshowsection-desc' => 'Adding the <cshow> tag to conditionally show/hide a section of wikitext', |
| 17 | +); |
| 18 | + |
Property changes on: trunk/extensions/ConditionalShowSection/ConditionalShowSection.i18n.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 19 | + native |