Hello and Happy Friday!
In the Localsettings.php of a private enterprise mediawiki site I am developing I have a access to a visitor's session header variable called "$HTTP_EMPLOYER ". I would like to automatically add users to a group called "approved-user" if the value of $HTTP_EMPLOYER matches the right text value. Assuming it can be done, can anyone guide me on how to use the $wgAutopromote variable[1] in Localsettings to automatically add users to a group based on a PHP condition that is not a predefined constant by mediawiki? Thank you!
[1] https://www.mediawiki.org/wiki/Manual:$wgAutopromote
-Rich
Looks like you can define custom conditions using the AutopromoteCondition hook:
https://www.mediawiki.org/wiki/Manual:Hooks/AutopromoteCondition
Thanks Bartosz,
Any chance you could give a concrete example of how to write a single line in LocalSettings that promotes a user to the group say 'mygroup' without condition.. just a straight automatic promotion to all users? (I would wrap that line of code in a PHP if statement with the condition I want.
Sorry to have to ask for explicit help.. this is my first time encountering hooks in localsettings and I am not a programmer by trade.
Truest thanks -Rich
Looks like you can define custom conditions using the AutopromoteCondition hook:
https://www.mediawiki.org/wiki/Manual:Hooks/AutopromoteCondition
-- Bartosz Dziewoński
ok.. so I get that my first line is:
$wgHooks['AutopromoteCondition'][] = 'MyExtensionHooks::onAutopromoteCondition';
and next I must define the function "onAutopromoteCondition" as:
public static function onAutopromoteCondition( $type, $args, $user, &$result ) { ... }
but I'm not clear on what to set for ( $type, $args, $user, &$result ) and what condition the code in { ... } is run.
Is it simply to say that in { ... } I should "return true;" if I want the user to be promoted and "return false;" if not?
-Rich
-----Original Message----- From: Evans, Richard K. (GRC-H000) Sent: Friday, November 03, 2017 9:32 AM To: MediaWiki announcements and site admin list Subject: RE: [MediaWiki-l] using $wgAutopromote based on session header variable
Thanks Bartosz,
Any chance you could give a concrete example of how to write a single line in LocalSettings that promotes a user to the group say 'mygroup' without condition.. just a straight automatic promotion to all users? (I would wrap that line of code in a PHP if statement with the condition I want.
Sorry to have to ask for explicit help.. this is my first time encountering hooks in localsettings and I am not a programmer by trade.
Truest thanks -Rich
Looks like you can define custom conditions using the AutopromoteCondition hook:
https://www.mediawiki.org/wiki/Manual:Hooks/AutopromoteCondition
-- Bartosz Dziewoński
Can anyone take a peek at this code and tell me if it looks right? (thank you)
$wgHooks['AutopromoteCondition'][] = 'MyExtensionHooks::onAutopromoteCondition'; function onAutopromoteCondition( APCOND_INGROUPS, 'name-of-group-to-promote-to-if-function-is-true', $user, &$result ) { if ($HTTP_HEADER_VARIABLE_I_AM_TESTING=="value that i'm looking for") { return true; } else { return false; } }
(Note - the goal is to automatically add a user to a group based on a session header variable from the host server)
i did it! (yay!) .... turns out the 'AutopromoteCondition' hook was a red hearing.. what i needed was accomplished with the following line of code in LocalSettings.php:
#automatically add a user to a group (implicit rights of a group) based on the value of a session header variable from the host server security agent) if($HTTP_COMPANYNAME=="Acme") { $wgAutopromote['approved-user'] = array( '&', true, true, ); }
Thanks to all who helped and gave me some insights and things to try. Thank you! -Rich
mediawiki-l@lists.wikimedia.org