18define(
"IL_WIKI_MODE_REPLACE", 
"replace");
 
   19define(
"IL_WIKI_MODE_COLLECT", 
"collect");
 
   20define(
"IL_WIKI_MODE_EXT_COLLECT", 
"ext_collect");
 
   82        $a_collect_non_ex = 
false,
 
   87        $wgLegalTitleChars = 
" %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+";
 
   90        include_once(
"./Modules/Wiki/classes/class.ilMediaWikiAdapter.php");
 
   92        $GLOBALS[
"wgInterWikiCache"] = 
false;
 
   94        # the % is needed to support urlencoded titles as well 
   96        $tc = $wgLegalTitleChars . 
'#%';
 
  100        #split the entire text string on occurences of [[ 
  101        $a = explode(
'[[', 
' ' . $s);
 
  102        #get the first element (all text up to first [[), and remove the space we added 
  103        $s = array_shift(
$a);
 
  106        # Match a link having the form [[namespace:link|alternate]]trail 
  107        $e1 = 
"/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD";
 
  109        # Match cases where there is no "]]", which might still be images
 
  113        # Match the end of a line for a word that's not followed by whitespace, 
  114        # e.g. in the case of 'The Arab al[[Razi]]', 'al' will be matched 
  135        $useSubpages = 
false;
 
  138        for ($k = 0; isset(
$a[$k]); $k++) {
 
  142            $might_be_img = 
false;
 
  145            if (preg_match($e1, $line, $m)) { # page with normal text or alt
 
  147                # If we get a ] at the beginning of $m[3] that means we have a link that's something like: 
  148                # [[Image:Foo.jpg|[http: 
  149                # the real problem is with the $e1 regex 
  152                # Still some problems for cases where the ] is meant to be outside punctuation, 
  153                # and no image is in sight. See bug 2095. 
  156                    substr($m[3], 0, 1) === 
']' &&
 
  157                    strpos($text, 
'[') !== false
 
  159                    $text .= 
']'; # so that replaceExternalLinks($text) works later
 
  160                    $m[3] = substr($m[3], 1);
 
  162                # fix up urlencoded title texts 
  163                if (strpos($m[1], 
'%') !== 
false) {
 
  164                    # Should anchors '#' also be rejected? 
  165                    $m[1] = str_replace(array(
'<', 
'>'), array(
'<', 
'>'), urldecode($m[1]));
 
  175            } 
else { # Invalid form; output directly
 
  176                $s .= $prefix . 
'[[' . $line ;
 
  183            # Don't allow internal links to pages containing 
  184            # PROTO: where PROTO is a valid URL protocol; these 
  185            # should be external links. 
  187                $s .= $prefix . 
'[[' . $line ;
 
  191            # Make subpage if necessary 
  198            $noforce = (substr($m[1], 0, 1) != 
':');
 
  200                # Strip off leading ':' 
  201                $link = substr($link, 1);
 
  208            include_once(
"./Modules/Wiki/mediawiki/Title.php");
 
  209            include_once(
"./Services/Utilities/classes/Sanitizer.php");
 
  217                $s .= $prefix . 
'[[' . $line;
 
  269            $wasblank = (
'' == $text);
 
  274            # Link not escaped by : , create the various objects 
  343            # Special and Media are pseudo-namespaces; no pages actually exist in them 
  379                if (is_object($nt)) {
 
  383                    $collect[] = array(
"nt" => $nt, 
"text" => $text,
 
  384                        "trail" => $trail, 
"db_title" => $db_title,
 
  385                        "url_title" => $url_title);
 
  392                include_once(
"./Modules/Wiki/classes/class.ilWikiPage.php");
 
  395                    !in_array($db_title, $collect)) {
 
  396                    $collect[] = $db_title;
 
  416        return str_replace(array(
"\x00", 
"\n", 
"\r", 
"\\", 
"'", 
'"', 
"\x1a"), 
"", $a_str);
 
  439        $ilCtrl = 
$DIC->ctrl();
 
  442        if (!is_object($nt)) {
 
  444            $retVal = 
"<!-- ERROR -->{$prefix}{$text}{$trail}";
 
  452            if ($nt->mFragment != 
"") {
 
  453                if (substr($text, strlen($text) - strlen(
"#" . $nt->mFragment))
 
  454                    == 
"#" . $nt->mFragment) {
 
  455                    $text = substr($text, 0, strlen($text) - strlen(
"#" . $nt->mFragment));
 
  456                    $anc = 
"#" . $nt->mFragment;
 
  458                    $anc = 
"#" . $nt->mFragment;
 
  462            # Separate the link trail from the rest of the link 
  466            $retVal = 
'***' . $text . 
"***" . $trail;
 
  469            if ($db_title != 
"") {
 
  479            $wiki_link_class = (!$pg_exists)
 
  480                ? 
' class="ilc_link_IntLink ilWikiPageMissing" ' 
  481                : 
' class="ilc_link_IntLink" ';
 
  484                if ($url_title != 
"") {
 
  485                    $ilCtrl->setParameterByClass(
"ilobjwikigui", 
"page", $url_title);
 
  486                    $retVal = 
'<a ' . $wiki_link_class . 
' href="' .
 
  487                        $ilCtrl->getLinkTargetByClass(
"ilobjwikigui", 
"gotoPage") . $anc .
 
  488                        '">' . $text . 
'</a>' . $trail;
 
  489                    $ilCtrl->setParameterByClass(
"ilobjwikigui", 
"page", 
$_GET[
"page"]);
 
  491                    $retVal = 
'<a ' . $wiki_link_class . 
' href="' .
 
  493                        '">' . $text . 
'</a>' . $trail;
 
  497                    if ($db_title != 
"") {
 
  499                        $retVal = 
'<a ' . $wiki_link_class . 
' href="' .
 
  500                            "wpg_" . $pg_id . 
".html" . $anc .
 
  501                            '">' . $text . 
'</a>' . $trail;
 
  503                        $retVal = 
'<a ' . $wiki_link_class . 
' href="' .
 
  505                            '">' . $text . 
'</a>' . $trail;
 
  508                    $retVal = $text . $trail;
 
  537        $wgUrlProtocols = array(
 
  552        if (is_array($wgUrlProtocols)) {
 
  553            $protocols = array();
 
  554            foreach ($wgUrlProtocols as $protocol) {
 
  555                $protocols[] = preg_quote($protocol, 
'/');
 
  558            return implode(
'|', $protocols);
 
  560            return $wgUrlProtocols;
 
  583        return str_replace(
"_", 
" ", $a_par);
 
  592        $a_par = str_replace(
" ", 
"_", $a_par);
 
  599        $regex = 
'/^([a-z]+)(.*)$/sD';
 
  605            if (preg_match($regex, $trail, $m)) {
 
  611        return array( $inside, $trail );
 
  614    public static function sendNotification($a_action, $a_type, $a_wiki_ref_id, $a_page_id, $a_comment = 
null)
 
  619        $log->debug(
"start... vvvvvvvvvvvvvvvvvvvvvvvvvvv");
 
  622        $ilObjDataCache = 
$DIC[
"ilObjDataCache"];
 
  623        $ilAccess = 
$DIC->access();
 
  625        if ((
int) $a_wiki_ref_id === 0) {
 
  629        include_once 
"./Services/Notification/classes/class.ilNotification.php";
 
  630        include_once 
"./Modules/Wiki/classes/class.ilObjWiki.php";
 
  631        include_once 
"./Modules/Wiki/classes/class.ilWikiPage.php";
 
  633        $wiki_id = $ilObjDataCache->lookupObjId($a_wiki_ref_id);
 
  634        $wiki = 
new ilObjWiki($a_wiki_ref_id, 
true);
 
  638        $ignore_threshold = ($a_action == 
"comment");
 
  641        if ($a_action == 
"new") {
 
  645        $log->debug(
"-- get notifications");
 
  649            $users = array_merge($users, $wiki_users);
 
  650            if (!
sizeof($users)) {
 
  651                $log->debug(
"no notifications... ^^^^^^^^^^^^^^^^^^");
 
  657            if (!
sizeof($users)) {
 
  658                $log->debug(
"no notifications... ^^^^^^^^^^^^^^^^^^");
 
  666        include_once 
"./Services/Link/classes/class.ilLink.php";
 
  669            $link = 
ilLink::_getLink(
"", 
"wiki", 
null, 
"wpage_" . $a_page_id . 
"_" . $a_wiki_ref_id);
 
  674        include_once 
"./Services/Mail/classes/class.ilMail.php";
 
  675        include_once 
"./Services/User/classes/class.ilObjUser.php";
 
  676        include_once 
"./Services/Language/classes/class.ilLanguageFactory.php";
 
  677        include_once(
"./Services/User/classes/class.ilUserUtil.php");
 
  683        $log->debug(
"-- prepare content");
 
  684        include_once 
"Modules/Wiki/classes/class.ilWikiPageGUI.php";
 
  686        $pgui->setRawPageContent(
true);
 
  687        $pgui->setAbstractOnly(
true);
 
  688        $pgui->setFileDownloadLink(
".");
 
  689        $pgui->setFullscreenLink(
".");
 
  690        $pgui->setSourcecodeDownloadScript(
".");
 
  691        $snippet = $pgui->showPage();
 
  695        $snippet = str_replace(
'<br/>', 
"\n", $snippet);
 
  696        $snippet = str_replace(
'<br />', 
"\n", $snippet);
 
  697        $snippet = str_replace(
'</p>', 
"\n", $snippet);
 
  698        $snippet = str_replace(
'</div>', 
"\n", $snippet);
 
  700        $snippet = trim(strip_tags($snippet));
 
  703        $current_version = array_shift($page->getHistoryEntries());
 
  704        $current_version = $current_version[
"nr"];
 
  705        if (!$current_version && $a_action != 
"comment") {
 
  710        $log->debug(
"-- sending mails");
 
  712        foreach (array_unique($users) as $idx => $user_id) {
 
  713            if ($user_id != 
$ilUser->getId() &&
 
  714                $ilAccess->checkAccessOfUser($user_id, 
'read', 
'', $a_wiki_ref_id)) {
 
  717                $ulng->loadLanguageModule(
'wiki');
 
  719                if ($a_action == 
"comment") {
 
  720                    $subject = sprintf($ulng->txt(
'wiki_notification_comment_subject'), $wiki->getTitle(), $page->getTitle());
 
  723                    $message .= $ulng->txt(
'wiki_notification_' . $a_action) . 
":\n\n";
 
  724                    $message .= $ulng->txt(
'wiki') . 
": " . $wiki->getTitle() . 
"\n";
 
  725                    $message .= $ulng->txt(
'page') . 
": " . $page->getTitle() . 
"\n";
 
  730                        $message .= 
"\n" . $ulng->txt(
'comment') . 
":\n\"" . trim($a_comment) . 
"\"\n";
 
  733                    $message .= 
"\n" . $ulng->txt(
'wiki_change_notification_page_link') . 
": " . $link;
 
  735                    $subject = sprintf($ulng->txt(
'wiki_change_notification_subject'), $wiki->getTitle(), $page->getTitle());
 
  740                        $message .= $ulng->txt(
'wiki_change_notification_page_body_' . $a_action) . 
":\n\n";
 
  741                        $message .= $ulng->txt(
'wiki') . 
": " . $wiki->getTitle() . 
"\n";
 
  742                        $message .= $ulng->txt(
'page') . 
": " . $page->getTitle() . 
"\n";
 
  746                            $message .= 
"\n" . $ulng->txt(
'content') . 
"\n" .
 
  747                                "----------------------------------------\n" .
 
  749                                "----------------------------------------\n";
 
  754                            $message .= 
"\n" . $ulng->txt(
'comment') . 
":\n\"" . trim($a_comment) . 
"\"\n";
 
  757                        $message .= 
"\n" . $ulng->txt(
'wiki_change_notification_page_link') . 
": " . $link;
 
  760                        $message .= $ulng->txt(
'wiki_change_notification_body_' . $a_action) . 
":\n\n";
 
  761                        $message .= $ulng->txt(
'wiki') . 
": " . $wiki->getTitle() . 
"\n";
 
  762                        $message .= $ulng->txt(
'page') . 
": " . $page->getTitle() . 
"\n";
 
  766                            $message .= $ulng->txt(
'content') . 
"\n" .
 
  767                                "----------------------------------------\n" .
 
  769                                "----------------------------------------\n\n";
 
  772                        $message .= $ulng->txt(
'wiki_change_notification_link') . 
": " . $link;
 
  777                $mail_obj->appendInstallationSignature(
true);
 
  778                $log->debug(
"before enqueue ($user_id)");
 
  800                $log->debug(
"after enqueue");
 
  805        if (count($mails) > 0) {
 
  814        $log->debug(
"end... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
 
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
An exception for terminatinating execution or to throw for unit testing.
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_REPLACE
Wiki link / page title handling:
const IL_WIKI_MODE_COLLECT
const IL_WIKI_MODE_EXT_COLLECT
static _getLanguageOfUser($a_usr_id)
Get language object of user.
static _getLink($a_ref_id, $a_type='', $a_params=array(), $append="")
static getLogger($a_component_id)
Get component logger.
static _getInstallationSignature()
static getNotificationsForObject($type, $id, $page_id=null, $ignore_threshold=false)
Get all users for given object.
static updateNotificationTime($type, $id, array $user_ids, $page_id=false)
Update the last mail timestamp for given object and users.
static _lookupLogin($a_user_id)
lookup login
static _lookupFullname($a_user_id)
Lookup Full Name.
static truncateHTML( $a_text, $a_length=100, $a_ending='...', $a_exact=false, $a_consider_html=true)
Truncate (html) string.
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
Class ilWikiPage GUI class.
static _wikiPageExists($a_wiki_id, $a_title)
Check whether page exists for wiki or not.
static getIdForPageTitle($a_wiki_id, $a_title)
Checks whether a page with given title exists.
static processInternalLinks( $s, $a_wiki_id, $a_mode=IL_WIKI_MODE_REPLACE, $a_collect_non_ex=false, $a_offline=false)
Process internal links.
static wfUrlProtocols()
From mediawiki GlobalFunctions.php.
static sendNotification($a_action, $a_type, $a_wiki_ref_id, $a_page_id, $a_comment=null)
static wfUrlencode($s)
From GlobalFunctions.php.
static makeLink(&$nt, $a_wiki_id, $text='', $query='', $trail='', $prefix='', $a_offline=false)
Make a wiki link, the following formats are supported:
static removeUnsafeCharacters($a_str)
See class.ilInitialisation.php.
static makeUrlTitle($a_par)
Set page parameter for Url Embedding.
static makeDbTitle($a_par)
Handle page GET parameter.
static replaceInternalLinks($s, $a_wiki_id, $a_offline=false)
This one is based on Mediawiki Parser->replaceInternalLinks since we display images in another way,...
static collectInternalLinks($s, $a_wiki_id, $a_collect_non_ex=false)
Collect internal wiki links of a string.
static splitTrail($trail)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples