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
e5bb2529
Commit
e5bb2529
authored
2 years ago
by
Mathieu Loiseau
Browse files
Options
Downloads
Patches
Plain Diff
Marche presque quoi que moche
parent
4cde8693
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
extension.json
+1
-2
1 addition, 2 deletions
extension.json
src/Connected.php
+29
-33
29 additions, 33 deletions
src/Connected.php
with
30 additions
and
35 deletions
extension.json
+
1
−
2
View file @
e5bb2529
...
...
@@ -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"
,
...
...
This diff is collapsed.
Click to expand it.
src/Connected.php
+
29
−
33
View file @
e5bb2529
...
...
@@ -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
->
get
Options
()
->
getOption
(
'connected'
)
==
string
(
true
))
{
$output
=
$if
LoggedIn
;
if
(
!
$parser
->
get
User
()
->
isRegistered
(
))
{
$output
=
$if
Not
;
}
else
{
$output
=
$if
Not
;
$output
=
$if
LoggedIn
;
}
return
[
$output
,
'noparse'
=>
false
];
}
...
...
@@ -52,24 +33,24 @@ class ConnectedHooks {
$result
=
false
;
switch
(
$magicWordId
){
case
'connected'
:
if
(
$parser
->
get
Options
()
->
getOption
(
'connected'
)
==
string
(
false
))
{
if
(
!
$parser
->
get
User
()
->
isRegistered
(
))
{
$ret
=
0
;
$result
=
true
;
}
else
{
$ret
=
1
;
$result
=
true
;
}
$result
=
true
;
break
;
case
'u_name'
:
if
(
$parser
->
get
Options
()
->
getOption
(
'connected'
)
==
string
(
false
))
{
$ret
=
$wg
User
->
getName
();
$re
sul
t
=
true
;
if
(
!
$parser
->
get
User
()
->
isRegistered
(
))
{
//
$ret =
self::$the
User->getName();
$ret
=
$parser
->
getUser
()
->
getName
()
;
}
else
{
$ret
=
$wg
User
->
getName
();
$re
sul
t
=
true
;
//
$ret =
self::$the
User->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
(
'connect
ed
'
)
==
string
(
false
)
)
{
if
(
!
$out
->
getUser
()
->
isRegister
ed
(
)
)
{
$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'
;
}
}
}
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