ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 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  }
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()

static ilWikiUtil::makeDbTitle (   $a_par)
static

◆ 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 427 of file class.ilWikiUtil.php.

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

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

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

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

Referenced by makeDbTitle(), and makeUrlTitle().

414  {
415  return str_replace(array("\x00", "\n", "\r", "\\", "'", '"', "\x1a"), "", $a_str);
416  }
+ 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 613 of file class.ilWikiUtil.php.

References $a_type, $DIC, $ilUser, $message, ilLanguageFactory\_getLanguageOfUser(), ilLink\_getLink(), ilObjUser\_lookupFullname(), ilObjUser\_lookupLogin(), 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().

614  {
615  global $DIC;
616 
617  $ilUser = $DIC->user();
618  $ilObjDataCache = $DIC["ilObjDataCache"];
619  $ilAccess = $DIC->access();
620 
621  include_once "./Services/Notification/classes/class.ilNotification.php";
622  include_once "./Modules/Wiki/classes/class.ilObjWiki.php";
623  include_once "./Modules/Wiki/classes/class.ilWikiPage.php";
624 
625  $wiki_id = $ilObjDataCache->lookupObjId($a_wiki_ref_id);
626  $wiki = new ilObjWiki($a_wiki_ref_id, true);
627  $page = new ilWikiPage($a_page_id);
628 
629  // #11138
630  $ignore_threshold = ($a_action == "comment");
631 
632  // 1st update will be converted to new - see below
633  if ($a_action == "new") {
634  return;
635  }
636 
638  $users = ilNotification::getNotificationsForObject($a_type, $a_page_id, null, $ignore_threshold);
639  $wiki_users = ilNotification::getNotificationsForObject(ilNotification::TYPE_WIKI, $wiki_id, $a_page_id, $ignore_threshold);
640  $users = array_merge($users, $wiki_users);
641  if (!sizeof($users)) {
642  return;
643  }
644 
646  } else {
647  $users = ilNotification::getNotificationsForObject(ilNotification::TYPE_WIKI, $wiki_id, $a_page_id, $ignore_threshold);
648  if (!sizeof($users)) {
649  return;
650  }
651  }
652 
654 
655  // #15192 - should always be present
656  include_once "./Services/Link/classes/class.ilLink.php";
657  if ($a_page_id) {
658  // #18804 - see ilWikiPageGUI::preview()
659  $link = ilLink::_getLink("", "wiki", null, "wpage_" . $a_page_id . "_" . $a_wiki_ref_id);
660  } else {
661  $link = ilLink::_getLink($a_wiki_ref_id);
662  }
663 
664  include_once "./Services/Mail/classes/class.ilMail.php";
665  include_once "./Services/User/classes/class.ilObjUser.php";
666  include_once "./Services/Language/classes/class.ilLanguageFactory.php";
667  include_once("./Services/User/classes/class.ilUserUtil.php");
668 
669 
670  // see ilBlogPostingGUI::getSnippet()
671  // see ilBlogPosting::getNotificationAbstract()
672 
673  include_once "Modules/Wiki/classes/class.ilWikiPageGUI.php";
674  $pgui = new ilWikiPageGUI($page->getId());
675  $pgui->setRawPageContent(true);
676  $pgui->setAbstractOnly(true);
677  $pgui->setFileDownloadLink(".");
678  $pgui->setFullscreenLink(".");
679  $pgui->setSourcecodeDownloadScript(".");
680  $snippet = $pgui->showPage();
681  $snippet = ilPageObject::truncateHTML($snippet, 500, "...");
682 
683  // making things more readable
684  $snippet = str_replace('<br/>', "\n", $snippet);
685  $snippet = str_replace('<br />', "\n", $snippet);
686  $snippet = str_replace('</p>', "\n", $snippet);
687  $snippet = str_replace('</div>', "\n", $snippet);
688 
689  $snippet = trim(strip_tags($snippet));
690 
691  // "fake" new (to enable snippet - if any)
692  $current_version = array_shift($page->getHistoryEntries());
693  $current_version = $current_version["nr"];
694  if (!$current_version && $a_action != "comment") {
696  $a_action = "new";
697  }
698 
699  foreach (array_unique($users) as $idx => $user_id) {
700  if ($user_id != $ilUser->getId() &&
701  $ilAccess->checkAccessOfUser($user_id, 'read', '', $a_wiki_ref_id)) {
702  // use language of recipient to compose message
703  $ulng = ilLanguageFactory::_getLanguageOfUser($user_id);
704  $ulng->loadLanguageModule('wiki');
705 
706  if ($a_action == "comment") {
707  $subject = sprintf($ulng->txt('wiki_notification_comment_subject'), $wiki->getTitle(), $page->getTitle());
708  $message = sprintf($ulng->txt('wiki_change_notification_salutation'), ilObjUser::_lookupFullname($user_id)) . "\n\n";
709 
710  $message .= $ulng->txt('wiki_notification_' . $a_action) . ":\n\n";
711  $message .= $ulng->txt('wiki') . ": " . $wiki->getTitle() . "\n";
712  $message .= $ulng->txt('page') . ": " . $page->getTitle() . "\n";
713  $message .= $ulng->txt('wiki_commented_by') . ": " . ilUserUtil::getNamePresentation($ilUser->getId()) . "\n";
714 
715  // include comment/note text
716  if ($a_comment) {
717  $message .= "\n" . $ulng->txt('comment') . ":\n\"" . trim($a_comment) . "\"\n";
718  }
719 
720  $message .= "\n" . $ulng->txt('wiki_change_notification_page_link') . ": " . $link;
721  } else {
722  $subject = sprintf($ulng->txt('wiki_change_notification_subject'), $wiki->getTitle(), $page->getTitle());
723  $message = sprintf($ulng->txt('wiki_change_notification_salutation'), ilObjUser::_lookupFullname($user_id)) . "\n\n";
724 
726  // update/delete
727  $message .= $ulng->txt('wiki_change_notification_page_body_' . $a_action) . ":\n\n";
728  $message .= $ulng->txt('wiki') . ": " . $wiki->getTitle() . "\n";
729  $message .= $ulng->txt('page') . ": " . $page->getTitle() . "\n";
730  $message .= $ulng->txt('wiki_changed_by') . ": " . ilUserUtil::getNamePresentation($ilUser->getId()) . "\n";
731 
732  if ($snippet) {
733  $message .= "\n" . $ulng->txt('content') . "\n" .
734  "----------------------------------------\n" .
735  $snippet . "\n" .
736  "----------------------------------------\n";
737  }
738 
739  // include comment/note text
740  if ($a_comment) {
741  $message .= "\n" . $ulng->txt('comment') . ":\n\"" . trim($a_comment) . "\"\n";
742  }
743 
744  $message .= "\n" . $ulng->txt('wiki_change_notification_page_link') . ": " . $link;
745  } else {
746  // new
747  $message .= $ulng->txt('wiki_change_notification_body_' . $a_action) . ":\n\n";
748  $message .= $ulng->txt('wiki') . ": " . $wiki->getTitle() . "\n";
749  $message .= $ulng->txt('page') . ": " . $page->getTitle() . "\n";
750  $message .= $ulng->txt('wiki_changed_by') . ": " . ilUserUtil::getNamePresentation($ilUser->getId()) . "\n\n";
751 
752  if ($snippet) {
753  $message .= $ulng->txt('content') . "\n" .
754  "----------------------------------------\n" .
755  $snippet . "\n" .
756  "----------------------------------------\n\n";
757  }
758 
759  $message .= $ulng->txt('wiki_change_notification_link') . ": " . $link;
760  }
761  }
762 
763  $mail_obj = new ilMail(ANONYMOUS_USER_ID);
764  $mail_obj->appendInstallationSignature(true);
765  $mail_obj->enqueue(
766  ilObjUser::_lookupLogin($user_id),
767  "",
768  "",
769  $subject,
770  $message,
771  array()
772  );
773  } else {
774  unset($users[$idx]);
775  }
776  }
777  }
static _lookupLogin($a_user_id)
lookup login
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.
$a_type
Definition: workflow.php:92
Class ilObjWiki.
setRawPageContent($a_rawpagecontent)
Set Get raw page content only.
Class ilWikiPage GUI class.
$ilUser
Definition: imgupload.php:18
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.
$DIC
Definition: xapitoken.php:46
$message
Definition: xapiexit.php:14
+ 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 596 of file class.ilWikiUtil.php.

Referenced by processInternalLinks().

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

◆ wfUrlencode()

static ilWikiUtil::wfUrlencode (   $s)
static

From GlobalFunctions.php.

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

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

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

◆ wfUrlProtocols()

static ilWikiUtil::wfUrlProtocols ( )
static

From mediawiki GlobalFunctions.php.

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

Referenced by processInternalLinks().

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

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