38 define (
"IL_WIKI_MODE_REPLACE",
"replace");
39 define (
"IL_WIKI_MODE_COLLECT",
"collect");
90 $wgLegalTitleChars =
" %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+";
93 include_once(
"./Modules/Wiki/classes/class.ilMediaWikiAdapter.php");
95 $GLOBALS[
"wgInterWikiCache"] =
false;
97 # the % is needed to support urlencoded titles as well
99 $tc = $wgLegalTitleChars.
'#%';
103 #split the entire text string on occurences of [[
104 $a = explode(
'[[',
' ' . $s );
105 #get the first element (all text up to first [[), and remove the space we added
106 $s = array_shift( $a );
107 $s = substr( $s, 1 );
109 # Match a link having the form [[namespace:link|alternate]]trail
110 $e1 =
"/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD";
112 # Match cases where there is no "]]", which might still be images
116 # Match the end of a line for a word that's not followed by whitespace,
117 # e.g. in the case of 'The Arab al[[Razi]]', 'al' will be matched
146 $useSubpages =
false;
149 for ($k = 0; isset( $a[$k] ); $k++)
169 $might_be_img =
false;
172 if ( preg_match( $e1, $line, $m ) ) { # page with normal text or alt
174 # If we get a ] at the beginning of $m[3] that means we have a link that's something like:
175 # [[Image:Foo.jpg|[http://example.com desc]]] <- having three ] in a row fucks up,
176 # the real problem is with the $e1 regex
179 # Still some problems for cases where the ] is meant to be outside punctuation,
180 # and no image is in sight. See bug 2095.
183 substr( $m[3], 0, 1 ) ===
']' &&
184 strpos($text,
'[') !== false
187 $text .=
']'; # so that replaceExternalLinks($text) works later
188 $m[3] = substr( $m[3], 1 );
190 # fix up urlencoded title texts
191 if( strpos( $m[1],
'%' ) !==
false ) {
192 # Should anchors '#' also be rejected?
193 $m[1] = str_replace( array(
'<',
'>'), array(
'<',
'>'), urldecode($m[1]) );
203 }
else { # Invalid form; output directly
204 $s .= $prefix .
'[[' . $line ;
211 # Don't allow internal links to pages containing
212 # PROTO: where PROTO is a valid URL protocol; these
213 # should be external links.
215 $s .= $prefix .
'[[' . $line ;
219 # Make subpage if necessary
226 $noforce = (substr($m[1], 0, 1) !=
':');
228 # Strip off leading ':'
229 $link = substr($link, 1);
236 include_once(
"./Modules/Wiki/mediawiki/Title.php");
237 include_once(
"./Services/Utilities/classes/Sanitizer.php");
245 $s .= $prefix .
'[[' . $line;
297 $wasblank = (
'' == $text );
298 if( $wasblank ) $text = $link;
300 # Link not escaped by : , create the various objects
369 # Special and Media are pseudo-namespaces; no pages actually exist in them
403 include_once(
"./Modules/Wiki/classes/class.ilWikiPage.php");
407 !in_array($db_title, $collect))
409 $collect[] = $db_title;
431 return str_replace(array(
"\x00",
"\n",
"\r",
"\\",
"'",
'"',
"\x1a"),
"", $a_str);
437 static function makeLink( &$nt, $a_wiki_id, $text =
'', $query =
'', $trail =
'', $prefix =
'' )
442 if ( ! is_object($nt) ) {
444 $retVal =
"<!-- ERROR -->{$prefix}{$text}{$trail}";
449 # Separate the link trail from the rest of the link
456 ?
' class="ilWikiPageMissing" ' :
"";
458 $ilCtrl->setParameterByClass(
"ilobjwikigui",
"page", $url_title);
459 $retVal =
'<a '.$wiki_link_class.
' href="'.
460 $ilCtrl->getLinkTargetByClass(
"ilobjwikigui",
"gotoPage").
461 '">'.$text.
'</a>'.$trail;
488 $wgUrlProtocols = array(
503 if ( is_array( $wgUrlProtocols ) ) {
504 $protocols = array();
505 foreach ($wgUrlProtocols as $protocol)
506 $protocols[] = preg_quote( $protocol,
'/' );
508 return implode(
'|', $protocols );
510 return $wgUrlProtocols;
519 $s = urlencode( $s );
533 return str_replace(
"_",
" ", $a_par);
542 $a_par = str_replace(
" ",
"_", $a_par);
554 $regex =
'/^([a-z]+)(.*)$/sD';
557 if (
'' != $trail ) {
560 if ( preg_match( $regex, $trail, $m ) ) {
566 return array( $inside, $trail );