ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilWikiPage.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/COPage/classes/class.ilPageObject.php");
5include_once("./Modules/Wiki/classes/class.ilWikiUtil.php");
15{
16 protected $blocked = false;
17 protected $rating = false; // [boo,]
18 protected $hide_adv_md = false; // [bool]
19
25 public function getParentType()
26 {
27 return "wpg";
28 }
29
36 public function afterConstructor()
37 {
38 $this->getPageConfig()->configureByObjectId($this->getParentId());
39 }
40
46 public function setTitle($a_title)
47 {
48 $this->title = ilWikiUtil::makeDbTitle($a_title);
49 }
50
56 public function getTitle()
57 {
58 return $this->title;
59 }
60
66 public function setWikiId($a_wikiid)
67 {
68 $this->setParentId($a_wikiid);
69 }
70
76 public function getWikiId()
77 {
78 return $this->getParentId();
79 }
80
86 public function setWikiRefId($a_wiki_ref_id)
87 {
88 $this->parent_ref_id = $a_wiki_ref_id;
89 }
90
96 public function getWikiRefId()
97 {
98 return $this->parent_ref_id;
99 }
100
106 public function setBlocked($a_val)
107 {
108 $this->blocked = $a_val;
109 }
110
116 public function getBlocked()
117 {
118 return $this->blocked;
119 }
120
126 public function setRating($a_val)
127 {
128 $this->rating = (bool) $a_val;
129 }
130
136 public function getRating()
137 {
138 return $this->rating;
139 }
140
146 public function hideAdvancedMetadata($a_val)
147 {
148 $this->hide_adv_md = (bool) $a_val;
149 }
150
156 public function isAdvancedMetadataHidden()
157 {
158 return $this->hide_adv_md;
159 }
160
164 public function createFromXML()
165 {
167
168 // ilWikiDataset creates wiki pages without copage objects
169 // (see create function in this class, parameter $a_prevent_page_creation)
170 // The ilCOPageImporter will call createFromXML without running through the read
171 // method -> we will miss the important wiki id, thus we read it now
172 // see also bug #12224
173 $set = $ilDB->query(
174 "SELECT id FROM il_wiki_page " .
175 " WHERE id = " . $ilDB->quote($this->getId(), "integer")
176 );
177 if ($rec = $ilDB->fetchAssoc($set)) {
178 $this->read(true);
179 }
180
181 parent::createFromXML();
182 }
183
187 public function create($a_prevent_page_creation = false)
188 {
190
191 $id = $ilDB->nextId("il_wiki_page");
192 $this->setId($id);
193 $query = "INSERT INTO il_wiki_page (" .
194 "id" .
195 ", title" .
196 ", wiki_id" .
197 ", blocked" .
198 ", rating" .
199 ", hide_adv_md" .
200 " ) VALUES (" .
201 $ilDB->quote($this->getId(), "integer")
202 . "," . $ilDB->quote($this->getTitle(), "text")
203 . "," . $ilDB->quote((int) $this->getWikiId(), "integer")
204 . "," . $ilDB->quote((int) $this->getBlocked(), "integer")
205 . "," . $ilDB->quote((int) $this->getRating(), "integer")
206 . "," . $ilDB->quote((int) $this->isAdvancedMetadataHidden(), "integer")
207 . ")";
208 $ilDB->manipulate($query);
209
210 // create page object
211 if (!$a_prevent_page_creation) {
212 parent::create();
213 $this->saveInternalLinks($this->getDomDoc());
214
215 include_once "./Modules/Wiki/classes/class.ilWikiStat.php";
217
218 include_once "./Services/Notification/classes/class.ilNotification.php";
220 }
221
222 $this->updateNews();
223 }
224
225 public function afterUpdate($a_domdoc = null, $a_xml = "")
226 {
227 // internal == wiki links
228 include_once "Modules/Wiki/classes/class.ilWikiUtil.php";
229 $this->log->debug("collect internal links");
230 $int_links = sizeof(ilWikiUtil::collectInternalLinks($a_xml, $this->getWikiId(), true));
231
232 $xpath = new DOMXPath($a_domdoc);
233
234 // external = internal + external links
235 $ext_links = sizeof($xpath->query('//IntLink'));
236 $ext_links += sizeof($xpath->query('//ExtLink'));
237
238 $footnotes = sizeof($xpath->query('//Footnote'));
239
240
241 // words/characters (xml)
242
243 $xml = strip_tags($a_xml);
244
245 include_once "Services/Utilities/classes/class.ilStr.php";
246 $num_chars = ilStr::strLen($xml);
247 $num_words = sizeof(explode(" ", $xml));
248
249 $page_data = array(
250 "int_links" => $int_links,
251 "ext_links" => $ext_links,
252 "footnotes" => $footnotes,
253 "num_words" => $num_words,
254 "num_chars" => $num_chars
255 );
256
257 include_once "./Modules/Wiki/classes/class.ilWikiStat.php";
258 $this->log->debug("handle stats");
260 }
261
268 public function update($a_validate = true, $a_no_history = false)
269 {
271 $this->log->debug("start...");
272 // update wiki page data
273 $query = "UPDATE il_wiki_page SET " .
274 " title = " . $ilDB->quote($this->getTitle(), "text") .
275 ",wiki_id = " . $ilDB->quote((int) $this->getWikiId(), "integer") .
276 ",blocked = " . $ilDB->quote((int) $this->getBlocked(), "integer") .
277 ",rating = " . $ilDB->quote((int) $this->getRating(), "integer") .
278 ",hide_adv_md = " . $ilDB->quote((int) $this->isAdvancedMetadataHidden(), "integer") .
279 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
280 $ilDB->manipulate($query);
281 $updated = parent::update($a_validate, $a_no_history);
282
283 if ($updated === true) {
284 include_once "./Services/Notification/classes/class.ilNotification.php";
285 $this->log->debug("send notification");
287
288 $this->log->debug("update news");
289 $this->updateNews(true);
290 } else {
291 return $updated;
292 }
293
294 return true;
295 }
296
300 public function read($a_omit_page_read = false)
301 {
303
304 $query = "SELECT * FROM il_wiki_page WHERE id = " .
305 $ilDB->quote($this->getId(), "integer");
306 $set = $ilDB->query($query);
307 $rec = $ilDB->fetchAssoc($set);
308
309 $this->setTitle($rec["title"]);
310 $this->setWikiId($rec["wiki_id"]);
311 $this->setBlocked($rec["blocked"]);
312 $this->setRating($rec["rating"]);
313 $this->hideAdvancedMetadata($rec["hide_adv_md"]);
314
315 // get co page
316 if (!$a_omit_page_read) {
317 parent::read();
318 }
319 }
320
321
327 public function delete()
328 {
330
331 // get other pages that link to this page
332 $linking_pages = ilWikiPage::getLinksToPage(
333 $this->getWikiId(),
334 $this->getId()
335 );
336
337 // delete important page
338 // note: the wiki might be already deleted here
339 if (ilObject::_exists($this->getWikiId())) {
340 $wiki = new ilObjWiki($this->getWikiId(), false);
341 if ($wiki->isImportantPage($this->getId())) {
342 $wiki->removeImportantPage($this->getId());
343 }
344 }
345
346 // delete internal links information to this page
347 include_once("./Services/Link/classes/class.ilInternalLink.php");
349
350 include_once "./Modules/Wiki/classes/class.ilWikiStat.php";
352
353 include_once "./Services/Notification/classes/class.ilNotification.php";
355
356 // remove all notifications
357 include_once "./Services/Notification/classes/class.ilNotification.php";
359
360 // delete record of table il_wiki_data
361 $query = "DELETE FROM il_wiki_page" .
362 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
363 $ilDB->manipulate($query);
364
365 // delete co page
366 parent::delete();
367
368 // make links of other pages to this page a missing link
369 foreach ($linking_pages as $lp) {
370 $ilDB->manipulateF(
371 "DELETE FROM il_wiki_missing_page " .
372 " WHERE wiki_id = %s AND source_id = %s AND target_name = %s ",
373 array("integer", "integer", "text"),
374 array($this->getWikiId(), $lp["id"], $this->getTitle())
375 );
376 $ilDB->manipulateF(
377 "INSERT INTO il_wiki_missing_page " .
378 "(wiki_id, source_id, target_name) VALUES " .
379 "(%s,%s,%s)",
380 array("integer", "integer", "text"),
381 array($this->getWikiId(), $lp["id"], $this->getTitle())
382 );
383 }
384
385 return true;
386 }
387
393 public static function deleteAllPagesOfWiki($a_wiki_id)
394 {
395 global $DIC;
396
397 $ilDB = $DIC->database();
398
399 // delete record of table il_wiki_data
400 $query = "SELECT * FROM il_wiki_page" .
401 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer");
402 $set = $ilDB->query($query);
403
404 while ($rec = $ilDB->fetchAssoc($set)) {
405 $wiki_page = new ilWikiPage($rec["id"]);
406 $wiki_page->delete();
407 }
408 }
409
413 public static function exists($a_wiki_id, $a_title)
414 {
415 global $DIC;
416
417 $ilDB = $DIC->database();
418
419 $a_title = ilWikiUtil::makeDbTitle($a_title);
420
421 $query = "SELECT id FROM il_wiki_page" .
422 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
423 " AND title = " . $ilDB->quote($a_title, "text");
424 $set = $ilDB->query($query);
425 if ($rec = $ilDB->fetchAssoc($set)) {
426 return true;
427 }
428
429 return false;
430 }
431
435 public static function getIdForPageTitle($a_wiki_id, $a_title)
436 {
437 global $DIC;
438
439 $ilDB = $DIC->database();
440
441 $a_title = ilWikiUtil::makeDbTitle($a_title);
442
443 $query = "SELECT id FROM il_wiki_page" .
444 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
445 " AND title = " . $ilDB->quote($a_title, "text");
446 $set = $ilDB->query($query);
447 if ($rec = $ilDB->fetchAssoc($set)) {
448 return $rec["id"];
449 }
450
451 return false;
452 }
453
457 public static function getPageIdForTitle($a_wiki_id, $a_title)
458 {
459 global $DIC;
460
461 $ilDB = $DIC->database();
462
463 $a_title = ilWikiUtil::makeDbTitle($a_title);
464
465 $query = "SELECT * FROM il_wiki_page" .
466 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
467 " AND title = " . $ilDB->quote($a_title, "text");
468 $set = $ilDB->query($query);
469 if ($rec = $ilDB->fetchAssoc($set)) {
470 return $rec["id"];
471 }
472
473 return false;
474 }
475
479 public static function lookupTitle($a_page_id)
480 {
481 global $DIC;
482
483 $ilDB = $DIC->database();
484
485 $query = "SELECT * FROM il_wiki_page" .
486 " WHERE id = " . $ilDB->quote($a_page_id, "integer");
487 $set = $ilDB->query($query);
488 if ($rec = $ilDB->fetchAssoc($set)) {
489 return $rec["title"];
490 }
491
492 return false;
493 }
494
498 public static function lookupWikiId($a_page_id)
499 {
500 global $DIC;
501
502 $ilDB = $DIC->database();
503
504 $query = "SELECT wiki_id FROM il_wiki_page" .
505 " WHERE id = " . $ilDB->quote($a_page_id, "integer");
506 $set = $ilDB->query($query);
507 if ($rec = $ilDB->fetchAssoc($set)) {
508 return $rec["wiki_id"];
509 }
510
511 return false;
512 }
513
519 public static function getAllWikiPages($a_wiki_id)
520 {
521 global $DIC;
522
523 $ilDB = $DIC->database();
524
525 $pages = parent::getAllPages("wpg", $a_wiki_id);
526
527 $query = "SELECT * FROM il_wiki_page" .
528 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
529 " ORDER BY title";
530 $set = $ilDB->query($query);
531
532 $pg = array();
533 while ($rec = $ilDB->fetchAssoc($set)) {
534 if (isset($pages[$rec["id"]])) {
535 $pg[$rec["id"]] = $pages[$rec["id"]];
536 $pg[$rec["id"]]["title"] = $rec["title"];
537 }
538 }
539
540 return $pg;
541 }
542
546 public static function getLinksToPage($a_wiki_id, $a_page_id)
547 {
548 global $DIC;
549
550 $ilDB = $DIC->database();
551
552 include_once("./Services/Link/classes/class.ilInternalLink.php");
553 $sources = ilInternalLink::_getSourcesOfTarget("wpg", $a_page_id, 0);
554
555 $ids = array();
556 foreach ($sources as $source) {
557 if ($source["type"] == "wpg:pg") {
558 $ids[] = $source["id"];
559 }
560 }
561 // get wiki page record
562 $query = "SELECT * FROM il_wiki_page wp, page_object p" .
563 " WHERE " . $ilDB->in("wp.id", $ids, false, "integer") .
564 " AND wp.id = p.page_id AND p.parent_type = " . $ilDB->quote("wpg", "text") .
565 " AND wp.wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
566 " ORDER BY title";
567 $set = $ilDB->query($query);
568
569 $pages = array();
570 while ($rec = $ilDB->fetchAssoc($set)) {
571 $pages[] = array_merge($rec, array("user" => $rec["last_change_user"],
572 "date" => $rec["last_change"]));
573 }
574
575 return $pages;
576 }
577
583 public static function getOrphanedPages($a_wiki_id)
584 {
585 global $DIC;
586
587 $ilDB = $DIC->database();
588
589 $pages = ilWikiPage::getAllWikiPages($a_wiki_id);
590
591 include_once("./Services/Link/classes/class.ilInternalLink.php");
592
593 $orphaned = array();
594 foreach ($pages as $k => $page) {
595 $sources = ilInternalLink::_getSourcesOfTarget("wpg", $page["id"], 0);
596
597 $ids = array();
598 foreach ($sources as $source) {
599 if ($source["type"] == "wpg:pg") {
600 $ids[] = $source["id"];
601 }
602 }
603 $query = "SELECT count(*) cnt FROM il_wiki_page" .
604 " WHERE " . $ilDB->in("id", $ids, false, "integer") .
605 " AND wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
606 " GROUP BY wiki_id";
607 $set = $ilDB->query($query);
608 $rec = $ilDB->fetchAssoc($set);
609 if ($rec["cnt"] == 0 &&
610 ilObjWiki::_lookupStartPage($a_wiki_id) != $page["title"]) {
611 $orphaned[] = $page;
612 }
613 }
614
615 return $orphaned;
616 }
617
623 public static function _wikiPageExists($a_wiki_id, $a_title)
624 {
625 global $DIC;
626
627 $ilDB = $DIC->database();
628
629 $a_title = ilWikiUtil::makeDbTitle($a_title);
630
631 $query = "SELECT id FROM il_wiki_page" .
632 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
633 " AND title = " . $ilDB->quote($a_title, "text");
634 $set = $ilDB->query($query);
635
636 $pages = array();
637 if ($rec = $ilDB->fetchAssoc($set)) {
638 return true;
639 }
640
641 return false;
642 }
643
649 public static function getWikiContributors($a_wiki_id)
650 {
651 global $DIC;
652
653 $ilDB = $DIC->database();
654
655 $contributors = parent::getParentObjectContributors("wpg", $a_wiki_id);
656
657 return $contributors;
658 }
659
665 public static function getWikiPageContributors($a_page_id)
666 {
667 global $DIC;
668
669 $ilDB = $DIC->database();
670
671 $contributors = parent::getPageContributors("wpg", $a_page_id);
672
673 return $contributors;
674 }
675
676
682 public function saveInternalLinks($a_domdoc)
683 {
685
686 $this->log->debug("start...");
687 // *** STEP 1: Standard Processing ***
688
689 parent::saveInternalLinks($a_domdoc);
690
691
692 // *** STEP 2: Other Pages -> This Page ***
693
694 // Check, whether ANOTHER page links to this page as a "missing" page
695 // (this is the case, when this page is created newly)
696 $set = $ilDB->queryF(
697 "SELECT * FROM il_wiki_missing_page WHERE " .
698 " wiki_id = %s AND target_name = %s",
699 array("integer", "text"),
700 array($this->getWikiId(), ilWikiUtil::makeDbTitle($this->getTitle()))
701 );
702 while ($anmiss = $ilDB->fetchAssoc($set)) { // insert internal links instead
703 //echo "adding link";
705 "wpg:pg",
706 $anmiss["source_id"],
707 "wpg",
708 $this->getId(),
709 0
710 );
711 }
712 //exit;
713 // now remove the missing page entries
714 $ilDB->manipulateF(
715 "DELETE FROM il_wiki_missing_page WHERE " .
716 " wiki_id = %s AND target_name = %s",
717 array("integer", "text"),
718 array($this->getWikiId(), $this->getTitle())
719 );
720
721
722 // *** STEP 3: This Page -> Other Pages ***
723
724 // remove the exising "missing page" links for THIS page (they will be re-inserted below)
725 $ilDB->manipulateF(
726 "DELETE FROM il_wiki_missing_page WHERE " .
727 " wiki_id = %s AND source_id = %s",
728 array("integer", "integer"),
729 array($this->getWikiId(), $this->getId())
730 );
731
732 // collect the wiki links of the page
733 include_once("./Modules/Wiki/classes/class.ilWikiUtil.php");
734 $xml = $a_domdoc->saveXML();
735 $int_wiki_links = ilWikiUtil::collectInternalLinks($xml, $this->getWikiId(), true);
736 foreach ($int_wiki_links as $wlink) {
737 $page_id = ilWikiPage::_getPageIdForWikiTitle($this->getWikiId(), $wlink);
738
739 if ($page_id > 0) { // save internal link for existing page
741 "wpg:pg",
742 $this->getId(),
743 "wpg",
744 $page_id,
745 0
746 );
747 } else { // save missing link for non-existing page
748 $ilDB->manipulateF(
749 "DELETE FROM il_wiki_missing_page WHERE" .
750 " wiki_id = %s AND source_id = %s AND target_name = %s",
751 array("integer", "integer", "text"),
752 array($this->getWikiId(), $this->getId(), $wlink)
753 );
754 $ilDB->manipulateF(
755 "INSERT INTO il_wiki_missing_page (wiki_id, source_id, target_name)" .
756 " VALUES (%s,%s,%s)",
757 array("integer", "integer", "text"),
758 array($this->getWikiId(), $this->getId(), $wlink)
759 );
760 }
761 }
762 $this->log->debug("...end");
763 }
764
768 public static function _getPageIdForWikiTitle($a_wiki_id, $a_title)
769 {
770 global $DIC;
771
772 $ilDB = $DIC->database();
773
774 $query = "SELECT id FROM il_wiki_page" .
775 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
776 " AND title = " . $ilDB->quote($a_title, "text");
777 $set = $ilDB->query($query);
778 if ($rec = $ilDB->fetchAssoc($set)) {
779 return $rec["id"];
780 }
781
782 return false;
783 }
784
790 public static function getPopularPages($a_wiki_id)
791 {
792 global $DIC;
793
794 $ilDB = $DIC->database();
795
796 $query = "SELECT wp.*, po.view_cnt as cnt FROM il_wiki_page wp, page_object po" .
797 " WHERE wp.wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
798 " AND wp.id = po.page_id " .
799 " AND po.parent_type = " . $ilDB->quote("wpg", "text") . " " .
800 " ORDER BY po.view_cnt";
801 $set = $ilDB->query($query);
802
803 $pages = array();
804 while ($rec = $ilDB->fetchAssoc($set)) {
805 $pages[] = $rec;
806 }
807
808 return $pages;
809 }
810
816 public static function countPages($a_wiki_id)
817 {
818 global $DIC;
819
820 $ilDB = $DIC->database();
821
822 // delete record of table il_wiki_data
823 $query = "SELECT count(*) as cnt FROM il_wiki_page" .
824 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer");
825 $s = $ilDB->query($query);
826 $r = $ilDB->fetchAssoc($s);
827
828 return $r["cnt"];
829 }
830
836 public static function getRandomPage($a_wiki_id)
837 {
838 global $DIC;
839
840 $ilDB = $DIC->database();
841
842 $cnt = ilWikiPage::countPages($a_wiki_id);
843
844 if ($cnt < 1) {
845 return "";
846 }
847
848 $random = new \ilRandom();
849 $rand = $random->int(1, $cnt);
850
851 // delete record of table il_wiki_data
852 $ilDB->setLimit(1, $rand);
853 $query = "SELECT title FROM il_wiki_page" .
854 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer");
855 $s = $ilDB->query($query);
856 $r = $ilDB->fetchAssoc($s);
857
858 return $r["title"];
859 }
860
866 public static function getNewWikiPages($a_wiki_id)
867 {
868 global $DIC;
869
870 $ilDB = $DIC->database();
871
872 $pages = parent::getNewPages("wpg", $a_wiki_id);
873
874 foreach ($pages as $k => $page) {
875 $pages[$k]["title"] = ilWikiPage::lookupTitle($page["id"]);
876 }
877
878 return $pages;
879 }
880
881
888 public static function lookupObjIdByPage($a_page_id)
889 {
890 global $DIC;
891
892 $ilDB = $DIC->database();
893
894 $query = "SELECT wiki_id FROM il_wiki_page" .
895 " WHERE id = " . $ilDB->quote($a_page_id, "integer");
896 $set = $ilDB->query($query);
897 if ($rec = $ilDB->fetchAssoc($set)) {
898 return $rec["wiki_id"];
899 }
900
901 return false;
902 }
903
907 public function rename($a_new_name)
908 {
910
911 // replace unallowed characters
912 $a_new_name = str_replace(array("<", ">"), '', $a_new_name);
913
914 // replace multiple whitespace characters by one single space
915 $a_new_name = trim(preg_replace('!\s+!', ' ', $a_new_name));
916
917 $page_title = ilWikiUtil::makeDbTitle($a_new_name);
918 $pg_id = ilWikiPage::_getPageIdForWikiTitle($this->getWikiId(), $page_title);
919
920 $xml_new_name = str_replace("&", "&amp;", $a_new_name);
921
922 if ($pg_id == 0 || $pg_id == $this->getId()) {
923 include_once("./Services/Link/classes/class.ilInternalLink.php");
924 $sources = ilInternalLink::_getSourcesOfTarget("wpg", $this->getId(), 0);
925
926 foreach ($sources as $s) {
927 if ($s["type"] == "wpg:pg" && ilPageObject::_exists("wpg", $s["id"])) {
928 $wpage = new ilWikiPage($s["id"]);
929
931 $wpage->getXmlContent(),
932 0,
934 );
935 $new_content = $wpage->getXmlContent();
936 foreach ($col as $c) {
937
938 // this complicated procedure is needed due to the fact
939 // that depending on the collation e = é is true
940 // in the (mysql) database
941 // see bug http://www.ilias.de/mantis/view.php?id=11227
942 $t1 = ilWikiUtil::makeDbTitle($c["nt"]->mTextform);
943 $t2 = ilWikiUtil::makeDbTitle($this->getTitle());
944
945 // this one replaces C2A0 (&nbsp;) by a usual space
946 // otherwise the comparision will fail, since you
947 // get these characters from tiny if more than one
948 // space is repeated in a string. This may not be
949 // 100% but we do not store $t1 anywhere and only
950 // modify it for the comparison
951 $t1 = preg_replace('/\xC2\xA0/', ' ', $t1);
952 $t2 = preg_replace('/\xC2\xA0/', ' ', $t2);
953
954 $set = $ilDB->query($q = "SELECT " . $ilDB->quote($t1, "text") . " = " . $ilDB->quote($t2, "text") . " isequal");
955 $rec = $ilDB->fetchAssoc($set);
956
957 if ($rec["isequal"]) {
958 $new_content =
959 str_replace(
960 "[[" . $c["nt"]->mTextform . "]]",
961 "[[" . $xml_new_name . "]]",
962 $new_content
963 );
964 if ($c["text"] != "") {
965 $new_content =
966 str_replace(
967 "[[" . $c["text"] . "]]",
968 "[[" . $xml_new_name . "]]",
969 $new_content
970 );
971 }
972 $add = ($c["text"] != "")
973 ? "|" . $c["text"]
974 : "";
975 $new_content =
976 str_replace(
977 "[[" . $c["nt"]->mTextform . $add . "]]",
978 "[[" . $xml_new_name . $add . "]]",
979 $new_content
980 );
981 }
982 }
983 $wpage->setXmlContent($new_content);
984 //echo htmlentities($new_content);
985 $wpage->update();
986 }
987 }
988
989 include_once("./Modules/Wiki/classes/class.ilObjWiki.php");
990 if (ilObjWiki::_lookupStartPage($this->getWikiId()) == $this->getTitle()) {
991 ilObjWiki::writeStartPage($this->getWikiId(), $a_new_name);
992 }
993
994 $this->setTitle($a_new_name);
995
996 $this->update();
997 }
998
999 return $a_new_name;
1000 }
1001
1002
1006 public function updateNews($a_update = false)
1007 {
1009
1010 $news_set = new ilSetting("news");
1011 $default_visibility = ($news_set->get("default_visibility") != "")
1012 ? $news_set->get("default_visibility")
1013 : "users";
1014
1015 include_once("./Services/News/classes/class.ilNewsItem.php");
1016 if (!$a_update) {
1017 $news_item = new ilNewsItem();
1018 $news_item->setContext(
1019 $this->getWikiId(),
1020 "wiki",
1021 $this->getId(),
1022 "wpg"
1023 );
1024 $news_item->setPriority(NEWS_NOTICE);
1025 $news_item->setTitle($this->getTitle());
1026 $news_item->setContentTextIsLangVar(true);
1027 $news_item->setContent("wiki_news_page_created");
1028 $news_item->setUserId($ilUser->getId());
1029 $news_item->setVisibility($default_visibility);
1030 $news_item->create();
1031 } else {
1032 // get last news item of the day (if existing)
1034 $this->getWikiId(),
1035 "wiki",
1036 $this->getId(),
1037 "wpg",
1038 true
1039 );
1040
1041 if ($news_id > 0) {
1042 $news_item = new ilNewsItem($news_id);
1043 $news_item->setContent("wiki_news_page_changed");
1044 $news_item->setUserId($ilUser->getId());
1045 $news_item->setTitle($this->getTitle());
1046 $news_item->setContentTextIsLangVar(true);
1047 $news_item->update(true);
1048 } else {
1049 $news_item = new ilNewsItem();
1050 $news_item->setContext(
1051 $this->getWikiId(),
1052 "wiki",
1053 $this->getId(),
1054 "wpg"
1055 );
1056 $news_item->setPriority(NEWS_NOTICE);
1057 $news_item->setTitle($this->getTitle());
1058 $news_item->setContentTextIsLangVar(true);
1059 $news_item->setContent("wiki_news_page_changed");
1060 $news_item->setUserId($ilUser->getId());
1061 $news_item->setVisibility($default_visibility);
1062 $news_item->create();
1063 }
1064 }
1065 }
1066
1070 public function getNewsContent()
1071 {
1072 return "12.1.1: Test User, Max";
1073 }
1074
1081 public static function getGotoForWikiPageTarget($a_target, $a_offline = false)
1082 {
1083 if (!$a_offline) {
1084 $href = "./goto.php?target=wiki_wpage_" . $a_target;
1085 } else {
1086 $href = ILIAS_HTTP_PATH . "/goto.php?target=wiki_wpage_" . $a_target;
1087 }
1088 return $href;
1089 }
1090
1091
1097 public function getContentTemplates()
1098 {
1099 include_once("./Modules/Wiki/classes/class.ilWikiPageTemplate.php");
1100 $wt = new ilWikiPageTemplate($this->getWikiId());
1101 $templates = array();
1102 foreach ($wt->getAllInfo(ilWikiPageTemplate::TYPE_ADD_TO_PAGE) as $t) {
1103 $templates[] = array("id" => $t["wpage_id"], "parent_type" => "wpg", "title" => $t["title"]);
1104 }
1105 return $templates;
1106 }
1107
1114 public static function getPagesForSearch($a_wiki_id, $a_term)
1115 {
1116 global $DIC;
1117
1118 $ilDB = $DIC->database();
1119
1120 $set = $ilDB->query("SELECT DISTINCT title FROM il_wiki_page" .
1121 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
1122 " AND " . $ilDB->like("title", "text", "%" . $a_term . "%") .
1123 " ORDER by title");
1124 $res = array();
1125 while ($rec = $ilDB->fetchAssoc($set)) {
1126 $res[] = $rec["title"];
1127 }
1128
1129 return $res;
1130 }
1131
1132 public static function lookupAdvancedMetadataHidden($a_page_id)
1133 {
1134 global $DIC;
1135
1136 $ilDB = $DIC->database();
1137
1138 $query = "SELECT * FROM il_wiki_page" .
1139 " WHERE id = " . $ilDB->quote($a_page_id, "integer");
1140 $set = $ilDB->query($query);
1141 if ($rec = $ilDB->fetchAssoc($set)) {
1142 return (bool) $rec["hide_adv_md"];
1143 }
1144
1145 return false;
1146 }
1147}
An exception for terminatinating execution or to throw for unit testing.
const NEWS_NOTICE
const IL_WIKI_MODE_EXT_COLLECT
static getLastNewsIdForContext( $a_context_obj_id, $a_context_obj_type, $a_context_sub_obj_id="", $a_context_sub_obj_type="", $a_only_today=false)
Get last news id of news set related to a certain context.
static removeForObject($type, $id)
Remove all notifications for given object.
Class ilObjWiki.
static writeStartPage($a_id, $a_name)
Write start page.
static _lookupStartPage($a_wiki_id)
Lookup start page.
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
read()
Read page data.
getPageConfig()
Get page config object.
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
getDomDoc()
Get dom doc (php5 dom document)
setId($a_id)
set id
ILIAS Setting Class.
static strLen($a_string)
Definition: class.ilStr.php:78
Class ilWikiPage.
getBlocked()
Get blocked.
create($a_prevent_page_creation=false)
Create new wiki page.
isAdvancedMetadataHidden()
Get adv md visibility status.
getTitle()
Get Title.
getContentTemplates()
Get content templates.
hideAdvancedMetadata($a_val)
Toggle adv md visibility.
setWikiId($a_wikiid)
Set Wiki Object Id.
getRating()
Get rating.
afterUpdate($a_domdoc=null, $a_xml="")
saveInternalLinks($a_domdoc)
save internal links of page
static lookupAdvancedMetadataHidden($a_page_id)
update($a_validate=true, $a_no_history=false)
update object data
static deleteAllPagesOfWiki($a_wiki_id)
delete wiki page and al related data
static exists($a_wiki_id, $a_title)
Checks whether a page with given title exists.
static getGotoForWikiPageTarget($a_target, $a_offline=false)
Get goto href for internal wiki page link target.
getWikiRefId()
Get Wiki Ref Id.
createFromXML()
Create page from xml.
static getPagesForSearch($a_wiki_id, $a_term)
Get pages for search.
static getPageIdForTitle($a_wiki_id, $a_title)
Get wiki page object for id and title.
static _wikiPageExists($a_wiki_id, $a_title)
Check whether page exists for wiki or not.
static getWikiContributors($a_wiki_id)
Get all contributors of wiki.
static getOrphanedPages($a_wiki_id)
Get orphaned pages of wiki.
static getAllWikiPages($a_wiki_id)
Get all pages of wiki.
setWikiRefId($a_wiki_ref_id)
Set Wiki Ref Id.
static getWikiPageContributors($a_page_id)
Get all contributors of wiki.
static countPages($a_wiki_id)
Count pages of wiki.
getWikiId()
Get Wiki Object Id.
static getLinksToPage($a_wiki_id, $a_page_id)
Get links to a page.
getNewsContent()
Get content for a wiki news item.
setRating($a_val)
Set rating.
getParentType()
Get parent type.
static lookupTitle($a_page_id)
Checks whether a page with given title exists.
setBlocked($a_val)
Set blocked.
static getNewWikiPages($a_wiki_id)
Get all pages of wiki.
static lookupObjIdByPage($a_page_id)
returns the wiki/object id to a given page id
static _getPageIdForWikiTitle($a_wiki_id, $a_title)
Checks whether a page with given title exists.
static getPopularPages($a_wiki_id)
Get popular pages of wiki.
rename($a_new_name)
Rename page.
updateNews($a_update=false)
Create.
afterConstructor()
After constructor.
static getRandomPage($a_wiki_id)
Get a random page.
read($a_omit_page_read=false)
Read wiki data.
setTitle($a_title)
Set Title.
static lookupWikiId($a_page_id)
Lookup wiki id.
static getIdForPageTitle($a_wiki_id, $a_title)
Checks whether a page with given title exists.
const EVENT_PAGE_UPDATED
const EVENT_PAGE_CREATED
const EVENT_PAGE_DELETED
static handleEvent($a_event, ilWikiPage $a_page_obj, $a_user_id=null, array $a_additional_data=null)
Handle wiki page event.
static processInternalLinks( $s, $a_wiki_id, $a_mode=IL_WIKI_MODE_REPLACE, $a_collect_non_ex=false, $a_offline=false)
Process internal links.
static sendNotification($a_action, $a_type, $a_wiki_ref_id, $a_page_id, $a_comment=null)
static makeDbTitle($a_par)
Handle page GET parameter.
static collectInternalLinks($s, $a_wiki_id, $a_collect_non_ex=false)
Collect internal wiki links of a string.
$c
Definition: cli.php:37
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
$source
Definition: metadata.php:76
$query
foreach($_POST as $key=> $value) $res
global $ilDB