Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4127042
MarkSymbolRenderer.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
MarkSymbolRenderer.php
View Options
<?php
namespace
Cite
;
/**
* Render the label for footnote marks, for example "1", "2", …
*
* Marks can be customized by group.
*
* @license GPL-2.0-or-later
*/
class
MarkSymbolRenderer
{
/** @var array<string,string[]> In-memory cache for the cite_link_label_group-… link label lists */
private
array
$legacyLinkLabels
=
[];
private
ReferenceMessageLocalizer
$messageLocalizer
;
public
function
__construct
(
ReferenceMessageLocalizer
$messageLocalizer
)
{
// TODO: deprecate the i18n mechanism.
$this
->
messageLocalizer
=
$messageLocalizer
;
}
public
function
makeLabel
(
string
$group
,
int
$number
,
?
int
$extendsIndex
=
null
):
string
{
$label
=
$this
->
fetchLegacyCustomLinkLabel
(
$group
,
$number
)
??
$this
->
makeDefaultLabel
(
$group
,
$number
);
if
(
$extendsIndex
!==
null
)
{
// TODO: design better behavior, especially when using custom group markers.
$label
.=
'.'
.
$this
->
messageLocalizer
->
localizeDigits
(
(
string
)
$extendsIndex
);
}
return
$label
;
}
private
function
makeDefaultLabel
(
string
$group
,
int
$number
):
string
{
$label
=
$this
->
messageLocalizer
->
localizeDigits
(
(
string
)
$number
);
return
$group
===
Cite
::
DEFAULT_GROUP
?
$label
:
"$group $label"
;
}
/**
* Look up the symbol in a literal sequence stored in a local system message override.
*
* @deprecated since 1.44
*/
private
function
fetchLegacyCustomLinkLabel
(
string
$group
,
int
$number
):
?
string
{
if
(
$group
===
Cite
::
DEFAULT_GROUP
)
{
// TODO: Possibly make the default group configurable, eg. to use a
// different numeral system than the content language or Western
// Arabic.
return
null
;
}
// TODO: deprecate this mechanism.
$message
=
"cite_link_label_group-$group"
;
if
(
!
array_key_exists
(
$group
,
$this
->
legacyLinkLabels
)
)
{
$msg
=
$this
->
messageLocalizer
->
msg
(
$message
);
$this
->
legacyLinkLabels
[
$group
]
=
$msg
->
isDisabled
()
?
[]
:
preg_split
(
'/
\s
+/'
,
$msg
->
plain
()
);
}
// Expected behavior for groups without custom labels
if
(
!
$this
->
legacyLinkLabels
[
$group
]
)
{
return
null
;
}
return
$this
->
legacyLinkLabels
[
$group
][
$number
-
1
]
??
null
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 08:24 (2 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
7e/54/2f3ae7eccfa86100693d6fcd2330
Default Alt Text
MarkSymbolRenderer.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment