1 | <?php |
||
23 | class Setup { |
||
24 | |||
25 | private $globals; |
||
26 | private $rootDirectory; |
||
27 | private $defaultGitHubRepo = 'JeroenDeDauw/GitHub'; |
||
28 | private $cacheTime = 600; |
||
29 | private $gitHubUrl = 'https://rawcdn.githack.com'; |
||
30 | private $gitHubFetcher = 'mediawiki'; |
||
31 | private $gitHubCache = 'full'; |
||
32 | private $repositoryWhitelist = []; |
||
33 | |||
34 | 1 | public function __construct( &$globals, string $rootDirectory ) { |
|
35 | 1 | $this->globals =& $globals; |
|
36 | 1 | $this->rootDirectory = $rootDirectory; |
|
37 | 1 | } |
|
38 | |||
39 | 1 | public function run() { |
|
40 | 1 | $this->loadSettings(); |
|
41 | |||
42 | 1 | $this->registerExtensionCredits(); |
|
43 | 1 | $this->registerParserHookHandler(); |
|
44 | 1 | } |
|
45 | |||
46 | 1 | private function registerExtensionCredits() { |
|
47 | 1 | $this->globals['wgExtensionCredits']['other'][] = [ |
|
48 | 1 | 'path' => $this->rootDirectory . '/GitHub.php', |
|
49 | 1 | 'name' => 'GitHub', |
|
50 | 1 | 'version' => GitHub_VERSION, |
|
51 | 'author' => [ |
||
52 | '[https://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]', |
||
53 | '[https://professional.wiki/ Professional.Wiki]' |
||
54 | ], |
||
55 | 1 | 'url' => 'https://github.com/JeroenDeDauw/GitHub', |
|
56 | 1 | 'descriptionmsg' => 'github-desc', |
|
57 | 1 | 'license-name' => 'GPL-2.0-or-later' |
|
58 | ]; |
||
59 | 1 | } |
|
60 | |||
61 | 1 | private function loadSettings() { |
|
62 | 1 | if ( array_key_exists( 'egGitHubDefaultRepo', $this->globals ) ) { |
|
63 | $this->defaultGitHubRepo = $this->globals['egGitHubDefaultRepo']; |
||
64 | } |
||
65 | |||
66 | 1 | if ( array_key_exists( 'egGitHubCacheTime', $this->globals ) ) { |
|
67 | $this->cacheTime = $this->globals['egGitHubCacheTime']; |
||
68 | } |
||
69 | |||
70 | 1 | if ( array_key_exists( 'egGitHubUrl', $this->globals ) ) { |
|
71 | $this->gitHubUrl = $this->globals['egGitHubUrl']; |
||
72 | } |
||
73 | |||
74 | 1 | if ( array_key_exists( 'egGitHubFetcher', $this->globals ) ) { |
|
75 | $this->gitHubFetcher = $this->globals['egGitHubFetcher']; |
||
76 | } |
||
77 | |||
78 | 1 | if ( array_key_exists( 'egGitHubCache', $this->globals ) ) { |
|
79 | $this->gitHubCache = $this->globals['egGitHubCache']; |
||
80 | } |
||
81 | |||
82 | 1 | if ( array_key_exists( 'egGitHubRepositoryWhitelist', $this->globals ) ) { |
|
83 | $this->repositoryWhitelist = $this->globals['egGitHubRepositoryWhitelist']; |
||
84 | } |
||
85 | 1 | } |
|
86 | |||
87 | 1 | private function registerParserHookHandler() { |
|
88 | 1 | $self = $this; |
|
89 | |||
90 | $this->globals['wgHooks']['ParserFirstCallInit'][] = function( \Parser &$parser ) use ( $self ) { |
||
91 | $hookRegistrant = new HookRegistrant( $parser ); |
||
92 | |||
93 | $hookRegistrant->registerFunction( |
||
94 | new FunctionRunner( |
||
95 | $self->getGitHubHookDefinition(), |
||
96 | $self->getGitHubHookHandler(), |
||
97 | array( |
||
98 | FunctionRunner::OPT_DO_PARSE => false |
||
99 | ) |
||
100 | ) |
||
101 | ); |
||
102 | |||
103 | return true; |
||
104 | }; |
||
105 | 1 | } |
|
106 | |||
107 | public function getGitHubHookDefinition(): HookDefinition { |
||
108 | return new HookDefinition( |
||
109 | 'github', |
||
110 | [ |
||
|
|||
111 | 'file' => [ |
||
112 | 'default' => 'README.md', |
||
113 | 'aliases' => 'filename', |
||
114 | 'message' => 'github-par-filename', |
||
115 | ], |
||
116 | 'repo' => [ |
||
117 | 'default' => $this->defaultGitHubRepo, |
||
118 | 'aliases' => 'reponame', |
||
119 | 'message' => 'github-par-reponame', |
||
120 | ], |
||
121 | 'branch' => [ |
||
122 | 'default' => 'master', |
||
123 | 'aliases' => 'branchname', |
||
124 | 'message' => 'github-par-branchname', |
||
125 | ], |
||
126 | 'lang' => [ |
||
127 | 'default' => '', |
||
128 | 'message' => 'github-par-lang', |
||
129 | ], |
||
130 | 'line' => [ |
||
131 | 'default' => false, |
||
132 | 'message' => 'github-par-line', |
||
133 | 'type' => 'boolean', |
||
134 | ], |
||
135 | 'start' => [ |
||
136 | 'default' => 1, |
||
137 | 'message' => 'github-par-start', |
||
138 | 'type' => 'integer', |
||
139 | ], |
||
140 | 'highlight' => [ |
||
141 | 'default' => '', |
||
142 | 'message' => 'github-par-highlight', |
||
143 | ], |
||
144 | 'inline' => [ |
||
145 | 'default' => false, |
||
146 | 'message' => 'github-par-inline', |
||
147 | 'type' => 'boolean', |
||
148 | ], |
||
149 | ], |
||
150 | [ |
||
151 | 'file', |
||
152 | 'repo', |
||
153 | 'branch', |
||
154 | 'lang' |
||
155 | ] |
||
156 | ); |
||
157 | } |
||
158 | |||
159 | 1 | public function getGitHubHookHandler(): HookHandler { |
|
160 | 1 | return new GitHubParserHook( |
|
161 | 1 | new GitHubFetcher( |
|
162 | 1 | $this->newFileFetcher(), |
|
163 | 1 | $this->gitHubUrl, |
|
164 | 1 | $this->repositoryWhitelist |
|
165 | ) |
||
166 | ); |
||
167 | } |
||
168 | |||
169 | 1 | private function newFileFetcher(): FileFetcher { |
|
170 | 1 | return $this->newCachingFileFetcher( |
|
171 | 1 | $this->newLoggingFileFetcher( |
|
172 | 1 | $this->gitHubFetcher === 'mediawiki' ? new MediaWikiFileFetcher() : new SimpleFileFetcher() |
|
173 | ) |
||
174 | ); |
||
175 | } |
||
176 | |||
177 | 1 | private function newLoggingFileFetcher( FileFetcher $fileFetcher ): FileFetcher { |
|
183 | |||
184 | 1 | private function newLogger(): LoggerInterface { |
|
187 | |||
188 | 1 | private function newCachingFileFetcher( FileFetcher $fileFetcher ): FileFetcher { |
|
201 | |||
202 | } |
||
203 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: