Skip to content
Snippets Groups Projects
Commit 66594e9f authored by Mathieu Loiseau's avatar Mathieu Loiseau
Browse files

tentative module

parent f21e1b21
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
"ExampleExtensionMagic": "Connected.i18n.magic.php" "ExampleExtensionMagic": "Connected.i18n.magic.php"
}, },
"Hooks": { "Hooks": {
"ParserGetVariableValueSwitch": "ConnectedHooks::onParserFirstCallInit" "ParserGetVariableValueSwitch": "ConnectedHooks::onParserFirstCallInit",
"MagicWordwgVariableIDs": "ConnectedHooks::connectedDeclareVarIds"
}, },
"manifest_version": 1 "manifest_version": 1
} }
...@@ -7,45 +7,70 @@ ...@@ -7,45 +7,70 @@
* @link https://gitlab.liris.cnrs.fr/mloiseau/mw_connected * @link https://gitlab.liris.cnrs.fr/mloiseau/mw_connected
* *
**/ **/
$wgExtensionMessagesFiles['Connected'] = __DIR__ . '/Connected.i18n.magic.php'; $wgExtensionMessagesFiles['Connected'] = __DIR__ . '/Connected.i18n.magic.php';
$wgHooks['ParserGetVariableValueSwitch'][] = 'wfConnectedAssignValue'; class ConnectedHooks {
function wfConnectedAssignValue( &$parser, &$cache, &$magicWordId, &$ret ) { // Register any render callbacks with the parser
global $wgUser; public static function onParserFirstCallInit( Parser $parser ) {
$result = false;
if($wgUser->isSafeToLoad()){ // Create a function hook associating the "example" magic word with renderExample()
if ( !$wgUser->isLoggedIn() ) { $parser->setFunctionHook( 'ifloggedin', [ self::class, 'ifConnectedRender' ] );
switch($magicWordId){ }
case 'connected' :
$ret = 0; // Render the output of {{#example:}}.
$result = true; public static function ifConnectedRender( Parser $parser, $ifLoggedIn = '', $ifNot = '') {
break; // The input parameters are wikitext with templates expanded.
case 'u_name': // The output should be wikitext too.
$ret = $wgUser->getName(); global $wgUser;
$result = true; if($wgUser->isSafeToLoad()){
break; if ( $wgUser->isLoggedIn() ) {
$output = $ifLoggedIn;
} }
} else{
else{ $output = $ifNot;
switch($magicWordId){ }
case 'connected' :
$ret = 1; return $output;
$result = true; }
break;
case 'u_name': public static function wfConnectedAssignValue( Parser $parser, &$cache, &$magicWordId, &$ret ) {
$ret = $wgUser->getName(); global $wgUser;
$result = true; $result = false;
break; if($wgUser->isSafeToLoad()){
if ( !$wgUser->isLoggedIn() ) {
switch($magicWordId){
case 'connected' :
$ret = 0;
$result = true;
break;
case 'u_name':
$ret = $wgUser->getName();
$result = true;
break;
}
}
else{
switch($magicWordId){
case 'connected' :
$ret = 1;
$result = true;
break;
case 'u_name':
$ret = $wgUser->getName();
$result = true;
break;
}
} }
} }
return $result;
}
function connectedDeclareVarIds( &$customVariableIds ) {
// $customVariableIds is where MediaWiki wants to store its list of custom
// variable IDs. We oblige by adding ours:
$customVariableIds[] = 'connected';
$customVariableIds[] = 'u_name';
} }
return $result;
} }
$wgHooks['MagicWordwgVariableIDs'][] = 'connectedMyDeclareVarIds'; $wgHooks['MagicWordwgVariableIDs'][] = 'connectedMyDeclareVarIds';
function connectedMyDeclareVarIds( &$customVariableIds ) {
// $customVariableIds is where MediaWiki wants to store its list of custom
// variable IDs. We oblige by adding ours:
$customVariableIds[] = 'connected';
$customVariableIds[] = 'u_name';
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment