diff --git a/README.md b/README.md index 279c35e7b514f7f576437952d05085a2a893ecd8..98cecc6cef621c48f281a3234f23228098c69bc9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A small mediawiki extension to have a variable to know if the user is connected or not. - Version 0 + Version 0.1 Mathieu Loiseau This is free software licensed under the GNU General Public License. Please @@ -15,18 +15,19 @@ Connected is an extension to MediaWiki that provides elements to adapt the conte The extension defines the following parser functions and variables: * ``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, their ip address 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 -your MediaWiki 'extensions' directory, then add the following line to -your 'LocalSettings.php' file: - - wfLoadExtension( 'Cargo' ); +The extension hides the sidebar for not logged in users. -Then, go to core MediaWiki's /maintenance directory, and call the -following: +It also provides two css depending on the status of the user : +* ``MediaWiki:NotLoggedIn.css`` +* ``MediaWiki:LoggedIn.css`` - php update.php +## Installation +To install the extension, place the entire 'Connected' directory within +your MediaWiki `extensions` directory, then add the following line to +your `LocalSettings.php` file: +```php + wfLoadExtension( 'Connected' ); +``` diff --git a/extension.json b/extension.json index 197fc306b15417f3b26b4af7b1514bda9563a85e..8cdba58d8429ed64c4a995a67534dfe48e3e7f10 100644 --- a/extension.json +++ b/extension.json @@ -1,11 +1,16 @@ { "name": "Connected", "author": "Mathieu Loiseau", - "version": "0.0", + "version": "0.1", "url": "https://gitlab.liris.cnrs.fr/mloiseau/mw_connected", - "descriptionmsg": "A small mediawiki extension to have a variable to know if the user is logged in or not.", "license-name": "GPL-2.0-or-later", + "descriptionmsg": "connected-desc", "type": "parserhook", + "MessagesDirs": { + "Connected": [ + "i18n" + ] + }, "AutoloadClasses": { "ConnectedHooks": "src/Connected.php" }, @@ -15,7 +20,9 @@ "Hooks": { "ParserFirstCallInit": "ConnectedHooks::onParserFirstCallInit", "ParserGetVariableValueSwitch": "ConnectedHooks::wfConnectedAssignValue", - "MagicWordwgVariableIDs": "ConnectedHooks::connectedDeclareVarIds" + "MagicWordwgVariableIDs": "ConnectedHooks::connectedDeclareVarIds", + "SkinBuildSidebar": "ConnectedHooks::lfHideSidebar", + "BeforePageDisplay": "ConnectedHooks::add_NotLoggedIncss" }, "manifest_version": 1 } diff --git a/i18n/en.json b/i18n/en.json new file mode 100644 index 0000000000000000000000000000000000000000..278e45b0195d266afe53fa62ed97aadf4b99c342 --- /dev/null +++ b/i18n/en.json @@ -0,0 +1,7 @@ +{"@metadata": { + "authors": [ + "Loizbek" + ] + }, + "connected-desc": "Small mediawiki to have a different view for logged-in users.\n*Hides the side-bar for external users.\n* Provides differentiated css [[MediaWiki:NotLoggedIn.css]] and [[MediaWiki:LoggedIn.css]] loaded accordingly.\n*Also provides <code><nowiki>{{LOGGEDIN}}</nowiki></code>, <code><nowiki>{{USERNAME}}</nowiki></code> [https://www.mediawiki.org/wiki/Help:Magic_words/en magic words] and <code><nowiki>{{#ifloggedin:yes|no}}</nowiki></code> [https://www.mediawiki.org/wiki/Manual:Parser_functions/en parser function]." +} diff --git a/i18n/fr.json b/i18n/fr.json new file mode 100644 index 0000000000000000000000000000000000000000..0e0eb58d7a9818d0b2550e8dd4771f8956b0b38e --- /dev/null +++ b/i18n/fr.json @@ -0,0 +1,7 @@ +{"@metadata": { + "authors": [ + "Loizbek" + ] + }, + "connected-desc": "Petite extension mediawiki pour un affichage différent selon que l'utilisateur est connecté ou non.\n* Supprime la barre latérale pour les utilisateurs non connectés ;\n* Fournit des css différentiées [[MediaWiki:NotLoggedIn.css]] et [[MediaWiki:LoggedIn.css]].\n* Fournit les ''[https://www.mediawiki.org/wiki/Help:Magic_words/fr mots magiques]'' <code><nowiki>{{LOGGEDIN}}</nowiki></code>, <code><nowiki>{{USERNAME}}</nowiki></code> et la ''[https://www.mediawiki.org/wiki/Manual:Parser_functions/fr fonction d'analyse]'' <code><nowiki>{{#ifloggedin:yes|no}}</nowiki></code>." +} diff --git a/src/Connected.php b/src/Connected.php index 9cd1de7b631c97cfb8bab38d6d865f96b1c2bb23..4b5fe6f989a0a5caa4ca24fa43cb3503d21e7ff0 100755 --- a/src/Connected.php +++ b/src/Connected.php @@ -68,4 +68,38 @@ class ConnectedHooks { $customVariableIds[] = 'connected'; $customVariableIds[] = 'u_name'; } + + #Cacher la barre de menu quand on n'est pas logué et charger une css supplémentaire +//https://www.mediawiki.org/wiki/Manual:Interface/Sidebar#Change_sidebar_content_when_logged_in_(PHP) +//https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL + public static function lfHideSidebar( $skin, &$bar ) { + global $wgUser; + // Hide sidebar for anonymous users + if ( !$wgUser->isLoggedIn() ) { + $bar = array( + 'navigation' => array( + array( + 'text' => wfMessage( 'login' ) -> text(), + 'href' => SpecialPage::getTitleFor( 'Login' )->getLocalURL(), + 'id' => 'n-login', + 'active' => '' + ) + ) + ); + } + return true; + } + + #Ajouter une feuille de style quand pas connecté + public static function add_NotLoggedIncss( OutputPage $out, Skin $skin ) { + global $wgUser; + if ( !$wgUser->isLoggedIn() ) { + $out->addStyle('/w/index.php?title=MediaWiki:NotLoggedIn.css&action=raw&ctype=text/css'); + $out->addMeta( "logged", "no" ); + } + else{ + $out->addStyle('/w/index.php?title=MediaWiki:LoggedIn.css&action=raw&ctype=text/css'); + $out->addMeta( "logged", "yes" ); + } + } }