Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
EntitySchemaRedirectTrait | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
getOutput | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getHookRunner | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getRequest | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
redirectToEntitySchema | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | declare( strict_types = 1 ); |
4 | |
5 | namespace EntitySchema\MediaWiki; |
6 | |
7 | use EntitySchema\DataAccess\EntitySchemaStatus; |
8 | use MediaWiki\HookContainer\HookRunner; |
9 | use MediaWiki\Output\OutputPage; |
10 | use MediaWiki\Request\WebRequest; |
11 | use MediaWiki\Title\Title; |
12 | use Wikimedia\Assert\Assert; |
13 | |
14 | /** |
15 | * Trait for a special page or action to redirect to an EntitySchema after an edit. |
16 | * |
17 | * If a temporary account was created during the edit, |
18 | * the redirect may be altered by a hook (e.g. CentralAuth might redirect to loginwiki). |
19 | * @license GPL-2.0-or-later |
20 | */ |
21 | trait EntitySchemaRedirectTrait { |
22 | |
23 | /** @return OutputPage */ |
24 | abstract public function getOutput(); |
25 | |
26 | /** @return HookRunner */ |
27 | abstract protected function getHookRunner(); |
28 | |
29 | /** @return WebRequest */ |
30 | abstract public function getRequest(); |
31 | |
32 | protected function redirectToEntitySchema( EntitySchemaStatus $status, string $redirectParams = '' ): void { |
33 | Assert::parameter( $status->isOK(), '$status', 'must be OK' ); |
34 | $title = Title::makeTitle( NS_ENTITYSCHEMA_JSON, $status->getEntitySchemaId()->getId() ); |
35 | $savedTempUser = $status->getSavedTempUser(); |
36 | $redirectUrl = ''; |
37 | if ( $savedTempUser !== null ) { |
38 | $this->getHookRunner()->onTempUserCreatedRedirect( |
39 | $this->getRequest()->getSession(), |
40 | $savedTempUser, |
41 | $title->getPrefixedDBkey(), |
42 | $redirectParams, |
43 | '', |
44 | $redirectUrl |
45 | ); |
46 | } |
47 | if ( !$redirectUrl ) { |
48 | $redirectUrl = $title->getFullURL( $redirectParams ); |
49 | } |
50 | $this->getOutput()->redirect( $redirectUrl ); |
51 | } |
52 | |
53 | } |