ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 54 of file class.ilWikiUtil.php.

References IL_WIKI_MODE_COLLECT, and processInternalLinks().

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

55  {
57  $a_collect_non_ex);
58  }
const IL_WIKI_MODE_COLLECT
static processInternalLinks($s, $a_wiki_id, $a_mode=IL_WIKI_MODE_REPLACE, $a_collect_non_ex=false, $a_offline=false)
Process internal links.
+ 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 440 of file class.ilWikiUtil.php.

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

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

442  {
443  global $ilCtrl;
444 
445  //wfProfileIn( __METHOD__ );
446  if ( ! is_object($nt) ) {
447  # Fail gracefully
448  $retVal = "<!-- ERROR -->{$prefix}{$text}{$trail}";
449  } else {
450 
451 //var_dump($trail);
452 //var_dump($nt);
453 
454  // remove anchor from text, define anchor
455  $anc = "";
456  if ($nt->mFragment != "")
457  {
458  if (substr($text, strlen($text) - strlen("#".$nt->mFragment))
459  == "#".$nt->mFragment)
460  {
461  $text = substr($text, 0, strlen($text) - strlen("#".$nt->mFragment));
462  $anc = "#".$nt->mFragment;
463  }
464  else
465  {
466  $anc = "#".$nt->mFragment;
467  }
468  }
469 
470  # Separate the link trail from the rest of the link
471  // outcommented due to bug #14590
472 // list( $inside, $trail ) = ilWikiUtil::splitTrail( $trail );
473 
474  $retVal = '***'.$text."***".$trail;
475  $url_title = ilWikiUtil::makeUrlTitle($nt->mTextform);
476  $db_title = ilWikiUtil::makeDbTitle($nt->mTextform);
477  if ($db_title != "")
478  {
479  $pg_exists = ilWikiPage::_wikiPageExists($a_wiki_id, $db_title);
480  }
481  else
482  {
483  // links on same page (only anchor used)
484  $pg_exists = true;
485  }
486 
487 //var_dump($nt);
488 //var_dump($inside);
489 //var_dump($trail);
490  $wiki_link_class = (!$pg_exists)
491  ? ' class="ilc_link_IntLink ilWikiPageMissing" '
492  : ' class="ilc_link_IntLink" ';
493 
494  if (!$a_offline)
495  {
496  if ($url_title != "")
497  {
498  $ilCtrl->setParameterByClass("ilobjwikigui", "page", $url_title);
499  $retVal = '<a '.$wiki_link_class.' href="'.
500  $ilCtrl->getLinkTargetByClass("ilobjwikigui", "gotoPage").$anc.
501  '">'.$text.'</a>'.$trail;
502  $ilCtrl->setParameterByClass("ilobjwikigui", "page", $_GET["page"]);
503  }
504  else
505  {
506  $retVal = '<a '.$wiki_link_class.' href="'.
507  $anc.
508  '">'.$text.'</a>'.$trail;
509  }
510  }
511  else
512  {
513  if ($pg_exists)
514  {
515  if ($db_title != "")
516  {
517  $pg_id = ilWikiPage::getIdForPageTitle($a_wiki_id, $db_title);
518  $retVal = '<a '.$wiki_link_class.' href="'.
519  "wpg_".$pg_id.".html".$anc.
520  '">'.$text.'</a>'.$trail;
521  }
522  else
523  {
524  $retVal = '<a '.$wiki_link_class.' href="'.
525  $anc.
526  '">'.$text.'</a>'.$trail;
527  }
528  }
529  else
530  {
531  $retVal = $text.$trail;
532  }
533  }
534 
535 //$ilCtrl->debug("ilWikiUtil::makeLink:-$inside-$trail-");
536 /* if ( $nt->isExternal() ) {
537  $nr = array_push( $this->mInterwikiLinkHolders['texts'], $prefix.$text.$inside );
538  $this->mInterwikiLinkHolders['titles'][] = $nt;
539  $retVal = '<!--IWLINK '. ($nr-1) ."-->{$trail}";
540  } else {
541  $nr = array_push( $this->mLinkHolders['namespaces'], $nt->getNamespace() );
542  $this->mLinkHolders['dbkeys'][] = $nt->getDBkey();
543  $this->mLinkHolders['queries'][] = $query;
544  $this->mLinkHolders['texts'][] = $prefix.$text.$inside;
545  $this->mLinkHolders['titles'][] = $nt;
546 
547  $retVal = '<!--LINK '. ($nr-1) ."-->{$trail}";
548  }
549 */
550  }
551  //wfProfileOut( __METHOD__ );
552 //echo "<br>".$retVal; exit;
553  return $retVal;
554  }
$_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.
$text
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 67 of file class.ilWikiUtil.php.

References $GLOBALS, $text, ilWikiPage\_wikiPageExists(), array, 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().

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

References array.

Referenced by makeDbTitle(), and makeUrlTitle().

427  {
428  return str_replace(array("\x00", "\n", "\r", "\\", "'", '"', "\x1a"), "", $a_str);
429  }
Create styles array
The data for the language used.
+ 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  {
44  return ilWikiUtil::processInternalLinks($s, $a_wiki_id,
45  IL_WIKI_MODE_REPLACE, false, $a_offline);
46  }
const IL_WIKI_MODE_REPLACE
Wiki link / page title handling:
static processInternalLinks($s, $a_wiki_id, $a_mode=IL_WIKI_MODE_REPLACE, $a_collect_non_ex=false, $a_offline=false)
Process internal links.
+ 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 642 of file class.ilWikiUtil.php.

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

643  {
644  global $ilUser, $ilObjDataCache, $ilAccess;
645 
646  include_once "./Services/Notification/classes/class.ilNotification.php";
647  include_once "./Modules/Wiki/classes/class.ilObjWiki.php";
648  include_once "./Modules/Wiki/classes/class.ilWikiPage.php";
649 
650  $wiki_id = $ilObjDataCache->lookupObjId($a_wiki_ref_id);
651  $wiki = new ilObjWiki($a_wiki_ref_id, true);
652  $page = new ilWikiPage($a_page_id);
653 
654  // #11138
655  $ignore_threshold = ($a_action == "comment");
656 
657  // 1st update will be converted to new - see below
658  if($a_action == "new")
659  {
660  return;
661  }
662 
664  {
665  $users = ilNotification::getNotificationsForObject($a_type, $a_page_id, null, $ignore_threshold);
666  $wiki_users = ilNotification::getNotificationsForObject(ilNotification::TYPE_WIKI, $wiki_id, $a_page_id, $ignore_threshold);
667  $users = array_merge($users, $wiki_users);
668  if(!sizeof($users))
669  {
670  return;
671  }
672 
674  }
675  else
676  {
677  $users = ilNotification::getNotificationsForObject(ilNotification::TYPE_WIKI, $wiki_id, $a_page_id, $ignore_threshold);
678  if(!sizeof($users))
679  {
680  return;
681  }
682  }
683 
685 
686  // #15192 - should always be present
687  include_once "./Services/Link/classes/class.ilLink.php";
688  if($a_page_id)
689  {
690  // #18804 - see ilWikiPageGUI::preview()
691  $link = ilLink::_getLink("", "wiki", null, "wpage_".$a_page_id."_".$a_wiki_ref_id);
692  }
693  else
694  {
695 
696  $link = ilLink::_getLink($a_wiki_ref_id);
697  }
698 
699  include_once "./Services/Mail/classes/class.ilMail.php";
700  include_once "./Services/User/classes/class.ilObjUser.php";
701  include_once "./Services/Language/classes/class.ilLanguageFactory.php";
702  include_once("./Services/User/classes/class.ilUserUtil.php");
703 
704 
705  // see ilBlogPostingGUI::getSnippet()
706  // see ilBlogPosting::getNotificationAbstract()
707 
708  include_once "Modules/Wiki/classes/class.ilWikiPageGUI.php";
709  $pgui = new ilWikiPageGUI($page->getId());
710  $pgui->setRawPageContent(true);
711  $pgui->setAbstractOnly(true);
712  $pgui->setFileDownloadLink(".");
713  $pgui->setFullscreenLink(".");
714  $pgui->setSourcecodeDownloadScript(".");
715  $snippet = $pgui->showPage();
716  $snippet = ilPageObject::truncateHTML($snippet, 500, "...");
717 
718  // making things more readable
719  $snippet = str_replace('<br/>', "\n", $snippet);
720  $snippet = str_replace('<br />', "\n", $snippet);
721  $snippet = str_replace('</p>', "\n", $snippet);
722  $snippet = str_replace('</div>', "\n", $snippet);
723 
724  $snippet = trim(strip_tags($snippet));
725 
726  // "fake" new (to enable snippet - if any)
727  $current_version = array_shift($page->getHistoryEntries());
728  $current_version = $current_version["nr"];
729  if(!$current_version)
730  {
732  $a_action = "new";
733  }
734 
735 
736  foreach(array_unique($users) as $idx => $user_id)
737  {
738  if($user_id != $ilUser->getId() &&
739  $ilAccess->checkAccessOfUser($user_id, 'read', '', $a_wiki_ref_id))
740  {
741  // use language of recipient to compose message
742  $ulng = ilLanguageFactory::_getLanguageOfUser($user_id);
743  $ulng->loadLanguageModule('wiki');
744 
745  $subject = sprintf($ulng->txt('wiki_change_notification_subject'), $wiki->getTitle(), $page->getTitle());
746  $message = sprintf($ulng->txt('wiki_change_notification_salutation'), ilObjUser::_lookupFullname($user_id))."\n\n";
747 
749  {
750  // update/delete
751  $message .= $ulng->txt('wiki_change_notification_page_body_'.$a_action).":\n\n";
752  $message .= $ulng->txt('wiki').": ".$wiki->getTitle()."\n";
753  $message .= $ulng->txt('page').": ".$page->getTitle()."\n";
754  $message .= $ulng->txt('wiki_changed_by').": ".ilUserUtil::getNamePresentation($ilUser->getId())."\n";
755 
756  if($snippet)
757  {
758  $message .= "\n".$ulng->txt('content')."\n".
759  "----------------------------------------\n".
760  $snippet."\n".
761  "----------------------------------------\n";
762  }
763 
764  // include comment/note text
765  if($a_comment)
766  {
767  $message .= "\n".$ulng->txt('comment').":\n\"".trim($a_comment)."\"\n";
768  }
769 
770  $message .= "\n".$ulng->txt('wiki_change_notification_page_link').": ".$link;
771  }
772  else
773  {
774  // new
775  $message .= $ulng->txt('wiki_change_notification_body_'.$a_action).":\n\n";
776  $message .= $ulng->txt('wiki').": ".$wiki->getTitle()."\n";
777  $message .= $ulng->txt('page').": ".$page->getTitle()."\n";
778  $message .= $ulng->txt('wiki_changed_by').": ".ilUserUtil::getNamePresentation($ilUser->getId())."\n\n";
779 
780  if($snippet)
781  {
782  $message .= $ulng->txt('content')."\n".
783  "----------------------------------------\n".
784  $snippet."\n".
785  "----------------------------------------\n\n";
786  }
787 
788  $message .= $ulng->txt('wiki_change_notification_link').": ".$link;
789  }
790 
791  $mail_obj = new ilMail(ANONYMOUS_USER_ID);
792  $mail_obj->appendInstallationSignature(true);
793  $mail_obj->sendMail(ilObjUser::_lookupLogin($user_id),
794  "", "", $subject, $message, array(), array("system"));
795  }
796  else
797  {
798  unset($users[$idx]);
799  }
800  }
801  }
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:93
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)
Default behaviour is:
This class handles base functions for mail handling.
Class ilObjWiki.
setRawPageContent($a_rawpagecontent)
Set Get raw page content only.
Class ilWikiPage GUI class.
$ilUser
Definition: imgupload.php:18
Class ilWikiPage.
Create styles array
The data for the language used.
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.
+ 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 620 of file class.ilWikiUtil.php.

References array.

Referenced by processInternalLinks().

621  {
622  /*static $regex = false;
623  if ( $regex === false ) {
624  global $wgContLang;
625  $regex = $wgContLang->linkTrail();
626  }*/
627  $regex = '/^([a-z]+)(.*)$/sD';
628 
629  $inside = '';
630  if ( '' != $trail ) {
631  $m = array();
632 
633  if ( preg_match( $regex, $trail, $m ) ) {
634  $inside = $m[1];
635  $trail = $m[2];
636  }
637  }
638 
639  return array( $inside, $trail );
640  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ wfUrlencode()

static ilWikiUtil::wfUrlencode (   $s)
static

From GlobalFunctions.php.

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

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

591  {
592  $s = urlencode( $s );
593 // $s = preg_replace( '/%3[Aa]/', ':', $s );
594 // $s = preg_replace( '/%2[Ff]/', '/', $s );
595 
596  return $s;
597  }
+ Here is the caller graph for this function:

◆ wfUrlProtocols()

static ilWikiUtil::wfUrlProtocols ( )
static

From mediawiki GlobalFunctions.php.

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

References array.

Referenced by processInternalLinks().

560  {
561  $wgUrlProtocols = array(
562  'http://',
563  'https://',
564  'ftp://',
565  'irc://',
566  'gopher://',
567  'telnet://', // Well if we're going to support the above.. -ævar
568  'nntp://', // @bug 3808 RFC 1738
569  'worldwind://',
570  'mailto:',
571  'news:'
572  );
573 
574  // Support old-style $wgUrlProtocols strings, for backwards compatibility
575  // with LocalSettings files from 1.5
576  if ( is_array( $wgUrlProtocols ) ) {
577  $protocols = array();
578  foreach ($wgUrlProtocols as $protocol)
579  $protocols[] = preg_quote( $protocol, '/' );
580 
581  return implode( '|', $protocols );
582  } else {
583  return $wgUrlProtocols;
584  }
585  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

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