ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 $int_links = sizeof(ilWikiUtil::collectInternalLinks($a_xml, $this->getWikiId(), true));
230
231 $xpath = new DOMXPath($a_domdoc);
232
233 // external = internal + external links
234 $ext_links = sizeof($xpath->query('//IntLink'));
235 $ext_links += sizeof($xpath->query('//ExtLink'));
236
237 $footnotes = sizeof($xpath->query('//Footnote'));
238
239
240 // words/characters (xml)
241
242 $xml = strip_tags($a_xml);
243
244 include_once "Services/Utilities/classes/class.ilStr.php";
245 $num_chars = ilStr::strLen($xml);
246 $num_words = sizeof(explode(" ", $xml));
247
248 $page_data = array(
249 "int_links" => $int_links,
250 "ext_links" => $ext_links,
251 "footnotes" => $footnotes,
252 "num_words" => $num_words,
253 "num_chars" => $num_chars
254 );
255
256 include_once "./Modules/Wiki/classes/class.ilWikiStat.php";
258 }
259
266 public function update($a_validate = true, $a_no_history = false)
267 {
269
270 // update wiki page data
271 $query = "UPDATE il_wiki_page SET " .
272 " title = " . $ilDB->quote($this->getTitle(), "text") .
273 ",wiki_id = " . $ilDB->quote((int) $this->getWikiId(), "integer") .
274 ",blocked = " . $ilDB->quote((int) $this->getBlocked(), "integer") .
275 ",rating = " . $ilDB->quote((int) $this->getRating(), "integer") .
276 ",hide_adv_md = " . $ilDB->quote((int) $this->isAdvancedMetadataHidden(), "integer") .
277 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
278 $ilDB->manipulate($query);
279 $updated = parent::update($a_validate, $a_no_history);
280
281 if ($updated === true) {
282 include_once "./Services/Notification/classes/class.ilNotification.php";
284
285 $this->updateNews(true);
286 } else {
287 return $updated;
288 }
289
290 return true;
291 }
292
296 public function read($a_omit_page_read = false)
297 {
299
300 $query = "SELECT * FROM il_wiki_page WHERE id = " .
301 $ilDB->quote($this->getId(), "integer");
302 $set = $ilDB->query($query);
303 $rec = $ilDB->fetchAssoc($set);
304
305 $this->setTitle($rec["title"]);
306 $this->setWikiId($rec["wiki_id"]);
307 $this->setBlocked($rec["blocked"]);
308 $this->setRating($rec["rating"]);
309 $this->hideAdvancedMetadata($rec["hide_adv_md"]);
310
311 // get co page
312 if (!$a_omit_page_read) {
313 parent::read();
314 }
315 }
316
317
323 public function delete()
324 {
326
327 // get other pages that link to this page
328 $linking_pages = ilWikiPage::getLinksToPage(
329 $this->getWikiId(),
330 $this->getId()
331 );
332
333 // delete internal links information to this page
334 include_once("./Services/Link/classes/class.ilInternalLink.php");
336
337 include_once "./Modules/Wiki/classes/class.ilWikiStat.php";
339
340 include_once "./Services/Notification/classes/class.ilNotification.php";
342
343 // remove all notifications
344 include_once "./Services/Notification/classes/class.ilNotification.php";
346
347 // delete record of table il_wiki_data
348 $query = "DELETE FROM il_wiki_page" .
349 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
350 $ilDB->manipulate($query);
351
352 // delete co page
353 parent::delete();
354
355 // make links of other pages to this page a missing link
356 foreach ($linking_pages as $lp) {
357 $ilDB->manipulateF(
358 "DELETE FROM il_wiki_missing_page " .
359 " WHERE wiki_id = %s AND source_id = %s AND target_name = %s ",
360 array("integer", "integer", "text"),
361 array($this->getWikiId(), $lp["id"], $this->getTitle())
362 );
363 $ilDB->manipulateF(
364 "INSERT INTO il_wiki_missing_page " .
365 "(wiki_id, source_id, target_name) VALUES " .
366 "(%s,%s,%s)",
367 array("integer", "integer", "text"),
368 array($this->getWikiId(), $lp["id"], $this->getTitle())
369 );
370 }
371
372 return true;
373 }
374
380 public static function deleteAllPagesOfWiki($a_wiki_id)
381 {
382 global $DIC;
383
384 $ilDB = $DIC->database();
385
386 // delete record of table il_wiki_data
387 $query = "SELECT * FROM il_wiki_page" .
388 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer");
389 $set = $ilDB->query($query);
390
391 while ($rec = $ilDB->fetchAssoc($set)) {
392 $wiki_page = new ilWikiPage($rec["id"]);
393 $wiki_page->delete();
394 }
395 }
396
400 public static function exists($a_wiki_id, $a_title)
401 {
402 global $DIC;
403
404 $ilDB = $DIC->database();
405
406 $a_title = ilWikiUtil::makeDbTitle($a_title);
407
408 $query = "SELECT id FROM il_wiki_page" .
409 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
410 " AND title = " . $ilDB->quote($a_title, "text");
411 $set = $ilDB->query($query);
412 if ($rec = $ilDB->fetchAssoc($set)) {
413 return true;
414 }
415
416 return false;
417 }
418
422 public static function getIdForPageTitle($a_wiki_id, $a_title)
423 {
424 global $DIC;
425
426 $ilDB = $DIC->database();
427
428 $a_title = ilWikiUtil::makeDbTitle($a_title);
429
430 $query = "SELECT id FROM il_wiki_page" .
431 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
432 " AND title = " . $ilDB->quote($a_title, "text");
433 $set = $ilDB->query($query);
434 if ($rec = $ilDB->fetchAssoc($set)) {
435 return $rec["id"];
436 }
437
438 return false;
439 }
440
444 public static function getPageIdForTitle($a_wiki_id, $a_title)
445 {
446 global $DIC;
447
448 $ilDB = $DIC->database();
449
450 $a_title = ilWikiUtil::makeDbTitle($a_title);
451
452 $query = "SELECT * FROM il_wiki_page" .
453 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
454 " AND title = " . $ilDB->quote($a_title, "text");
455 $set = $ilDB->query($query);
456 if ($rec = $ilDB->fetchAssoc($set)) {
457 return $rec["id"];
458 }
459
460 return false;
461 }
462
466 public static function lookupTitle($a_page_id)
467 {
468 global $DIC;
469
470 $ilDB = $DIC->database();
471
472 $query = "SELECT * FROM il_wiki_page" .
473 " WHERE id = " . $ilDB->quote($a_page_id, "integer");
474 $set = $ilDB->query($query);
475 if ($rec = $ilDB->fetchAssoc($set)) {
476 return $rec["title"];
477 }
478
479 return false;
480 }
481
485 public static function lookupWikiId($a_page_id)
486 {
487 global $DIC;
488
489 $ilDB = $DIC->database();
490
491 $query = "SELECT wiki_id FROM il_wiki_page" .
492 " WHERE id = " . $ilDB->quote($a_page_id, "integer");
493 $set = $ilDB->query($query);
494 if ($rec = $ilDB->fetchAssoc($set)) {
495 return $rec["wiki_id"];
496 }
497
498 return false;
499 }
500
506 public static function getAllWikiPages($a_wiki_id)
507 {
508 global $DIC;
509
510 $ilDB = $DIC->database();
511
512 $pages = parent::getAllPages("wpg", $a_wiki_id);
513
514 $query = "SELECT * FROM il_wiki_page" .
515 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
516 " ORDER BY title";
517 $set = $ilDB->query($query);
518
519 $pg = array();
520 while ($rec = $ilDB->fetchAssoc($set)) {
521 if (isset($pages[$rec["id"]])) {
522 $pg[$rec["id"]] = $pages[$rec["id"]];
523 $pg[$rec["id"]]["title"] = $rec["title"];
524 }
525 }
526
527 return $pg;
528 }
529
533 public static function getLinksToPage($a_wiki_id, $a_page_id)
534 {
535 global $DIC;
536
537 $ilDB = $DIC->database();
538
539 include_once("./Services/Link/classes/class.ilInternalLink.php");
540 $sources = ilInternalLink::_getSourcesOfTarget("wpg", $a_page_id, 0);
541
542 $ids = array();
543 foreach ($sources as $source) {
544 if ($source["type"] == "wpg:pg") {
545 $ids[] = $source["id"];
546 }
547 }
548 // get wiki page record
549 $query = "SELECT * FROM il_wiki_page wp, page_object p" .
550 " WHERE " . $ilDB->in("wp.id", $ids, false, "integer") .
551 " AND wp.id = p.page_id AND p.parent_type = " . $ilDB->quote("wpg", "text") .
552 " AND wp.wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
553 " ORDER BY title";
554 $set = $ilDB->query($query);
555
556 $pages = array();
557 while ($rec = $ilDB->fetchAssoc($set)) {
558 $pages[] = array_merge($rec, array("user" => $rec["last_change_user"],
559 "date" => $rec["last_change"]));
560 }
561
562 return $pages;
563 }
564
570 public static function getOrphanedPages($a_wiki_id)
571 {
572 global $DIC;
573
574 $ilDB = $DIC->database();
575
576 $pages = ilWikiPage::getAllWikiPages($a_wiki_id);
577
578 include_once("./Services/Link/classes/class.ilInternalLink.php");
579
580 $orphaned = array();
581 foreach ($pages as $k => $page) {
582 $sources = ilInternalLink::_getSourcesOfTarget("wpg", $page["id"], 0);
583
584 $ids = array();
585 foreach ($sources as $source) {
586 if ($source["type"] == "wpg:pg") {
587 $ids[] = $source["id"];
588 }
589 }
590 $query = "SELECT count(*) cnt FROM il_wiki_page" .
591 " WHERE " . $ilDB->in("id", $ids, false, "integer") .
592 " AND wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
593 " GROUP BY wiki_id";
594 $set = $ilDB->query($query);
595 $rec = $ilDB->fetchAssoc($set);
596 if ($rec["cnt"] == 0 &&
597 ilObjWiki::_lookupStartPage($a_wiki_id) != $page["title"]) {
598 $orphaned[] = $page;
599 }
600 }
601
602 return $orphaned;
603 }
604
610 public static function _wikiPageExists($a_wiki_id, $a_title)
611 {
612 global $DIC;
613
614 $ilDB = $DIC->database();
615
616 $a_title = ilWikiUtil::makeDbTitle($a_title);
617
618 $query = "SELECT id FROM il_wiki_page" .
619 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
620 " AND title = " . $ilDB->quote($a_title, "text");
621 $set = $ilDB->query($query);
622
623 $pages = array();
624 if ($rec = $ilDB->fetchAssoc($set)) {
625 return true;
626 }
627
628 return false;
629 }
630
636 public static function getWikiContributors($a_wiki_id)
637 {
638 global $DIC;
639
640 $ilDB = $DIC->database();
641
642 $contributors = parent::getParentObjectContributors("wpg", $a_wiki_id);
643
644 return $contributors;
645 }
646
652 public static function getWikiPageContributors($a_page_id)
653 {
654 global $DIC;
655
656 $ilDB = $DIC->database();
657
658 $contributors = parent::getPageContributors("wpg", $a_page_id);
659
660 return $contributors;
661 }
662
663
669 public function saveInternalLinks($a_domdoc)
670 {
672
673
674 // *** STEP 1: Standard Processing ***
675
676 parent::saveInternalLinks($a_domdoc);
677
678
679 // *** STEP 2: Other Pages -> This Page ***
680
681 // Check, whether ANOTHER page links to this page as a "missing" page
682 // (this is the case, when this page is created newly)
683 $set = $ilDB->queryF(
684 "SELECT * FROM il_wiki_missing_page WHERE " .
685 " wiki_id = %s AND target_name = %s",
686 array("integer", "text"),
687 array($this->getWikiId(), ilWikiUtil::makeDbTitle($this->getTitle()))
688 );
689 while ($anmiss = $ilDB->fetchAssoc($set)) { // insert internal links instead
690 //echo "adding link";
692 "wpg:pg",
693 $anmiss["source_id"],
694 "wpg",
695 $this->getId(),
696 0
697 );
698 }
699 //exit;
700 // now remove the missing page entries
701 $ilDB->manipulateF(
702 "DELETE FROM il_wiki_missing_page WHERE " .
703 " wiki_id = %s AND target_name = %s",
704 array("integer", "text"),
705 array($this->getWikiId(), $this->getTitle())
706 );
707
708
709 // *** STEP 3: This Page -> Other Pages ***
710
711 // remove the exising "missing page" links for THIS page (they will be re-inserted below)
712 $ilDB->manipulateF(
713 "DELETE FROM il_wiki_missing_page WHERE " .
714 " wiki_id = %s AND source_id = %s",
715 array("integer", "integer"),
716 array($this->getWikiId(), $this->getId())
717 );
718
719 // collect the wiki links of the page
720 include_once("./Modules/Wiki/classes/class.ilWikiUtil.php");
721 $xml = $a_domdoc->saveXML();
722 $int_wiki_links = ilWikiUtil::collectInternalLinks($xml, $this->getWikiId(), true);
723 foreach ($int_wiki_links as $wlink) {
724 $page_id = ilWikiPage::_getPageIdForWikiTitle($this->getWikiId(), $wlink);
725
726 if ($page_id > 0) { // save internal link for existing page
728 "wpg:pg",
729 $this->getId(),
730 "wpg",
731 $page_id,
732 0
733 );
734 } else { // save missing link for non-existing page
735 $ilDB->manipulateF(
736 "DELETE FROM il_wiki_missing_page WHERE" .
737 " wiki_id = %s AND source_id = %s AND target_name = %s",
738 array("integer", "integer", "text"),
739 array($this->getWikiId(), $this->getId(), $wlink)
740 );
741 $ilDB->manipulateF(
742 "INSERT INTO il_wiki_missing_page (wiki_id, source_id, target_name)" .
743 " VALUES (%s,%s,%s)",
744 array("integer", "integer", "text"),
745 array($this->getWikiId(), $this->getId(), $wlink)
746 );
747 }
748 }
749 }
750
754 public static function _getPageIdForWikiTitle($a_wiki_id, $a_title)
755 {
756 global $DIC;
757
758 $ilDB = $DIC->database();
759
760 $query = "SELECT id FROM il_wiki_page" .
761 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
762 " AND title = " . $ilDB->quote($a_title, "text");
763 $set = $ilDB->query($query);
764 if ($rec = $ilDB->fetchAssoc($set)) {
765 return $rec["id"];
766 }
767
768 return false;
769 }
770
776 public static function getPopularPages($a_wiki_id)
777 {
778 global $DIC;
779
780 $ilDB = $DIC->database();
781
782 $query = "SELECT wp.*, po.view_cnt as cnt FROM il_wiki_page wp, page_object po" .
783 " WHERE wp.wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
784 " AND wp.id = po.page_id " .
785 " AND po.parent_type = " . $ilDB->quote("wpg", "text") . " " .
786 " ORDER BY po.view_cnt";
787 $set = $ilDB->query($query);
788
789 $pages = array();
790 while ($rec = $ilDB->fetchAssoc($set)) {
791 $pages[] = $rec;
792 }
793
794 return $pages;
795 }
796
802 public static function countPages($a_wiki_id)
803 {
804 global $DIC;
805
806 $ilDB = $DIC->database();
807
808 // delete record of table il_wiki_data
809 $query = "SELECT count(*) as cnt FROM il_wiki_page" .
810 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer");
811 $s = $ilDB->query($query);
812 $r = $ilDB->fetchAssoc($s);
813
814 return $r["cnt"];
815 }
816
822 public static function getRandomPage($a_wiki_id)
823 {
824 global $DIC;
825
826 $ilDB = $DIC->database();
827
828 $cnt = ilWikiPage::countPages($a_wiki_id);
829
830 if ($cnt < 1) {
831 return "";
832 }
833
834 $random = new \ilRandom();
835 $rand = $random->int(1, $cnt);
836
837 // delete record of table il_wiki_data
838 $ilDB->setLimit(1, $rand);
839 $query = "SELECT title FROM il_wiki_page" .
840 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer");
841 $s = $ilDB->query($query);
842 $r = $ilDB->fetchAssoc($s);
843
844 return $r["title"];
845 }
846
852 public static function getNewWikiPages($a_wiki_id)
853 {
854 global $DIC;
855
856 $ilDB = $DIC->database();
857
858 $pages = parent::getNewPages("wpg", $a_wiki_id);
859
860 foreach ($pages as $k => $page) {
861 $pages[$k]["title"] = ilWikiPage::lookupTitle($page["id"]);
862 }
863
864 return $pages;
865 }
866
867
874 public static function lookupObjIdByPage($a_page_id)
875 {
876 global $DIC;
877
878 $ilDB = $DIC->database();
879
880 $query = "SELECT wiki_id FROM il_wiki_page" .
881 " WHERE id = " . $ilDB->quote($a_page_id, "integer");
882 $set = $ilDB->query($query);
883 if ($rec = $ilDB->fetchAssoc($set)) {
884 return $rec["wiki_id"];
885 }
886
887 return false;
888 }
889
893 public function rename($a_new_name)
894 {
896
897 // replace unallowed characters
898 $a_new_name = str_replace(array("<", ">"), '', $a_new_name);
899
900 // replace multiple whitespace characters by one single space
901 $a_new_name = trim(preg_replace('!\s+!', ' ', $a_new_name));
902
903 $page_title = ilWikiUtil::makeDbTitle($a_new_name);
904 $pg_id = ilWikiPage::_getPageIdForWikiTitle($this->getWikiId(), $page_title);
905
906 $xml_new_name = str_replace("&", "&amp;", $a_new_name);
907
908 if ($pg_id == 0 || $pg_id == $this->getId()) {
909 include_once("./Services/Link/classes/class.ilInternalLink.php");
910 $sources = ilInternalLink::_getSourcesOfTarget("wpg", $this->getId(), 0);
911
912 foreach ($sources as $s) {
913 if ($s["type"] == "wpg:pg" && ilPageObject::_exists("wpg", $s["id"])) {
914 $wpage = new ilWikiPage($s["id"]);
915
917 $wpage->getXmlContent(),
918 0,
920 );
921 $new_content = $wpage->getXmlContent();
922 foreach ($col as $c) {
923
924 // this complicated procedure is needed due to the fact
925 // that depending on the collation e = é is true
926 // in the (mysql) database
927 // see bug http://www.ilias.de/mantis/view.php?id=11227
928 $t1 = ilWikiUtil::makeDbTitle($c["nt"]->mTextform);
929 $t2 = ilWikiUtil::makeDbTitle($this->getTitle());
930
931 // this one replaces C2A0 (&nbsp;) by a usual space
932 // otherwise the comparision will fail, since you
933 // get these characters from tiny if more than one
934 // space is repeated in a string. This may not be
935 // 100% but we do not store $t1 anywhere and only
936 // modify it for the comparison
937 $t1 = preg_replace('/\xC2\xA0/', ' ', $t1);
938 $t2 = preg_replace('/\xC2\xA0/', ' ', $t2);
939
940 $set = $ilDB->query($q = "SELECT " . $ilDB->quote($t1, "text") . " = " . $ilDB->quote($t2, "text") . " isequal");
941 $rec = $ilDB->fetchAssoc($set);
942
943 if ($rec["isequal"]) {
944 $new_content =
945 str_replace(
946 "[[" . $c["nt"]->mTextform . "]]",
947 "[[" . $xml_new_name . "]]",
948 $new_content
949 );
950 if ($c["text"] != "") {
951 $new_content =
952 str_replace(
953 "[[" . $c["text"] . "]]",
954 "[[" . $xml_new_name . "]]",
955 $new_content
956 );
957 }
958 $add = ($c["text"] != "")
959 ? "|" . $c["text"]
960 : "";
961 $new_content =
962 str_replace(
963 "[[" . $c["nt"]->mTextform . $add . "]]",
964 "[[" . $xml_new_name . $add . "]]",
965 $new_content
966 );
967 }
968 }
969 $wpage->setXmlContent($new_content);
970 //echo htmlentities($new_content);
971 $wpage->update();
972 }
973 }
974
975 include_once("./Modules/Wiki/classes/class.ilObjWiki.php");
976 if (ilObjWiki::_lookupStartPage($this->getWikiId()) == $this->getTitle()) {
977 ilObjWiki::writeStartPage($this->getWikiId(), $a_new_name);
978 }
979
980 $this->setTitle($a_new_name);
981
982 $this->update();
983 }
984
985 return $a_new_name;
986 }
987
988
992 public function updateNews($a_update = false)
993 {
995
996 $news_set = new ilSetting("news");
997 $default_visibility = ($news_set->get("default_visibility") != "")
998 ? $news_set->get("default_visibility")
999 : "users";
1000
1001 include_once("./Services/News/classes/class.ilNewsItem.php");
1002 if (!$a_update) {
1003 $news_item = new ilNewsItem();
1004 $news_item->setContext(
1005 $this->getWikiId(),
1006 "wiki",
1007 $this->getId(),
1008 "wpg"
1009 );
1010 $news_item->setPriority(NEWS_NOTICE);
1011 $news_item->setTitle($this->getTitle());
1012 $news_item->setContentTextIsLangVar(true);
1013 $news_item->setContent("wiki_news_page_created");
1014 $news_item->setUserId($ilUser->getId());
1015 $news_item->setVisibility($default_visibility);
1016 $news_item->create();
1017 } else {
1018 // get last news item of the day (if existing)
1020 $this->getWikiId(),
1021 "wiki",
1022 $this->getId(),
1023 "wpg",
1024 true
1025 );
1026
1027 if ($news_id > 0) {
1028 $news_item = new ilNewsItem($news_id);
1029 $news_item->setContent("wiki_news_page_changed");
1030 $news_item->setUserId($ilUser->getId());
1031 $news_item->setTitle($this->getTitle());
1032 $news_item->setContentTextIsLangVar(true);
1033 $news_item->update(true);
1034 } else {
1035 $news_item = new ilNewsItem();
1036 $news_item->setContext(
1037 $this->getWikiId(),
1038 "wiki",
1039 $this->getId(),
1040 "wpg"
1041 );
1042 $news_item->setPriority(NEWS_NOTICE);
1043 $news_item->setTitle($this->getTitle());
1044 $news_item->setContentTextIsLangVar(true);
1045 $news_item->setContent("wiki_news_page_changed");
1046 $news_item->setUserId($ilUser->getId());
1047 $news_item->setVisibility($default_visibility);
1048 $news_item->create();
1049 }
1050 }
1051 }
1052
1056 public function getNewsContent()
1057 {
1058 return "12.1.1: Test User, Max";
1059 }
1060
1067 public static function getGotoForWikiPageTarget($a_target, $a_offline = false)
1068 {
1069 if (!$a_offline) {
1070 $href = "./goto.php?target=wiki_wpage_" . $a_target;
1071 } else {
1072 $href = ILIAS_HTTP_PATH . "/goto.php?target=wiki_wpage_" . $a_target;
1073 }
1074 return $href;
1075 }
1076
1077
1083 public function getContentTemplates()
1084 {
1085 include_once("./Modules/Wiki/classes/class.ilWikiPageTemplate.php");
1086 $wt = new ilWikiPageTemplate($this->getWikiId());
1087 $templates = array();
1088 foreach ($wt->getAllInfo(ilWikiPageTemplate::TYPE_ADD_TO_PAGE) as $t) {
1089 $templates[] = array("id" => $t["wpage_id"], "parent_type" => "wpg", "title" => $t["title"]);
1090 }
1091 return $templates;
1092 }
1093
1100 public static function getPagesForSearch($a_wiki_id, $a_term)
1101 {
1102 global $DIC;
1103
1104 $ilDB = $DIC->database();
1105
1106 $set = $ilDB->query("SELECT DISTINCT title FROM il_wiki_page" .
1107 " WHERE wiki_id = " . $ilDB->quote($a_wiki_id, "integer") .
1108 " AND " . $ilDB->like("title", "text", "%" . $a_term . "%") .
1109 " ORDER by title");
1110 $res = array();
1111 while ($rec = $ilDB->fetchAssoc($set)) {
1112 $res[] = $rec["title"];
1113 }
1114
1115 return $res;
1116 }
1117
1118 public static function lookupAdvancedMetadataHidden($a_page_id)
1119 {
1120 global $DIC;
1121
1122 $ilDB = $DIC->database();
1123
1124 $query = "SELECT * FROM il_wiki_page" .
1125 " WHERE id = " . $ilDB->quote($a_page_id, "integer");
1126 $set = $ilDB->query($query);
1127 if ($rec = $ilDB->fetchAssoc($set)) {
1128 return (bool) $rec["hide_adv_md"];
1129 }
1130
1131 return false;
1132 }
1133}
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.
static writeStartPage($a_id, $a_name)
Write start page.
static _lookupStartPage($a_wiki_id)
Lookup start page.
Class ilPageObject.
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.
$source
Definition: metadata.php:76
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46