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
66594e9f
Commit
66594e9f
authored
3 years ago
by
Mathieu Loiseau
Browse files
Options
Downloads
Patches
Plain Diff
tentative module
parent
f21e1b21
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
extension.json
+2
-1
2 additions, 1 deletion
extension.json
src/Connected.php
+59
-34
59 additions, 34 deletions
src/Connected.php
with
61 additions
and
35 deletions
extension.json
+
2
−
1
View file @
66594e9f
...
@@ -13,7 +13,8 @@
...
@@ -13,7 +13,8 @@
"ExampleExtensionMagic"
:
"Connected.i18n.magic.php"
"ExampleExtensionMagic"
:
"Connected.i18n.magic.php"
},
},
"Hooks"
:
{
"Hooks"
:
{
"ParserGetVariableValueSwitch"
:
"ConnectedHooks::onParserFirstCallInit"
"ParserGetVariableValueSwitch"
:
"ConnectedHooks::onParserFirstCallInit"
,
"MagicWordwgVariableIDs"
:
"ConnectedHooks::connectedDeclareVarIds"
},
},
"manifest_version"
:
1
"manifest_version"
:
1
}
}
This diff is collapsed.
Click to expand it.
src/Connected.php
+
59
−
34
View file @
66594e9f
...
@@ -7,45 +7,70 @@
...
@@ -7,45 +7,70 @@
* @link https://gitlab.liris.cnrs.fr/mloiseau/mw_connected
* @link https://gitlab.liris.cnrs.fr/mloiseau/mw_connected
*
*
**/
**/
$wgExtensionMessagesFiles
[
'Connected'
]
=
__DIR__
.
'/Connected.i18n.magic.php'
;
$wgExtensionMessagesFiles
[
'Connected'
]
=
__DIR__
.
'/Connected.i18n.magic.php'
;
$wgHooks
[
'ParserGetVariableValueSwitch'
][]
=
'wfConnectedAssignValue'
;
class
ConnectedHooks
{
function
wfConnectedAssignValue
(
&
$parser
,
&
$cache
,
&
$magicWordId
,
&
$ret
)
{
// Register any render callbacks with the parser
global
$wgUser
;
public
static
function
onParserFirstCallInit
(
Parser
$parser
)
{
$result
=
false
;
if
(
$wgUser
->
isSafeToLoad
()){
// Create a function hook associating the "example" magic word with renderExample()
if
(
!
$wgUser
->
isLoggedIn
()
)
{
$parser
->
setFunctionHook
(
'ifloggedin'
,
[
self
::
class
,
'ifConnectedRender'
]
);
switch
(
$magicWordId
){
}
case
'connected'
:
$ret
=
0
;
// Render the output of {{#example:}}.
$result
=
true
;
public
static
function
ifConnectedRender
(
Parser
$parser
,
$ifLoggedIn
=
''
,
$ifNot
=
''
)
{
break
;
// The input parameters are wikitext with templates expanded.
case
'u_name'
:
// The output should be wikitext too.
$ret
=
$wgUser
->
getName
();
global
$wgUser
;
$result
=
true
;
if
(
$wgUser
->
isSafeToLoad
()){
break
;
if
(
$wgUser
->
isLoggedIn
()
)
{
$output
=
$ifLoggedIn
;
}
}
}
else
{
else
{
$output
=
$ifNot
;
switch
(
$magicWordId
){
}
case
'connected'
:
$ret
=
1
;
return
$output
;
$result
=
true
;
}
break
;
case
'u_name'
:
public
static
function
wfConnectedAssignValue
(
Parser
$parser
,
&
$cache
,
&
$magicWordId
,
&
$ret
)
{
$ret
=
$wgUser
->
getName
();
global
$wgUser
;
$result
=
true
;
$result
=
false
;
break
;
if
(
$wgUser
->
isSafeToLoad
()){
if
(
!
$wgUser
->
isLoggedIn
()
)
{
switch
(
$magicWordId
){
case
'connected'
:
$ret
=
0
;
$result
=
true
;
break
;
case
'u_name'
:
$ret
=
$wgUser
->
getName
();
$result
=
true
;
break
;
}
}
else
{
switch
(
$magicWordId
){
case
'connected'
:
$ret
=
1
;
$result
=
true
;
break
;
case
'u_name'
:
$ret
=
$wgUser
->
getName
();
$result
=
true
;
break
;
}
}
}
}
}
return
$result
;
}
function
connectedDeclareVarIds
(
&
$customVariableIds
)
{
// $customVariableIds is where MediaWiki wants to store its list of custom
// variable IDs. We oblige by adding ours:
$customVariableIds
[]
=
'connected'
;
$customVariableIds
[]
=
'u_name'
;
}
}
return
$result
;
}
}
$wgHooks
[
'MagicWordwgVariableIDs'
][]
=
'connectedMyDeclareVarIds'
;
$wgHooks
[
'MagicWordwgVariableIDs'
][]
=
'connectedMyDeclareVarIds'
;
function
connectedMyDeclareVarIds
(
&
$customVariableIds
)
{
// $customVariableIds is where MediaWiki wants to store its list of custom
// variable IDs. We oblige by adding ours:
$customVariableIds
[]
=
'connected'
;
$customVariableIds
[]
=
'u_name'
;
}
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