Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5983385
CitizenComponentPageTools.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
CitizenComponentPageTools.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Skins\Citizen\Components
;
use
Exception
;
use
MediaWiki\Config\Config
;
use
MediaWiki\Permissions\PermissionManager
;
use
MediaWiki\Title\Title
;
use
MediaWiki\User\User
;
use
MessageLocalizer
;
/**
* CitizenComponentPageTools component
* FIXME: Need unit test
*/
class
CitizenComponentPageTools
implements
CitizenComponent
{
/** @var string */
public
const
TOOLBOX_ID
=
'p-tb'
;
public
function
__construct
(
private
readonly
Config
$config
,
private
readonly
MessageLocalizer
$localizer
,
private
readonly
Title
$title
,
private
readonly
User
$user
,
private
readonly
PermissionManager
$permissionManager
,
private
readonly
int
$numLanguages
,
private
readonly
array
$pageToolsMenu
,
private
readonly
array
$languagesData
,
private
readonly
array
$variantsData
)
{
}
/**
* Check if views and actions should show
*
* Possible visibility conditions:
* * true: always visible (bool)
* * false: never visible (bool)
* * 'login': only visible if logged in (string)
* * 'permission-*': only visible if user has permission
* e.g. permission-edit = only visible if user can edit pages
*/
private
function
shouldShowPageTools
():
bool
{
$condition
=
$this
->
config
->
get
(
'CitizenShowPageTools'
);
$user
=
$this
->
user
;
// Login-based condition, return true if condition is met
if
(
$condition
===
'login'
)
{
$condition
=
$user
->
isRegistered
();
}
// Permission-based condition, return true if condition is met
if
(
is_string
(
$condition
)
&&
strpos
(
$condition
,
'permission'
)
===
0
)
{
$permission
=
substr
(
$condition
,
11
);
try
{
$condition
=
$this
->
permissionManager
->
userCan
(
$permission
,
$user
,
$this
->
title
);
}
catch
(
Exception
$e
)
{
$condition
=
false
;
}
}
return
(
bool
)
$condition
;
}
public
function
getTemplateData
():
array
{
$hasLanguages
=
(
$this
->
languagesData
&&
$this
->
languagesData
[
'is-empty'
]
!==
true
)
||
(
$this
->
variantsData
&&
$this
->
variantsData
[
'is-empty'
]
!==
true
);
$articleTools
=
$this
->
pageToolsMenu
;
return
[
'data-article-tools'
=>
$articleTools
,
'is-visible'
=>
$this
->
shouldShowPageTools
(),
// There are edge cases where the menu is completely empty
'has-overflow'
=>
(
bool
)
$articleTools
,
'has-languages'
=>
$hasLanguages
,
/*
* FIXME: ULS does not trigger for some reason, disabling it for now
* 'is-uls-ready' => $this->shouldShowULS( $variantsData ),
*/
'is-uls-ready'
=>
false
,
'int-language-count'
=>
$this
->
numLanguages
,
'is-sharable'
=>
$this
->
title
->
exists
()
&&
$this
->
title
->
isContentPage
(),
'msg-citizen-share'
=>
$this
->
localizer
->
msg
(
"citizen-share"
)->
text
()
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 22:51 (1 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
08/e9/0c92b6824e96bd8df13000cd9c0a
Default Alt Text
CitizenComponentPageTools.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment