33 if (!defined(
'UTF8_REPLACEMENT')) {
34 define(
'UTF8_REPLACEMENT',
"\xef\xbf\xbd" );
55 bool $a_offline =
false,
58 return self::processInternalLinks(
74 bool $a_collect_non_ex =
false,
79 $log->debug(
"collect interna links wiki id: " . $a_wiki_id .
", collect nonex: " . $a_collect_non_ex);
81 $result = self::processInternalLinks(
87 $log->debug(
"content: " . $s);
88 $log->debug(
"found: " . print_r($result,
true));
101 bool $a_collect_non_ex =
false,
102 bool $a_offline =
false,
106 $page_repo = $DIC->wiki()->internal()->repo()->page();
108 include_once(
"./Modules/Wiki/libs/Sanitizer.php");
111 $wgLegalTitleChars =
" %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+";
114 $GLOBALS[
"wgContLang"] =
new class () {
115 public function getNsIndex($a_p):
bool 119 public function lc($a_key):
bool 124 $GLOBALS[
"wgInterWikiCache"] =
false;
126 # the % is needed to support urlencoded titles as well 128 $tc = $wgLegalTitleChars .
'#%';
132 #split the entire text string on occurences of [[ 133 $a = explode(
'[[',
' ' . $s);
134 #get the first element (all text up to first [[), and remove the space we added 135 $s = array_shift(
$a);
138 # Match a link having the form [[namespace:link|alternate]]trail 139 $e1 =
"/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD";
141 # Match cases where there is no "]]", which might still be images 145 # Match the end of a line for a word that's not followed by whitespace, 146 # e.g. in the case of 'The Arab al[[Razi]]', 'al' will be matched 167 $useSubpages =
false;
170 for ($k = 0; isset(
$a[$k]); $k++) {
174 $might_be_img =
false;
177 if (preg_match($e1, $line, $m)) { # page with normal text or alt
179 # If we get a ] at the beginning of $m[3] that means we have a link that's something like: 180 # [[Image:Foo.jpg|[http://example.com desc]]] <- having three ] in a row fucks up, 181 # the real problem is with the $e1 regex 184 # Still some problems for cases where the ] is meant to be outside punctuation, 185 # and no image is in sight. See bug 2095. 188 strpos($m[3],
']') === 0 &&
189 strpos($text,
'[') !== false
191 $text .=
']'; # so that replaceExternalLinks($text) works later
192 $m[3] = substr($m[3], 1);
194 # fix up urlencoded title texts 195 if (strpos($m[1],
'%') !==
false) {
196 # Should anchors '#' also be rejected? 197 $m[1] = str_replace(array(
'<',
'>'), array(
'<',
'>'), urldecode($m[1]));
207 }
else { # Invalid
form; output directly
208 $s .= $prefix .
'[[' . $line ;
215 # Don't allow internal links to pages containing 216 # PROTO: where PROTO is a valid URL protocol; these 217 # should be external links. 218 if (preg_match(
'/^\b%na' . self::wfUrlProtocols() .
'me/', $m[1])) {
219 $s .= $prefix .
'[[' . $line ;
223 # Make subpage if necessary 230 $noforce = (strpos($m[1],
':') !== 0);
232 # Strip off leading ':' 233 $link = substr($link, 1);
242 $s .= $prefix .
'[[' . $line;
246 $wasblank = (
'' == $text);
253 $s .= self::makeLink(
265 if (is_object($nt)) {
266 $url_title = self::makeUrlTitle($nt->mTextform);
267 $db_title = self::makeDbTitle($nt->mTextform);
268 [$inside, $trail] = self::splitTrail($trail);
269 $collect[] = array(
"nt" => $nt,
"text" => $text,
270 "trail" => $trail,
"db_title" => $db_title,
271 "url_title" => $url_title);
274 $db_title = self::makeDbTitle($nt->mTextform);
276 if (($a_collect_non_ex || $page_repo->existsByTitle($a_wiki_id, $db_title,
$lang))
278 !in_array($db_title, $collect)) {
279 $collect[] = $db_title;
297 return str_replace(array(
"\x00",
"\n",
"\r",
"\\",
"'",
'"',
"\x1a"),
"", $a_str);
316 bool $a_offline =
false,
325 $page_repo = $DIC->wiki()->internal()->repo()->page();
327 $ilCtrl = $DIC->ctrl();
329 if (!is_object($nt)) {
331 $retVal =
"<!-- ERROR -->{$prefix}{$text}{$trail}";
335 if ($nt->mFragment !=
"") {
336 if (substr($text, strlen($text) - strlen(
"#" . $nt->mFragment)) ===
"#" . $nt->mFragment) {
337 $text = substr($text, 0, strlen($text) - strlen(
"#" . $nt->mFragment));
339 $anc =
"#copganc_" . $nt->mFragment;
342 # Separate the link trail from the rest of the link 346 $retVal =
'***' . $text .
"***" . $trail;
347 $url_title = self::makeUrlTitle($nt->mTextform);
348 $db_title = self::makeDbTitle($nt->mTextform);
349 if ($db_title !=
"") {
350 $pg_exists = $page_repo->existsByTitle($a_wiki_id, $db_title,
$lang);
359 $wiki_link_class = (!$pg_exists)
360 ?
' class="ilc_link_IntLink ilWikiPageMissing" ' 361 :
' class="ilc_link_IntLink" ';
364 if ($url_title !=
"") {
365 $ilCtrl->setParameterByClass(
"ilobjwikigui",
"wpg_id", null);
366 $ilCtrl->setParameterByClass(
"ilwikipagegui",
"wpg_id", null);
367 $ilCtrl->setParameterByClass(
"ilobjwikigui",
"page", $url_title);
368 $retVal =
'<a ' . $wiki_link_class .
' href="' .
369 $ilCtrl->getLinkTargetByClass(
"ilobjwikigui",
"gotoPage") . $anc .
370 '">' . $text .
'</a>' . $trail;
371 $ilCtrl->setParameterByClass(
377 $retVal =
'<a ' . $wiki_link_class .
' href="' .
379 '">' . $text .
'</a>' . $trail;
383 if ($db_title !=
"") {
385 $retVal =
'<a ' . $wiki_link_class .
' href="' .
386 "wpg_" . $pg_id .
".html" . $anc .
387 '">' . $text .
'</a>' . $trail;
389 $retVal =
'<a ' . $wiki_link_class .
' href="' .
391 '">' . $text .
'</a>' . $trail;
394 $retVal = $text . $trail;
407 $wgUrlProtocols = array(
422 $protocols = array();
423 foreach ($wgUrlProtocols as $protocol) {
424 $protocols[] = preg_quote($protocol,
'/');
427 return implode(
'|', $protocols);
440 $a_par = self::removeUnsafeCharacters($a_par);
441 return str_replace(
"_",
" ", $a_par);
447 $a_par = self::removeUnsafeCharacters($a_par);
448 $a_par = str_replace(
" ",
"_", $a_par);
449 return self::wfUrlencode($a_par);
455 $regex =
'/^([a-z]+)(.*)$/sD';
461 if (preg_match($regex, $trail, $m)) {
467 return array( $inside, $trail );
475 ?
string $a_comment = null
480 $log->debug(
"start... vvvvvvvvvvvvvvvvvvvvvvvvvvv");
482 $ilUser = $DIC->user();
483 $ilObjDataCache = $DIC[
"ilObjDataCache"];
484 $ilAccess = $DIC->access();
486 if ($a_wiki_ref_id === 0) {
490 $wiki_id = $ilObjDataCache->lookupObjId($a_wiki_ref_id);
491 $wiki =
new ilObjWiki($a_wiki_ref_id,
true);
495 $ignore_threshold = ($a_action ===
"comment");
498 if ($a_action ===
"new") {
502 $log->debug(
"-- get notifications");
506 $users = array_merge($users, $wiki_users);
507 if (!count($users)) {
508 $log->debug(
"no notifications... ^^^^^^^^^^^^^^^^^^");
513 $log->debug(
"--->" . print_r($users));
514 if (!count($users)) {
515 $log->debug(
"no notifications... ^^^^^^^^^^^^^^^^^^");
525 $link = ilLink::_getLink(null,
"wiki", [],
"wpage_" . $a_page_id .
"_" . $a_wiki_ref_id);
527 $link = ilLink::_getLink($a_wiki_ref_id);
530 $log->debug(
"-- prepare content");
533 $pgui->setAbstractOnly(
true);
534 $pgui->setFileDownloadLink(
".");
535 $pgui->setFullscreenLink(
".");
536 $pgui->setSourcecodeDownloadScript(
".");
537 $snippet = $pgui->showPage();
541 $snippet = str_replace([
'<br/>',
'<br />',
'</p>',
'</div>'],
"\n", $snippet);
543 $snippet = trim(strip_tags($snippet));
546 $hist = $page->getHistoryEntries();
547 $current_version = array_shift($hist);
548 $current_version = $current_version[
"nr"] ?? 0;
549 if (!$current_version && $a_action !==
"comment") {
554 $log->debug(
"-- sending mails");
556 foreach (array_unique($users) as $idx => $user_id) {
557 if ($user_id != $ilUser->getId() &&
558 $ilAccess->checkAccessOfUser($user_id,
'read',
'', $a_wiki_ref_id)) {
561 $ulng->loadLanguageModule(
'wiki');
563 if ($a_action ===
"comment") {
564 $subject = sprintf($ulng->txt(
'wiki_notification_comment_subject'), $wiki->getTitle(), $page->getTitle());
567 $message .= $ulng->txt(
'wiki_notification_' . $a_action) .
":\n\n";
568 $message .= $ulng->txt(
'wiki') .
": " . $wiki->getTitle() .
"\n";
569 $message .= $ulng->txt(
'page') .
": " . $page->getTitle() .
"\n";
574 $message .=
"\n" . $ulng->txt(
'comment') .
":\n\"" . trim($a_comment) .
"\"\n";
577 $message .=
"\n" . $ulng->txt(
'wiki_change_notification_page_link') .
": " . $link;
579 $subject = sprintf($ulng->txt(
'wiki_change_notification_subject'), $wiki->getTitle(), $page->getTitle());
584 $message .= $ulng->txt(
'wiki_change_notification_page_body_' . $a_action) .
":\n\n";
585 $message .= $ulng->txt(
'wiki') .
": " . $wiki->getTitle() .
"\n";
586 $message .= $ulng->txt(
'page') .
": " . $page->getTitle() .
"\n";
590 $message .=
"\n" . $ulng->txt(
'content') .
"\n" .
591 "----------------------------------------\n" .
593 "----------------------------------------\n";
598 $message .=
"\n" . $ulng->txt(
'comment') .
":\n\"" . trim($a_comment) .
"\"\n";
601 $message .=
"\n" . $ulng->txt(
'wiki_change_notification_page_link') .
": " . $link;
604 $message .= $ulng->txt(
'wiki_change_notification_body_' . $a_action) .
":\n\n";
605 $message .= $ulng->txt(
'wiki') .
": " . $wiki->getTitle() .
"\n";
606 $message .= $ulng->txt(
'page') .
": " . $page->getTitle() .
"\n";
610 $message .= $ulng->txt(
'content') .
"\n" .
611 "----------------------------------------\n" .
613 "----------------------------------------\n\n";
616 $message .= $ulng->txt(
'wiki_change_notification_link') .
": " . $link;
621 $mail_obj->appendInstallationSignature(
true);
622 $log->debug(
"before enqueue ($user_id)");
644 $log->debug(
"after enqueue");
649 if (count($mails) > 0) {
658 $log->debug(
"end... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
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:
static getLogger(string $a_component_id)
Get component logger.
static _lookupFullname(int $a_user_id)
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 processInternalLinks(string $s, int $a_wiki_id, string $a_mode=IL_WIKI_MODE_REPLACE, bool $a_collect_non_ex=false, bool $a_offline=false, string $lang="-")
Process internal links (internal)
static getNotificationsForObject(int $type, int $id, ?int $page_id=null, bool $ignore_threshold=false)
Get all users/recipients for given object.
static replaceInternalLinks(string $s, int $a_wiki_id, bool $a_offline=false, string $lang="-")
This one is based on Mediawiki Parser->replaceInternalLinks since we display images in another way...
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 truncateHTML(string $a_text, int $a_length=100, string $a_ending='...', bool $a_exact=false, bool $a_consider_html=true)
Truncate (html) string.
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 _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...
Class ilWikiPage GUI class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
form( $class_path, string $cmd, string $submit_caption="")
static wfUrlProtocols()
From mediawiki GlobalFunctions.php.
static makeDbTitle(string $a_par)
static getPageIdForTitle(int $a_wiki_id, string $a_title, string $lang="-")
Get wiki page object for id and title.
const IL_WIKI_MODE_EXT_COLLECT
$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)