diff --git a/Connected.i18n.magic.php b/Connected.i18n.magic.php new file mode 100644 index 0000000000000000000000000000000000000000..4d5f911ced5cdb91b82f694ab123f511c0c48835 --- /dev/null +++ b/Connected.i18n.magic.php @@ -0,0 +1,8 @@ +<?php +$magicWords = []; + +$magicWords['en'] = [ + 'connected' => [1, 'LOGGEDIN'], + 'u_name' => [1, 'USERNAME'], + 'iflogged' => [0, 'ifloggedin'] +]; diff --git a/Connected.php b/Connected.php new file mode 100644 index 0000000000000000000000000000000000000000..259b650ab85cf586cf64376611c6de1645a893f7 --- /dev/null +++ b/Connected.php @@ -0,0 +1,59 @@ +<?php +/** + * Connected + * + * @license GPL + * @package Connected + * @link https://gitlab.liris.cnrs.fr/mloiseau/mw_connected + * + **/ + $wgExtensionMessagesFiles['Connected'] = __DIR__ . '/Connected.i18n.magic.php'; + + $wgHooks['ParserGetVariableValueSwitch'][] = 'wfConnectedAssignValue'; + function wfConnectedAssignValue( &$parser, &$cache, &$magicWordId, &$ret ) { + global $wgUser; + $result = false; + 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; +} + +$wgExtensionCredits['variable'][] = [ + 'name' => 'Connected', + 'author' => 'Mathieu Loiseau', + 'version' => '0', + 'description' => 'A small mediawiki extension to have a variable to know if the user is logged in or not.', + 'url' => 'https://gitlab.liris.cnrs.fr/mloiseau/mw_connected', + ]; + + $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'; + } diff --git a/README.md b/README.md index 9b05dbdf36f3c6c14ea85db6e712cb405d710910..279c35e7b514f7f576437952d05085a2a893ecd8 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,10 @@ full text and terms of the license. Connected is an extension to MediaWiki that provides elements to adapt the content of a page to the user (or lack thereof). The extension defines the following parser functions and variables: -* ``connected`` : ``1`` if the user is logged in, ``0`` otherwise ; +* ``LOGGEDIN`` : ``1`` if the user is logged in, ``0`` otherwise ; * ``USERNAME`` : the user's screen name, if they are logged in, empty string otherwise ; * ``#ifloggedin`` : displays the first parameter if the user is logged in, the second otherwise. + ## Installation TODO To install the extension, place the entire 'Cargo' directory within