108 : array|bool|string {
110 $page_repo =
$DIC->wiki()->internal()->repo()->page();
111
112 $collect = array();
113
114 $wgLegalTitleChars = " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+";
115
116
117 $GLOBALS[
"wgContLang"] =
new class () {
118 public function getNsIndex($a_p): bool
119 {
120 return false;
121 }
122 public function lc($a_key): bool
123 {
124 return false;
125 }
126 };
127 $GLOBALS[
"wgInterWikiCache"] =
false;
128
129 # the % is needed to support urlencoded titles as well
130
131 $tc = $wgLegalTitleChars . '#%';
132
133
134
135 #split the entire text string on occurences of [[
136 $a = explode(
'[[',
' ' . $s);
137 #get the first element (all text up to first [[), and remove the space we added
138 $s = array_shift(
$a);
139 $s = substr($s, 1);
140
141 # Match a link having the form [[namespace:link|alternate]]trail
142 $e1 = "/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD";
143
144 # Match cases where there is no "]]", which might still be images
145
146
147
148 # Match the end of a line for a word that's not followed by whitespace,
149 # e.g. in the case of 'The Arab al[[Razi]]', 'al' will be matched
150
151
152
153
154
155
156
157 $nottalk = true;
158
159
160
161
162
163
164
165
166
167 $prefix = '';
168
169
170 $useSubpages = false;
171
172 # Loop for each link
173 for ($k = 0; isset(
$a[$k]); $k++) {
175
176
177 $might_be_img = false;
178
179
180 if (preg_match($e1, $line, $m)) { # page with normal text or alt
182 # If we get a ] at the beginning of $m[3] that means we have a link that's something like:
183 # [[Image:Foo.jpg|[http:
184 # the real problem is with the $e1 regex
185 # See bug 1300.
186 #
187 # Still some problems for cases where the ] is meant to be outside punctuation,
188 # and no image is in sight. See bug 2095.
189 #
191 strpos($m[3], ']') === 0 &&
192 strpos(
$text,
'[') !== false
193 ) {
194 $text .=
']'; # so that replaceExternalLinks(
$text) works later
195 $m[3] = substr($m[3], 1);
196 }
197 # fix up urlencoded title texts
198 if (strpos($m[1], '%') !== false) {
199 # Should anchors '#' also be rejected?
200 $m[1] = str_replace(array('<', '>'), array('<', '>'), urldecode($m[1]));
201 }
202 $trail = $m[3];
203
204
205
206
207
208
209
210 }
else { # Invalid
form; output directly
211 $s .= $prefix . '[[' . $line ;
212
213 continue;
214 }
215
216
217
218 # Don't allow internal links to pages containing
219 # PROTO: where PROTO is a valid URL protocol; these
220 # should be external links.
221 if (preg_match('/^\b%na' . self::wfUrlProtocols() . 'me/', $m[1])) {
222 $s .= $prefix . '[[' . $line ;
223 continue;
224 }
225
226 # Make subpage if necessary
227
228
229
230 $link = $m[1];
231
232
233 $noforce = (strpos($m[1], ':') !== 0);
234 if (!$noforce) {
235 # Strip off leading ':'
236 $link = substr($link, 1);
237 }
238
239
240
241
243
244 if (!$nt) {
245 $s .= $prefix . '[[' . $line;
246 continue;
247 }
248
249 $wasblank = (
'' ==
$text);
250 if ($wasblank) {
252 }
253
254
257 $nt,
258 $a_wiki_id,
260 '',
261 $trail,
262 $prefix,
263 $a_offline,
264 $lang
265 );
266 }
268 if (is_object($nt)) {
272 $collect[] = array(
"nt" => $nt,
"text" =>
$text,
273 "trail" => $trail, "db_title" => $db_title,
274 "url_title" => $url_title);
275 }
276 } else {
278
279 if (($a_collect_non_ex || $page_repo->existsByTitle($a_wiki_id, $db_title, $lang))
280 &&
281 !in_array($db_title, $collect)) {
282 $collect[] = $db_title;
283 }
284 }
285 }
286
287
288
291 return $collect;
292 } else {
293 return $s;
294 }
295 }
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
const IL_WIKI_MODE_COLLECT
if(!defined('UTF8_REPLACEMENT')) const IL_WIKI_MODE_REPLACE
Wiki link / page title handling:
const IL_WIKI_MODE_EXT_COLLECT
static splitTrail(string $trail)
static makeLink(object $nt, int $a_wiki_id, string $text='', string $query='', string $trail='', string $prefix='', bool $a_offline=false, string $lang="-")
Make a wiki link, the following formats are supported:
form(?array $class_path, string $cmd, string $submit_caption="")
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples