MediaWiki
master
AudienceDesignation.php
Go to the documentation of this file.
1
<?php
2
3
namespace
MediaWiki\Rest\Module
;
4
11
enum
AudienceDesignation
:
string
{
12
// This is the default if no audience designation is specified. We therefore don't expect any
13
// module to actually specify this (although it would work as expected if one did).
14
case
PUBLISHED =
'published'
;
15
16
case
INTERNAL =
'internal'
;
17
18
case
BETA =
'beta'
;
19
27
public
static
function
fromModuleId
(
string
$moduleId ): ?
AudienceDesignation
{
28
// Module ids with no audience designation are assumed to be "published".
29
//
30
// Return null for module ids of invalid format, or whose audience designation is present
31
// but unrecognized. Generally, structure tests should identify invalid module ids and
32
// audience designations, so this should be a rare case.
33
$pattern =
'!^([-.\w]+)/v[0-9]+(-[a-zA-Z]+)?(?:[0-9]+)?$!'
;
34
if
( !preg_match( $pattern, $moduleId,
$matches
) ) {
35
return
null
;
36
}
37
38
// $match[1] is the (required) module name, e.g. the "mymodule" in "mymodule/v1-beta".
39
if
( !isset(
$matches
[1] ) ) {
40
return
null
;
41
}
42
43
// $match[2], if present, is the audience designation, including its leading dash.
44
// For example, the "-beta" in "mymodule/v1-beta".
45
if
( !isset(
$matches
[2] ) ) {
46
return
self::PUBLISHED;
47
}
48
49
// The leading character of $matches[2] is guaranteed to be a dash. Strip it.
50
$adStr = substr(
$matches
[2], 1 );
51
return
self::tryFrom( $adStr );
52
}
53
}
$matches
$matches
Definition
NoLocalSettings.php:13
MediaWiki\Rest\Module
Definition
AudienceDesignation.php:3
MediaWiki\Rest\Module\AudienceDesignation
AudienceDesignation
Describes the set of audience designations available to REST modules.
Definition
AudienceDesignation.php:11
MediaWiki\Rest\Module\fromModuleId
@ fromModuleId
Gets a module's audience designation from its module id.
Definition
AudienceDesignation.php:27
includes
Rest
Module
AudienceDesignation.php
Generated on Tue Jul 21 2026 22:27:24 for MediaWiki by
1.10.0