4 * Copyright (C) 2006 $ThePhpWikiProgrammingTeam
5 * Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
7 * This file is part of PhpWiki.
9 * PhpWiki is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * PhpWiki is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * Plugin to manage notifications e-mails per page. action=WatchPage
27 * pagename = pagename to be added
29 * Prefs are stored in metadata in the current session,
30 * within the user's home page or in a database.
32 class WikiPlugin_WatchPage
37 return _("WatchPage");
40 function getDescription()
42 return _("Manage notifications e-mails per page.");
45 function getDefaultArguments()
47 return array('page' => '[pagename]',
52 function contains($pagelist, $page)
54 if (!isset($this->_explodePageList))
55 $this->_explodePageList = explodePageList($pagelist);
56 return in_array($page, $this->_explodePageList);
59 // This could be expanded as in Mediawiki to a list of each page with a remove button.
60 function showWatchList($pagelist)
62 return HTML::strong(HTML::tt(empty($pagelist) ? _("<empty>") : $pagelist));
65 function addpagelist($page, $pagelist)
67 if (!empty($pagelist)) {
68 if ($this->contains($pagelist, $page))
71 return "$pagelist, $page";
76 function showNotify(&$request, $messages, $page, $pagelist, $verified)
78 $isNecessary = !$this->contains($pagelist, $page);
79 $form = HTML::form(array('action' => $request->getPostURL(),
81 HiddenInputs(array('verify' => 1)),
82 HiddenInputs($request->getArgs(), false, array('verify')),
84 HTML::p(_("Your current watchlist: "), $this->showWatchList($pagelist)));
86 $form->pushContent(HTML::p(_("New watchlist: "),
87 $this->showWatchList($this->addpagelist($page, $pagelist))),
88 HTML::p(sprintf(_("Do you %s want to add this page \"%s\" to your WatchList?"),
89 ($verified ? _("really") : ""), $page)),
90 HTML::p(Button('submit:add', _("Yes")),
92 Button('submit:cancel', _("Cancel"))));
94 $form->pushContent(HTML::p(fmt("The page %s is already watched!", $page)),
95 HTML::p(Button('submit:edit', _("Edit")),
97 Button('submit:cancel', _("Cancel"))));
99 $fieldset = HTML::fieldset(HTML::legend(_("Watch Page")), $form);
103 function run($dbi, $argstr, &$request, $basepage)
106 $args = $this->getArgs($argstr, $request);
107 if (isa($request, 'MockRequest'))
109 $user =& $request->_user;
110 $userid = $user->UserName();
111 $page = $args['page'];
112 if (!$user->isAuthenticated() or empty($userid)) {
113 // wrong or unauthenticated user
114 if (defined('FUSIONFORGE') and FUSIONFORGE) {
115 // No login banner for FusionForge
116 return HTML::div(array('class' => 'error'),
117 HTML::p(_("You must sign in to watch pages.")));
119 return $request->_notAuthorized(WIKIAUTH_BOGO);
121 $pref = &$request->_prefs;
123 if (!defined('FUSIONFORGE') or !FUSIONFORGE) {
124 $email = $pref->get("email");
127 array('class' => 'error'),
128 _("ERROR: No e-mail defined! You need to do this in your "),
129 WikiLink(_("UserPreferences")));
131 $emailVerified = $pref->get("emailVerified");
132 if (empty($emailVerified)) {
133 $messages = HTML::div(array('class' => 'mw-warning'),
134 HTML::p("WARNING! Your email address was not verifed yet!"),
135 HTML::p("EmailNotifications currently disabled. <TODO>"));
138 $pagelist = $pref->get("notifyPages");
139 if (!$request->isPost()) {
140 return $this->showNotify($request, $messages, $page, $pagelist, false);
143 if ($request->getArg('cancel')) {
144 $request->redirect(WikiURL($request->getArg('pagename'),
145 array('warningmsg' => _('WatchPage cancelled')),
150 if ($request->getArg('edit')) {
151 $request->redirect(WikiURL(_("UserPreferences"),
152 false, 'absolute_url')); // noreturn
155 $add = $request->getArg('add');
156 if ($add and !$request->getArg('verify')) {
157 return $this->showNotify($request, $messages, $page, $pagelist, true);
158 } elseif ($add and $request->getArg('verify')) { // this is not executed so far.
159 // add page to watchlist, verified
160 $rp = clone($user->getPreferences());
161 $rp->set('notifyPages', $this->addpagelist($page, $pagelist));
162 $user->setPreferences($rp);
163 $request->_setUser($user);
164 $request->setArg("verify", false);
165 $request->setArg("add", false);
166 $errmsg .= _("E-mail notification for the current page successfully stored in your preferences.");
167 $args['errmsg'] = HTML::div(array('class' => 'feedback'), HTML::p($errmsg));
168 return Template('userprefs', $args);
179 // c-hanging-comment-ender-p: nil
180 // indent-tabs-mode: nil