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
92bb738f
Commit
92bb738f
authored
3 years ago
by
Mathieu Loiseau
Browse files
Options
Downloads
Patches
Plain Diff
Semble marcher quoi que peu testé
parent
e5bb2529
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Connected.php
+46
-11
46 additions, 11 deletions
src/Connected.php
with
46 additions
and
11 deletions
src/Connected.php
+
46
−
11
View file @
92bb738f
...
...
@@ -8,6 +8,45 @@
*
**/
class
ConnectedHooks
{
private
static
$user
=
false
;
//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
();
}
}
if
(
$res
===
false
){
global
$wgUser
;
$res
=
$wgUser
;
}
self
::
$user
=
$res
;
}
else
{
$res
=
self
::
$user
;
}
return
$res
;
}
// Register any render callbacks with the parser
public
static
function
onParserFirstCallInit
(
Parser
$parser
)
{
...
...
@@ -19,7 +58,7 @@ class ConnectedHooks {
public
static
function
ifConnectedRender
(
Parser
$parser
,
$ifLoggedIn
=
''
,
$ifNot
=
''
)
{
// The input parameters are wikitext with templates expanded.
// The output should be wikitext too.
if
(
!
$parser
->
get
U
ser
()
->
isRegistered
())
{
if
(
!
self
::
get
_u
ser
(
$parser
)
->
isRegistered
())
{
$output
=
$ifNot
;
}
else
{
...
...
@@ -33,7 +72,7 @@ class ConnectedHooks {
$result
=
false
;
switch
(
$magicWordId
){
case
'connected'
:
if
(
!
$parser
->
get
U
ser
()
->
isRegistered
())
{
if
(
!
self
::
get
_u
ser
(
$parser
)
->
isRegistered
())
{
$ret
=
0
;
}
else
{
...
...
@@ -42,13 +81,13 @@ class ConnectedHooks {
$result
=
true
;
break
;
case
'u_name'
:
if
(
!
$parser
->
get
U
ser
()
->
isRegistered
())
{
if
(
!
self
::
get
_u
ser
(
$parser
)
->
isRegistered
())
{
//$ret = self::$theUser->getName();
$ret
=
$parser
->
get
U
ser
()
->
getName
();
$ret
=
self
::
get
_u
ser
(
$parser
)
->
getName
();
}
else
{
//$ret = self::$theUser->getName();
$ret
=
$parser
->
get
U
ser
()
->
getName
();
$ret
=
self
::
get
_u
ser
(
$parser
)
->
getName
();
}
$resutl
=
true
;
break
;
...
...
@@ -68,9 +107,8 @@ 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
(
!
$wgUser
->
isLoggedIn
()
)
{
if
(
!
self
::
get_user
()
)
{
$bar
=
array
(
'navigation'
=>
array
(
array
(
...
...
@@ -87,7 +125,7 @@ class ConnectedHooks {
#Ajouter une feuille de style quand pas connecté
public
static
function
add_NotLoggedIncss
(
OutputPage
$out
,
Skin
$skin
)
{
if
(
!
$out
->
get
U
ser
()
->
isRegistered
()
)
{
if
(
!
self
::
get
_u
ser
(
$out
)
->
isRegistered
()
)
{
$out
->
addStyle
(
'/w/index.php?title=MediaWiki:NotLoggedIn.css&action=raw&ctype=text/css'
);
$out
->
addMeta
(
"logged"
,
"no"
);
}
...
...
@@ -101,9 +139,6 @@ class ConnectedHooks {
// 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'
;
...
...
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