ILIAS  Release_4_0_x_branch Revision 61816
 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)
24  {
25  global $tpl;
26 
27  parent::__construct("wpg", $a_id, $a_old_nr);
28 
29  // content style
30  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
31 
32  $tpl->setCurrentBlock("SyntaxStyle");
33  $tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
35  $tpl->parseCurrentBlock();
36 
37  $this->setEnabledMaps(true);
38  $this->setPreventHTMLUnmasking(true);
39  $this->setEnabledInternalLinks(false);
40  $this->setEnabledWikiLinks(true);
41  $this->setEnabledPCTabs(true);
42 
43  }
44 
45  function initPageObject($a_parent_type, $a_id, $a_old_nr)
46  {
47  $page = new ilWikiPage($a_id, $a_old_nr);
48  $this->setPageObject($page);
49  }
50 
54  function &executeCommand()
55  {
56  global $ilCtrl, $ilTabs;
57 
58  $next_class = $this->ctrl->getNextClass($this);
59  $cmd = $this->ctrl->getCmd();
60 
61  switch($next_class)
62  {
63  case "ilnotegui":
64  $this->getTabs();
65  $ilTabs->setTabActive("pg");
66  return $this->preview();
67  break;
68 
69  case "ilratinggui":
70  include_once("./Services/Rating/classes/class.ilRatingGUI.php");
71  $rating_gui = new ilRatingGUI();
72  $rating_gui->setObject($this->getPageObject()->getParentId(), "wiki",
73  $this->getPageObject()->getId(), "wpg");
74  $this->ctrl->forwardCommand($rating_gui);
75  $ilCtrl->redirect($this, "preview");
76  break;
77 
78  case "ilpageobjectgui":
79  $page_gui = new ilPageObjectGUI("wpg",
80  $this->getPageObject()->getId(), $this->getPageObject()->old_nr);
81  $page_gui->setPresentationTitle($this->getWikiPage()->getTitle());
82  return $ilCtrl->forwardCommand($page_gui);
83 
84  default:
85  $this->setPresentationTitle($this->getWikiPage()->getTitle());
86  return parent::executeCommand();
87  }
88  }
89 
95  function setWikiPage($a_wikipage)
96  {
97  $this->setPageObject($a_wikipage);
98  }
99 
105  function getWikiPage()
106  {
107  return $this->getPageObject();
108  }
109 
113  static function getGUIForTitle($a_wiki_id, $a_title, $a_old_nr = 0)
114  {
115  global $ilDB;
116 
117  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
118  $id = ilWikiPage::getPageIdForTitle($a_wiki_id, $a_title);
119  $page_gui = new ilWikiPageGUI($id, $a_old_nr);
120 
121  return $page_gui;
122  }
123 
124  function setSideBlock()
125  {
126  global $tpl;
127 
128  // side block
129  include_once("./Modules/Wiki/classes/class.ilWikiSideBlockGUI.php");
130  $wiki_side_block = new ilWikiSideBlockGUI();
131  $wiki_side_block->setPageObject($this->getWikiPage());
132 
133  // search block
134  include_once("./Modules/Wiki/classes/class.ilWikiSearchBlockGUI.php");
135  $wiki_search_block = new ilWikiSearchBlockGUI();
136  $rcontent = $wiki_side_block->getHTML().$wiki_search_block->getHTML();
137 
138  $tpl->setRightContent($rcontent);
139  }
140 
144  function preview()
145  {
146  global $ilCtrl, $ilAccess, $lng;
147 
148  $this->getWikiPage()->increaseViewCnt(); // todo: move to page object
149  $this->setSideBlock();
150  $wtpl = new ilTemplate("tpl.wiki_page_view_main_column.html",
151  true, true, "Modules/Wiki");
152 
153  // wiki page commands
154  // delete
155  $page_commands = false;
156  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
157  {
158  $st_page = ilObjWiki::_lookupStartPage($this->getPageObject()->getParentId());
159  if ($st_page != $this->getPageObject()->getTitle())
160  {
161  $wtpl->setCurrentBlock("page_command");
162  $wtpl->setVariable("HREF_PAGE_CMD",
163  $ilCtrl->getLinkTarget($this, "deleteWikiPageConfirmationScreen"));
164  $wtpl->setVariable("TXT_PAGE_CMD", $lng->txt("delete"));
165  $wtpl->parseCurrentBlock();
166  }
167  }
168  if ($page_commands)
169  {
170  $wtpl->setCurrentBlock("page_commands");
171  $wtpl->parseCurrentBlock();
172  }
173 
174  // rating
175  if (ilObjWiki::_lookupRating($this->getPageObject()->getParentId())
176  && $this->getPageObject()->old_nr == 0)
177  {
178  include_once("./Services/Rating/classes/class.ilRatingGUI.php");
179  $rating_gui = new ilRatingGUI();
180  $rating_gui->setObject($this->getPageObject()->getParentId(), "wiki",
181  $this->getPageObject()->getId(), "wpg");
182  $wtpl->setVariable("RATING", $ilCtrl->getHtml($rating_gui));
183  }
184 
185  // notes
186  include_once("Services/Notes/classes/class.ilNoteGUI.php");
187  $pg_id = $this->getPageObject()->getId();
188  $notes_gui = new ilNoteGUI($this->getPageObject()->getParentId(),
189  $pg_id, "wpg");
190  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
191  {
192  $notes_gui->enablePublicNotesDeletion(true);
193  }
194  $notes_gui->enablePrivateNotes();
195  //if ($this->lm->publicNotes())
196  //{
197  $notes_gui->enablePublicNotes();
198  //}
199 
200  $next_class = $this->ctrl->getNextClass($this);
201  if ($next_class == "ilnotegui")
202  {
203  $html = $this->ctrl->forwardCommand($notes_gui);
204  }
205  else
206  {
207  $html = $notes_gui->getNotesHTML();
208  }
209  $wtpl->setVariable("NOTES", $html);
210 
211  // permanent link
212  $append = ($_GET["page"] != "")
213  ? "_".ilWikiUtil::makeUrlTitle($_GET["page"])
214  : "";
215  include_once("./Services/PermanentLink/classes/class.ilPermanentLinkGUI.php");
216  $perma_link = new ilPermanentLinkGUI("wiki", $_GET["ref_id"], $append);
217  $wtpl->setVariable("PERMA_LINK", $perma_link->getHTML());
218 
219  $wtpl->setVariable("PAGE", parent::preview());
220  return $wtpl->get();
221  }
222 
223  function showPage()
224  {
225  global $tpl, $ilCtrl;
226 
227  // content style
228 /* include_once("./classes/class.ilObjStyleSheet.php");
229  $tpl->setCurrentBlock("ContentStyle");
230  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
231  ilObjStyleSheet::getContentStylePath(0));
232  $tpl->parseCurrentBlock();
233 */
234  $this->setTemplateOutput(false);
235  $this->setPresentationTitle($this->getWikiPage()->getTitle());
236  $this->getWikiPage()->increaseViewCnt();
237  $output = parent::showPage();
238 
239  return $output;
240  }
241 
245  function postOutputProcessing($a_output)
246  {
247 //echo htmlentities($a_output);
248  include_once("./Modules/Wiki/classes/class.ilWikiUtil.php");
249  $output = ilWikiUtil::replaceInternalLinks($a_output,
250  $this->getWikiPage()->getWikiId());
251  return $output;
252  }
253 
257  function whatLinksHere()
258  {
259  global $tpl;
260 
261  include_once("./Modules/Wiki/classes/class.ilWikiPagesTableGUI.php");
262 
263  $this->setSideBlock($_GET["wpg_id"]);
264  $table_gui = new ilWikiPagesTableGUI($this, "whatLinksHere",
265  $this->getWikiPage()->getWikiId(), IL_WIKI_WHAT_LINKS_HERE, $_GET["wpg_id"]);
266 
267  $tpl->setContent($table_gui->getHTML());
268  }
269 
270  function getTabs($a_activate = "")
271  {
272  global $ilTabs, $ilCtrl;
273 
274  parent::getTabs($a_activate);
275 
276  $ilCtrl->setParameterByClass("ilobjwikigui", "wpg_id",
277  ilWikiPage::getPageIdForTitle($this->getPageObject()->getParentId(),
278  ilWikiUtil::makeDbTitle($_GET["page"])));
279  $ilCtrl->setParameterByClass("ilobjwikigui", "page", ilWikiUtil::makeUrlTitle($_GET["page"]));
280 
281  $ilTabs->addTarget("wiki_what_links_here",
282  $this->ctrl->getLinkTargetByClass("ilwikipagegui",
283  "whatLinksHere"), "whatLinksHere");
284  $ilTabs->addTarget("wiki_print_view",
285  $this->ctrl->getLinkTargetByClass("ilobjwikigui",
286  "printView"), "printView", "", "_blank");
287 
288  }
289 
294  {
295  global $ilAccess, $tpl, $ilCtrl, $lng;
296 
297  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
298  {
299  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
300  $confirmation_gui = new ilConfirmationGUI();
301  $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
302  $confirmation_gui->setHeaderText($lng->txt("wiki_page_deletion_confirmation"));
303  $confirmation_gui->setCancel($lng->txt("cancel"), "cancelWikiPageDeletion");
304  $confirmation_gui->setConfirm($lng->txt("delete"), "confirmWikiPageDeletion");
305 
306  $dtpl = new ilTemplate("tpl.wiki_page_deletion_confirmation.html", true,
307  true, "Modules/Wiki");
308 
309  $dtpl->setVariable("PAGE_TITLE", $this->getWikiPage()->getTitle());
310 
311  // other pages that link to this page
312  $dtpl->setVariable("TXT_OTHER_PAGES", $lng->txt("wiki_other_pages_linking"));
313  $pages = ilWikiPage::getLinksToPage($this->getWikiPage()->getWikiId(),
314  $this->getWikiPage()->getId());
315  if (count($pages) > 0)
316  {
317  foreach($pages as $page)
318  {
319  $dtpl->setCurrentBlock("lpage");
320  $dtpl->setVariable("TXT_LINKING_PAGE", $page["title"]);
321  $dtpl->parseCurrentBlock();
322  }
323  }
324  else
325  {
326  $dtpl->setCurrentBlock("lpage");
327  $dtpl->setVariable("TXT_LINKING_PAGE", "-");
328  $dtpl->parseCurrentBlock();
329  }
330 
331  // contributors
332  $dtpl->setVariable("TXT_CONTRIBUTORS", $lng->txt("wiki_contributors"));
333  $contributors = ilWikiPage::getPageContributors($this->getWikiPage()->getId());
334  foreach($contributors as $contributor)
335  {
336  $dtpl->setCurrentBlock("contributor");
337  $dtpl->setVariable("TXT_CONTRIBUTOR",
338  $contributor["lastname"].", ".$contributor["firstname"]);
339  $dtpl->parseCurrentBlock();
340  }
341 
342  // notes/comments
343  include_once("./Services/Notes/classes/class.ilNote.php");
344  $cnt_note_users = ilNote::getUserCount($this->getPageObject()->getParentId(),
345  $this->getPageObject()->getId(), "wpg");
346  $dtpl->setVariable("TXT_NUMBER_USERS_NOTES_OR_COMMENTS",
347  $lng->txt("wiki_number_users_notes_or_comments"));
348  $dtpl->setVariable("TXT_NR_NOTES_COMMENTS", $cnt_note_users);
349 
350  $confirmation_gui->addItem("", "", $dtpl->get());
351 
352  $tpl->setContent($confirmation_gui->getHTML());
353  }
354  }
355 
360  {
361  global $lng, $ilCtrl;
362 
363  $ilCtrl->redirect($this, "preview");
364 
365  }
366 
371  {
372  global $ilAccess, $tpl, $ilCtrl, $lng;
373 
374  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
375  {
376  $this->getPageObject()->delete();
377 
378  ilUtil::sendSuccess($lng->txt("wiki_page_deleted"), true);
379  }
380 
381  $ilCtrl->redirectByClass("ilobjwikigui", "allPages");
382  }
383 
384 } // END class.ilWikiPageGUI
385 ?>