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::samp(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);
100 * @param string $argstr
101 * @param WikiRequest $request
102 * @param string $basepage
105 function run($dbi, $argstr, &$request, $basepage)
108 $args = $this->getArgs($argstr, $request);
109 if (isa($request, 'MockRequest'))
111 $user =& $request->_user;
112 $userid = $user->UserName();
113 $page = $args['page'];
114 if (!$user->isAuthenticated() or empty($userid)) {
115 // wrong or unauthenticated user
116 if (defined('FUSIONFORGE') and FUSIONFORGE) {
117 // No login banner for FusionForge
118 return HTML::div(array('class' => 'error'),
119 HTML::p(_("You must sign in to watch pages.")));
121 return $request->_notAuthorized(WIKIAUTH_BOGO);
123 $pref = &$request->_prefs;
125 if (!defined('FUSIONFORGE') or !FUSIONFORGE) {
126 $email = $pref->get("email");
129 array('class' => 'error'),
130 _("ERROR: No e-mail defined! You need to do this in your "),
131 WikiLink(_("UserPreferences")));
133 $emailVerified = $pref->get("emailVerified");
134 if (empty($emailVerified)) {
135 $messages = HTML::div(array('class' => 'mw-warning'),
136 HTML::p("WARNING! Your email address was not verifed yet!"),
137 HTML::p("EmailNotifications currently disabled. <TODO>"));
140 $pagelist = $pref->get("notifyPages");
141 if (!$request->isPost()) {
142 return $this->showNotify($request, $messages, $page, $pagelist, false);
145 if ($request->getArg('cancel')) {
146 $request->redirect(WikiURL($request->getArg('pagename'),
147 array('warningmsg' => _('WatchPage cancelled')),
152 if ($request->getArg('edit')) {
153 $request->redirect(WikiURL(_("UserPreferences"), array(), 'absolute_url')); // noreturn
156 $add = $request->getArg('add');
157 if ($add and !$request->getArg('verify')) {
158 return $this->showNotify($request, $messages, $page, $pagelist, true);
159 } elseif ($add and $request->getArg('verify')) { // this is not executed so far.
160 // add page to watchlist, verified
161 $rp = clone($user->getPreferences());
162 $rp->set('notifyPages', $this->addpagelist($page, $pagelist));
163 $user->setPreferences($rp);
164 $request->_setUser($user);
165 $request->setArg("verify", false);
166 $request->setArg("add", false);
167 $errmsg .= _("E-mail notification for the current page successfully stored in your preferences.");
168 $args['errmsg'] = HTML::div(array('class' => 'feedback'), HTML::p($errmsg));
169 return Template('userprefs', $args);
181 // c-hanging-comment-ender-p: nil
182 // indent-tabs-mode: nil