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
20 along with PhpWiki; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Plugin to manage notifications emails 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
36 return _("WatchPage");
39 function getVersion() {
40 return preg_replace("/[Revision: $]/", '',
44 function getDefaultArguments() {
45 return array('page' => '[pagename]',
50 function contains($pagelist, $page) {
51 if (!isset($this->_explodePageList))
52 $this->_explodePageList = explodePageList($pagelist);
53 return in_array($page, $this->_explodePageList);
56 // This could be expanded as in Mediawiki to a list of each page with a remove button.
57 function showWatchList($pagelist) {
58 return HTML::strong(HTML::tt(empty($pagelist) ? _("<empty>") : $pagelist));
61 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) {
72 $isNecessary = ! $this->contains($pagelist, $page);
74 (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)),
80 HTML::p(_("New watchlist: "),
81 $this->showWatchList($this->addpagelist($page, $pagelist))));
83 $form->pushContent(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"))));
97 function run($dbi, $argstr, &$request, $basepage) {
100 $args = $this->getArgs($argstr, $request);
101 if (isa($request,'MockRequest'))
103 $user =& $request->_user;
104 $userid = $user->UserName();
105 $page = $args['page'];
106 if (!$user->isAuthenticated() or empty($userid)) {
107 // wrong or unauthenticated user
108 return $request->_notAuthorized(WIKIAUTH_BOGO);
109 //return $user->PrintLoginForm ($request, $args, false, false);
111 $pref = &$request->_prefs;
113 $email = $pref->get("email");
116 array('class' => 'errors'),
117 _("ERROR: No email defined! You need to do this in your "),
118 WikiLink(_("UserPreferences")));
120 $emailVerified = $pref->get("emailVerified");
121 if (empty($emailVerified))
122 $messages = HTML::div(array('class' => 'mw-warning'),
123 HTML::p("WARNING! Your email address was not verifed yet!"),
124 HTML::p("EmailNotifications currently disabled. <TODO>"));
125 $pagelist = $pref->get("notifyPages");
126 if (! $request->isPost() ) {
127 return $this->showNotify($request, $messages, $page, $pagelist, false);
130 if ($request->getArg('cancel')) {
131 $request->redirect(WikiURL($request->getArg('pagename'),
132 false, 'absolute_url')); // noreturn
135 if ($request->getArg('edit')) {
136 $request->redirect(WikiURL(_("UserPreferences"),
137 false, 'absolute_url')); // noreturn
140 $add = $request->getArg('add');
141 if ($add and !$request->getArg('verify')) {
142 return $this->showNotify($request, $messages, $page, $pagelist, true);
144 elseif ($add and $request->getArg('verify')) { // this is not executed so far.
145 // add page to watchlist, verified
146 $pref = &$request->_prefs;
147 $pref->set('notifyPages', $this->addpagelist($page, $pagelist));
148 $user->setPreferences($pref);
149 $request->_setUser($user);
150 $request->setArg("verify",false);
151 $request->setArg("add",false);
152 // No alert for Gforge
153 if (isa($WikiTheme, 'WikiTheme_gforge')) {
158 _("E-Mail Notification for the current page successfully stored in your preferences."));
172 // c-hanging-comment-ender-p: nil
173 // indent-tabs-mode: nil