ILIAS  release_8 Revision v8.24
class.ilWikiPage.php
Go to the documentation of this file.
1<?php
2
25{
26 protected int $parent_ref_id = 0;
27 protected string $title = "";
28 protected bool $blocked = false;
29 protected bool $rating = false;
30 protected bool $hide_adv_md = false;
31
32 public function getParentType(): string
33 {
34 return "wpg";
35 }
36
37 public function afterConstructor(): void
38 {
39 $this->getPageConfig()->configureByObjectId($this->getParentId());
40 }
41
42 public function setTitle(string $a_title): void
43 {
44 $this->title = ilWikiUtil::makeDbTitle($a_title);
45 }
46
47 public function getTitle(): string
48 {
49 return $this->title;
50 }
51
52 public function setWikiId(int $a_wikiid): void
53 {
54 $this->setParentId($a_wikiid);
55 }
56
57 public function getWikiId(): int
58 {
59 return $this->getParentId();
60 }
61
62 public function setWikiRefId(int $a_wiki_ref_id): void
63 {
64 $this->parent_ref_id = $a_wiki_ref_id;
65 }
66
67 public function getWikiRefId(): int
68 {
70 }
71
72 public function setBlocked(bool $a_val): void
73 {
74 $this->blocked = $a_val;
75 }
76
77 public function getBlocked(): bool
78 {
79 return $this->blocked;
80 }
81
82 public function setRating(bool $a_val): void
83 {
84 $this->rating = $a_val;
85 }
86
87 public function getRating(): bool
88 {
89 return $this->rating;
90 }
91
92 public function hideAdvancedMetadata(bool $a_val): void
93 {
94 $this->hide_adv_md = $a_val;
95 }
96
97 public function isAdvancedMetadataHidden(): bool
98 {
99 return $this->hide_adv_md;
100 }
101
102 public function createFromXML(): void
103 {
105
106 // ilWikiDataset creates wiki pages without copage objects
107 // (see create function in this class, parameter $a_prevent_page_creation)
108 // The ilCOPageImporter will call createFromXML without running through the read
109 // method -> we will miss the important wiki id, thus we read it now
110 // see also bug #12224
111 $set = $ilDB->query(
112 "SELECT id FROM il_wiki_page " .
113 " WHERE id = " . $ilDB->quote($this->getId(), "integer")
114 );
115 if ($rec = $ilDB->fetchAssoc($set)) {
116 $this->read(true);
117 }
118
119 parent::createFromXML();
120 }
121
122 public function create(
123 bool $a_import = false
124 ): void {
125 $ilDB = $this->db;
126
127 $id = $ilDB->nextId("il_wiki_page");
128 $this->setId($id);
129 $query = "INSERT INTO il_wiki_page (" .
130 "id" .
131 ", title" .
132 ", wiki_id" .
133 ", blocked" .
134 ", rating" .
135 ", hide_adv_md" .
136 " ) VALUES (" .
137 $ilDB->quote($this->getId(), "integer")
138 . "," . $ilDB->quote($this->getTitle(), "text")
139 . "," . $ilDB->quote($this->getWikiId(), "integer")
140 . "," . $ilDB->quote((int) $this->getBlocked(), "integer")
141 . "," . $ilDB->quote((int) $this->getRating(), "integer")
142 . "," . $ilDB->quote((int) $this->isAdvancedMetadataHidden(), "integer")
143 . ")";
144 $ilDB->manipulate($query);
145
146 // create page object
147 if (!$a_import) {
148 parent::create($a_import);
149 $this->saveInternalLinks($this->getDomDoc());
150
153 }
154
155 $this->updateNews();
156 }
157
158 public function afterUpdate(
159 DOMDocument $domdoc,
160 string $xml
161 ): void {
162 // internal == wiki links
163
164 $this->log->debug("collect internal links");
165 $int_links = count(ilWikiUtil::collectInternalLinks($xml, $this->getWikiId(), true));
166
167 $xpath = new DOMXPath($domdoc);
168
169 // external = internal + external links
170 $ext_links = count($xpath->query('//IntLink'));
171 $ext_links += count($xpath->query('//ExtLink'));
172
173 $footnotes = count($xpath->query('//Footnote'));
174
175
176 // words/characters (xml)
177
178 $xml = strip_tags($xml);
179
180 $num_chars = ilStr::strLen($xml);
181 $num_words = count(explode(" ", $xml));
182
183 $page_data = array(
184 "int_links" => $int_links,
185 "ext_links" => $ext_links,
186 "footnotes" => $footnotes,
187 "num_words" => $num_words,
188 "num_chars" => $num_chars
189 );
190 $this->log->debug("handle stats");
192 }
193
198 public function update(
199 bool $a_validate = true,
200 bool $a_no_history = false
201 ) {
202 $ilDB = $this->db;
203 $this->log->debug("start...");
204 // update wiki page data
205 $query = "UPDATE il_wiki_page SET " .
206 " title = " . $ilDB->quote($this->getTitle(), "text") .
207 ",wiki_id = " . $ilDB->quote($this->getWikiId(), "integer") .
208 ",blocked = " . $ilDB->quote((int) $this->getBlocked(), "integer") .
209 ",rating = " . $ilDB->quote((int) $this->getRating(), "integer") .
210 ",hide_adv_md = " . $ilDB->quote((int) $this->isAdvancedMetadataHidden(), "integer") .
211 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
212 $ilDB->manipulate($query);
213 $updated = parent::update($a_validate, $a_no_history);
214
215 if ($updated === true) {
216 $this->log->debug("send notification");
217 ilWikiUtil::sendNotification("update", ilNotification::TYPE_WIKI_PAGE, $this->getWikiRefId(), $this->getId());
218
219 $this->log->debug("update news");
220 $this->updateNews(true);
221 } else {
222 return $updated;
223 }
224
225 return true;
226 }
227
228 public function read(
229 bool $a_omit_page_read = false
230 ): void {
231 $ilDB = $this->db;
232
233 $query = "SELECT * FROM il_wiki_page WHERE id = " .
234 $ilDB->quote($this->getId(), "integer");
235 $set = $ilDB->query($query);
236 $rec = $ilDB->fetchAssoc($set);
237
238 $this->setTitle($rec["title"]);
239 $this->setWikiId((int) $rec["wiki_id"]);
240 $this->setBlocked((bool) $rec["blocked"]);
241 $this->setRating((bool) $rec["rating"]);
242 $this->hideAdvancedMetadata((bool) $rec["hide_adv_md"]);
243
244 // get co page
245 if (!$a_omit_page_read) {
246 parent::read();
247 }
248 }
249
250
251 public function delete(): void
252 {
253 $ilDB = $this->db;
254
255 // get other pages that link to this page
256 $linking_pages = self::getLinksToPage(
257 $this->getWikiId(),
258 $this->getId()
259 );
260
261 // delete important page
262 // note: the wiki might be already deleted here
263 if (ilObject::_exists($this->getWikiId())) {
264 $wiki = new ilObjWiki($this->getWikiId(), false);
265 if ($wiki->isImportantPage($this->getId())) {
266 $wiki->removeImportantPage($this->getId());
267 }
268 }
269
270 // delete internal links information to this page
272
274
275 ilWikiUtil::sendNotification("delete", ilNotification::TYPE_WIKI_PAGE, $this->getWikiRefId(), $this->getId());
276
277 // remove all notifications
279
280 // delete record of table il_wiki_data
281 $query = "DELETE FROM il_wiki_page" .
282 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
283 $ilDB->manipulate($query);
284
285 // delete co page
286 parent::delete();
287
288 // make links of other pages to this page a missing link
289 foreach ($linking_pages as $lp) {
290 $ilDB->manipulateF(
291 "DELETE FROM il_wiki_missing_page " .
292 " WHERE wiki_id = %s AND source_id = %s AND target_name = %s ",
293 array("integer", "integer", "text"),
294 array($this->getWikiId(), $lp["id"], $this->getTitle())
295 );
296 $ilDB->manipulateF(
297 "INSERT INTO il_wiki_missing_page " .
298 "(wiki_id, source_id, target_name) VALUES " .
299 "(%s,%s,%s)",
300 array("integer", "integer", "text"),
301 array($this->getWikiId(), $lp["id"], $this->getTitle())
302 );
303 }
304 }
305
306 public static function deleteAllPagesOfWiki(int $a_wiki_id): void
307 {
308 global $DIC;
309
310 $ilDB = $DIC->database();
311
312 // delete record of table il_wiki_data
313 $query = "SELECT * FROM il_wiki_page" .
314 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer");
315 $set = $ilDB->query($query);
316
317 while ($rec = $ilDB->fetchAssoc($set)) {
318 $wiki_page = new ilWikiPage($rec["id"]);
319 $wiki_page->delete();
320 }
321 }
322
326 public static function exists(
327 int $a_wiki_id,
328 string $a_title
329 ): bool {
330 global $DIC;
331
332 $ilDB = $DIC->database();
333
334 $a_title = ilWikiUtil::makeDbTitle($a_title);
335
336 $query = "SELECT id FROM il_wiki_page" .
337 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
338 " AND title = " . $ilDB->quote($a_title, "text");
339 $set = $ilDB->query($query);
340 if ($rec = $ilDB->fetchAssoc($set)) {
341 return true;
342 }
343
344 return false;
345 }
346
347
351 public static function getPageIdForTitle(
352 int $a_wiki_id,
353 string $a_title
354 ): ?int {
355 global $DIC;
356
357 $ilDB = $DIC->database();
358
359 $a_title = ilWikiUtil::makeDbTitle($a_title);
360
361 $query = "SELECT * FROM il_wiki_page" .
362 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
363 " AND title = " . $ilDB->quote($a_title, "text");
364 $set = $ilDB->query($query);
365 if ($rec = $ilDB->fetchAssoc($set)) {
366 return (int) $rec["id"];
367 }
368
369 return null;
370 }
371
372 public static function lookupTitle(int $a_page_id): ?string
373 {
374 global $DIC;
375
376 $ilDB = $DIC->database();
377
378 $query = "SELECT * FROM il_wiki_page" .
379 " WHERE id = " . $ilDB->quote($a_page_id, "integer");
380 $set = $ilDB->query($query);
381 if ($rec = $ilDB->fetchAssoc($set)) {
382 return (string) $rec["title"];
383 }
384 return null;
385 }
386
387 public static function lookupWikiId(
388 int $a_page_id
389 ): ?int {
390 global $DIC;
391
392 $ilDB = $DIC->database();
393
394 $query = "SELECT wiki_id FROM il_wiki_page" .
395 " WHERE id = " . $ilDB->quote($a_page_id, "integer");
396 $set = $ilDB->query($query);
397 if ($rec = $ilDB->fetchAssoc($set)) {
398 return (int) $rec["wiki_id"];
399 }
400
401 return null;
402 }
403
404 public static function getAllWikiPages(
405 int $a_wiki_id
406 ): array {
407 global $DIC;
408
409 $ilDB = $DIC->database();
410
411 $pages = parent::getAllPages("wpg", $a_wiki_id);
412
413 $query = "SELECT * FROM il_wiki_page" .
414 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
415 " ORDER BY title";
416 $set = $ilDB->query($query);
417
418 $pg = array();
419 while ($rec = $ilDB->fetchAssoc($set)) {
420 if (isset($pages[$rec["id"]])) {
421 $pg[$rec["id"]] = $pages[$rec["id"]];
422 $pg[$rec["id"]]["title"] = $rec["title"];
423 }
424 }
425
426 return $pg;
427 }
428
429 public static function getLinksToPage(
430 int $a_wiki_id,
431 int $a_page_id
432 ): array {
433 global $DIC;
434
435 $ilDB = $DIC->database();
436
437 $sources = ilInternalLink::_getSourcesOfTarget("wpg", $a_page_id, 0);
438
439 $ids = array();
440 foreach ($sources as $source) {
441 if ($source["type"] === "wpg:pg") {
442 $ids[] = $source["id"];
443 }
444 }
445 // get wiki page record
446 $query = "SELECT * FROM il_wiki_page wp, page_object p" .
447 " WHERE " . $ilDB->in("wp.id", $ids, false, "integer") .
448 " AND wp.id = p.page_id AND p.parent_type = " . $ilDB->quote("wpg", "text") .
449 " AND wp.wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
450 " ORDER BY title";
451 $set = $ilDB->query($query);
452
453 $pages = array();
454 while ($rec = $ilDB->fetchAssoc($set)) {
455 $pages[] = array_merge($rec, array("user" => $rec["last_change_user"],
456 "date" => $rec["last_change"]));
457 }
458
459 return $pages;
460 }
461
462 public static function getOrphanedPages(
463 int $a_wiki_id
464 ): array {
465 global $DIC;
466
467 $ilDB = $DIC->database();
468
469 $pages = self::getAllWikiPages($a_wiki_id);
470
471 $orphaned = array();
472 foreach ($pages as $k => $page) {
473 $sources = ilInternalLink::_getSourcesOfTarget("wpg", $page["id"], 0);
474 $ids = array();
475 foreach ($sources as $source) {
476 if ($source["type"] === "wpg:pg") {
477 $ids[] = $source["id"];
478 }
479 }
480 $query = "SELECT count(*) cnt FROM il_wiki_page" .
481 " WHERE " . $ilDB->in("id", $ids, false, "integer") .
482 " AND wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
483 " GROUP BY wiki_id";
484 $set = $ilDB->query($query);
485 $rec = $ilDB->fetchAssoc($set);
486 if (count($ids) === 0 || ($rec && (int) $rec["cnt"] === 0)) {
487 if (ilObjWiki::_lookupStartPage($a_wiki_id) !== $page["title"]) {
488 $orphaned[] = $page;
489 }
490 }
491 }
492
493 return $orphaned;
494 }
495
496 public static function _wikiPageExists(
497 int $a_wiki_id,
498 string $a_title
499 ): bool {
500 global $DIC;
501
502 $ilDB = $DIC->database();
503
504 $a_title = ilWikiUtil::makeDbTitle($a_title);
505
506 $query = "SELECT id FROM il_wiki_page" .
507 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
508 " AND title = " . $ilDB->quote($a_title, "text");
509 $set = $ilDB->query($query);
510
511 if ($ilDB->fetchAssoc($set)) {
512 return true;
513 }
514
515 return false;
516 }
517
518 public static function getWikiContributors(
519 int $a_wiki_id
520 ): array {
521 return parent::getParentObjectContributors("wpg", $a_wiki_id);
522 }
523
524 public static function getWikiPageContributors(
525 int $a_page_id
526 ): array {
527 return parent::getPageContributors("wpg", $a_page_id);
528 }
529
530 public function saveInternalLinks(
531 DOMDocument $a_domdoc
532 ): void {
533 $ilDB = $this->db;
534
535 $this->log->debug("start...");
536 // *** STEP 1: Standard Processing ***
537
538 parent::saveInternalLinks($a_domdoc);
539
540
541 // *** STEP 2: Other Pages -> This Page ***
542 $this->log->debug("this page <- other pages.");
543
544 // Check, whether ANOTHER page links to this page as a "missing" page
545 // (this is the case, when this page is created newly)
546 $set = $ilDB->queryF(
547 "SELECT * FROM il_wiki_missing_page WHERE " .
548 " wiki_id = %s AND target_name = %s",
549 array("integer", "text"),
550 array($this->getWikiId(), ilWikiUtil::makeDbTitle($this->getTitle()))
551 );
552 while ($anmiss = $ilDB->fetchAssoc($set)) { // insert internal links instead
553 $this->log->debug("link found, source: " . $anmiss["source_id"] . ", target" .
554 $this->getId());
555 //echo "adding link";
557 "wpg:pg",
558 $anmiss["source_id"],
559 "wpg",
560 $this->getId(),
561 0
562 );
563 }
564 //exit;
565 // now remove the missing page entries
566 $ilDB->manipulateF(
567 "DELETE FROM il_wiki_missing_page WHERE " .
568 " wiki_id = %s AND target_name = %s",
569 array("integer", "text"),
570 array($this->getWikiId(), $this->getTitle())
571 );
572
573
574 // *** STEP 3: This Page -> Other Pages ***
575 $this->log->debug("this page -> other pages.");
576
577 // remove the exising "missing page" links for THIS page (they will be re-inserted below)
578 $ilDB->manipulateF(
579 "DELETE FROM il_wiki_missing_page WHERE " .
580 " wiki_id = %s AND source_id = %s",
581 array("integer", "integer"),
582 array($this->getWikiId(), $this->getId())
583 );
584
585 // collect the wiki links of the page
586 $xml = $a_domdoc->saveXML();
587 $int_wiki_links = ilWikiUtil::collectInternalLinks($xml, $this->getWikiId(), true);
588 foreach ($int_wiki_links as $wlink) {
589 $this->log->debug("found link : " . $wlink);
590 $page_id = self::_getPageIdForWikiTitle($this->getWikiId(), $wlink);
591 if ($page_id > 0) { // save internal link for existing page
592 $this->log->debug("save link " .
593 $this->getId() . ", target " . $page_id);
595 "wpg:pg",
596 $this->getId(),
597 "wpg",
598 $page_id,
599 0
600 );
601 } else { // save missing link for non-existing page
602 $ilDB->manipulateF(
603 "DELETE FROM il_wiki_missing_page WHERE" .
604 " wiki_id = %s AND source_id = %s AND target_name = %s",
605 array("integer", "integer", "text"),
606 array($this->getWikiId(), $this->getId(), $wlink)
607 );
608 $this->log->debug("target does not exist, save missing page source" .
609 $this->getId() . ", target " . $wlink);
610 $ilDB->manipulateF(
611 "INSERT INTO il_wiki_missing_page (wiki_id, source_id, target_name)" .
612 " VALUES (%s,%s,%s)",
613 array("integer", "integer", "text"),
614 array($this->getWikiId(), $this->getId(), $wlink)
615 );
616 }
617 }
618 $this->log->debug("...end");
619 }
620
624 public static function _getPageIdForWikiTitle(
625 int $a_wiki_id,
626 string $a_title
627 ): ?int {
628 return self::getPageIdForTitle($a_wiki_id, $a_title);
629 }
630
631 public static function getPopularPages(
632 int $a_wiki_id
633 ): array {
634 global $DIC;
635
636 $ilDB = $DIC->database();
637
638 $query = "SELECT wp.*, po.view_cnt as cnt FROM il_wiki_page wp, page_object po" .
639 " WHERE wp.wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
640 " AND wp.id = po.page_id " .
641 " AND po.parent_type = " . $ilDB->quote("wpg", "text") . " " .
642 " ORDER BY po.view_cnt";
643 $set = $ilDB->query($query);
644
645 $pages = array();
646 while ($rec = $ilDB->fetchAssoc($set)) {
647 $pages[] = $rec;
648 }
649
650 return $pages;
651 }
652
653 public static function countPages(
654 int $a_wiki_id
655 ): int {
656 global $DIC;
657
658 $ilDB = $DIC->database();
659
660 // delete record of table il_wiki_data
661 $query = "SELECT count(*) as cnt FROM il_wiki_page" .
662 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer");
663 $s = $ilDB->query($query);
664 $r = $ilDB->fetchAssoc($s);
665
666 return $r["cnt"];
667 }
668
669 public static function getRandomPage(
670 int $a_wiki_id
671 ): string {
672 global $DIC;
673
674 $ilDB = $DIC->database();
675
676 $cnt = self::countPages($a_wiki_id);
677
678 if ($cnt < 1) {
679 return "";
680 }
681
682 $random = new \ilRandom();
683 $rand = $random->int(1, $cnt);
684
685 // delete record of table il_wiki_data
686 $ilDB->setLimit(1, $rand);
687 $query = "SELECT title FROM il_wiki_page" .
688 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer");
689 $s = $ilDB->query($query);
690 $r = $ilDB->fetchAssoc($s);
691
692 return $r["title"];
693 }
694
695 public static function getNewWikiPages(
696 int $a_wiki_id
697 ): array {
698 $pages = parent::getNewPages("wpg", $a_wiki_id);
699 foreach ($pages as $k => $page) {
700 $pages[$k]["title"] = self::lookupTitle($page["id"]);
701 }
702
703 return $pages;
704 }
705
706
710 public static function lookupObjIdByPage(
711 int $a_page_id
712 ): ?int {
713 global $DIC;
714
715 $ilDB = $DIC->database();
716
717 $query = "SELECT wiki_id FROM il_wiki_page" .
718 " WHERE id = " . $ilDB->quote($a_page_id, "integer");
719 $set = $ilDB->query($query);
720 if ($rec = $ilDB->fetchAssoc($set)) {
721 return (int) $rec["wiki_id"];
722 }
723
724 return null;
725 }
726
730 public function rename(
731 string $a_new_name
732 ): string {
733 $ilDB = $this->db;
734
735 // replace unallowed characters
736 $a_new_name = str_replace(array("<", ">"), '', $a_new_name);
737
738 // replace multiple whitespace characters by one single space
739 $a_new_name = trim(preg_replace('!\s+!', ' ', $a_new_name));
740
741 $page_title = ilWikiUtil::makeDbTitle($a_new_name);
742 $pg_id = self::_getPageIdForWikiTitle($this->getWikiId(), $page_title);
743
744 $xml_new_name = str_replace("&", "&amp;", $a_new_name);
745
746 if ($pg_id == 0 || $pg_id == $this->getId()) {
747 $sources = ilInternalLink::_getSourcesOfTarget("wpg", $this->getId(), 0);
748
749 $this->log->debug("nr of pages linking to renamed page: " . count($sources));
750 foreach ($sources as $s) {
751 if ($s["type"] === "wpg:pg" && ilPageObject::_exists("wpg", $s["id"])) {
752 $wpage = new ilWikiPage($s["id"]);
753 $wiki_id = ilWikiPage::lookupWikiId($s["id"]);
754 $this->log->debug("Getting links of page " . $s["id"]);
756 $wpage->getXMLContent(),
757 $wiki_id,
758 false,
760 );
761 $this->log->debug("nr internal links: " . count($col));
762 $new_content = $wpage->getXMLContent();
763 foreach ($col as $c) {
764
765 $this->log->debug("found link " . print_r($c, true));
766
767 // this complicated procedure is needed due to the fact
768 // that depending on the collation e = é is true
769 // in the (mysql) database
770 // see bug http://www.ilias.de/mantis/view.php?id=11227
771 $t1 = ilWikiUtil::makeDbTitle($c["nt"]->mTextform);
772 $t2 = ilWikiUtil::makeDbTitle($this->getTitle());
773
774 // this one replaces C2A0 (&nbsp;) by a usual space
775 // otherwise the comparision will fail, since you
776 // get these characters from tiny if more than one
777 // space is repeated in a string. This may not be
778 // 100% but we do not store $t1 anywhere and only
779 // modify it for the comparison
780 $t1 = preg_replace('/\xC2\xA0/', ' ', $t1);
781 $t2 = preg_replace('/\xC2\xA0/', ' ', $t2);
782
783 $set = $ilDB->query($q = "SELECT " . $ilDB->quote($t1, "text") . " = " . $ilDB->quote($t2, "text") . " isequal");
784 $rec = $ilDB->fetchAssoc($set);
785
786 if ($rec["isequal"]) {
787 $new_content =
788 str_replace(
789 "[[" . $c["nt"]->mTextform . "]]",
790 "[[" . $xml_new_name . "]]",
791 $new_content
792 );
793 if ($c["text"] != "") {
794 $new_content =
795 str_replace(
796 "[[" . $c["text"] . "]]",
797 "[[" . $xml_new_name . "]]",
798 $new_content
799 );
800 }
801 $add = ($c["text"] != "")
802 ? "|" . $c["text"]
803 : "";
804 $new_content =
805 str_replace(
806 "[[" . $c["nt"]->mTextform . $add . "]]",
807 "[[" . $xml_new_name . $add . "]]",
808 $new_content
809 );
810 }
811 }
812 $wpage->setXMLContent($new_content);
813 //echo htmlentities($new_content);
814 $wpage->update();
815 }
816 }
817
818 if (ilObjWiki::_lookupStartPage($this->getWikiId()) === $this->getTitle()) {
819 ilObjWiki::writeStartPage($this->getWikiId(), $a_new_name);
820 }
821
822 $this->setTitle($a_new_name);
823
824 $this->update();
825 }
826
827 return $a_new_name;
828 }
829
830
831 public function updateNews(
832 bool $a_update = false
833 ): void {
834 $ilUser = $this->user;
835
836 $news_set = new ilSetting("news");
837 $default_visibility = ($news_set->get("default_visibility") != "")
838 ? $news_set->get("default_visibility")
839 : "users";
840
841 if (!$a_update) {
842 $news_item = new ilNewsItem();
843 $news_item->setContext(
844 $this->getWikiId(),
845 "wiki",
846 $this->getId(),
847 "wpg"
848 );
849 $news_item->setPriority(NEWS_NOTICE);
850 $news_item->setTitle($this->getTitle());
851 $news_item->setContentTextIsLangVar(true);
852 $news_item->setContent("wiki_news_page_created");
853 $news_item->setUserId($ilUser->getId());
854 $news_item->setVisibility($default_visibility);
855 $news_item->create();
856 } else {
857 // get last news item of the day (if existing)
859 $this->getWikiId(),
860 "wiki",
861 $this->getId(),
862 "wpg",
863 true
864 );
865
866 if ($news_id > 0) {
867 $news_item = new ilNewsItem($news_id);
868 $news_item->setContent("wiki_news_page_changed");
869 $news_item->setUserId($ilUser->getId());
870 $news_item->setTitle($this->getTitle());
871 $news_item->setContentTextIsLangVar(true);
872 $news_item->update(true);
873 } else {
874 $news_item = new ilNewsItem();
875 $news_item->setContext(
876 $this->getWikiId(),
877 "wiki",
878 $this->getId(),
879 "wpg"
880 );
881 $news_item->setPriority(NEWS_NOTICE);
882 $news_item->setTitle($this->getTitle());
883 $news_item->setContentTextIsLangVar(true);
884 $news_item->setContent("wiki_news_page_changed");
885 $news_item->setUserId($ilUser->getId());
886 $news_item->setVisibility($default_visibility);
887 $news_item->create();
888 }
889 }
890 }
891
892 public static function getGotoForWikiPageTarget(
893 string $a_target,
894 bool $a_offline = false
895 ): string {
896 if (!$a_offline) {
897 $href = "./goto.php?target=wiki_wpage_" . $a_target;
898 } else {
899 $href = ILIAS_HTTP_PATH . "/goto.php?target=wiki_wpage_" . $a_target;
900 }
901 return $href;
902 }
903
904
909 public function getContentTemplates(): array
910 {
911 $wt = new ilWikiPageTemplate($this->getWikiId());
912 $templates = array();
913 foreach ($wt->getAllInfo(ilWikiPageTemplate::TYPE_ADD_TO_PAGE) as $t) {
914 $templates[] = array("id" => $t["wpage_id"], "parent_type" => "wpg", "title" => $t["title"]);
915 }
916 return $templates;
917 }
918
919 public static function getPagesForSearch(
920 int $a_wiki_id,
921 string $a_term
922 ): array {
923 global $DIC;
924
925 $ilDB = $DIC->database();
926
927 $set = $ilDB->query("SELECT DISTINCT title FROM il_wiki_page" .
928 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
929 " AND " . $ilDB->like("title", "text", "%" . $a_term . "%") .
930 " ORDER by title");
931 $res = array();
932 while ($rec = $ilDB->fetchAssoc($set)) {
933 $res[] = $rec["title"];
934 }
935
936 return $res;
937 }
938
939 public static function lookupAdvancedMetadataHidden(
940 int $a_page_id
941 ): bool {
942 global $DIC;
943
944 $ilDB = $DIC->database();
945
946 $query = "SELECT * FROM il_wiki_page" .
947 " WHERE id = " . $ilDB->quote($a_page_id, "integer");
948 $set = $ilDB->query($query);
949 if ($rec = $ilDB->fetchAssoc($set)) {
950 return (bool) $rec["hide_adv_md"];
951 }
952
953 return false;
954 }
955
956 protected function preparePageForCompare(ilPageObject $page) : void
957 {
958 $page->setWikiRefId($this->getWikiRefId());
959 }
960}
const NEWS_NOTICE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_WIKI_MODE_EXT_COLLECT
A news item can be created by different sources.
static getLastNewsIdForContext(int $a_context_obj_id, string $a_context_obj_type, int $a_context_sub_obj_id=0, string $a_context_sub_obj_type="", bool $a_only_today=false)
Get last news id of news set related to a certain context.
static removeForObject(int $type, int $id)
Remove all notifications for given object.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static writeStartPage(int $a_id, string $a_name)
static _lookupStartPage(int $a_wiki_id)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
read()
Read page data.
ilDBInterface $db
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
setParentId(int $a_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static strLen(string $a_string)
Definition: class.ilStr.php:63
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
updateNews(bool $a_update=false)
static getAllWikiPages(int $a_wiki_id)
create(bool $a_import=false)
create new page (with current xml data)
getContentTemplates()
Get content templates.
static lookupObjIdByPage(int $a_page_id)
returns the wiki/object id to a given page id
static getPagesForSearch(int $a_wiki_id, string $a_term)
setWikiRefId(int $a_wiki_ref_id)
static exists(int $a_wiki_id, string $a_title)
Checks whether a page with given title exists.
setRating(bool $a_val)
update(bool $a_validate=true, bool $a_no_history=false)
static getWikiPageContributors(int $a_page_id)
static lookupWikiId(int $a_page_id)
createFromXML()
Create new page object with current xml content.
preparePageForCompare(ilPageObject $page)
afterUpdate(DOMDocument $domdoc, string $xml)
After update.
setBlocked(bool $a_val)
hideAdvancedMetadata(bool $a_val)
static lookupAdvancedMetadataHidden(int $a_page_id)
setWikiId(int $a_wikiid)
setTitle(string $a_title)
saveInternalLinks(DOMDocument $a_domdoc)
save internal links of page
static getWikiContributors(int $a_wiki_id)
read(bool $a_omit_page_read=false)
static getLinksToPage(int $a_wiki_id, int $a_page_id)
static getPageIdForTitle(int $a_wiki_id, string $a_title)
Get wiki page object for id and title.
rename(string $a_new_name)
Rename page.
static getPopularPages(int $a_wiki_id)
static countPages(int $a_wiki_id)
static getNewWikiPages(int $a_wiki_id)
static getGotoForWikiPageTarget(string $a_target, bool $a_offline=false)
static deleteAllPagesOfWiki(int $a_wiki_id)
static getRandomPage(int $a_wiki_id)
static _wikiPageExists(int $a_wiki_id, string $a_title)
static lookupTitle(int $a_page_id)
static _getPageIdForWikiTitle(int $a_wiki_id, string $a_title)
static getOrphanedPages(int $a_wiki_id)
const EVENT_PAGE_UPDATED
static handleEvent(int $a_event, ilWikiPage $a_page_obj, ?int $a_user_id=null, array $a_additional_data=null)
Handle wiki page event.
const EVENT_PAGE_CREATED
const EVENT_PAGE_DELETED
static sendNotification(string $a_action, int $a_type, int $a_wiki_ref_id, int $a_page_id, ?string $a_comment=null)
static collectInternalLinks(string $s, int $a_wiki_id, bool $a_collect_non_ex=false, string $mode=IL_WIKI_MODE_COLLECT)
Collect internal wiki links of a string.
static makeDbTitle(string $a_par)
$c
Definition: cli.php:38
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
$res
Definition: ltiservices.php:69
$source
Definition: metadata.php:93
$xml
Definition: metadata.php:351
int $updated
Timestamp for when the object was last updated.
Definition: System.php:158
$query