ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
4 include_once("./Services/COPage/classes/class.ilPageObject.php");
5 include_once("./Modules/Wiki/classes/class.ilWikiUtil.php");
14 class ilWikiPage extends ilPageObject
15 {
16  protected $blocked = false;
17  protected $rating = false; // [boo,]
18  protected $hide_adv_md = false; // [bool]
19 
25  function getParentType()
26  {
27  return "wpg";
28  }
29 
36  function afterConstructor()
37  {
38  $this->getPageConfig()->configureByObjectId($this->getParentId());
39  }
40 
46  function setTitle($a_title)
47  {
48  $this->title = ilWikiUtil::makeDbTitle($a_title);
49  }
50 
56  function getTitle()
57  {
58  return $this->title;
59  }
60 
66  function setWikiId($a_wikiid)
67  {
68  $this->setParentId($a_wikiid);
69  }
70 
76  function getWikiId()
77  {
78  return $this->getParentId();
79  }
80 
86  function setWikiRefId($a_wiki_ref_id)
87  {
88  $this->parent_ref_id = $a_wiki_ref_id;
89  }
90 
96  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  function createFromXML()
165  {
166  global $ilDB;
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("SELECT id FROM il_wiki_page ".
174  " WHERE id = ".$ilDB->quote($this->getId(), "integer")
175  );
176  if ($rec = $ilDB->fetchAssoc($set))
177  {
178  $this->read(true);
179  }
180 
182  }
183 
187  function create($a_prevent_page_creation = false)
188  {
189  global $ilDB;
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  {
213  parent::create();
214  $this->saveInternalLinks($this->getDomDoc());
215 
216  include_once "./Modules/Wiki/classes/class.ilWikiStat.php";
218 
219  include_once "./Services/Notification/classes/class.ilNotification.php";
221  }
222 
223  $this->updateNews();
224  }
225 
226  public function afterUpdate($a_domdoc, $a_xml)
227  {
228  // internal == wiki links
229  include_once "Modules/Wiki/classes/class.ilWikiUtil.php";
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  ilWikiStat::handleEvent(ilWikiStat::EVENT_PAGE_UPDATED, $this, null, $page_data);
259  }
260 
267  function update($a_validate = true, $a_no_history = false)
268  {
269  global $ilDB;
270 
271  // update wiki page data
272  $query = "UPDATE il_wiki_page SET ".
273  " title = ".$ilDB->quote($this->getTitle(), "text").
274  ",wiki_id = ".$ilDB->quote((int) $this->getWikiId(), "integer").
275  ",blocked = ".$ilDB->quote((int) $this->getBlocked(), "integer").
276  ",rating = ".$ilDB->quote((int) $this->getRating(), "integer").
277  ",hide_adv_md = ".$ilDB->quote((int) $this->isAdvancedMetadataHidden(), "integer").
278  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
279  $ilDB->manipulate($query);
280  $updated = parent::update($a_validate, $a_no_history);
281 
282  if ($updated === true)
283  {
284  include_once "./Services/Notification/classes/class.ilNotification.php";
286 
287  $this->updateNews(true);
288  }
289  else
290  {
291  return $updated;
292  }
293 
294  return true;
295  }
296 
300  function read($a_omit_page_read = false)
301  {
302  global $ilDB;
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  {
318  parent::read();
319  }
320  }
321 
322 
328  function delete()
329  {
330  global $ilDB;
331 
332  // get other pages that link to this page
333  $linking_pages = ilWikiPage::getLinksToPage($this->getWikiId(),
334  $this->getId());
335 
336  // delete internal links information to this page
337  include_once("./Services/Link/classes/class.ilInternalLink.php");
339 
340  include_once "./Modules/Wiki/classes/class.ilWikiStat.php";
342 
343  include_once "./Services/Notification/classes/class.ilNotification.php";
345 
346  // remove all notifications
347  include_once "./Services/Notification/classes/class.ilNotification.php";
349 
350  // delete record of table il_wiki_data
351  $query = "DELETE FROM il_wiki_page".
352  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
353  $ilDB->manipulate($query);
354 
355  // delete co page
356  parent::delete();
357 
358  // make links of other pages to this page a missing link
359  foreach($linking_pages as $lp)
360  {
361  $ilDB->manipulateF("DELETE FROM il_wiki_missing_page ".
362  " WHERE wiki_id = %s AND source_id = %s AND target_name = %s ",
363  array("integer", "integer", "text"),
364  array($this->getWikiId(), $lp["id"], $this->getTitle()));
365  $ilDB->manipulateF("INSERT INTO il_wiki_missing_page ".
366  "(wiki_id, source_id, target_name) VALUES ".
367  "(%s,%s,%s)",
368  array("integer", "integer", "text"),
369  array($this->getWikiId(), $lp["id"], $this->getTitle()));
370  }
371 
372  return true;
373  }
374 
380  static function deleteAllPagesOfWiki($a_wiki_id)
381  {
382  global $ilDB;
383 
384  // delete record of table il_wiki_data
385  $query = "SELECT * FROM il_wiki_page".
386  " WHERE wiki_id = ".$ilDB->quote($a_wiki_id, "integer");
387  $set = $ilDB->query($query);
388 
389  while($rec = $ilDB->fetchAssoc($set))
390  {
391  $wiki_page = new ilWikiPage($rec["id"]);
392  $wiki_page->delete();
393 
394 
395  }
396  }
397 
401  static function exists($a_wiki_id, $a_title)
402  {
403  global $ilDB;
404 
405  $a_title = ilWikiUtil::makeDbTitle($a_title);
406 
407  $query = "SELECT id FROM il_wiki_page".
408  " WHERE wiki_id = ".$ilDB->quote($a_wiki_id, "integer").
409  " AND title = ".$ilDB->quote($a_title, "text");
410  $set = $ilDB->query($query);
411  if($rec = $ilDB->fetchAssoc($set))
412  {
413  return true;
414  }
415 
416  return false;
417  }
418 
422  static function getIdForPageTitle($a_wiki_id, $a_title)
423  {
424  global $ilDB;
425 
426  $a_title = ilWikiUtil::makeDbTitle($a_title);
427 
428  $query = "SELECT id FROM il_wiki_page".
429  " WHERE wiki_id = ".$ilDB->quote($a_wiki_id, "integer").
430  " AND title = ".$ilDB->quote($a_title, "text");
431  $set = $ilDB->query($query);
432  if($rec = $ilDB->fetchAssoc($set))
433  {
434  return $rec["id"];
435  }
436 
437  return false;
438  }
439 
443  static function getPageIdForTitle($a_wiki_id, $a_title)
444  {
445  global $ilDB;
446 
447  $a_title = ilWikiUtil::makeDbTitle($a_title);
448 
449  $query = "SELECT * FROM il_wiki_page".
450  " WHERE wiki_id = ".$ilDB->quote($a_wiki_id, "integer").
451  " AND title = ".$ilDB->quote($a_title, "text");
452  $set = $ilDB->query($query);
453  if($rec = $ilDB->fetchAssoc($set))
454  {
455  return $rec["id"];
456  }
457 
458  return false;
459  }
460 
464  static function lookupTitle($a_page_id)
465  {
466  global $ilDB;
467 
468  $query = "SELECT * FROM il_wiki_page".
469  " WHERE id = ".$ilDB->quote($a_page_id, "integer");
470  $set = $ilDB->query($query);
471  if($rec = $ilDB->fetchAssoc($set))
472  {
473  return $rec["title"];
474  }
475 
476  return false;
477  }
478 
482  static function lookupWikiId($a_page_id)
483  {
484  global $ilDB;
485 
486  $query = "SELECT wiki_id FROM il_wiki_page".
487  " WHERE id = ".$ilDB->quote($a_page_id, "integer");
488  $set = $ilDB->query($query);
489  if ($rec = $ilDB->fetchAssoc($set))
490  {
491  return $rec["wiki_id"];
492  }
493 
494  return false;
495  }
496 
502  static function getAllPages($a_wiki_id)
503  {
504  global $ilDB;
505 
506  $pages = parent::getAllPages("wpg", $a_wiki_id);
507 
508  $query = "SELECT * FROM il_wiki_page".
509  " WHERE wiki_id = ".$ilDB->quote($a_wiki_id, "integer").
510  " ORDER BY title";
511  $set = $ilDB->query($query);
512 
513  $pg = array();
514  while($rec = $ilDB->fetchAssoc($set))
515  {
516  if (isset($pages[$rec["id"]]))
517  {
518  $pg[$rec["id"]] = $pages[$rec["id"]];
519  $pg[$rec["id"]]["title"] = $rec["title"];
520  }
521  }
522 
523  return $pg;
524  }
525 
529  static function getLinksToPage($a_wiki_id, $a_page_id)
530  {
531  global $ilDB;
532 
533  include_once("./Services/Link/classes/class.ilInternalLink.php");
534  $sources = ilInternalLink::_getSourcesOfTarget("wpg", $a_page_id, 0);
535 
536  $ids = array();
537  foreach ($sources as $source)
538  {
539  if ($source["type"] == "wpg:pg")
540  {
541  $ids[] = $source["id"];
542  }
543  }
544  // get wiki page record
545  $query = "SELECT * FROM il_wiki_page wp, page_object p".
546  " WHERE ".$ilDB->in("wp.id", $ids, false, "integer").
547  " AND wp.id = p.page_id AND p.parent_type = ".$ilDB->quote("wpg", "text").
548  " AND wp.wiki_id = ".$ilDB->quote($a_wiki_id, "integer").
549  " ORDER BY title";
550  $set = $ilDB->query($query);
551 
552  $pages = array();
553  while ($rec = $ilDB->fetchAssoc($set))
554  {
555  $pages[] = array_merge($rec, array("user" => $rec["last_change_user"],
556  "date" => $rec["last_change"]));
557  }
558 
559  return $pages;
560  }
561 
567  static function getOrphanedPages($a_wiki_id)
568  {
569  global $ilDB;
570 
571  $pages = ilWikiPage::getAllPages($a_wiki_id);
572 
573  include_once("./Services/Link/classes/class.ilInternalLink.php");
574 
575  $orphaned = array();
576  foreach ($pages as $k => $page)
577  {
578  $sources = ilInternalLink::_getSourcesOfTarget("wpg", $page["id"], 0);
579 
580  $ids = array();
581  foreach ($sources as $source)
582  {
583  if ($source["type"] == "wpg:pg")
584  {
585  $ids[] = $source["id"];
586  }
587  }
588  $query = "SELECT count(*) cnt FROM il_wiki_page".
589  " WHERE ".$ilDB->in("id", $ids, false, "integer").
590  " AND wiki_id = ".$ilDB->quote($a_wiki_id, "integer").
591  " GROUP BY wiki_id";
592  $set = $ilDB->query($query);
593  $rec = $ilDB->fetchAssoc($set);
594  if ($rec["cnt"] == 0 &&
595  ilObjWiki::_lookupStartPage($a_wiki_id) != $page["title"])
596  {
597  $orphaned[] = $page;
598  }
599  }
600 
601  return $orphaned;
602  }
603 
609  static function _wikiPageExists($a_wiki_id, $a_title)
610  {
611  global $ilDB;
612 
613  $a_title = ilWikiUtil::makeDbTitle($a_title);
614 
615  $query = "SELECT id FROM il_wiki_page".
616  " WHERE wiki_id = ".$ilDB->quote($a_wiki_id, "integer").
617  " AND title = ".$ilDB->quote($a_title, "text");
618  $set = $ilDB->query($query);
619 
620  $pages = array();
621  if ($rec = $ilDB->fetchAssoc($set))
622  {
623  return true;
624  }
625 
626  return false;
627  }
628 
634  static function getParentObjectContributors($a_wiki_id)
635  {
636  global $ilDB;
637 
638  $contributors = parent::getParentObjectContributors("wpg", $a_wiki_id);
639 
640  return $contributors;
641  }
642 
648  static function getPageContributors($a_page_id)
649  {
650  global $ilDB;
651 
652  $contributors = parent::getPageContributors("wpg", $a_page_id);
653 
654  return $contributors;
655  }
656 
657 
663  function saveInternalLinks($a_domdoc)
664  {
665  global $ilDB;
666 
667 
668  // *** STEP 1: Standard Processing ***
669 
670  parent::saveInternalLinks($a_domdoc);
671 
672 
673  // *** STEP 2: Other Pages -> This Page ***
674 
675  // Check, whether ANOTHER page links to this page as a "missing" page
676  // (this is the case, when this page is created newly)
677  $set = $ilDB->queryF("SELECT * FROM il_wiki_missing_page WHERE ".
678  " wiki_id = %s AND target_name = %s",
679  array("integer", "text"),
680  array($this->getWikiId(), ilWikiUtil::makeDbTitle($this->getTitle())));
681  while ($anmiss = $ilDB->fetchAssoc($set)) // insert internal links instead
682  {
683 //echo "adding link";
684  ilInternalLink::_saveLink("wpg:pg", $anmiss["source_id"], "wpg",
685  $this->getId(), 0);
686  }
687 //exit;
688  // now remove the missing page entries
689  $ilDB->manipulateF("DELETE FROM il_wiki_missing_page WHERE ".
690  " wiki_id = %s AND target_name = %s",
691  array("integer", "text"),
692  array($this->getWikiId(), $this->getTitle()));
693 
694 
695  // *** STEP 3: This Page -> Other Pages ***
696 
697  // remove the exising "missing page" links for THIS page (they will be re-inserted below)
698  $ilDB->manipulateF("DELETE FROM il_wiki_missing_page WHERE ".
699  " wiki_id = %s AND source_id = %s",
700  array("integer", "integer"),
701  array($this->getWikiId(), $this->getId()));
702 
703  // collect the wiki links of the page
704  include_once("./Modules/Wiki/classes/class.ilWikiUtil.php");
705  $xml = $a_domdoc->saveXML();
706  $int_wiki_links = ilWikiUtil::collectInternalLinks($xml, $this->getWikiId(), true);
707  foreach($int_wiki_links as $wlink)
708  {
709  $page_id = ilWikiPage::_getPageIdForWikiTitle($this->getWikiId(), $wlink);
710 
711  if ($page_id > 0) // save internal link for existing page
712  {
713  ilInternalLink::_saveLink("wpg:pg", $this->getId(), "wpg",
714  $page_id, 0);
715  }
716  else // save missing link for non-existing page
717  {
718  $ilDB->manipulateF("DELETE FROM il_wiki_missing_page WHERE".
719  " wiki_id = %s AND source_id = %s AND target_name = %s",
720  array("integer", "integer", "text"),
721  array($this->getWikiId(), $this->getId(), $wlink));
722  $ilDB->manipulateF("INSERT INTO il_wiki_missing_page (wiki_id, source_id, target_name)".
723  " VALUES (%s,%s,%s)",
724  array("integer", "integer", "text"),
725  array($this->getWikiId(), $this->getId(), $wlink));
726  }
727  }
728  }
729 
733  static function _getPageIdForWikiTitle($a_wiki_id, $a_title)
734  {
735  global $ilDB;
736 
737  $query = "SELECT id FROM il_wiki_page".
738  " WHERE wiki_id = ".$ilDB->quote($a_wiki_id, "integer").
739  " AND title = ".$ilDB->quote($a_title, "text");
740  $set = $ilDB->query($query);
741  if($rec = $ilDB->fetchAssoc($set))
742  {
743  return $rec["id"];
744  }
745 
746  return false;
747  }
748 
754  static function getPopularPages($a_wiki_id)
755  {
756  global $ilDB;
757 
758  $query = "SELECT wp.*, po.view_cnt as cnt FROM il_wiki_page wp, page_object po".
759  " WHERE wp.wiki_id = ".$ilDB->quote($a_wiki_id, "integer").
760  " AND wp.id = po.page_id ".
761  " AND po.parent_type = ".$ilDB->quote("wpg", "text")." ".
762  " ORDER BY po.view_cnt";
763  $set = $ilDB->query($query);
764 
765  $pages = array();
766  while($rec = $ilDB->fetchAssoc($set))
767  {
768  $pages[] = $rec;
769  }
770 
771  return $pages;
772  }
773 
779  static function countPages($a_wiki_id)
780  {
781  global $ilDB;
782 
783  // delete record of table il_wiki_data
784  $query = "SELECT count(*) as cnt FROM il_wiki_page".
785  " WHERE wiki_id = ".$ilDB->quote($a_wiki_id, "integer");
786  $s = $ilDB->query($query);
787  $r = $ilDB->fetchAssoc($s);
788 
789  return $r["cnt"];
790  }
791 
797  static function getRandomPage($a_wiki_id)
798  {
799  global $ilDB;
800 
801  $cnt = ilWikiPage::countPages($a_wiki_id);
802 
803  if ($cnt < 1)
804  {
805  return "";
806  }
807 
808  $rand = rand(1, $cnt);
809 
810  // delete record of table il_wiki_data
811  $ilDB->setLimit(1, $rand);
812  $query = "SELECT title FROM il_wiki_page".
813  " WHERE wiki_id = ".$ilDB->quote($a_wiki_id, "integer");
814  $s = $ilDB->query($query);
815  $r = $ilDB->fetchAssoc($s);
816 
817  return $r["title"];
818  }
819 
825  static function getNewPages($a_wiki_id)
826  {
827  global $ilDB;
828 
829  $pages = parent::getNewPages("wpg", $a_wiki_id);
830 
831  foreach($pages as $k => $page)
832  {
833  $pages[$k]["title"] = ilWikiPage::lookupTitle($page["id"]);
834  }
835 
836  return $pages;
837  }
838 
839 
846  public static function lookupObjIdByPage($a_page_id)
847  {
848  global $ilDB;
849 
850  $query = "SELECT wiki_id FROM il_wiki_page".
851  " WHERE id = ".$ilDB->quote($a_page_id, "integer");
852  $set = $ilDB->query($query);
853  if($rec = $ilDB->fetchAssoc($set))
854  {
855  return $rec["wiki_id"];
856  }
857 
858  return false;
859  }
860 
864  function rename($a_new_name)
865  {
866  global $ilDB;
867 
868  // replace unallowed characters
869  $a_new_name = str_replace(array("<", ">"), '', $a_new_name);
870 
871  // replace multiple whitespace characters by one single space
872  $a_new_name = trim(preg_replace('!\s+!', ' ', $a_new_name));
873 
874  $page_title = ilWikiUtil::makeDbTitle($a_new_name);
875  $pg_id = ilWikiPage::_getPageIdForWikiTitle($this->getWikiId(), $page_title);
876 
877  $xml_new_name = str_replace("&", "&amp;", $a_new_name);
878 
879  if ($pg_id == 0 || $pg_id == $this->getId())
880  {
881  include_once("./Services/Link/classes/class.ilInternalLink.php");
882  $sources = ilInternalLink::_getSourcesOfTarget("wpg", $this->getId(), 0);
883 
884  foreach ($sources as $s)
885  {
886  if ($s["type"] == "wpg:pg" && ilPageObject::_exists("wpg", $s["id"]))
887  {
888  $wpage = new ilWikiPage($s["id"]);
889 
890  $col = ilWikiUtil::processInternalLinks($wpage->getXmlContent(), 0,
892  $new_content = $wpage->getXmlContent();
893  foreach ($col as $c)
894  {
895 
896  // this complicated procedure is needed due to the fact
897  // that depending on the collation e = é is true
898  // in the (mysql) database
899  // see bug http://www.ilias.de/mantis/view.php?id=11227
900  $t1 = ilWikiUtil::makeDbTitle($c["nt"]->mTextform);
901  $t2 = ilWikiUtil::makeDbTitle($this->getTitle());
902 
903  // this one replaces C2A0 (&nbsp;) by a usual space
904  // otherwise the comparision will fail, since you
905  // get these characters from tiny if more than one
906  // space is repeated in a string. This may not be
907  // 100% but we do not store $t1 anywhere and only
908  // modify it for the comparison
909  $t1 = preg_replace('/\xC2\xA0/', ' ', $t1);
910  $t2 = preg_replace('/\xC2\xA0/', ' ', $t2);
911 
912  $set = $ilDB->query($q = "SELECT ".$ilDB->quote($t1, "text")." = ".$ilDB->quote($t2, "text")." isequal");
913  $rec = $ilDB->fetchAssoc($set);
914 
915  if ($rec["isequal"])
916  {
917  $new_content =
918  str_replace("[[".$c["nt"]->mTextform."]]",
919  "[[".$xml_new_name."]]", $new_content);
920  if ($c["text"] != "")
921  {
922  $new_content =
923  str_replace("[[".$c["text"]."]]",
924  "[[".$xml_new_name."]]", $new_content);
925  }
926  $add = ($c["text"] != "")
927  ? "|".$c["text"]
928  : "";
929  $new_content =
930  str_replace("[[".$c["nt"]->mTextform.$add."]]",
931  "[[".$xml_new_name.$add."]]", $new_content);
932  }
933  }
934  $wpage->setXmlContent($new_content);
935 //echo htmlentities($new_content);
936  $wpage->update();
937  }
938  }
939 
940  include_once("./Modules/Wiki/classes/class.ilObjWiki.php");
941  if (ilObjWiki::_lookupStartPage($this->getWikiId()) == $this->getTitle())
942  {
943  ilObjWiki::writeStartPage($this->getWikiId(), $a_new_name);
944  }
945 
946  $this->setTitle($a_new_name);
947 
948  $this->update();
949  }
950 
951  return $a_new_name;
952  }
953 
954 
958  function updateNews($a_update = false)
959  {
960  global $ilUser;
961 
962  $news_set = new ilSetting("news");
963  $default_visibility = ($news_set->get("default_visibility") != "")
964  ? $news_set->get("default_visibility")
965  : "users";
966 
967  include_once("./Services/News/classes/class.ilNewsItem.php");
968  if (!$a_update)
969  {
970  $news_item = new ilNewsItem();
971  $news_item->setContext(
972  $this->getWikiId(), "wiki",
973  $this->getId(), "wpg");
974  $news_item->setPriority(NEWS_NOTICE);
975  $news_item->setTitle($this->getTitle());
976  $news_item->setContentTextIsLangVar(true);
977  $news_item->setContent("wiki_news_page_created");
978  $news_item->setUserId($ilUser->getId());
979  $news_item->setVisibility($default_visibility);
980  $news_item->create();
981  }
982  else
983  {
984  // get last news item of the day (if existing)
986  $this->getWikiId(), "wiki",
987  $this->getId(), "wpg", true);
988 
989  if ($news_id > 0)
990  {
991  $news_item = new ilNewsItem($news_id);
992  $news_item->setContent("wiki_news_page_changed");
993  $news_item->setUserId($ilUser->getId());
994  $news_item->setTitle($this->getTitle());
995  $news_item->setContentTextIsLangVar(true);
996  $news_item->update(true);
997  }
998  else
999  {
1000  $news_item = new ilNewsItem();
1001  $news_item->setContext(
1002  $this->getWikiId(), "wiki",
1003  $this->getId(), "wpg");
1004  $news_item->setPriority(NEWS_NOTICE);
1005  $news_item->setTitle($this->getTitle());
1006  $news_item->setContentTextIsLangVar(true);
1007  $news_item->setContent("wiki_news_page_changed");
1008  $news_item->setUserId($ilUser->getId());
1009  $news_item->setVisibility($default_visibility);
1010  $news_item->create();
1011  }
1012  }
1013  }
1014 
1018  function getNewsContent()
1019  {
1020  return "12.1.1: Test User, Max";
1021  }
1022 
1029  static function getGotoForWikiPageTarget($a_target, $a_offline = false)
1030  {
1031  if (!$a_offline)
1032  {
1033  $href = "./goto.php?target=wiki_wpage_".$a_target;
1034  }
1035  else
1036  {
1037  $href = ILIAS_HTTP_PATH."/goto.php?target=wiki_wpage_".$a_target;
1038  }
1039  return $href;
1040  }
1041 
1042 
1049  {
1050  include_once("./Modules/Wiki/classes/class.ilWikiPageTemplate.php");
1051  $wt = new ilWikiPageTemplate($this->getWikiId());
1052  $templates = array();
1053  foreach ($wt->getAllInfo(ilWikiPageTemplate::TYPE_ADD_TO_PAGE) as $t)
1054  {
1055  $templates[] = array("id" => $t["wpage_id"], "parent_type" => "wpg", "title" => $t["title"]);
1056  }
1057  return $templates;
1058  }
1059 
1066  static function getPagesForSearch($a_wiki_id, $a_term)
1067  {
1068  global $ilDB;
1069 
1070  $set = $ilDB->query("SELECT DISTINCT title FROM il_wiki_page".
1071  " WHERE wiki_id = ".$ilDB->quote($a_wiki_id, "integer").
1072  " AND ".$ilDB->like("title", "text", "%".$a_term."%").
1073  " ORDER by title");
1074  $res = array();
1075  while ($rec = $ilDB->fetchAssoc($set))
1076  {
1077  $res[] = $rec["title"];
1078  }
1079 
1080  return $res;
1081  }
1082 
1083  public static function lookupAdvancedMetadataHidden($a_page_id)
1084  {
1085  global $ilDB;
1086 
1087  $query = "SELECT * FROM il_wiki_page".
1088  " WHERE id = ".$ilDB->quote($a_page_id, "integer");
1089  $set = $ilDB->query($query);
1090  if($rec = $ilDB->fetchAssoc($set))
1091  {
1092  return (bool)$rec["hide_adv_md"];
1093  }
1094 
1095  return false;
1096  }
1097 }
1098 ?>