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 getDescription () {
40 return _("Manage notifications emails per page.");
43 function getVersion() {
44 return preg_replace("/[Revision: $]/", '',
48 function getDefaultArguments() {
49 return array('page' => '[pagename]',
54 function contains($pagelist, $page) {
55 if (!isset($this->_explodePageList))
56 $this->_explodePageList = explodePageList($pagelist);
57 return in_array($page, $this->_explodePageList);
60 // This could be expanded as in Mediawiki to a list of each page with a remove button.
61 function showWatchList($pagelist) {
62 return HTML::strong(HTML::tt(empty($pagelist) ? _("<empty>") : $pagelist));
65 function addpagelist($page, $pagelist) {
66 if (!empty($pagelist)) {
67 if ($this->contains($pagelist, $page))
70 return "$pagelist,$page";
75 function showNotify(&$request, $messages, $page, $pagelist, $verified) {
76 $isNecessary = ! $this->contains($pagelist, $page);
78 (array('action' => $request->getPostURL(),
80 HiddenInputs(array('verify' => 1)),
81 HiddenInputs($request->getArgs(),false,array('verify')),
83 HTML::p(_("Your current watchlist: "), $this->showWatchList($pagelist)),
84 HTML::p(_("New watchlist: "),
85 $this->showWatchList($this->addpagelist($page, $pagelist))));
87 $form->pushContent(HTML::p(sprintf(_("Do you %s want to add this page \"%s\" to your WatchList?"),
88 ($verified ? _("really") : ""), $page)),
89 HTML::p(Button('submit:add', _("Yes")),
91 Button('submit:cancel', _("Cancel"))));
93 $form->pushContent(HTML::p(fmt("The page %s is already watched!", $page)),
94 HTML::p(Button('submit:edit', _("Edit")),
96 Button('submit:cancel', _("Cancel"))));
101 function run($dbi, $argstr, &$request, $basepage) {
104 $args = $this->getArgs($argstr, $request);
105 if (isa($request,'MockRequest'))
107 $user =& $request->_user;
108 $userid = $user->UserName();
109 $page = $args['page'];
110 if (!$user->isAuthenticated() or empty($userid)) {
111 // wrong or unauthenticated user
112 return $request->_notAuthorized(WIKIAUTH_BOGO);
113 //return $user->PrintLoginForm ($request, $args, false, false);
115 $pref = &$request->_prefs;
117 $email = $pref->get("email");
120 array('class' => 'errors'),
121 _("ERROR: No email defined! You need to do this in your "),
122 WikiLink(_("UserPreferences")));
124 $emailVerified = $pref->get("emailVerified");
125 if (empty($emailVerified))
126 $messages = HTML::div(array('class' => 'mw-warning'),
127 HTML::p("WARNING! Your email address was not verifed yet!"),
128 HTML::p("EmailNotifications currently disabled. <TODO>"));
129 $pagelist = $pref->get("notifyPages");
130 if (! $request->isPost() ) {
131 return $this->showNotify($request, $messages, $page, $pagelist, false);
134 if ($request->getArg('cancel')) {
135 $request->redirect(WikiURL($request->getArg('pagename'),
136 false, 'absolute_url')); // noreturn
139 if ($request->getArg('edit')) {
140 $request->redirect(WikiURL(_("UserPreferences"),
141 false, 'absolute_url')); // noreturn
144 $add = $request->getArg('add');
145 if ($add and !$request->getArg('verify')) {
146 return $this->showNotify($request, $messages, $page, $pagelist, true);
148 elseif ($add and $request->getArg('verify')) { // this is not executed so far.
149 // add page to watchlist, verified
150 $pref = &$request->_prefs;
151 $pref->set('notifyPages', $this->addpagelist($page, $pagelist));
152 $user->setPreferences($pref);
153 $request->_setUser($user);
154 $request->setArg("verify",false);
155 $request->setArg("add",false);
156 $errmsg .= _("E-Mail Notification for the current page successfully stored in your preferences.");
157 $args['errmsg'] = HTML::div(array('class' => 'feedback'), HTML::p($errmsg));
158 return Template('userprefs', $args);
170 // c-hanging-comment-ender-p: nil
171 // indent-tabs-mode: nil