Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Connected
Manage
Activity
Members
Labels
Plan
Issues
3
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mathieu Loiseau
Connected
Commits
d7531b15
Commit
d7531b15
authored
7 months ago
by
Mathieu Loiseau
Browse files
Options
Downloads
Patches
Plain Diff
update 1.42
parent
31f02fc7
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+1
-1
1 addition, 1 deletion
README.md
extension.json
+1
-1
1 addition, 1 deletion
extension.json
i18n/Connected.php
+6
-0
6 additions, 0 deletions
i18n/Connected.php
src/Connected.php
+28
-47
28 additions, 47 deletions
src/Connected.php
with
36 additions
and
49 deletions
README.md
+
1
−
1
View file @
d7531b15
...
...
@@ -2,7 +2,7 @@
A small mediawiki extension to have a variable to know if the user is connected or not.
Version 0.
2
Version 0.
3
Mathieu Loiseau
This is free software licensed under the GNU General Public License. Please
...
...
This diff is collapsed.
Click to expand it.
extension.json
+
1
−
1
View file @
d7531b15
...
...
@@ -18,7 +18,7 @@
"ConnectedHooks"
:
"src/Connected.php"
},
"ExtensionMessagesFiles"
:
{
"
ExampleExtension
Magic"
:
"Connected.
i18n.magic.
php"
"
Connected
Magic"
:
"
i18n/
Connected.php"
},
"Hooks"
:
{
"ParserFirstCallInit"
:
"ConnectedHooks::onParserFirstCallInit"
,
...
...
This diff is collapsed.
Click to expand it.
Connected.
i18n.magic.
php
→
i18n/
Connected.php
+
6
−
0
View file @
d7531b15
...
...
@@ -6,3 +6,9 @@ $magicWords['en'] = [
'u_name'
=>
[
1
,
'USERNAME'
],
'iflogged'
=>
[
0
,
'ifloggedin'
]
];
$magicWords
[
'fr'
]
=
[
'connected'
=>
[
1
,
'CONNECTE'
],
'u_name'
=>
[
1
,
'NOM'
],
'iflogged'
=>
[
0
,
'siconnecte'
]
];
This diff is collapsed.
Click to expand it.
src/Connected.php
+
28
−
47
View file @
d7531b15
...
...
@@ -7,68 +7,54 @@
* @link https://gitlab.liris.cnrs.fr/mloiseau/mw_connected
*
**/
class
ConnectedHooks
{
private
static
$user
=
false
;
// 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'
]
);
}
//try to get the user anyway I can
//through user or parser or output or wgUser…
//and set it for next time
private
static
function
get_user
(
$parserOrOther
=
null
){
if
(
self
::
$user
===
false
){
$res
=
false
;
if
(
!
is_null
(
$parserOrOther
)){
if
(
get_class
(
$parserOrOther
)
==
"User"
){
$res
=
$parserOrOther
;
}
else
if
(
get_class
(
$parserOrOther
)
==
"Parser"
){
//cf. https://github.com/wikimedia/mediawiki-extensions-WikiTextLoggedInOut/blob/d764bd3972ed6b84a4af3ed423a3a5fd9b82c493/includes/WikiTextLoggedInOut.php#L39
if
(
method_exists
(
$parserOrOther
,
'getUserIdentity'
)
)
{
// MW 1.36+
$res
=
$parserOrOther
->
getUserIdentity
();
}
else
{
if
(
method_exists
(
$parserOrOther
,
'getUser'
)){
$res
=
$parserOrOther
->
getUser
();
}
}
}
else
if
(
get_class
(
$parserOrOther
)
==
"OutputPage"
){
$res
=
$parserOrOther
->
getUser
();
}
}
self
::
$user
=
$res
;
if
(
self
::
$user
===
false
){
self
::
$user
=
RequestContext
::
getMain
()
->
getUser
();
}
else
{
$res
=
self
::
$user
;
}
return
$res
;
return
self
::
$user
;
}
// 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'
]
);
private
static
function
is_registered
(){
return
self
::
$user
!=
false
&&
self
::
$user
->
mId
!=
0
;
}
// 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
(
!
self
::
get_user
(
$parser
)
->
isRegistered
())
{
$output
=
$ifNot
;
$parser
->
getOutput
()
->
updateCacheExpiry
(
0
);
self
::
get_user
(
$parser
);
if
(
self
::
is_registered
())
{
$output
=
$ifLoggedIn
;
}
else
{
$output
=
$if
LoggedIn
;
$output
=
$if
Not
;
}
return
[
$output
,
'noparse'
=>
false
];
return
[
$output
,
'noparse'
=>
false
];
}
//calcul des variables
public
static
function
wfConnectedAssignValue
(
Parser
$parser
,
&
$cache
,
$magicWordId
,
&
$ret
,
$frame
)
{
$result
=
false
;
self
::
get_user
();
$parser
->
getOutput
()
->
updateCacheExpiry
(
0
);
switch
(
$magicWordId
){
case
'connected'
:
if
(
!
self
::
get_user
(
$parser
)
->
isR
egistered
())
{
if
(
!
self
::
is_r
egistered
())
{
$ret
=
0
;
}
else
{
...
...
@@ -77,15 +63,8 @@ class ConnectedHooks {
$result
=
true
;
break
;
case
'u_name'
:
if
(
!
self
::
get_user
(
$parser
)
->
isRegistered
())
{
//$ret = self::$theUser->getName();
$ret
=
self
::
get_user
(
$parser
)
->
getName
();
}
else
{
//$ret = self::$theUser->getName();
$ret
=
self
::
get_user
(
$parser
)
->
getName
();
}
$resutl
=
true
;
$ret
=
self
::
$user
->
mName
;
$result
=
true
;
break
;
}
return
$result
;
...
...
@@ -104,7 +83,8 @@ class ConnectedHooks {
//https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
public
static
function
lfHideSidebar
(
$skin
,
&
$bar
)
{
// Hide sidebar for anonymous users
if
(
!
self
::
get_user
()
->
isRegistered
()
)
{
$user
=
self
::
get_user
();
if
(
!
self
::
is_registered
())
{
$bar
=
array
(
'navigation'
=>
array
(
array
(
...
...
@@ -121,7 +101,8 @@ class ConnectedHooks {
#Ajouter une feuille de style quand pas connecté
public
static
function
add_NotLoggedIncss
(
OutputPage
$out
,
Skin
$skin
)
{
if
(
!
self
::
get_user
(
$out
)
->
isRegistered
()
)
{
$user
=
self
::
get_user
(
$out
);
if
(
!
self
::
is_registered
())
{
$out
->
addStyle
(
'/w/index.php?title=MediaWiki:NotLoggedIn.css&action=raw&ctype=text/css'
);
$out
->
addMeta
(
"logged"
,
"no"
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment