Translate extension for MediaWiki
Loading...
Searching...
No Matches
MediaWikiPageNameValidator.php
1
<?php
2
declare( strict_types = 1 );
3
4
namespace
MediaWiki\Extension\Translate\Validation\Validators;
5
6
use
MediaWiki\Extension\Translate\MessageLoading\Message
;
7
use
MediaWiki\Extension\Translate\Validation\MessageValidator
;
8
use
MediaWiki\Extension\Translate\Validation\ValidationIssue
;
9
use
MediaWiki\Extension\Translate\Validation\ValidationIssues
;
10
17
class
MediaWikiPageNameValidator
implements
MessageValidator
{
18
public
function
getIssues(
Message
$message,
string
$targetLanguage ):
ValidationIssues
{
19
$issues =
new
ValidationIssues
();
20
21
$definition = $message->
definition
();
22
$translation = $message->
translation
();
23
24
$namespaces =
'help|project|\{\{ns:project}}|mediawiki'
;
25
$matches = [];
26
if
( preg_match(
"/^($namespaces):[\w\s]+$/ui"
, $definition, $matches ) &&
27
!preg_match(
"/^{$matches[1]}:.+$/u"
, $translation )
28
) {
29
$issue =
new
ValidationIssue
(
30
'pagename'
,
31
'namespace'
,
32
'translate-checks-pagename'
33
);
34
$issues->add( $issue );
35
}
36
37
return
$issues;
38
}
39
}
MediaWiki\Extension\Translate\MessageLoading\Message
Interface for message objects used by MessageCollection.
Definition
Message.php:13
MediaWiki\Extension\Translate\MessageLoading\Message\definition
definition()
Get the message definition.
Definition
Message.php:48
MediaWiki\Extension\Translate\MessageLoading\Message\translation
translation()
Get the message translation.
MediaWiki\Extension\Translate\Validation\ValidationIssue
Value object.
Definition
ValidationIssue.php:16
MediaWiki\Extension\Translate\Validation\ValidationIssues
Mutable collection for validation issues.
Definition
ValidationIssues.php:21
MediaWiki\Extension\Translate\Validation\Validators\MediaWikiPageNameValidator
Ensures that translations do not translate namespaces.
Definition
MediaWikiPageNameValidator.php:17
MediaWiki\Extension\Translate\Validation\MessageValidator
Interim interface for message validators.
Definition
MessageValidator.php:22
src
Validation
Validators
MediaWikiPageNameValidator.php
Generated by
1.10.0