ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilWikiPageGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
25 include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
26 
39 {
43  function __construct($a_id = 0, $a_old_nr = 0)
44  {
45  global $tpl;
46 
47  parent::__construct("wpg", $a_id, $a_old_nr);
48 
49  // content style
50  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
51  $tpl->setCurrentBlock("ContentStyle");
52  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
54  $tpl->parseCurrentBlock();
55 
56  $tpl->setCurrentBlock("SyntaxStyle");
57  $tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
59  $tpl->parseCurrentBlock();
60 
61  $this->setEnabledMaps(true);
62  $this->setPreventHTMLUnmasking(true);
63  $this->setEnabledInternalLinks(false);
64  $this->setEnabledWikiLinks(true);
65 
66  }
67 
68  function initPageObject($a_parent_type, $a_id, $a_old_nr)
69  {
70  $page = new ilWikiPage($a_id, $a_old_nr);
71  $this->setPageObject($page);
72  }
73 
77  function &executeCommand()
78  {
79  global $ilCtrl, $ilTabs;
80 
81  $next_class = $this->ctrl->getNextClass($this);
82  $cmd = $this->ctrl->getCmd();
83 
84  switch($next_class)
85  {
86  case "ilnotegui":
87  $this->getTabs();
88  $ilTabs->setTabActive("pg");
89  return $this->preview();
90  break;
91 
92  case "ilratinggui":
93  include_once("./Services/Rating/classes/class.ilRatingGUI.php");
94  $rating_gui = new ilRatingGUI();
95  $rating_gui->setObject($this->getPageObject()->getParentId(), "wiki",
96  $this->getPageObject()->getId(), "wpg");
97  $this->ctrl->forwardCommand($rating_gui);
98  $ilCtrl->redirect($this, "preview");
99  break;
100 
101  case "ilpageobjectgui":
102  $page_gui = new ilPageObjectGUI("wpg",
103  $this->getPageObject()->getId(), $this->getPageObject()->old_nr);
104  return $ilCtrl->forwardCommand($page_gui);
105 
106  default:
107  return parent::executeCommand();
108  }
109  }
110 
116  function setWikiPage($a_wikipage)
117  {
118  $this->setPageObject($a_wikipage);
119  }
120 
126  function getWikiPage()
127  {
128  return $this->getPageObject();
129  }
130 
134  static function getGUIForTitle($a_wiki_id, $a_title, $a_old_nr = 0)
135  {
136  global $ilDB;
137 
138  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
139  $id = ilWikiPage::getPageIdForTitle($a_wiki_id, $a_title);
140  $page_gui = new ilWikiPageGUI($id, $a_old_nr);
141 
142  return $page_gui;
143  }
144 
145  function setSideBlock()
146  {
147  global $tpl;
148 
149  // side block
150  include_once("./Modules/Wiki/classes/class.ilWikiSideBlockGUI.php");
151  $wiki_side_block = new ilWikiSideBlockGUI();
152  $wiki_side_block->setPageObject($this->getWikiPage());
153 
154  // search block
155  include_once("./Modules/Wiki/classes/class.ilWikiSearchBlockGUI.php");
156  $wiki_search_block = new ilWikiSearchBlockGUI();
157  $rcontent = $wiki_side_block->getHTML().$wiki_search_block->getHTML();
158 
159  $tpl->setRightContent($rcontent);
160  }
161 
165  function preview()
166  {
167  global $ilCtrl, $ilAccess, $lng;
168 
169  $this->getWikiPage()->increaseViewCnt(); // todo: move to page object
170  $this->setSideBlock();
171  $wtpl = new ilTemplate("tpl.wiki_page_view_main_column.html",
172  true, true, "Modules/Wiki");
173 
174  // wiki page commands
175  // delete
176  $page_commands = false;
177  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
178  {
179  $st_page = ilObjWiki::_lookupStartPage($this->getPageObject()->getParentId());
180  if ($st_page != $this->getPageObject()->getTitle())
181  {
182  $wtpl->setCurrentBlock("page_command");
183  $wtpl->setVariable("HREF_PAGE_CMD",
184  $ilCtrl->getLinkTarget($this, "deleteWikiPageConfirmationScreen"));
185  $wtpl->setVariable("TXT_PAGE_CMD", $lng->txt("delete"));
186  $wtpl->parseCurrentBlock();
187  }
188  }
189  if ($page_commands)
190  {
191  $wtpl->setCurrentBlock("page_commands");
192  $wtpl->parseCurrentBlock();
193  }
194 
195  // rating
196  if (ilObjWiki::_lookupRating($this->getPageObject()->getParentId())
197  && $this->getPageObject()->old_nr == 0)
198  {
199  include_once("./Services/Rating/classes/class.ilRatingGUI.php");
200  $rating_gui = new ilRatingGUI();
201  $rating_gui->setObject($this->getPageObject()->getParentId(), "wiki",
202  $this->getPageObject()->getId(), "wpg");
203  $wtpl->setVariable("RATING", $ilCtrl->getHtml($rating_gui));
204  }
205 
206  // notes
207  include_once("Services/Notes/classes/class.ilNoteGUI.php");
208  $pg_id = $this->getPageObject()->getId();
209  $notes_gui = new ilNoteGUI($this->getPageObject()->getParentId(),
210  $pg_id, "wpg");
211  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
212  {
213  $notes_gui->enablePublicNotesDeletion(true);
214  }
215  $notes_gui->enablePrivateNotes();
216  //if ($this->lm->publicNotes())
217  //{
218  $notes_gui->enablePublicNotes();
219  //}
220 
221  $next_class = $this->ctrl->getNextClass($this);
222  if ($next_class == "ilnotegui")
223  {
224  $html = $this->ctrl->forwardCommand($notes_gui);
225  }
226  else
227  {
228  $html = $notes_gui->getNotesHTML();
229  }
230  $wtpl->setVariable("NOTES", $html);
231 
232  // permanent link
233  $append = ($_GET["page"] != "")
234  ? "_".ilWikiUtil::makeUrlTitle($_GET["page"])
235  : "";
236  include_once("./Services/PermanentLink/classes/class.ilPermanentLinkGUI.php");
237  $perma_link = new ilPermanentLinkGUI("wiki", $_GET["ref_id"], $append);
238  $wtpl->setVariable("PERMA_LINK", $perma_link->getHTML());
239 
240  $wtpl->setVariable("PAGE", parent::preview());
241  return $wtpl->get();
242  }
243 
244  function showPage()
245  {
246  global $tpl, $ilCtrl;
247 
248  // content style
249 /* include_once("./classes/class.ilObjStyleSheet.php");
250  $tpl->setCurrentBlock("ContentStyle");
251  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
252  ilObjStyleSheet::getContentStylePath(0));
253  $tpl->parseCurrentBlock();
254 */
255  $this->setTemplateOutput(false);
256  $this->setPresentationTitle($this->getWikiPage()->getTitle());
257  $this->getWikiPage()->increaseViewCnt();
258  $output = parent::showPage();
259 
260  return $output;
261  }
262 
266  function postOutputProcessing($a_output)
267  {
268 //echo htmlentities($a_output);
269  include_once("./Modules/Wiki/classes/class.ilWikiUtil.php");
270  $output = ilWikiUtil::replaceInternalLinks($a_output,
271  $this->getWikiPage()->getWikiId());
272  return $output;
273  }
274 
278  function whatLinksHere()
279  {
280  global $tpl;
281 
282  include_once("./Modules/Wiki/classes/class.ilWikiPagesTableGUI.php");
283 
284  $this->setSideBlock($_GET["wpg_id"]);
285  $table_gui = new ilWikiPagesTableGUI($this, "whatLinksHere",
286  $this->getWikiPage()->getWikiId(), IL_WIKI_WHAT_LINKS_HERE, $_GET["wpg_id"]);
287 
288  $tpl->setContent($table_gui->getHTML());
289  }
290 
291  function getTabs($a_activate = "")
292  {
293  global $ilTabs, $ilCtrl;
294 
295  parent::getTabs($a_activate);
296 
297  $ilCtrl->setParameterByClass("ilobjwikigui", "wpg_id",
298  ilWikiPage::getPageIdForTitle($this->getPageObject()->getParentId(),
299  ilWikiUtil::makeDbTitle($_GET["page"])));
300  $ilCtrl->setParameterByClass("ilobjwikigui", "page", ilWikiUtil::makeUrlTitle($_GET["page"]));
301 
302  $ilTabs->addTarget("wiki_what_links_here",
303  $this->ctrl->getLinkTargetByClass("ilwikipagegui",
304  "whatLinksHere"), "whatLinksHere");
305  $ilTabs->addTarget("wiki_print_view",
306  $this->ctrl->getLinkTargetByClass("ilobjwikigui",
307  "printView"), "printView");
308 
309  }
310 
315  {
316  global $ilAccess, $tpl, $ilCtrl, $lng;
317 
318  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
319  {
320  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
321  $confirmation_gui = new ilConfirmationGUI();
322  $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
323  $confirmation_gui->setHeaderText($lng->txt("wiki_page_deletion_confirmation"));
324  $confirmation_gui->setCancel($lng->txt("cancel"), "cancelWikiPageDeletion");
325  $confirmation_gui->setConfirm($lng->txt("delete"), "confirmWikiPageDeletion");
326 
327  $dtpl = new ilTemplate("tpl.wiki_page_deletion_confirmation.html", true,
328  true, "Modules/Wiki");
329 
330  $dtpl->setVariable("PAGE_TITLE", $this->getWikiPage()->getTitle());
331 
332  // other pages that link to this page
333  $dtpl->setVariable("TXT_OTHER_PAGES", $lng->txt("wiki_other_pages_linking"));
334  $pages = ilWikiPage::getLinksToPage($this->getWikiPage()->getWikiId(),
335  $this->getWikiPage()->getId());
336  if (count($pages) > 0)
337  {
338  foreach($pages as $page)
339  {
340  $dtpl->setCurrentBlock("lpage");
341  $dtpl->setVariable("TXT_LINKING_PAGE", $page["title"]);
342  $dtpl->parseCurrentBlock();
343  }
344  }
345  else
346  {
347  $dtpl->setCurrentBlock("lpage");
348  $dtpl->setVariable("TXT_LINKING_PAGE", "-");
349  $dtpl->parseCurrentBlock();
350  }
351 
352  // contributors
353  $dtpl->setVariable("TXT_CONTRIBUTORS", $lng->txt("wiki_contributors"));
354  $contributors = ilWikiPage::getPageContributors($this->getWikiPage()->getId());
355  foreach($contributors as $contributor)
356  {
357  $dtpl->setCurrentBlock("contributor");
358  $dtpl->setVariable("TXT_CONTRIBUTOR",
359  $contributor["lastname"].", ".$contributor["firstname"]);
360  $dtpl->parseCurrentBlock();
361  }
362 
363  // notes/comments
364  include_once("./Services/Notes/classes/class.ilNote.php");
365  $cnt_note_users = ilNote::getUserCount($this->getPageObject()->getParentId(),
366  $this->getPageObject()->getId(), "wpg");
367  $dtpl->setVariable("TXT_NUMBER_USERS_NOTES_OR_COMMENTS",
368  $lng->txt("wiki_number_users_notes_or_comments"));
369  $dtpl->setVariable("TXT_NR_NOTES_COMMENTS", $cnt_note_users);
370 
371  $confirmation_gui->addItem("", "", $dtpl->get());
372 
373  $tpl->setContent($confirmation_gui->getHTML());
374  }
375  }
376 
381  {
382  global $lng, $ilCtrl;
383 
384  ilUtil::sendInfo($lng->txt("action_aborted"), true);
385  $ilCtrl->redirect($this, "preview");
386 
387  }
388 
393  {
394  global $ilAccess, $tpl, $ilCtrl, $lng;
395 
396  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
397  {
398  $this->getPageObject()->delete();
399 
400  ilUtil::sendInfo($lng->txt("wiki_page_deleted"), true);
401  }
402 
403  $ilCtrl->redirectByClass("ilobjwikigui", "allPages");
404  }
405 
406 } // END class.ilWikiPageGUI
407 ?>