Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5993192
CentralAuthUtilityService.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
CentralAuthUtilityService.php
View Options
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
namespace
MediaWiki\Extension\CentralAuth
;
use
MediaWiki\Auth\AuthManager
;
use
MediaWiki\Config\Config
;
use
MediaWiki\Context\RequestContext
;
use
MediaWiki\Extension\CentralAuth\User\CentralAuthUser
;
use
MediaWiki\JobQueue\JobFactory
;
use
MediaWiki\JobQueue\JobQueueGroupFactory
;
use
MediaWiki\Logger\LoggerFactory
;
use
MediaWiki\Permissions\Authority
;
use
MediaWiki\Title\TitleFactory
;
use
MediaWiki\User\User
;
use
MediaWiki\WikiMap\WikiMap
;
use
Profiler
;
use
RuntimeException
;
use
StatusValue
;
/**
* Utility services that are useful in many parts of CentralAuth.
*
* @since 1.36
*/
class
CentralAuthUtilityService
{
private
Config
$config
;
private
AuthManager
$authManager
;
private
TitleFactory
$titleFactory
;
private
JobQueueGroupFactory
$jobQueueGroupFactory
;
private
JobFactory
$jobFactory
;
public
function
__construct
(
Config
$config
,
AuthManager
$authManager
,
TitleFactory
$titleFactory
,
JobQueueGroupFactory
$jobQueueGroupFactory
,
JobFactory
$jobFactory
)
{
$this
->
config
=
$config
;
$this
->
authManager
=
$authManager
;
$this
->
titleFactory
=
$titleFactory
;
$this
->
jobQueueGroupFactory
=
$jobQueueGroupFactory
;
$this
->
jobFactory
=
$jobFactory
;
}
/**
* Auto-create an account
*
* @param User $user User to auto-create
* @param bool $log Whether to generate a user creation log entry
* @param Authority|null $performer The user performing the creation
* @return StatusValue a status value
*/
public
function
autoCreateUser
(
User
$user
,
$log
=
true
,
?
Authority
$performer
=
null
):
StatusValue
{
// Ignore warnings about primary database connections/writes...hard to avoid here
Profiler
::
instance
()->
getTransactionProfiler
()->
resetExpectations
();
$source
=
CentralAuthPrimaryAuthenticationProvider
::
ID
;
if
(
!
$this
->
authManager
->
getAuthenticationProvider
(
$source
)
)
{
$source
=
AuthManager
::
AUTOCREATE_SOURCE_SESSION
;
}
$sv
=
$this
->
authManager
->
autoCreateUser
(
$user
,
$source
,
false
,
$log
,
$performer
);
LoggerFactory
::
getInstance
(
'authevents'
)->
info
(
'Central autocreation attempt'
,
[
'event'
=>
'autocreate'
,
'successful'
=>
$sv
->
isGood
(),
'status'
=>
(
$sv
->
getErrorsArray
()
?:
$sv
->
getWarningsArray
()
)[
0
][
0
]
??
'-'
,
'accountType'
=>
$user
->
isNamed
()
?
'named'
:
'temp'
,
'extension'
=>
'CentralAuth'
,
]
);
return
$sv
;
}
/**
* Sets up jobs to create and attach a local account for the given user on every wiki listed in
* $wgCentralAuthAutoCreateWikis.
* @param CentralAuthUser $centralUser
*/
public
function
scheduleCreationJobs
(
CentralAuthUser
$centralUser
)
{
$name
=
$centralUser
->
getName
();
$thisWiki
=
WikiMap
::
getCurrentWikiId
();
$session
=
RequestContext
::
getMain
()->
exportSession
();
$title
=
$this
->
titleFactory
->
makeTitleSafe
(
NS_USER
,
$name
);
if
(
!
$title
)
{
throw
new
RuntimeException
(
"Failed to create title for user page of $name"
);
}
foreach
(
$this
->
config
->
get
(
'CentralAuthAutoCreateWikis'
)
as
$wiki
)
{
if
(
$wiki
===
$thisWiki
)
{
continue
;
}
$job
=
$this
->
jobFactory
->
newJob
(
'CentralAuthCreateLocalAccountJob'
,
[
'name'
=>
$name
,
'from'
=>
$thisWiki
,
'session'
=>
$session
]
);
$this
->
jobQueueGroupFactory
->
makeJobQueueGroup
(
$wiki
)->
lazyPush
(
$job
);
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Oct 4 2026, 02:37 (4 w, 6 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
de/70/c9c175c9613322a721a6a0b5532d
Default Alt Text
CentralAuthUtilityService.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment