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

Marche presque quoi que moche

parent 4cde8693
No related branches found
No related tags found
No related merge requests found
......@@ -22,8 +22,7 @@
},
"Hooks": {
"ParserFirstCallInit": "ConnectedHooks::onParserFirstCallInit",
"ParserOptionsRegister": "ConnectedHooks::onParserOptionsRegister",
"onPageRenderingHash": "ConnectedHooks::setParserOptions",
"PageRenderingHash": "ConnectedHooks::onPageRenderingHash",
"ParserGetVariableValueSwitch": "ConnectedHooks::wfConnectedAssignValue",
"MagicWordwgVariableIDs": "ConnectedHooks::connectedDeclareVarIds",
"SkinBuildSidebar": "ConnectedHooks::lfHideSidebar",
......
......@@ -8,41 +8,22 @@
*
**/
class ConnectedHooks {
// Register any render callbacks with the parser
public static function onParserFirstCallInit( Parser $parser ) {
// Create a function hook associating the "example" magic word with renderExample()
$parser->setFunctionHook( 'iflogged', [ self::class, 'ifConnectedRender' ] );
// TODO: Le getuser ne marche pas car $parser est null ne marche pas ici à voir comment on fait
//cf. https://github.com/wikimedia/mediawiki-extensions-WikiTextLoggedInOut/blob/d764bd3972ed6b84a4af3ed423a3a5fd9b82c493/includes/WikiTextLoggedInOut.php#L39
if ( method_exists( $parser, 'getUserIdentity' ) ) {
// MW 1.36+
$res = $parser->getUserIdentity()->isRegistered();
} else {
if (method_exists( $parser, 'getUser' )){
$res = $parser->getUser()->isRegistered();
}
else{
$res = '';
}
}
$parser->getOptions()->setOption( 'connected', string($res) );
}
public static function onParserOptionsRegister( &$defaults, &$inCacheKey, &$lazyOptions ) {
$inCacheKey['connected'] = true;
$defaults['connected'] = '';
return true;
}
// Render the output of {{#ifloggedin:}} i.e. iflogged function.
public static function ifConnectedRender( Parser $parser, $ifLoggedIn = '', $ifNot = '') {
// The input parameters are wikitext with templates expanded.
// The output should be wikitext too.
if ( $parser->getOptions()->getOption('connected') == string(true)) {
$output = $ifLoggedIn;
if (!$parser->getUser()->isRegistered()) {
$output = $ifNot;
}
else{
$output = $ifNot;
$output = $ifLoggedIn;
}
return [ $output, 'noparse' => false ];
}
......@@ -52,24 +33,24 @@ class ConnectedHooks {
$result = false;
switch($magicWordId){
case 'connected' :
if ( $parser->getOptions()->getOption('connected') == string(false)) {
if (!$parser->getUser()->isRegistered()) {
$ret = 0;
$result = true;
}
else{
$ret = 1;
$result = true;
}
$result = true;
break;
case 'u_name':
if ( $parser->getOptions()->getOption('connected') == string(false)) {
$ret = $wgUser->getName();
$result = true;
if (!$parser->getUser()->isRegistered()) {
//$ret = self::$theUser->getName();
$ret = $parser->getUser()->getName();
}
else{
$ret = $wgUser->getName();
$result = true;
//$ret = self::$theUser->getName();
$ret = $parser->getUser()->getName();
}
$resutl = true;
break;
}
return $result;
......@@ -87,8 +68,9 @@ class ConnectedHooks {
//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 ( $parser->getOptions()->getOption('connected') == string(false)) {
if ( !$wgUser->isLoggedIn() ) {
$bar = array(
'navigation' => array(
array(
......@@ -105,7 +87,7 @@ class ConnectedHooks {
#Ajouter une feuille de style quand pas connecté
public static function add_NotLoggedIncss( OutputPage $out, Skin $skin ) {
if ( $parser->getOptions()->getOption('connected') == string(false)) {
if ( !$out->getUser()->isRegistered() ) {
$out->addStyle('/w/index.php?title=MediaWiki:NotLoggedIn.css&action=raw&ctype=text/css');
$out->addMeta( "logged", "no" );
}
......@@ -114,4 +96,18 @@ class ConnectedHooks {
$out->addMeta( "logged", "yes" );
}
}
// *** use a specific cache hash key for registered users
// so the cache of a page is always related to anonymous/registered_users
//https://github.com/thomas-topway-it/mediawiki-extensions-PageOwnership/blob/13c379e0bac178a963d08a63fd776a30fa85a339/includes/PageOwnership.php#L326
public static function onPageRenderingHash( &$confstr, User $user, &$forOptions ) {
// *** see also parserOptions->addExtraKey
// *** for some reason we cannot rely on $user->isRegistered()
if ( $user->isRegistered() ) {
$confstr .= '+registered_user';
}
}
}
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