Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 35 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
SpecialCreateObject | |
0.00% |
0 / 35 |
|
0.00% |
0 / 5 |
210 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDescription | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
42 | |||
userCanExecute | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
execute | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * WikiLambda Special:CreateObject page |
4 | * |
5 | * @file |
6 | * @ingroup Extensions |
7 | * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt |
8 | * @license MIT |
9 | */ |
10 | |
11 | namespace MediaWiki\Extension\WikiLambda\Special; |
12 | |
13 | use MediaWiki\Extension\WikiLambda\Registry\ZTypeRegistry; |
14 | use MediaWiki\Extension\WikiLambda\ZObjectEditingPageTrait; |
15 | use MediaWiki\SpecialPage\SpecialPage; |
16 | use MediaWiki\User\User; |
17 | |
18 | class SpecialCreateObject extends SpecialPage { |
19 | use ZObjectEditingPageTrait; |
20 | |
21 | public function __construct() { |
22 | parent::__construct( 'CreateObject', 'wikilambda-create' ); |
23 | } |
24 | |
25 | /** |
26 | * @inheritDoc |
27 | */ |
28 | protected function getGroupName() { |
29 | // Triggers use of message specialpages-group-wikilambda |
30 | return 'wikilambda'; |
31 | } |
32 | |
33 | /** |
34 | * @inheritDoc |
35 | */ |
36 | public function getDescription() { |
37 | // we do not know which object type will be created, so we need to be generic here |
38 | $request = $this->getRequest(); |
39 | $zid = $request->getText( 'zid' ); |
40 | $description = null; |
41 | |
42 | switch ( $zid ) { |
43 | case ZTypeRegistry::Z_TYPE: |
44 | $description = $this->msg( 'wikilambda-special-create-type' ); |
45 | break; |
46 | case ZTypeRegistry::Z_FUNCTION: |
47 | $description = $this->msg( 'wikilambda-special-create-function' ); |
48 | break; |
49 | case ZTypeRegistry::Z_IMPLEMENTATION: |
50 | $description = $this->msg( 'wikilambda-special-create-implementation' ); |
51 | break; |
52 | case ZTypeRegistry::Z_TESTER: |
53 | $description = $this->msg( 'wikilambda-special-create-test' ); |
54 | break; |
55 | default: |
56 | $description = $this->msg( 'wikilambda-special-createobject' ); |
57 | } |
58 | return $description; |
59 | } |
60 | |
61 | /** |
62 | * @inheritDoc |
63 | * |
64 | * @param User $user |
65 | * @return bool |
66 | */ |
67 | public function userCanExecute( User $user ) { |
68 | $block = $user->getBlock(); |
69 | |
70 | return ( |
71 | // Does the user have the relevant right (wikilambda-create, as set above)? |
72 | parent::userCanExecute( $user ) && |
73 | // If they're blocked in some way, does it block page creations or is site-wide? |
74 | ( !$block || !$block->appliesToRight( 'createpage' ) || !$block->isSitewide() ) |
75 | ); |
76 | } |
77 | |
78 | /** |
79 | * @inheritDoc |
80 | */ |
81 | public function execute( $subPage ) { |
82 | if ( !$this->userCanExecute( $this->getUser() ) ) { |
83 | $this->displayRestrictionError(); |
84 | } |
85 | |
86 | // NOTE: We ignore $subPage server-side, and extract and pre-fill type/etc. in Vue |
87 | |
88 | $this->setHeaders(); |
89 | |
90 | $output = $this->getOutput(); |
91 | |
92 | $output->addModules( [ 'ext.wikilambda.edit', 'mediawiki.special' ] ); |
93 | |
94 | $output->addWikiMsg( 'wikilambda-special-createobject-intro' ); |
95 | |
96 | $this->addHelpLink( 'Extension:WikiLambda/Creating Objects' ); |
97 | |
98 | $this->generateZObjectPayload( $output, $this->getContext(), [ |
99 | 'createNewPage' => true, |
100 | ] ); |
101 | } |
102 | } |