Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4086671
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
Config
$config
,
private
MessageLocalizer
$localizer
,
private
Title
$title
,
private
User
$user
,
private
PermissionManager
$permissionManager
,
private
int
$numLanguages
,
private
array
$pageToolsMenu
,
private
array
$languagesData
,
private
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
;
}
/**
* @inheritDoc
*/
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
Aug 18 2026, 09:06 (6 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
c4/13/5aa182f3b54423ed5077b7934f8f
Default Alt Text
CitizenComponentPageTools.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment