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

Include in div with class

parent d7531b15
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
A small mediawiki extension to have a variable to know if the user is connected or not. A small mediawiki extension to have a variable to know if the user is connected or not.
Version 0.3 Version 0.4
Mathieu Loiseau Mathieu Loiseau
This is free software licensed under the GNU General Public License. Please This is free software licensed under the GNU General Public License. Please
...@@ -16,7 +16,7 @@ Connected is an extension to MediaWiki that provides elements to adapt the conte ...@@ -16,7 +16,7 @@ Connected is an extension to MediaWiki that provides elements to adapt the conte
The extension defines the following parser functions and variables: The extension defines the following parser functions and variables:
* ``LOGGEDIN`` : ``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, their ip address otherwise ; * ``USERNAME`` : the user's screen name, if they are logged in, their ip address 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. If a third parameter is provided, it can specify that this text should not be included in a div (which is default).
The extension hides the sidebar for not logged in users. The extension hides the sidebar for not logged in users.
...@@ -31,3 +31,6 @@ your `LocalSettings.php` file: ...@@ -31,3 +31,6 @@ your `LocalSettings.php` file:
```php ```php
wfLoadExtension( 'Connected' ); wfLoadExtension( 'Connected' );
``` ```
## Configuration
* `$wgConnectedPrivateCSSClass` : css class for loggedIn content
* `$wgConnectedPublicCSSClass` : css class for not loggedIn content
{ {
"name": "Connected", "name": "Connected",
"author": "Mathieu Loiseau", "author": "Mathieu Loiseau",
"version": "0.2", "version": "0.4",
"url": "https://gitlab.liris.cnrs.fr/mloiseau/mw_connected", "url": "https://gitlab.liris.cnrs.fr/mloiseau/mw_connected",
"license-name": "GPL-2.0-or-later", "license-name": "GPL-2.0-or-later",
"descriptionmsg": "connected-desc", "descriptionmsg": "connected-desc",
...@@ -28,5 +28,18 @@ ...@@ -28,5 +28,18 @@
"SidebarBeforeOutput": "ConnectedHooks::lfHideSidebar", "SidebarBeforeOutput": "ConnectedHooks::lfHideSidebar",
"BeforePageDisplay": "ConnectedHooks::add_NotLoggedIncss" "BeforePageDisplay": "ConnectedHooks::add_NotLoggedIncss"
}, },
"manifest_version": 1 "config": {
"ConnectedPrivateCSSClass": {
"value": "",
"description": "If not empty, puts every ifLoggedIn wiki code in a div with the said class (unless notDiv parameter is provided)."
},
"ConnectedPublicCSSClass": {
"value": "",
"description": "If not empty, puts every ifNotLoggedIn wiki code in a div with the said class (unless notDiv parameter is provided)."
}
},
"ConfigRegistry": {
"Connected": "GlobalVarConfig::newInstance"
},
"manifest_version": 2
} }
...@@ -7,14 +7,22 @@ ...@@ -7,14 +7,22 @@
* @link https://gitlab.liris.cnrs.fr/mloiseau/mw_connected * @link https://gitlab.liris.cnrs.fr/mloiseau/mw_connected
* *
**/ **/
use MediaWiki\MediaWikiServices;
class ConnectedHooks { class ConnectedHooks {
private static $user = false; private static $user = false;
private static $privateCSSClass = false;
private static $publicCSSClass = false;
// Register any render callbacks with the parser // Register any render callbacks with the parser
public static function onParserFirstCallInit( Parser $parser ) { public static function onParserFirstCallInit( Parser $parser ) {
// Create a function hook associating the "example" magic word with renderExample() // Create a function hook associating the "example" magic word with renderExample()
$parser->setFunctionHook( 'iflogged', [ self::class, 'ifConnectedRender' ] ); $parser->setFunctionHook( 'iflogged', [ self::class, 'ifConnectedRender' ] );
// Get the $wgConnectedPrivateCSSClass configured value
if (self::$privateCSSClass === false){
self::$privateCSSClass = MediaWikiServices::getInstance()->getMainConfig()->get( 'ConnectedPrivateCSSClass' );
self::$publicCSSClass = MediaWikiServices::getInstance()->getMainConfig()->get( 'ConnectedPublicCSSClass' );
}
} }
//try to get the user anyway I can //try to get the user anyway I can
...@@ -32,17 +40,26 @@ class ConnectedHooks { ...@@ -32,17 +40,26 @@ class ConnectedHooks {
} }
// Render the output of {{#ifloggedin:}} i.e. iflogged function. // Render the output of {{#ifloggedin:}} i.e. iflogged function.
public static function ifConnectedRender( Parser $parser, $ifLoggedIn = '', $ifNot = '') { //isDiv is tested to see if it is a div with a class…
public static function ifConnectedRender( Parser $parser, $ifLoggedIn = '', $ifNot = '', $isDiv='') {
// The input parameters are wikitext with templates expanded. // The input parameters are wikitext with templates expanded.
// The output should be wikitext too. // The output should be wikitext too.
$parser->getOutput()->updateCacheExpiry( 0 ); $parser->getOutput()->updateCacheExpiry( 0 );
self::get_user($parser); self::get_user($parser);
if (self::is_registered()) { if (self::is_registered()) {
$output = $ifLoggedIn; $output = $ifLoggedIn;
if (($isDiv == '') && (self::$privateCSSClass != '')){
$output = "<div class='".self::$privateCSSClass."'>".$output."</div>";
}
} }
else{ else{
$output = $ifNot; $output = $ifNot;
if (($isDiv == '') && (self::$publicCSSClass != '')){
$output = "<div class='".self::$publicCSSClass."'>".$output."</div>";
}
} }
return [$output, 'noparse' => false ]; return [$output, 'noparse' => false ];
} }
......
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