r56227 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56226‎ | r56227 | r56228 >
Date:11:36, 12 September 2009
Author:raymond
Status:ok
Tags:
Comment:
Run code through stylize.php
Update extension credits
Add i18n file
Add extension to translatewiki.net
Modified paths:
  • /trunk/extensions/ConditionalShowSection/ConditionalShowSection.i18n.php (added) (history)
  • /trunk/extensions/ConditionalShowSection/ConditionalShowSection.php (modified) (history)
  • /trunk/extensions/Translate/groups/mediawiki-defines.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/groups/mediawiki-defines.txt
@@ -195,6 +195,8 @@
196196 Community Voice
197197 aliasfile = CommunityVoice/CommunityVoice.alias.php
198198
 199+Conditional Show Section
 200+
199201 Configure
200202 aliasfile = Configure/Configure.alias.php
201203 optional = configure-section-html, configure-section-ajax
Index: trunk/extensions/ConditionalShowSection/ConditionalShowSection.php
@@ -1,16 +1,16 @@
22 <?php
3 -/*
 3+/**
44 * ConditionalShowSection MediaWiki extension
55 *
66 * @author Jean-Lou Dupont
77 * @package MediaWiki
88 * @subpackage Extensions
9 - * @licence GNU General Public Licence 2.0
 9+ * @license GNU General Public Licence 2.0
1010 * This extension enables to conditionally show/hide a section
1111 * of wikitext that appears between the <cshow> </cshow> tags.
1212 *
1313 * Add to LocalSettings.php
14 - * with: require_once("extensions/ConditionalShowSection/ConditionalShowSection.php");
 14+ * with: require_once( "$IP/extensions/conditionalshowsection/conditionalshowsection.php" );
1515 *
1616 * HISTORY:
1717 * 1.1: corrected bug when "ingroup" option not present, wrong results.
@@ -20,14 +20,18 @@
2121 * to the implicit '*' group and the default group for logged users 'user'.
2222 * 1.5: Allow to check multiple groups - separated by ","
2323 */
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',
2931 );
30 -
3132
 33+$dir = dirname( __FILE__ ) . '/';
 34+$wgExtensionMessagesFiles['ConditionalShowSection'] = $dir . 'ConditionalShowSection.i18n.php';
 35+
3236 if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
3337 $wgHooks['ParserFirstCallInit'][] = 'wfConditionalShowSection';
3438 } else { // Otherwise do things the old fashioned way
@@ -39,62 +43,61 @@
4044 $wgParser->setHook( "cshow", "ConditionalShowSection" );
4145 return true;
4246 }
43 -
 47+
4448 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)
5349 #
 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+ #
5458 # In other words, if no 'ingroup' parameter is given,
5559 # then the condition 'ingroup' is never met.
56 - #
 60+ #
5761 # 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.
6162 #
 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+ #
6266 # <cshow ingroup='user'> Test </cshow>
6367 # shows 'Test' if the user viewing the page is logged and by default part of the 'user' group.
64 - #
 68+ #
6569 global $wgUser;
66 -
 70+
6771 $userReqLogged = null; # default is "don't care"
6872 $userReqGroup = "" ; # assuming no group membership required
6973 $output = ""; # assuming the section is hidden by default.
7074
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+
7478 # Extract the parameters passed
7579 # the parser lowers the case of all the parameters passed...
76 - if (isset($argv["logged"]))
 80+ if ( isset( $argv["logged"] ) )
7781 {
7882 $userReqLogged = $argv["logged"];
 83+
 84+ if ( $userReqLogged === "1" && ( $wgUser->isLoggedIn() === true ) )
 85+ $cond1 = true;
7986
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"] ) )
8791 {
88 - $userReqGroup = explode(',',$argv["ingroup"]);
 92+ $userReqGroup = explode( ',', $argv["ingroup"] );
8993 # which groups is the user part of?
9094 $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;
9498 # 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 );
97101 }
98 -
 102+
99103 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
119 + native

Status & tagging log