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

LOGGEDIN & USERNAME = OK

parent e6d4cd30
No related branches found
No related tags found
No related merge requests found
<?php
$magicWords = [];
$magicWords['en'] = [
'connected' => [1, 'LOGGEDIN'],
'u_name' => [1, 'USERNAME'],
'iflogged' => [0, 'ifloggedin']
];
<?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';
}
...@@ -14,9 +14,10 @@ full text and terms of the license. ...@@ -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). 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: 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 ; * ``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. * ``#ifloggedin`` : displays the first parameter if the user is logged in, the second otherwise.
## Installation ## Installation
TODO TODO
To install the extension, place the entire 'Cargo' directory within To install the extension, place the entire 'Cargo' directory within
......
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