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
35 function getDescription()
37 return _("Manage notifications e-mails per page.");
40 function getDefaultArguments()
42 return array('page' => '[pagename]',
47 function contains($pagelist, $page)
49 if (!isset($this->_explodePageList))
50 $this->_explodePageList = explodePageList($pagelist);
51 return in_array($page, $this->_explodePageList);
54 // This could be expanded as in Mediawiki to a list of each page with a remove button.
55 function showWatchList($pagelist)
57 return HTML::strong(HTML::tt(empty($pagelist) ? _("<empty>") : $pagelist));
60 function addpagelist($page, $pagelist)
62 if (!empty($pagelist)) {
63 if ($this->contains($pagelist, $page))
66 return "$pagelist, $page";
71 function showNotify(&$request, $messages, $page, $pagelist, $verified)
73 $isNecessary = !$this->contains($pagelist, $page);
74 $form = HTML::form(array('action' => $request->getPostURL(),
76 HiddenInputs(array('verify' => 1)),
77 HiddenInputs($request->getArgs(), false, array('verify')),
79 HTML::p(_("Your current watchlist: "), $this->showWatchList($pagelist)));
81 $form->pushContent(HTML::p(_("New watchlist: "),
82 $this->showWatchList($this->addpagelist($page, $pagelist))),
83 HTML::p(sprintf(_("Do you %s want to add this page \"%s\" to your WatchList?"),
84 ($verified ? _("really") : ""), $page)),
85 HTML::p(Button('submit:add', _("Yes")),
87 Button('submit:cancel', _("Cancel"))));
89 $form->pushContent(HTML::p(fmt("The page %s is already watched!", $page)),
90 HTML::p(Button('submit:edit', _("Edit")),
92 Button('submit:cancel', _("Cancel"))));
94 $fieldset = HTML::fieldset(HTML::legend(_("Watch Page")), $form);
98 function run($dbi, $argstr, &$request, $basepage)
101 $args = $this->getArgs($argstr, $request);
102 if (isa($request, 'MockRequest'))
104 $user =& $request->_user;
105 $userid = $user->UserName();
106 $page = $args['page'];
107 if (!$user->isAuthenticated() or empty($userid)) {
108 // wrong or unauthenticated user
109 if (defined('FUSIONFORGE') and FUSIONFORGE) {
110 // No login banner for FusionForge
111 return HTML::div(array('class' => 'error'),
112 HTML::p(_("You must sign in to watch pages.")));
114 return $request->_notAuthorized(WIKIAUTH_BOGO);
116 $pref = &$request->_prefs;
118 if (!defined('FUSIONFORGE') or !FUSIONFORGE) {
119 $email = $pref->get("email");
122 array('class' => 'error'),
123 _("ERROR: No e-mail defined! You need to do this in your "),
124 WikiLink(_("UserPreferences")));
126 $emailVerified = $pref->get("emailVerified");
127 if (empty($emailVerified)) {
128 $messages = HTML::div(array('class' => 'mw-warning'),
129 HTML::p("WARNING! Your email address was not verifed yet!"),
130 HTML::p("EmailNotifications currently disabled. <TODO>"));
133 $pagelist = $pref->get("notifyPages");
134 if (!$request->isPost()) {
135 return $this->showNotify($request, $messages, $page, $pagelist, false);
138 if ($request->getArg('cancel')) {
139 $request->redirect(WikiURL($request->getArg('pagename'),
140 array('warningmsg' => _('WatchPage cancelled')),
145 if ($request->getArg('edit')) {
146 $request->redirect(WikiURL(_("UserPreferences"),
147 false, 'absolute_url')); // noreturn
150 $add = $request->getArg('add');
151 if ($add and !$request->getArg('verify')) {
152 return $this->showNotify($request, $messages, $page, $pagelist, true);
153 } elseif ($add and $request->getArg('verify')) { // this is not executed so far.
154 // add page to watchlist, verified
155 $rp = clone($user->getPreferences());
156 $rp->set('notifyPages', $this->addpagelist($page, $pagelist));
157 $user->setPreferences($rp);
158 $request->_setUser($user);
159 $request->setArg("verify", false);
160 $request->setArg("add", false);
161 $errmsg .= _("E-mail notification for the current page successfully stored in your preferences.");
162 $args['errmsg'] = HTML::div(array('class' => 'feedback'), HTML::p($errmsg));
163 return Template('userprefs', $args);
175 // c-hanging-comment-ender-p: nil
176 // indent-tabs-mode: nil