ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilWikiPageGUI.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.ilPageObjectGUI.php");
5 include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
6 
19 {
23  function __construct($a_id = 0, $a_old_nr = 0, $a_wiki_ref_id = 0)
24  {
25  global $tpl;
26 
27  // needed for notifications
28  $this->setWikiRefId($a_wiki_ref_id);
29 
30  parent::__construct("wpg", $a_id, $a_old_nr);
31 
32  // content style
33  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
34 
35  $tpl->setCurrentBlock("SyntaxStyle");
36  $tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
38  $tpl->parseCurrentBlock();
39 
40  $this->setEnabledMaps(true);
41  $this->setPreventHTMLUnmasking(true);
42  $this->setEnabledInternalLinks(false);
43  $this->setEnabledWikiLinks(true);
44  $this->setEnabledPCTabs(true);
45 
46  }
47 
48  function initPageObject($a_parent_type, $a_id, $a_old_nr)
49  {
50  $page = new ilWikiPage($a_id, $a_old_nr);
51  $page->setWikiRefId($this->getWikiRefId());
52  $this->setPageObject($page);
53  }
54 
55  function setWikiRefId($a_ref_id)
56  {
57  $this->wiki_ref_id = $a_ref_id;
58  }
59 
60  function getWikiRefId()
61  {
62  return $this->wiki_ref_id;
63  }
64 
68  function &executeCommand()
69  {
70  global $ilCtrl, $ilTabs, $ilUser;
71 
72  $next_class = $this->ctrl->getNextClass($this);
73  $cmd = $this->ctrl->getCmd();
74 
75  switch($next_class)
76  {
77  case "ilnotegui":
78  $this->getTabs();
79  $ilTabs->setTabActive("pg");
80  return $this->preview();
81  break;
82 
83  case "ilratinggui":
84  include_once("./Services/Rating/classes/class.ilRatingGUI.php");
85  $rating_gui = new ilRatingGUI();
86  $rating_gui->setObject($this->getPageObject()->getParentId(), "wiki",
87  $this->getPageObject()->getId(), "wpg");
88  $this->ctrl->forwardCommand($rating_gui);
89  $ilCtrl->redirect($this, "preview");
90  break;
91 
92  case "ilpageobjectgui":
93  $page_gui = new ilPageObjectGUI("wpg",
94  $this->getPageObject()->getId(), $this->getPageObject()->old_nr);
95  $page_gui->setPresentationTitle($this->getWikiPage()->getTitle());
96  return $ilCtrl->forwardCommand($page_gui);
97 
98  default:
99 
100  if($_GET["ntf"])
101  {
102  include_once "./Services/Notification/classes/class.ilNotification.php";
103  switch($_GET["ntf"])
104  {
105  case 1:
106  ilNotification::setNotification(ilNotification::TYPE_WIKI, $ilUser->getId(), $this->getPageObject()->getParentId(), false);
107  break;
108 
109  case 2:
110  // remove all page notifications here?
111  ilNotification::setNotification(ilNotification::TYPE_WIKI, $ilUser->getId(), $this->getPageObject()->getParentId(), true);
112  break;
113 
114  case 3:
115  ilNotification::setNotification(ilNotification::TYPE_WIKI_PAGE, $ilUser->getId(), $this->getPageObject()->getId(), false);
116  break;
117 
118  case 4:
119  ilNotification::setNotification(ilNotification::TYPE_WIKI_PAGE, $ilUser->getId(), $this->getPageObject()->getId(), true);
120  break;
121  }
122  $ilCtrl->redirect($this, "preview");
123  }
124 
125  $this->setPresentationTitle($this->getWikiPage()->getTitle());
126  return parent::executeCommand();
127  }
128  }
129 
135  function setWikiPage($a_wikipage)
136  {
137  $this->setPageObject($a_wikipage);
138  }
139 
145  function getWikiPage()
146  {
147  return $this->getPageObject();
148  }
149 
153  static function getGUIForTitle($a_wiki_id, $a_title, $a_old_nr = 0, $a_wiki_ref_id = 0)
154  {
155  global $ilDB;
156 
157  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
158  $id = ilWikiPage::getPageIdForTitle($a_wiki_id, $a_title);
159  $page_gui = new ilWikiPageGUI($id, $a_old_nr, $a_wiki_ref_id);
160 
161  return $page_gui;
162  }
163 
164  function setSideBlock()
165  {
166  global $tpl;
167 
168  // side block
169  include_once("./Modules/Wiki/classes/class.ilWikiSideBlockGUI.php");
170  $wiki_side_block = new ilWikiSideBlockGUI();
171  $wiki_side_block->setPageObject($this->getWikiPage());
172 
173  // search block
174  include_once("./Modules/Wiki/classes/class.ilWikiSearchBlockGUI.php");
175  $wiki_search_block = new ilWikiSearchBlockGUI();
176  $rcontent = $wiki_side_block->getHTML().$wiki_search_block->getHTML();
177 
178  $tpl->setRightContent($rcontent);
179  }
180 
184  function preview()
185  {
186  global $ilCtrl, $ilAccess, $lng, $tpl, $ilUser;
187 
188  $this->getWikiPage()->increaseViewCnt(); // todo: move to page object
189  $this->setSideBlock();
190  $wtpl = new ilTemplate("tpl.wiki_page_view_main_column.html",
191  true, true, "Modules/Wiki");
192 
193  // wiki page commands
194  // delete
195  $page_commands = false;
196  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
197  {
198  $st_page = ilObjWiki::_lookupStartPage($this->getPageObject()->getParentId());
199  if ($st_page != $this->getPageObject()->getTitle())
200  {
201  $wtpl->setCurrentBlock("page_command");
202  $wtpl->setVariable("HREF_PAGE_CMD",
203  $ilCtrl->getLinkTarget($this, "deleteWikiPageConfirmationScreen"));
204  $wtpl->setVariable("TXT_PAGE_CMD", $lng->txt("delete"));
205  $wtpl->parseCurrentBlock();
206  }
207  }
208  if ($page_commands)
209  {
210  $wtpl->setCurrentBlock("page_commands");
211  $wtpl->parseCurrentBlock();
212  }
213 
214  // notification
215  if ($ilUser->getId() != ANONYMOUS_USER_ID)
216  {
217  $wtpl->setCurrentBlock("notification");
218  include_once "./Services/Notification/classes/class.ilNotification.php";
219  $wtpl->setVariable("TXT_NOTIFICATION", $lng->txt("wiki_notification_toggle_info"));
220  if(ilNotification::hasNotification(ilNotification::TYPE_WIKI, $ilUser->getId(), $this->getPageObject()->getParentId()))
221  {
222  $ilCtrl->setParameter($this, "ntf", 1);
223  $wtpl->setVariable("URL_NOTIFICATION_TOGGLE_WIKI", $ilCtrl->getLinkTarget($this));
224 
225  $wtpl->setVariable("TXT_NOTIFICATION_TOGGLE_WIKI", $lng->txt("wiki_notification_toggle_wiki_deactivate"));
226  }
227  else
228  {
229  $ilCtrl->setParameter($this, "ntf", 2);
230  $wtpl->setVariable("URL_NOTIFICATION_TOGGLE_WIKI", $ilCtrl->getLinkTarget($this));
231 
232  $wtpl->setVariable("TXT_NOTIFICATION_TOGGLE_WIKI", $lng->txt("wiki_notification_toggle_wiki_activate"));
233  $wtpl->setVariable("TXT_NOTIFICATION_TOGGLE_DIVIDER", "|");
234 
235  if(ilNotification::hasNotification(ilNotification::TYPE_WIKI_PAGE, $ilUser->getId(), $this->getPageObject()->getId()))
236  {
237  $ilCtrl->setParameter($this, "ntf", 3);
238  $wtpl->setVariable("URL_NOTIFICATION_TOGGLE_PAGE", $ilCtrl->getLinkTarget($this));
239 
240  $wtpl->setVariable("TXT_NOTIFICATION_TOGGLE_PAGE", $lng->txt("wiki_notification_toggle_page_deactivate"));
241  }
242  else
243  {
244  $ilCtrl->setParameter($this, "ntf", 4);
245  $wtpl->setVariable("URL_NOTIFICATION_TOGGLE_PAGE", $ilCtrl->getLinkTarget($this));
246 
247  $wtpl->setVariable("TXT_NOTIFICATION_TOGGLE_PAGE", $lng->txt("wiki_notification_toggle_page_activate"));
248  }
249  }
250  $ilCtrl->setParameter($this, "ntf", "");
251  $wtpl->parseCurrentBlock();
252  }
253 
254  // rating
255  if (ilObjWiki::_lookupRating($this->getPageObject()->getParentId())
256  && $this->getPageObject()->old_nr == 0)
257  {
258  include_once("./Services/Rating/classes/class.ilRatingGUI.php");
259  $rating_gui = new ilRatingGUI();
260  $rating_gui->setObject($this->getPageObject()->getParentId(), "wiki",
261  $this->getPageObject()->getId(), "wpg");
262  $wtpl->setVariable("RATING", $ilCtrl->getHtml($rating_gui));
263  }
264 
265  // notes
266  include_once("Services/Notes/classes/class.ilNoteGUI.php");
267  $pg_id = $this->getPageObject()->getId();
268  $notes_gui = new ilNoteGUI($this->getPageObject()->getParentId(),
269  $pg_id, "wpg");
270  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
271  {
272  $notes_gui->enablePublicNotesDeletion(true);
273  }
274  $notes_gui->enablePrivateNotes();
275  //if ($this->lm->publicNotes())
276  //{
277  $notes_gui->enablePublicNotes();
278  //}
279 
280  $next_class = $this->ctrl->getNextClass($this);
281  if ($next_class == "ilnotegui")
282  {
283  $html = $this->ctrl->forwardCommand($notes_gui);
284  }
285  else
286  {
287  $html = $notes_gui->getNotesHTML();
288  }
289  $wtpl->setVariable("NOTES", $html);
290 
291  // permanent link
292  $append = ($_GET["page"] != "")
293  ? "_".ilWikiUtil::makeUrlTitle($_GET["page"])
294  : "";
295  include_once("./Services/PermanentLink/classes/class.ilPermanentLinkGUI.php");
296  $perma_link = new ilPermanentLinkGUI("wiki", $_GET["ref_id"], $append);
297  $wtpl->setVariable("PERMA_LINK", $perma_link->getHTML());
298 
299  $wtpl->setVariable("PAGE", parent::preview());
300 
301  $tpl->setLoginTargetPar("wiki_".$_GET["ref_id"].$append);
302 
303  //highlighting
304  if ($_GET["srcstring"] != "")
305  {
306  include_once './Services/Search/classes/class.ilUserSearchCache.php';
307  $cache = ilUserSearchCache::_getInstance($ilUser->getId());
308  $cache->switchSearchType(ilUserSearchCache::LAST_QUERY);
309  $search_string = $cache->getQuery();
310 
311  include_once("./Services/UIComponent/TextHighlighter/classes/class.ilTextHighlighterGUI.php");
312  include_once("./Services/Search/classes/class.ilQueryParser.php");
313  $p = new ilQueryParser($search_string);
314  $p->parse();
315 
316  $words = $p->getQuotedWords();
317  if (is_array($words))
318  {
319  foreach ($words as $w)
320  {
321  ilTextHighlighterGUI::highlight("ilCOPageContent", $w, $tpl);
322  }
323  }
324  $this->fill_on_load_code = true;
325  }
326 
327  return $wtpl->get();
328  }
329 
330  function showPage()
331  {
332  global $tpl, $ilCtrl;
333 
334  // content style
335 /* include_once("./classes/class.ilObjStyleSheet.php");
336  $tpl->setCurrentBlock("ContentStyle");
337  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
338  ilObjStyleSheet::getContentStylePath(0));
339  $tpl->parseCurrentBlock();
340 */
341  $this->setTemplateOutput(false);
342  $this->setPresentationTitle($this->getWikiPage()->getTitle());
343  $this->getWikiPage()->increaseViewCnt();
344  $output = parent::showPage();
345 
346  return $output;
347  }
348 
352  function postOutputProcessing($a_output)
353  {
354 //echo htmlentities($a_output);
355  include_once("./Modules/Wiki/classes/class.ilWikiUtil.php");
356  $output = ilWikiUtil::replaceInternalLinks($a_output,
357  $this->getWikiPage()->getWikiId());
358  return $output;
359  }
360 
364  function whatLinksHere()
365  {
366  global $tpl;
367 
368  include_once("./Modules/Wiki/classes/class.ilWikiPagesTableGUI.php");
369 
370  $this->setSideBlock($_GET["wpg_id"]);
371  $table_gui = new ilWikiPagesTableGUI($this, "whatLinksHere",
372  $this->getWikiPage()->getWikiId(), IL_WIKI_WHAT_LINKS_HERE, $_GET["wpg_id"]);
373 
374  $tpl->setContent($table_gui->getHTML());
375  }
376 
377  function getTabs($a_activate = "")
378  {
379  global $ilTabs, $ilCtrl;
380 
381  parent::getTabs($a_activate);
382 
383  $ilCtrl->setParameterByClass("ilobjwikigui", "wpg_id",
384  ilWikiPage::getPageIdForTitle($this->getPageObject()->getParentId(),
385  ilWikiUtil::makeDbTitle($_GET["page"])));
386  $ilCtrl->setParameterByClass("ilobjwikigui", "page", ilWikiUtil::makeUrlTitle($_GET["page"]));
387 
388  $ilTabs->addTarget("wiki_what_links_here",
389  $this->ctrl->getLinkTargetByClass("ilwikipagegui",
390  "whatLinksHere"), "whatLinksHere");
391  //$ilTabs->addTarget("wiki_print_view",
392  // $this->ctrl->getLinkTargetByClass("ilobjwikigui",
393  // "printViewSelection"), "printViewSelection");
394  $ilTabs->addTarget("wiki_print_view",
395  $this->ctrl->getLinkTargetByClass("ilwikipagegui",
396  "printViewSelection"), "printViewSelection");
397 
398  }
399 
404  {
405  global $ilAccess, $tpl, $ilCtrl, $lng;
406 
407  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
408  {
409  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
410  $confirmation_gui = new ilConfirmationGUI();
411  $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
412  $confirmation_gui->setHeaderText($lng->txt("wiki_page_deletion_confirmation"));
413  $confirmation_gui->setCancel($lng->txt("cancel"), "cancelWikiPageDeletion");
414  $confirmation_gui->setConfirm($lng->txt("delete"), "confirmWikiPageDeletion");
415 
416  $dtpl = new ilTemplate("tpl.wiki_page_deletion_confirmation.html", true,
417  true, "Modules/Wiki");
418 
419  $dtpl->setVariable("PAGE_TITLE", $this->getWikiPage()->getTitle());
420 
421  // other pages that link to this page
422  $dtpl->setVariable("TXT_OTHER_PAGES", $lng->txt("wiki_other_pages_linking"));
423  $pages = ilWikiPage::getLinksToPage($this->getWikiPage()->getWikiId(),
424  $this->getWikiPage()->getId());
425  if (count($pages) > 0)
426  {
427  foreach($pages as $page)
428  {
429  $dtpl->setCurrentBlock("lpage");
430  $dtpl->setVariable("TXT_LINKING_PAGE", $page["title"]);
431  $dtpl->parseCurrentBlock();
432  }
433  }
434  else
435  {
436  $dtpl->setCurrentBlock("lpage");
437  $dtpl->setVariable("TXT_LINKING_PAGE", "-");
438  $dtpl->parseCurrentBlock();
439  }
440 
441  // contributors
442  $dtpl->setVariable("TXT_CONTRIBUTORS", $lng->txt("wiki_contributors"));
443  $contributors = ilWikiPage::getPageContributors($this->getWikiPage()->getId());
444  foreach($contributors as $contributor)
445  {
446  $dtpl->setCurrentBlock("contributor");
447  $dtpl->setVariable("TXT_CONTRIBUTOR",
448  $contributor["lastname"].", ".$contributor["firstname"]);
449  $dtpl->parseCurrentBlock();
450  }
451 
452  // notes/comments
453  include_once("./Services/Notes/classes/class.ilNote.php");
454  $cnt_note_users = ilNote::getUserCount($this->getPageObject()->getParentId(),
455  $this->getPageObject()->getId(), "wpg");
456  $dtpl->setVariable("TXT_NUMBER_USERS_NOTES_OR_COMMENTS",
457  $lng->txt("wiki_number_users_notes_or_comments"));
458  $dtpl->setVariable("TXT_NR_NOTES_COMMENTS", $cnt_note_users);
459 
460  $confirmation_gui->addItem("", "", $dtpl->get());
461 
462  $tpl->setContent($confirmation_gui->getHTML());
463  }
464  }
465 
470  {
471  global $lng, $ilCtrl;
472 
473  $ilCtrl->redirect($this, "preview");
474 
475  }
476 
481  {
482  global $ilAccess, $tpl, $ilCtrl, $lng;
483 
484  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
485  {
486  $this->getPageObject()->delete();
487 
488  ilUtil::sendSuccess($lng->txt("wiki_page_deleted"), true);
489  }
490 
491  $ilCtrl->redirectByClass("ilobjwikigui", "allPages");
492  }
493 
497 
505  {
506  global $ilUser, $lng, $ilToolbar, $ilCtrl, $tpl;
507 
508  $ilToolbar->setFormAction($ilCtrl->getFormActionByClass("ilobjwikigui", "printView"),
509  false, "print_view");
510  $ilToolbar->addFormButton($lng->txt("cont_show_print_view"), "printView");
511  $ilToolbar->setCloseFormTag(false);
512 
514 
515  $tpl->setContent($this->form->getHTML());
516  }
517 
521  public function initPrintViewSelectionForm()
522  {
523  global $lng, $ilCtrl;
524 
526 
527  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
528  $this->form = new ilPropertyFormGUI();
529 //var_dump($pages);
530  // selection type
531  $radg = new ilRadioGroupInputGUI($lng->txt("cont_selection"), "sel_type");
532  $radg->setValue("page");
533  $op1 = new ilRadioOption($lng->txt("cont_current_page"), "page");
534  $radg->addOption($op1);
535  $op2 = new ilRadioOption($lng->txt("wiki_whole_wiki")
536  ." (".$lng->txt("wiki_pages").": ".count($pages).")", "wiki");
537  $radg->addOption($op2);
538  $op3= new ilRadioOption($lng->txt("wiki_selected_pages"), "selection");
539  $radg->addOption($op3);
540 
541  include_once("./Services/Form/classes/class.ilNestedListInputGUI.php");
542  $nl = new ilNestedListInputGUI("", "obj_id");
543  $op3->addSubItem($nl);
544 
545  foreach ($pages as $p)
546  {
547  $nl->addListNode($p["id"], $p["title"], 0, false, false,
548  ilUtil::getImagePath("icon_pg_s.gif"), $lng->txt("wiki_page"));
549  }
550 
551  $this->form->addItem($radg);
552 
553  $this->form->addCommandButton("printView", $lng->txt("cont_show_print_view"));
554  //$this->form->setOpenTag(false);
555  $this->form->setCloseTag(false);
556 
557  $this->form->setTitle($lng->txt("cont_print_selection"));
558  //$this->form->setFormAction($ilCtrl->getFormAction($this));
559  }
560 
561 }
562 ?>