Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 38 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
SpecialRunFunction | |
0.00% |
0 / 38 |
|
0.00% |
0 / 5 |
90 | |
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 / 1 |
|
0.00% |
0 / 1 |
2 | |||
userCanExecute | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
execute | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * WikiLambda Special:RunFunction 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\ZLangRegistry; |
14 | use MediaWiki\Html\Html; |
15 | use MediaWiki\SpecialPage\SpecialPage; |
16 | use MediaWiki\User\User; |
17 | |
18 | class SpecialRunFunction extends SpecialPage { |
19 | |
20 | public function __construct() { |
21 | parent::__construct( 'RunFunction', 'wikilambda-execute' ); |
22 | } |
23 | |
24 | /** |
25 | * @inheritDoc |
26 | */ |
27 | protected function getGroupName() { |
28 | // Triggers use of message specialpages-group-wikilambda |
29 | return 'wikilambda'; |
30 | } |
31 | |
32 | /** |
33 | * @inheritDoc |
34 | */ |
35 | public function getDescription() { |
36 | return $this->msg( 'wikilambda-special-runfunction' ); |
37 | } |
38 | |
39 | /** |
40 | * @inheritDoc |
41 | * |
42 | * @param User $user |
43 | * @return bool |
44 | */ |
45 | public function userCanExecute( User $user ) { |
46 | if ( !$this->getConfig()->get( 'WikiLambdaEnableRepoMode' ) ) { |
47 | // No usage allowed on client-mode wikis. |
48 | return false; |
49 | } |
50 | |
51 | $block = $user->getBlock(); |
52 | |
53 | return ( |
54 | // Does the user have the relevant right (wikilambda-execute, as set above)? |
55 | parent::userCanExecute( $user ) && |
56 | // If they're blocked in some way, is it site-wide? |
57 | ( !$block || !$block->isSitewide() ) |
58 | ); |
59 | } |
60 | |
61 | /** |
62 | * @inheritDoc |
63 | */ |
64 | public function execute( $subPage ) { |
65 | if ( !$this->userCanExecute( $this->getUser() ) ) { |
66 | $this->displayRestrictionError(); |
67 | } |
68 | |
69 | // TODO (T359573): Use $subPage to extract and pre-fill target Z8? |
70 | |
71 | $this->setHeaders(); |
72 | $this->outputHeader( 'wikilambda-special-runfunction-summary' ); |
73 | |
74 | $output = $this->getOutput(); |
75 | $output->addModules( [ 'ext.wikilambda.app', 'mediawiki.special' ] ); |
76 | |
77 | $output->addWikiMsg( 'wikilambda-special-runfunction-intro' ); |
78 | |
79 | $this->addHelpLink( 'Help:Wikifunctions/Run function' ); |
80 | |
81 | // TODO (T362240): Can we re-use parts of ZObjectEditingPageTrait rather than re-use? |
82 | $userLang = $this->getLanguage(); |
83 | |
84 | // Fallback no-JS notice. |
85 | $output->addHtml( Html::element( |
86 | 'div', |
87 | [ 'class' => [ 'client-nojs', 'ext-wikilambda-editor-nojswarning' ] ], |
88 | $this->msg( 'wikilambda-special-runfunction-nojs' )->inLanguage( $userLang )->text() |
89 | ) ); |
90 | |
91 | $userLangCode = $userLang->getCode(); |
92 | |
93 | $zLangRegistry = ZLangRegistry::singleton(); |
94 | // If the userLang isn't recognised (e.g. it's qqx, or a language we don't support yet, or it's |
95 | // nonsense), then fall back to English. |
96 | $userLangZid = $zLangRegistry->getLanguageZidFromCode( $userLangCode, true ); |
97 | // Normalise our used language code from what the Language object says |
98 | $userLangCode = $zLangRegistry->getLanguageCodeFromZid( $userLangZid ); |
99 | |
100 | $editingData = [ |
101 | 'zlang' => $userLangCode, |
102 | 'zlangZid' => $userLangZid, |
103 | 'createNewPage' => false, |
104 | 'runFunction' => true, |
105 | 'viewmode' => false |
106 | ]; |
107 | |
108 | $output->addJsConfigVars( 'wgWikiLambda', $editingData ); |
109 | |
110 | // Vue app element |
111 | $output->addHtml( Html::element( 'div', [ 'id' => 'ext-wikilambda-app' ] ) ); |
112 | } |
113 | } |