33 if (!defined(
'UTF8_REPLACEMENT')) {
34 define(
'UTF8_REPLACEMENT',
"\xef\xbf\xbd" );
55 bool $a_offline =
false 57 return self::processInternalLinks(
72 bool $a_collect_non_ex =
false,
77 $log->debug(
"collect interna links wiki id: " . $a_wiki_id .
", collect nonex: " . $a_collect_non_ex);
79 $result = self::processInternalLinks(
85 $log->debug(
"content: " . $s);
86 $log->debug(
"found: " . print_r($result,
true));
99 bool $a_collect_non_ex =
false,
100 bool $a_offline =
false 103 include_once(
"./Modules/Wiki/libs/Sanitizer.php");
106 $wgLegalTitleChars =
" %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+";
109 $GLOBALS[
"wgContLang"] =
new class () {
110 public function getNsIndex($a_p):
bool 114 public function lc($a_key):
bool 119 $GLOBALS[
"wgInterWikiCache"] =
false;
121 # the % is needed to support urlencoded titles as well 123 $tc = $wgLegalTitleChars .
'#%';
127 #split the entire text string on occurences of [[ 128 $a = explode(
'[[',
' ' . $s);
129 #get the first element (all text up to first [[), and remove the space we added 130 $s = array_shift(
$a);
133 # Match a link having the form [[namespace:link|alternate]]trail 134 $e1 =
"/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD";
136 # Match cases where there is no "]]", which might still be images 140 # Match the end of a line for a word that's not followed by whitespace, 141 # e.g. in the case of 'The Arab al[[Razi]]', 'al' will be matched 162 $useSubpages =
false;
165 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 strpos($m[3],
']') === 0 &&
184 strpos($text,
'[') !== false
186 $text .=
']'; # so that replaceExternalLinks($text) works later
187 $m[3] = substr($m[3], 1);
189 # fix up urlencoded title texts 190 if (strpos($m[1],
'%') !==
false) {
191 # Should anchors '#' also be rejected? 192 $m[1] = str_replace(array(
'<',
'>'), array(
'<',
'>'), urldecode($m[1]));
202 }
else { # Invalid
form; output directly
203 $s .= $prefix .
'[[' . $line ;
210 # Don't allow internal links to pages containing 211 # PROTO: where PROTO is a valid URL protocol; these 212 # should be external links. 213 if (preg_match(
'/^\b%na' . self::wfUrlProtocols() .
'me/', $m[1])) {
214 $s .= $prefix .
'[[' . $line ;
218 # Make subpage if necessary 225 $noforce = (strpos($m[1],
':') !== 0);
227 # Strip off leading ':' 228 $link = substr($link, 1);
237 $s .= $prefix .
'[[' . $line;
241 $wasblank = (
'' == $text);
248 $s .= self::makeLink(
259 if (is_object($nt)) {
260 $url_title = self::makeUrlTitle($nt->mTextform);
261 $db_title = self::makeDbTitle($nt->mTextform);
262 [$inside, $trail] = self::splitTrail($trail);
263 $collect[] = array(
"nt" => $nt,
"text" => $text,
264 "trail" => $trail,
"db_title" => $db_title,
265 "url_title" => $url_title);
268 $db_title = self::makeDbTitle($nt->mTextform);
272 !in_array($db_title, $collect)) {
273 $collect[] = $db_title;
291 return str_replace(array(
"\x00",
"\n",
"\r",
"\\",
"'",
'"',
"\x1a"),
"", $a_str);
310 bool $a_offline =
false 321 $ilCtrl = $DIC->ctrl();
323 if (!is_object($nt)) {
325 $retVal =
"<!-- ERROR -->{$prefix}{$text}{$trail}";
330 if ($nt->mFragment !=
"") {
331 if (substr($text, strlen($text) - strlen(
"#" . $nt->mFragment)) ===
"#" . $nt->mFragment) {
332 $text = substr($text, 0, strlen($text) - strlen(
"#" . $nt->mFragment));
334 $anc =
"#copganc_" . $nt->mFragment;
337 # Separate the link trail from the rest of the link 341 $retVal =
'***' . $text .
"***" . $trail;
342 $url_title = self::makeUrlTitle($nt->mTextform);
343 $db_title = self::makeDbTitle($nt->mTextform);
344 if ($db_title !=
"") {
354 $wiki_link_class = (!$pg_exists)
355 ?
' class="ilc_link_IntLink ilWikiPageMissing" ' 356 :
' class="ilc_link_IntLink" ';
359 if ($url_title !=
"") {
360 $ilCtrl->setParameterByClass(
"ilobjwikigui",
"page", $url_title);
361 $retVal =
'<a ' . $wiki_link_class .
' href="' .
362 $ilCtrl->getLinkTargetByClass(
"ilobjwikigui",
"gotoPage") . $anc .
363 '">' . $text .
'</a>' . $trail;
364 $ilCtrl->setParameterByClass(
370 $retVal =
'<a ' . $wiki_link_class .
' href="' .
372 '">' . $text .
'</a>' . $trail;
376 if ($db_title !=
"") {
378 $retVal =
'<a ' . $wiki_link_class .
' href="' .
379 "wpg_" . $pg_id .
".html" . $anc .
380 '">' . $text .
'</a>' . $trail;
382 $retVal =
'<a ' . $wiki_link_class .
' href="' .
384 '">' . $text .
'</a>' . $trail;
387 $retVal = $text . $trail;
400 $wgUrlProtocols = array(
415 $protocols = array();
416 foreach ($wgUrlProtocols as $protocol) {
417 $protocols[] = preg_quote($protocol,
'/');
420 return implode(
'|', $protocols);
433 $a_par = self::removeUnsafeCharacters($a_par);
434 return str_replace(
"_",
" ", $a_par);
440 $a_par = self::removeUnsafeCharacters($a_par);
441 $a_par = str_replace(
" ",
"_", $a_par);
442 return self::wfUrlencode($a_par);
448 $regex =
'/^([a-z]+)(.*)$/sD';
454 if (preg_match($regex, $trail, $m)) {
460 return array( $inside, $trail );
468 ?
string $a_comment = null
473 $log->debug(
"start... vvvvvvvvvvvvvvvvvvvvvvvvvvv");
476 $ilObjDataCache = $DIC[
"ilObjDataCache"];
477 $ilAccess = $DIC->access();
479 if ($a_wiki_ref_id === 0) {
483 $wiki_id = $ilObjDataCache->lookupObjId($a_wiki_ref_id);
484 $wiki =
new ilObjWiki($a_wiki_ref_id,
true);
488 $ignore_threshold = ($a_action ===
"comment");
491 if ($a_action ===
"new") {
495 $log->debug(
"-- get notifications");
499 $users = array_merge($users, $wiki_users);
500 if (!count($users)) {
501 $log->debug(
"no notifications... ^^^^^^^^^^^^^^^^^^");
506 $log->debug(
"--->" . print_r($users));
507 if (!count($users)) {
508 $log->debug(
"no notifications... ^^^^^^^^^^^^^^^^^^");
518 $link =
ilLink::_getLink(null,
"wiki", [],
"wpage_" . $a_page_id .
"_" . $a_wiki_ref_id);
523 $log->debug(
"-- prepare content");
526 $pgui->setAbstractOnly(
true);
527 $pgui->setFileDownloadLink(
".");
528 $pgui->setFullscreenLink(
".");
529 $pgui->setSourcecodeDownloadScript(
".");
530 $snippet = $pgui->showPage();
534 $snippet = str_replace([
'<br/>',
'<br />',
'</p>',
'</div>'],
"\n", $snippet);
536 $snippet = trim(strip_tags($snippet));
539 $hist = $page->getHistoryEntries();
540 $current_version = array_shift($hist);
541 $current_version = $current_version[
"nr"] ?? 0;
542 if (!$current_version && $a_action !==
"comment") {
547 $log->debug(
"-- sending mails");
549 foreach (array_unique($users) as $idx => $user_id) {
550 if ($user_id !=
$ilUser->getId() &&
551 $ilAccess->checkAccessOfUser($user_id,
'read',
'', $a_wiki_ref_id)) {
554 $ulng->loadLanguageModule(
'wiki');
556 if ($a_action ===
"comment") {
557 $subject = sprintf($ulng->txt(
'wiki_notification_comment_subject'), $wiki->getTitle(), $page->getTitle());
560 $message .= $ulng->txt(
'wiki_notification_' . $a_action) .
":\n\n";
561 $message .= $ulng->txt(
'wiki') .
": " . $wiki->getTitle() .
"\n";
562 $message .= $ulng->txt(
'page') .
": " . $page->getTitle() .
"\n";
567 $message .=
"\n" . $ulng->txt(
'comment') .
":\n\"" . trim($a_comment) .
"\"\n";
570 $message .=
"\n" . $ulng->txt(
'wiki_change_notification_page_link') .
": " . $link;
572 $subject = sprintf($ulng->txt(
'wiki_change_notification_subject'), $wiki->getTitle(), $page->getTitle());
577 $message .= $ulng->txt(
'wiki_change_notification_page_body_' . $a_action) .
":\n\n";
578 $message .= $ulng->txt(
'wiki') .
": " . $wiki->getTitle() .
"\n";
579 $message .= $ulng->txt(
'page') .
": " . $page->getTitle() .
"\n";
583 $message .=
"\n" . $ulng->txt(
'content') .
"\n" .
584 "----------------------------------------\n" .
586 "----------------------------------------\n";
591 $message .=
"\n" . $ulng->txt(
'comment') .
":\n\"" . trim($a_comment) .
"\"\n";
594 $message .=
"\n" . $ulng->txt(
'wiki_change_notification_page_link') .
": " . $link;
597 $message .= $ulng->txt(
'wiki_change_notification_body_' . $a_action) .
":\n\n";
598 $message .= $ulng->txt(
'wiki') .
": " . $wiki->getTitle() .
"\n";
599 $message .= $ulng->txt(
'page') .
": " . $page->getTitle() .
"\n";
603 $message .= $ulng->txt(
'content') .
"\n" .
604 "----------------------------------------\n" .
606 "----------------------------------------\n\n";
609 $message .= $ulng->txt(
'wiki_change_notification_link') .
": " . $link;
614 $mail_obj->appendInstallationSignature(
true);
615 $log->debug(
"before enqueue ($user_id)");
637 $log->debug(
"after enqueue");
642 if (count($mails) > 0) {
651 $log->debug(
"end... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
static makeLink(object $nt, int $a_wiki_id, string $text='', string $query='', string $trail='', string $prefix='', bool $a_offline=false)
Make a wiki link, the following formats are supported:
static getLogger(string $a_component_id)
Get component logger.
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link="", bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static _lookupFullname(int $a_user_id)
static processInternalLinks(string $s, int $a_wiki_id, string $a_mode=IL_WIKI_MODE_REPLACE, bool $a_collect_non_ex=false, bool $a_offline=false)
Process internal links (internal)
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
if(!defined('UTF8_REPLACEMENT')) const IL_WIKI_MODE_REPLACE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static removeUnsafeCharacters(string $a_str)
static getNotificationsForObject(int $type, int $id, ?int $page_id=null, bool $ignore_threshold=false)
Get all users/recipients for given object.
const IL_WIKI_MODE_COLLECT
static sendNotification(string $a_action, int $a_type, int $a_wiki_ref_id, int $a_page_id, ?string $a_comment=null)
static getPageIdForTitle(int $a_wiki_id, string $a_title)
Get wiki page object for id and title.
static truncateHTML(string $a_text, int $a_length=100, string $a_ending='...', bool $a_exact=false, bool $a_consider_html=true)
Truncate (html) string.
static _getLanguageOfUser(int $a_usr_id)
Get language object of user.
setRawPageContent(bool $a_rawpagecontent)
Set Get raw page content only.
static collectInternalLinks(string $s, int $a_wiki_id, bool $a_collect_non_ex=false, string $mode=IL_WIKI_MODE_COLLECT)
Collect internal wiki links of a string.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static replaceInternalLinks(string $s, int $a_wiki_id, bool $a_offline=false)
This one is based on Mediawiki Parser->replaceInternalLinks since we display images in another way...
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getLink(?int $a_ref_id, string $a_type='', array $a_params=array(), string $append="")
form( $class_path, string $cmd)
static updateNotificationTime(int $type, int $id, array $user_ids, ?int $page_id=null, bool $activate_new_entries=true)
Update the last mail timestamp for given object and users.
static makeUrlTitle(string $a_par)
static wfUrlProtocols()
From mediawiki GlobalFunctions.php.
static makeDbTitle(string $a_par)
const IL_WIKI_MODE_EXT_COLLECT
static _wikiPageExists(int $a_wiki_id, string $a_title)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
static wfUrlencode(string $s)
static splitTrail(string $trail)
static _getInstallationSignature()
static _lookupLogin(int $a_user_id)