Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1430936
DtdFormat.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
DtdFormat.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\FileFormatSupport
;
use
MediaWiki\Extension\Translate\MessageLoading\Message
;
use
MediaWiki\Extension\Translate\MessageLoading\MessageCollection
;
use
MediaWiki\Extension\Translate\Utilities\Utilities
;
/**
* File format support for DTD.
* @author Guillaume Duhamel
* @author Niklas Laxström
* @author Siebrand Mazeland
* @copyright Copyright © 2009-2010, Guillaume Duhamel, Niklas Laxström, Siebrand Mazeland
* @license GPL-2.0-or-later
* @ingroup FileFormatSupport
*/
class
DtdFormat
extends
SimpleFormat
{
public
function
getFileExtensions
():
array
{
return
[
'.dtd'
];
}
public
function
readFromVariable
(
string
$data
):
array
{
preg_match_all
(
',# Author: ([^
\n
]+)
\n
,'
,
$data
,
$matches
);
$authors
=
$matches
[
1
];
preg_match_all
(
',<!ENTITY[ ]+([^ ]+)
\s
+"([^"]+)"[^>]*>,'
,
$data
,
$matches
);
[
,
$keys
,
$messages
]
=
$matches
;
$messages
=
array_combine
(
$keys
,
array_map
(
static
function
(
$message
)
{
return
html_entity_decode
(
$message
,
ENT_QUOTES
);
},
$messages
)
);
$messages
=
$this
->
group
->
getMangler
()->
mangleArray
(
$messages
);
return
[
'AUTHORS'
=>
$authors
,
'MESSAGES'
=>
$messages
,
];
}
protected
function
writeReal
(
MessageCollection
$collection
):
string
{
$collection
->
loadTranslations
();
$header
=
"<!--
\n
"
;
$header
.=
$this
->
doHeader
(
$collection
);
$header
.=
$this
->
doAuthors
(
$collection
);
$header
.=
"-->
\n
"
;
$output
=
''
;
$mangler
=
$this
->
group
->
getMangler
();
/** @var Message $message */
foreach
(
$collection
as
$key
=>
$message
)
{
$key
=
$mangler
->
unmangle
(
$key
);
$trans
=
$message
->
translation
()
??
''
;
if
(
$trans
===
''
)
{
continue
;
}
$trans
=
str_replace
(
TRANSLATE_FUZZY
,
''
,
$trans
);
$trans
=
str_replace
(
'"'
,
'"'
,
$trans
);
$output
.=
"<!ENTITY $key
\"
$trans
\"
>
\n
"
;
}
if
(
$output
)
{
return
$header
.
$output
;
}
return
''
;
}
private
function
doHeader
(
MessageCollection
$collection
):
string
{
global
$wgSitename
;
$code
=
$collection
->
code
;
$name
=
Utilities
::
getLanguageName
(
$code
);
$native
=
Utilities
::
getLanguageName
(
$code
,
$code
);
$output
=
"# Messages for $name ($native)
\n
"
;
$output
.=
"# Exported from $wgSitename
\n\n
"
;
return
$output
;
}
private
function
doAuthors
(
MessageCollection
$collection
):
string
{
$output
=
''
;
$authors
=
$collection
->
getAuthors
();
$authors
=
$this
->
filterAuthors
(
$authors
,
$collection
->
code
);
foreach
(
$authors
as
$author
)
{
$output
.=
"# Author: $author
\n
"
;
}
return
$output
;
}
}
class_alias
(
DtdFormat
::
class
,
'DtdFFS'
);
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 19:48 (3 h, 55 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
90/01/9682a8048b512b702753a53c794c
Default Alt Text
DtdFormat.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment