ILIAS  release_7 Revision v7.30-3-g800a261c036
ilWikiUtil Class Reference

Utility class for wiki. More...

+ Collaboration diagram for ilWikiUtil:

Static Public Member Functions

static replaceInternalLinks ($s, $a_wiki_id, $a_offline=false)
 This one is based on Mediawiki Parser->replaceInternalLinks since we display images in another way, only text links are processed. More...
 
static collectInternalLinks ($s, $a_wiki_id, $a_collect_non_ex=false)
 Collect internal wiki links of a string. More...
 
static processInternalLinks ( $s, $a_wiki_id, $a_mode=IL_WIKI_MODE_REPLACE, $a_collect_non_ex=false, $a_offline=false)
 Process internal links. More...
 
static removeUnsafeCharacters ($a_str)
 See class.ilInitialisation.php. More...
 
static makeLink (&$nt, $a_wiki_id, $text='', $query='', $trail='', $prefix='', $a_offline=false)
 Make a wiki link, the following formats are supported: More...
 
static wfUrlProtocols ()
 From mediawiki GlobalFunctions.php. More...
 
static wfUrlencode ($s)
 From GlobalFunctions.php. More...
 
static makeDbTitle ($a_par)
 Handle page GET parameter. More...
 
static makeUrlTitle ($a_par)
 Set page parameter for Url Embedding. More...
 
static splitTrail ($trail)
 
static sendNotification ($a_action, $a_type, $a_wiki_ref_id, $a_page_id, $a_comment=null)
 

Detailed Description

Utility class for wiki.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 30 of file class.ilWikiUtil.php.

Member Function Documentation

◆ collectInternalLinks()

static ilWikiUtil::collectInternalLinks (   $s,
  $a_wiki_id,
  $a_collect_non_ex = false 
)
static

Collect internal wiki links of a string.

Parameters
stringinput string
Returns
string output string

Definition at line 59 of file class.ilWikiUtil.php.

References $result, IL_WIKI_MODE_COLLECT, and processInternalLinks().

Referenced by ilWikiPage\afterUpdate(), and ilWikiPage\saveInternalLinks().

60  {
62  $s,
63  $a_wiki_id,
65  $a_collect_non_ex
66  );
67 
68  return $result;
69  }
$result
static processInternalLinks( $s, $a_wiki_id, $a_mode=IL_WIKI_MODE_REPLACE, $a_collect_non_ex=false, $a_offline=false)
Process internal links.
const IL_WIKI_MODE_COLLECT
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ makeDbTitle()

◆ makeLink()

static ilWikiUtil::makeLink ( $nt,
  $a_wiki_id,
  $text = '',
  $query = '',
  $trail = '',
  $prefix = '',
  $a_offline = false 
)
static

Make a wiki link, the following formats are supported:

[[Page Title]] [[Page Title|Presentation Text]] [[Page Title::Anchor]] [[Page Title::Anchor|Presentation Text]] [[#Anchor|Presentation Text]] (link to anchor on same wiki page)

Definition at line 428 of file class.ilWikiUtil.php.

References $_GET, $DIC, ilWikiPage\_wikiPageExists(), ilWikiPage\getIdForPageTitle(), makeDbTitle(), and makeUrlTitle().

Referenced by ilPCAMDPageList\modifyPageContentPostXsl(), and processInternalLinks().

436  {
437  global $DIC;
438 
439  $ilCtrl = $DIC->ctrl();
440 
441  //wfProfileIn( __METHOD__ );
442  if (!is_object($nt)) {
443  # Fail gracefully
444  $retVal = "<!-- ERROR -->{$prefix}{$text}{$trail}";
445  } else {
446 
447 //var_dump($trail);
448  //var_dump($nt);
449 
450  // remove anchor from text, define anchor
451  $anc = "";
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;
457  } else {
458  $anc = "#" . $nt->mFragment;
459  }
460  }
461 
462  # Separate the link trail from the rest of the link
463  // outcommented due to bug #14590
464  // list( $inside, $trail ) = ilWikiUtil::splitTrail( $trail );
465 
466  $retVal = '***' . $text . "***" . $trail;
467  $url_title = ilWikiUtil::makeUrlTitle($nt->mTextform);
468  $db_title = ilWikiUtil::makeDbTitle($nt->mTextform);
469  if ($db_title != "") {
470  $pg_exists = ilWikiPage::_wikiPageExists($a_wiki_id, $db_title);
471  } else {
472  // links on same page (only anchor used)
473  $pg_exists = true;
474  }
475 
476  //var_dump($nt);
477  //var_dump($inside);
478  //var_dump($trail);
479  $wiki_link_class = (!$pg_exists)
480  ? ' class="ilc_link_IntLink ilWikiPageMissing" '
481  : ' class="ilc_link_IntLink" ';
482 
483  if (!$a_offline) {
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"]);
490  } else {
491  $retVal = '<a ' . $wiki_link_class . ' href="' .
492  $anc .
493  '">' . $text . '</a>' . $trail;
494  }
495  } else {
496  if ($pg_exists) {
497  if ($db_title != "") {
498  $pg_id = ilWikiPage::getIdForPageTitle($a_wiki_id, $db_title);
499  $retVal = '<a ' . $wiki_link_class . ' href="' .
500  "wpg_" . $pg_id . ".html" . $anc .
501  '">' . $text . '</a>' . $trail;
502  } else {
503  $retVal = '<a ' . $wiki_link_class . ' href="' .
504  $anc .
505  '">' . $text . '</a>' . $trail;
506  }
507  } else {
508  $retVal = $text . $trail;
509  }
510  }
511 
512  /* if ( $nt->isExternal() ) {
513  $nr = array_push( $this->mInterwikiLinkHolders['texts'], $prefix.$text.$inside );
514  $this->mInterwikiLinkHolders['titles'][] = $nt;
515  $retVal = '<!--IWLINK '. ($nr-1) ."-->{$trail}";
516  } else {
517  $nr = array_push( $this->mLinkHolders['namespaces'], $nt->getNamespace() );
518  $this->mLinkHolders['dbkeys'][] = $nt->getDBkey();
519  $this->mLinkHolders['queries'][] = $query;
520  $this->mLinkHolders['texts'][] = $prefix.$text.$inside;
521  $this->mLinkHolders['titles'][] = $nt;
522 
523  $retVal = '<!--LINK '. ($nr-1) ."-->{$trail}";
524  }
525  */
526  }
527  //wfProfileOut( __METHOD__ );
528  //echo "<br>".$retVal; exit;
529  return $retVal;
530  }
$_GET["client_id"]
static makeUrlTitle($a_par)
Set page parameter for Url Embedding.
global $DIC
Definition: goto.php:24
static makeDbTitle($a_par)
Handle page GET parameter.
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.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ makeUrlTitle()

◆ processInternalLinks()

static ilWikiUtil::processInternalLinks (   $s,
  $a_wiki_id,
  $a_mode = IL_WIKI_MODE_REPLACE,
  $a_collect_non_ex = false,
  $a_offline = false 
)
static

Process internal links.

string $s string that includes internal wiki links int $a_wiki_id wiki id mode

Strip the whitespace Category links produce, see bug 87

Todo:
We might want to use trim($tmp, "\n") here.

Definition at line 78 of file class.ilWikiUtil.php.

References Vendor\Package\$a, $GLOBALS, ilWikiPage\_wikiPageExists(), IL_WIKI_MODE_COLLECT, IL_WIKI_MODE_EXT_COLLECT, IL_WIKI_MODE_REPLACE, makeDbTitle(), makeLink(), makeUrlTitle(), Title\newFromText(), splitTrail(), and wfUrlProtocols().

Referenced by collectInternalLinks(), WikiUtilTest\processInternalLinksCollect(), WikiUtilTest\processInternalLinksExtCollect(), WikiUtilTest\processInternalLinksReplace(), ilWikiPage\rename(), and replaceInternalLinks().

84  {
85  $collect = array();
86  // both from mediawiki DefaulSettings.php
87  $wgLegalTitleChars = " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+";
88 
89  // Adapter for media wiki classes
90  include_once("./Modules/Wiki/classes/class.ilMediaWikiAdapter.php");
91  $GLOBALS["wgContLang"] = new ilMediaWikiAdapter();
92  $GLOBALS["wgInterWikiCache"] = false;
93 
94  # the % is needed to support urlencoded titles as well
95  //$tc = Title::legalChars().'#%';
96  $tc = $wgLegalTitleChars . '#%';
97 
98  //$sk = $this->mOptions->getSkin();
99 
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);
104  $s = substr($s, 1);
105 
106  # Match a link having the form [[namespace:link|alternate]]trail
107  $e1 = "/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD";
108 
109  # Match cases where there is no "]]", which might still be images
110  // static $e1_img = FALSE;
111  // if ( !$e1_img ) { $e1_img = "/^([{$tc}]+)\\|(.*)\$/sD"; }
112 
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
115  // $e2 = wfMsgForContent( 'linkprefix' );
116 
117  /* $useLinkPrefixExtension = $wgContLang->linkPrefixExtension();
118  if( is_null( $this->mTitle ) ) {
119  throw new MWException( __METHOD__.": \$this->mTitle is null\n" );
120  }
121  $nottalk = !$this->mTitle->isTalkPage();*/
122  $nottalk = true;
123 
124  /* if ( $useLinkPrefixExtension ) {
125  $m = array();
126  if ( preg_match( $e2, $s, $m ) ) {
127  $first_prefix = $m[2];
128  } else {
129  $first_prefix = false;
130  }
131  } else {*/
132  $prefix = '';
133  // }
134 
135  $useSubpages = false;
136 
137  # Loop for each link
138  for ($k = 0; isset($a[$k]); $k++) {
139  $line = $a[$k];
140 
141 
142  $might_be_img = false;
143 
144  //wfProfileIn( "$fname-e1" );
145  if (preg_match($e1, $line, $m)) { # page with normal text or alt
146  $text = $m[2];
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://example.com desc]]] <- having three ] in a row fucks up,
149  # the real problem is with the $e1 regex
150  # See bug 1300.
151  #
152  # Still some problems for cases where the ] is meant to be outside punctuation,
153  # and no image is in sight. See bug 2095.
154  #
155  if ($text !== '' &&
156  substr($m[3], 0, 1) === ']' &&
157  strpos($text, '[') !== false
158  ) {
159  $text .= ']'; # so that replaceExternalLinks($text) works later
160  $m[3] = substr($m[3], 1);
161  }
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('&lt;', '&gt;'), urldecode($m[1]));
166  }
167  $trail = $m[3];
168  /* } elseif( preg_match($e1_img, $line, $m) ) { # Invalid, but might be an image with a link in its caption
169  $might_be_img = true;
170  $text = $m[2];
171  if ( strpos( $m[1], '%' ) !== false ) {
172  $m[1] = urldecode($m[1]);
173  }
174  $trail = "";*/
175  } else { # Invalid form; output directly
176  $s .= $prefix . '[[' . $line ;
177  //wfProfileOut( "$fname-e1" );
178  continue;
179  }
180  //wfProfileOut( "$fname-e1" );
181  //wfProfileIn( "$fname-misc" );
182 
183  # Don't allow internal links to pages containing
184  # PROTO: where PROTO is a valid URL protocol; these
185  # should be external links.
186  if (preg_match('/^\b(?:' . ilWikiUtil::wfUrlProtocols() . ')/', $m[1])) {
187  $s .= $prefix . '[[' . $line ;
188  continue;
189  }
190 
191  # Make subpage if necessary
192  /* if( $useSubpages ) {
193  $link = $this->maybeDoSubpageLink( $m[1], $text );
194  } else {*/
195  $link = $m[1];
196  // }
197 
198  $noforce = (substr($m[1], 0, 1) != ':');
199  if (!$noforce) {
200  # Strip off leading ':'
201  $link = substr($link, 1);
202  }
203 
204  // wfProfileOut( "$fname-misc" );
205  // wfProfileIn( "$fname-title" );
206 
207  // todo
208  include_once("./Modules/Wiki/mediawiki/Title.php");
209  include_once("./Services/Utilities/classes/Sanitizer.php");
210  //$nt = Title::newFromText( $this->mStripState->unstripNoWiki($link) );
211 
212  // todo: check step by step
213  //echo "<br>".htmlentities($link)."---";
214  $nt = Title::newFromText($link);
215 
216  if (!$nt) {
217  $s .= $prefix . '[[' . $line;
218  //wfProfileOut( "$fname-title" );
219  continue;
220  }
221 
222  /* $ns = $nt->getNamespace();
223  $iw = $nt->getInterWiki();
224  wfProfileOut( "$fname-title" );
225 
226  /* if ($might_be_img) { # if this is actually an invalid link
227  wfProfileIn( "$fname-might_be_img" );
228  if ($ns == NS_IMAGE && $noforce) { #but might be an image
229  $found = false;
230  while (isset ($a[$k+1]) ) {
231  #look at the next 'line' to see if we can close it there
232  $spliced = array_splice( $a, $k + 1, 1 );
233  $next_line = array_shift( $spliced );
234  $m = explode( ']]', $next_line, 3 );
235  if ( count( $m ) == 3 ) {
236  # the first ]] closes the inner link, the second the image
237  $found = true;
238  $text .= "[[{$m[0]}]]{$m[1]}";
239  $trail = $m[2];
240  break;
241  } elseif ( count( $m ) == 2 ) {
242  #if there's exactly one ]] that's fine, we'll keep looking
243  $text .= "[[{$m[0]}]]{$m[1]}";
244  } else {
245  #if $next_line is invalid too, we need look no further
246  $text .= '[[' . $next_line;
247  break;
248  }
249  }
250  if ( !$found ) {
251  # we couldn't find the end of this imageLink, so output it raw
252  #but don't ignore what might be perfectly normal links in the text we've examined
253  $text = $this->replaceInternalLinks($text);
254  $s .= "{$prefix}[[$link|$text";
255  # note: no $trail, because without an end, there *is* no trail
256  wfProfileOut( "$fname-might_be_img" );
257  continue;
258  }
259  } else { #it's not an image, so output it raw
260  $s .= "{$prefix}[[$link|$text";
261  # note: no $trail, because without an end, there *is* no trail
262  wfProfileOut( "$fname-might_be_img" );
263  continue;
264  }
265  wfProfileOut( "$fname-might_be_img" );
266  }
267  */
268 
269  $wasblank = ('' == $text);
270  if ($wasblank) {
271  $text = $link;
272  }
273 
274  # Link not escaped by : , create the various objects
275  if ($noforce) {
276  # Interwikis
277  /*wfProfileIn( "$fname-interwiki" );
278  if( $iw && $this->mOptions->getInterwikiMagic() && $nottalk && $wgContLang->getLanguageName( $iw ) ) {
279  $this->mOutput->addLanguageLink( $nt->getFullText() );
280  $s = rtrim($s . $prefix);
281  $s .= trim($trail, "\n") == '' ? '': $prefix . $trail;
282  wfProfileOut( "$fname-interwiki" );
283  continue;
284  }
285  wfProfileOut( "$fname-interwiki" );*/
286 
287 /* if ( $ns == NS_IMAGE ) {
288  wfProfileIn( "$fname-image" );
289  if ( !wfIsBadImage( $nt->getDBkey(), $this->mTitle ) ) {
290  # recursively parse links inside the image caption
291  # actually, this will parse them in any other parameters, too,
292  # but it might be hard to fix that, and it doesn't matter ATM
293  $text = $this->replaceExternalLinks($text);
294  $text = $this->replaceInternalLinks($text);
295 
296  # cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
297  $s .= $prefix . $this->armorLinks( $this->makeImage( $nt, $text ) ) . $trail;
298  $this->mOutput->addImage( $nt->getDBkey() );
299 
300  wfProfileOut( "$fname-image" );
301  continue;
302  } else {
303  # We still need to record the image's presence on the page
304  $this->mOutput->addImage( $nt->getDBkey() );
305  }
306  wfProfileOut( "$fname-image" );
307 
308  }
309 */
310 /* if ( $ns == NS_CATEGORY ) {
311  wfProfileIn( "$fname-category" );
312  $s = rtrim($s . "\n"); # bug 87
313 
314  if ( $wasblank ) {
315  $sortkey = $this->getDefaultSort();
316  } else {
317  $sortkey = $text;
318  }
319  $sortkey = Sanitizer::decodeCharReferences( $sortkey );
320  $sortkey = str_replace( "\n", '', $sortkey );
321  $sortkey = $wgContLang->convertCategoryKey( $sortkey );
322  $this->mOutput->addCategory( $nt->getDBkey(), $sortkey );
323 */
328 // $s .= trim($prefix . $trail, "\n") == '' ? '': $prefix . $trail;
329 
330 // wfProfileOut( "$fname-category" );
331 // continue;
332 // }
333  }
334 
335  # Self-link checking
336  /* if( $nt->getFragment() === '' ) {
337  if( in_array( $nt->getPrefixedText(), $selflink, true ) ) {
338  $s .= $prefix . $sk->makeSelfLinkObj( $nt, $text, '', $trail );
339  continue;
340  }
341  }*/
342 
343  # Special and Media are pseudo-namespaces; no pages actually exist in them
344  /* if( $ns == NS_MEDIA ) {
345  $link = $sk->makeMediaLinkObj( $nt, $text );
346  # Cloak with NOPARSE to avoid replacement in replaceExternalLinks
347  $s .= $prefix . $this->armorLinks( $link ) . $trail;
348  $this->mOutput->addImage( $nt->getDBkey() );
349  continue;
350  } elseif( $ns == NS_SPECIAL ) {
351  $s .= $this->makeKnownLinkHolder( $nt, $text, '', $trail, $prefix );
352  continue;
353  } elseif( $ns == NS_IMAGE ) {
354  $img = new Image( $nt );
355  if( $img->exists() ) {
356  // Force a blue link if the file exists; may be a remote
357  // upload on the shared repository, and we want to see its
358  // auto-generated page.
359  $s .= $this->makeKnownLinkHolder( $nt, $text, '', $trail, $prefix );
360  $this->mOutput->addLink( $nt );
361  continue;
362  }
363  }*/
364 
365  // Media wiki performs an intermediate step here (Parser->makeLinkHolder)
366  if ($a_mode == IL_WIKI_MODE_REPLACE) {
367  $s .= ilWikiUtil::makeLink(
368  $nt,
369  $a_wiki_id,
370  $text,
371  '',
372  $trail,
373  $prefix,
374  $a_offline
375  );
376  //echo "<br>-".htmlentities($s)."-";
377  }
378  if ($a_mode == IL_WIKI_MODE_EXT_COLLECT) {
379  if (is_object($nt)) {
380  $url_title = ilWikiUtil::makeUrlTitle($nt->mTextform);
381  $db_title = ilWikiUtil::makeDbTitle($nt->mTextform);
382  list($inside, $trail) = ilWikiUtil::splitTrail($trail);
383  $collect[] = array("nt" => $nt, "text" => $text,
384  "trail" => $trail, "db_title" => $db_title,
385  "url_title" => $url_title);
386  }
387  } else {
388  $url_title = ilWikiUtil::makeUrlTitle($nt->mTextform);
389  $db_title = ilWikiUtil::makeDbTitle($nt->mTextform);
390 
391  //$s .= ilWikiUtil::makeLink($nt, $a_wiki_id, $text, '', $trail, $prefix);
392  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
393  if (($a_collect_non_ex || ilWikiPage::_wikiPageExists($a_wiki_id, $db_title))
394  &&
395  !in_array($db_title, $collect)) {
396  $collect[] = $db_title;
397  }
398  }
399  }
400 
401  //wfProfileOut( $fname );
402 
403  if ($a_mode == IL_WIKI_MODE_COLLECT ||
404  $a_mode == IL_WIKI_MODE_EXT_COLLECT) {
405  return $collect;
406  } else {
407  return $s;
408  }
409  }
static makeLink(&$nt, $a_wiki_id, $text='', $query='', $trail='', $prefix='', $a_offline=false)
Make a wiki link, the following formats are supported:
This class implements some dummy methods, normally provided by media wiki classes.
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:124
const IL_WIKI_MODE_COLLECT
static makeUrlTitle($a_par)
Set page parameter for Url Embedding.
const IL_WIKI_MODE_REPLACE
Wiki link / page title handling:
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static makeDbTitle($a_par)
Handle page GET parameter.
static _wikiPageExists($a_wiki_id, $a_title)
Check whether page exists for wiki or not.
static wfUrlProtocols()
From mediawiki GlobalFunctions.php.
const IL_WIKI_MODE_EXT_COLLECT
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
static splitTrail($trail)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeUnsafeCharacters()

static ilWikiUtil::removeUnsafeCharacters (   $a_str)
static

See class.ilInitialisation.php.

Definition at line 414 of file class.ilWikiUtil.php.

Referenced by makeDbTitle(), and makeUrlTitle().

415  {
416  return str_replace(array("\x00", "\n", "\r", "\\", "'", '"', "\x1a"), "", $a_str);
417  }
+ Here is the caller graph for this function:

◆ replaceInternalLinks()

static ilWikiUtil::replaceInternalLinks (   $s,
  $a_wiki_id,
  $a_offline = false 
)
static

This one is based on Mediawiki Parser->replaceInternalLinks since we display images in another way, only text links are processed.

Parameters
stringinput string
stringinput string
Returns
string output string

Definition at line 42 of file class.ilWikiUtil.php.

References IL_WIKI_MODE_REPLACE, and processInternalLinks().

Referenced by ilWikiPageGUI\postOutputProcessing().

43  {
45  $s,
46  $a_wiki_id,
48  false,
49  $a_offline
50  );
51  }
static processInternalLinks( $s, $a_wiki_id, $a_mode=IL_WIKI_MODE_REPLACE, $a_collect_non_ex=false, $a_offline=false)
Process internal links.
const IL_WIKI_MODE_REPLACE
Wiki link / page title handling:
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendNotification()

static ilWikiUtil::sendNotification (   $a_action,
  $a_type,
  $a_wiki_ref_id,
  $a_page_id,
  $a_comment = null 
)
static

Definition at line 614 of file class.ilWikiUtil.php.

References $DIC, $ilUser, $log, $message, ilMail\_getInstallationSignature(), ilLanguageFactory\_getLanguageOfUser(), ilLink\_getLink(), ilObjUser\_lookupFullname(), ilObjUser\_lookupLogin(), ANONYMOUS_USER_ID, ilLoggerFactory\getLogger(), ilUserUtil\getNamePresentation(), ilNotification\getNotificationsForObject(), ilPageObjectGUI\setRawPageContent(), ilPageObject\truncateHTML(), ilNotification\TYPE_WIKI, ilNotification\TYPE_WIKI_PAGE, and ilNotification\updateNotificationTime().

Referenced by ilWikiPage\create(), ilWikiPage\delete(), ilWikiPageGUI\observeNoteAction(), and ilWikiPage\update().

615  {
616  global $DIC;
617 
619  $log->debug("start... vvvvvvvvvvvvvvvvvvvvvvvvvvv");
620 
621  $ilUser = $DIC->user();
622  $ilObjDataCache = $DIC["ilObjDataCache"];
623  $ilAccess = $DIC->access();
624 
625  if ((int) $a_wiki_ref_id === 0) {
626  return;
627  }
628 
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";
632 
633  $wiki_id = $ilObjDataCache->lookupObjId($a_wiki_ref_id);
634  $wiki = new ilObjWiki($a_wiki_ref_id, true);
635  $page = new ilWikiPage($a_page_id);
636 
637  // #11138
638  $ignore_threshold = ($a_action == "comment");
639 
640  // 1st update will be converted to new - see below
641  if ($a_action == "new") {
642  return;
643  }
644 
645  $log->debug("-- get notifications");
646  if ($a_type == ilNotification::TYPE_WIKI_PAGE) {
647  $users = ilNotification::getNotificationsForObject($a_type, $a_page_id, null, $ignore_threshold);
648  $wiki_users = ilNotification::getNotificationsForObject(ilNotification::TYPE_WIKI, $wiki_id, $a_page_id, $ignore_threshold);
649  $users = array_merge($users, $wiki_users);
650  if (!sizeof($users)) {
651  $log->debug("no notifications... ^^^^^^^^^^^^^^^^^^");
652  return;
653  }
655  } else {
656  $users = ilNotification::getNotificationsForObject(ilNotification::TYPE_WIKI, $wiki_id, $a_page_id, $ignore_threshold);
657  if (!sizeof($users)) {
658  $log->debug("no notifications... ^^^^^^^^^^^^^^^^^^");
659  return;
660  }
661  }
662 
664 
665  // #15192 - should always be present
666  include_once "./Services/Link/classes/class.ilLink.php";
667  if ($a_page_id) {
668  // #18804 - see ilWikiPageGUI::preview()
669  $link = ilLink::_getLink("", "wiki", null, "wpage_" . $a_page_id . "_" . $a_wiki_ref_id);
670  } else {
671  $link = ilLink::_getLink($a_wiki_ref_id);
672  }
673 
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");
678 
679 
680  // see ilBlogPostingGUI::getSnippet()
681  // see ilBlogPosting::getNotificationAbstract()
682 
683  $log->debug("-- prepare content");
684  include_once "Modules/Wiki/classes/class.ilWikiPageGUI.php";
685  $pgui = new ilWikiPageGUI($page->getId());
686  $pgui->setRawPageContent(true);
687  $pgui->setAbstractOnly(true);
688  $pgui->setFileDownloadLink(".");
689  $pgui->setFullscreenLink(".");
690  $pgui->setSourcecodeDownloadScript(".");
691  $snippet = $pgui->showPage();
692  $snippet = ilPageObject::truncateHTML($snippet, 500, "...");
693 
694  // making things more readable
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);
699 
700  $snippet = trim(strip_tags($snippet));
701 
702  // "fake" new (to enable snippet - if any)
703  $current_version = array_shift($page->getHistoryEntries());
704  $current_version = $current_version["nr"];
705  if (!$current_version && $a_action != "comment") {
706  $a_type = ilNotification::TYPE_WIKI;
707  $a_action = "new";
708  }
709 
710  $log->debug("-- sending mails");
711  $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)) {
715  // use language of recipient to compose message
716  $ulng = ilLanguageFactory::_getLanguageOfUser($user_id);
717  $ulng->loadLanguageModule('wiki');
718 
719  if ($a_action == "comment") {
720  $subject = sprintf($ulng->txt('wiki_notification_comment_subject'), $wiki->getTitle(), $page->getTitle());
721  $message = sprintf($ulng->txt('wiki_change_notification_salutation'), ilObjUser::_lookupFullname($user_id)) . "\n\n";
722 
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";
726  $message .= $ulng->txt('wiki_commented_by') . ": " . ilUserUtil::getNamePresentation($ilUser->getId()) . "\n";
727 
728  // include comment/note text
729  if ($a_comment) {
730  $message .= "\n" . $ulng->txt('comment') . ":\n\"" . trim($a_comment) . "\"\n";
731  }
732 
733  $message .= "\n" . $ulng->txt('wiki_change_notification_page_link') . ": " . $link;
734  } else {
735  $subject = sprintf($ulng->txt('wiki_change_notification_subject'), $wiki->getTitle(), $page->getTitle());
736  $message = sprintf($ulng->txt('wiki_change_notification_salutation'), ilObjUser::_lookupFullname($user_id)) . "\n\n";
737 
738  if ($a_type == ilNotification::TYPE_WIKI_PAGE) {
739  // update/delete
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";
743  $message .= $ulng->txt('wiki_changed_by') . ": " . ilUserUtil::getNamePresentation($ilUser->getId()) . "\n";
744 
745  if ($snippet) {
746  $message .= "\n" . $ulng->txt('content') . "\n" .
747  "----------------------------------------\n" .
748  $snippet . "\n" .
749  "----------------------------------------\n";
750  }
751 
752  // include comment/note text
753  if ($a_comment) {
754  $message .= "\n" . $ulng->txt('comment') . ":\n\"" . trim($a_comment) . "\"\n";
755  }
756 
757  $message .= "\n" . $ulng->txt('wiki_change_notification_page_link') . ": " . $link;
758  } else {
759  // new
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";
763  $message .= $ulng->txt('wiki_changed_by') . ": " . ilUserUtil::getNamePresentation($ilUser->getId()) . "\n\n";
764 
765  if ($snippet) {
766  $message .= $ulng->txt('content') . "\n" .
767  "----------------------------------------\n" .
768  $snippet . "\n" .
769  "----------------------------------------\n\n";
770  }
771 
772  $message .= $ulng->txt('wiki_change_notification_link') . ": " . $link;
773  }
774  }
775 
776  $mail_obj = new ilMail(ANONYMOUS_USER_ID);
777  $mail_obj->appendInstallationSignature(true);
778  $log->debug("before enqueue ($user_id)");
779  /*
780  $mail_obj->enqueue(
781  ilObjUser::_lookupLogin($user_id),
782  "",
783  "",
784  $subject,
785  $message,
786  array()
787  );*/
788  $message .= ilMail::_getInstallationSignature();
789  $mails[] = new ilMailValueObject(
790  '',
791  ilObjUser::_lookupLogin($user_id),
792  '',
793  '',
794  $subject,
795  $message,
796  [],
797  false,
798  false
799  );
800  $log->debug("after enqueue");
801  } else {
802  unset($users[$idx]);
803  }
804  }
805  if (count($mails) > 0) {
806  $processor = new ilMassMailTaskProcessor();
807  $processor->run(
808  $mails,
810  "",
811  []
812  );
813  }
814  $log->debug("end... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
815  }
static _lookupLogin($a_user_id)
lookup login
const ANONYMOUS_USER_ID
Definition: constants.php:25
static _lookupFullname($a_user_id)
Lookup Full Name.
static updateNotificationTime($type, $id, array $user_ids, $page_id=false)
Update the last mail timestamp for given object and users.
static getNotificationsForObject($type, $id, $page_id=null, $ignore_threshold=false)
Get all users for given object.
$log
Definition: result.php:15
Class ilObjWiki.
global $DIC
Definition: goto.php:24
setRawPageContent($a_rawpagecontent)
Set Get raw page content only.
Class ilWikiPage GUI class.
Class ilWikiPage.
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:
static _getLanguageOfUser($a_usr_id)
Get language object of user.
static truncateHTML( $a_text, $a_length=100, $a_ending='...', $a_exact=false, $a_consider_html=true)
Truncate (html) string.
$message
Definition: xapiexit.php:14
static getLogger($a_component_id)
Get component logger.
$ilUser
Definition: imgupload.php:18
static _getInstallationSignature()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ splitTrail()

static ilWikiUtil::splitTrail (   $trail)
static

Definition at line 597 of file class.ilWikiUtil.php.

Referenced by processInternalLinks().

598  {
599  $regex = '/^([a-z]+)(.*)$/sD';
600 
601  $inside = '';
602  if ('' != $trail) {
603  $m = array();
604 
605  if (preg_match($regex, $trail, $m)) {
606  $inside = $m[1];
607  $trail = $m[2];
608  }
609  }
610 
611  return array( $inside, $trail );
612  }
+ Here is the caller graph for this function:

◆ wfUrlencode()

static ilWikiUtil::wfUrlencode (   $s)
static

From GlobalFunctions.php.

Definition at line 567 of file class.ilWikiUtil.php.

Referenced by makeUrlTitle(), and Title\secureAndSplit().

568  {
569  $s = urlencode($s);
570  // $s = preg_replace( '/%3[Aa]/', ':', $s );
571  // $s = preg_replace( '/%2[Ff]/', '/', $s );
572 
573  return $s;
574  }
+ Here is the caller graph for this function:

◆ wfUrlProtocols()

static ilWikiUtil::wfUrlProtocols ( )
static

From mediawiki GlobalFunctions.php.

Definition at line 535 of file class.ilWikiUtil.php.

Referenced by processInternalLinks().

536  {
537  $wgUrlProtocols = array(
538  'http://',
539  'https://',
540  'ftp://',
541  'irc://',
542  'gopher://',
543  'telnet://', // Well if we're going to support the above.. -ævar
544  'nntp://', // @bug 3808 RFC 1738
545  'worldwind://',
546  'mailto:',
547  'news:'
548  );
549 
550  // Support old-style $wgUrlProtocols strings, for backwards compatibility
551  // with LocalSettings files from 1.5
552  if (is_array($wgUrlProtocols)) {
553  $protocols = array();
554  foreach ($wgUrlProtocols as $protocol) {
555  $protocols[] = preg_quote($protocol, '/');
556  }
557 
558  return implode('|', $protocols);
559  } else {
560  return $wgUrlProtocols;
561  }
562  }
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: