MediaWiki
REL1_39
MultiUsernameFilter.php
Go to the documentation of this file.
1
<?php
21
namespace
MediaWiki\Preferences
;
22
23
use
CentralIdLookup
;
24
use
MediaWiki\MediaWikiServices
;
25
use
MediaWiki\Permissions\Authority
;
26
27
class
MultiUsernameFilter
implements
Filter
{
31
private
$lookup;
33
private
$authorityOrAudience;
34
39
public
function
__construct
(
40
CentralIdLookup
$lookup =
null
,
41
$authorityOrAudience =
CentralIdLookup::AUDIENCE_PUBLIC
42
) {
43
$this->lookup = $lookup;
44
$this->authorityOrAudience = $authorityOrAudience;
45
}
46
50
public
function
filterFromForm
( $names ) {
51
$names = trim( $names );
52
if
( $names !==
''
) {
53
$names = preg_split(
'/\n/'
, $names, -1, PREG_SPLIT_NO_EMPTY );
54
$ids = $this->getLookup()->centralIdsFromNames( $names, $this->authorityOrAudience );
55
if
( $ids ) {
56
return
implode(
"\n"
, $ids );
57
}
58
}
59
// If the user list is empty, it should be null (don't save) rather than an empty string
60
return
null
;
61
}
62
66
public
function
filterForForm
( $value ) {
67
$ids =
self::splitIds
( $value );
68
$names = $ids ? $this->getLookup()->namesFromCentralIds( $ids, $this->authorityOrAudience ) : [];
69
return
implode(
"\n"
, $names );
70
}
71
78
public
static
function
splitIds
( $str ) {
79
return
array_map(
'intval'
, preg_split(
'/\n/'
, $str, -1, PREG_SPLIT_NO_EMPTY ) );
80
}
81
85
private
function
getLookup() {
86
$this->lookup = $this->lookup ??
MediaWikiServices::getInstance
()->getCentralIdLookup();
87
return
$this->lookup;
88
}
89
}
CentralIdLookup
The CentralIdLookup service allows for connecting local users with cluster-wide IDs.
Definition
CentralIdLookup.php:35
CentralIdLookup\AUDIENCE_PUBLIC
const AUDIENCE_PUBLIC
Definition
CentralIdLookup.php:37
MediaWiki\MediaWikiServices
Service locator for MediaWiki core services.
Definition
MediaWikiServices.php:212
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition
MediaWikiServices.php:273
MediaWiki\Preferences\MultiUsernameFilter
Definition
MultiUsernameFilter.php:27
MediaWiki\Preferences\MultiUsernameFilter\splitIds
static splitIds( $str)
Splits a newline separated list of user ids into an array.
Definition
MultiUsernameFilter.php:78
MediaWiki\Preferences\MultiUsernameFilter\__construct
__construct(CentralIdLookup $lookup=null, $authorityOrAudience=CentralIdLookup::AUDIENCE_PUBLIC)
Definition
MultiUsernameFilter.php:39
MediaWiki\Preferences\MultiUsernameFilter\filterFromForm
filterFromForm( $names)
mixed
Definition
MultiUsernameFilter.php:50
MediaWiki\Preferences\MultiUsernameFilter\filterForForm
filterForForm( $value)
mixed
Definition
MultiUsernameFilter.php:66
MediaWiki\Permissions\Authority
This interface represents the authority associated the current execution context, such as a web reque...
Definition
Authority.php:37
MediaWiki\Preferences\Filter
Base interface for user preference filters that work as a middleware between storage and interface.
Definition
Filter.php:27
MediaWiki\Preferences
Definition
DefaultPreferencesFactory.php:21
includes
preferences
MultiUsernameFilter.php
Generated on Tue Sep 10 2024 06:23:44 for MediaWiki by
1.10.0