4 Copyright (C) 2006 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Plugin to manage notifications emails per page. action=WatchPage
26 * pagename = pagename to be added
28 * Prefs are stored in metadata in the current session,
29 * within the user's home page or in a database.
31 class WikiPlugin_WatchPage
35 return _("WatchPage");
38 function getVersion() {
39 return preg_replace("/[Revision: $]/", '',
43 function getDefaultArguments() {
44 return array('page' => '[pagename]',
49 function contains($pagelist, $page) {
50 if (!isset($this->_explodePageList))
51 $this->_explodePageList = explodePageList($pagelist);
52 return in_array($page, $this->_explodePageList);
55 // This could be expanded as in mediawiki to a list of each page with a remove button.
56 function showWatchList($pagelist) {
57 return HTML::strong(HTML::tt(empty($pagelist) ? "<empty>" : $pagelist));
60 function addpagelist($page, $pagelist) {
61 if (!empty($pagelist)) {
62 if ($this->contains($pagelist, $page))
65 return "$pagelist,$page";
70 function showNotify(&$request, $messages, $page, $pagelist, $verified) {
71 $isNecessary = ! $this->contains($pagelist, $page);
73 (array('action' => $request->getPostURL(),
75 HiddenInputs(array('verify' => 1)),
76 HiddenInputs($request->getArgs(),false,array('verify')),
78 HTML::p(_("Your current watchlist: "), $this->showWatchList($pagelist)),
79 HTML::p(_("New watchlist: "),
80 $this->showWatchList($this->addpagelist($page, $pagelist))));
82 $form->pushContent(HTML::p(sprintf(_("Do you %s want to add this page \"%s\" to your WatchList?"),
83 ($verified ? _("really") : ""), $page)),
84 HTML::p(Button('submit:add', _("Yes")),
86 Button('submit:cancel', _("Cancel"))));
88 $form->pushContent(HTML::p(fmt("The page %s is already watched!", $page)),
89 HTML::p(Button('submit:edit', _("Edit")),
91 Button('submit:cancel', _("Cancel"))));
96 function run($dbi, $argstr, &$request, $basepage) {
97 $args = $this->getArgs($argstr, $request);
98 if (isa($request,'MockRequest'))
100 $user =& $request->_user;
101 $userid = $user->UserName();
102 $page = $args['page'];
103 if (!$user->isAuthenticated() or empty($userid)) {
104 // wrong or unauthenticated user
105 return $request->_notAuthorized(WIKIAUTH_BOGO);
106 //return $user->PrintLoginForm ($request, $args, false, false);
108 $pref = &$request->_prefs;
110 $email = $pref->get("email");
113 array('class' => 'errors'),
114 _("ERROR: No email defined! You need to do this in your "),
115 WikiLink(_("UserPreferences")));
117 $emailVerified = $pref->get("emailVerified");
118 if (empty($emailVerified))
119 $messages = HTML::div(array('class' => 'mw-warning'),
120 HTML::p("WARNING! Your email address was not verifed yet!"),
121 HTML::p("EmailNotifications currently disabled. <TODO>"));
122 $pagelist = $pref->get("notifyPages");
123 if (! $request->isPost() ) {
124 return $this->showNotify($request, $messages, $page, $pagelist, false);
127 if ($request->getArg('cancel')) {
128 $request->redirect(WikiURL($request->getArg('pagename'),
129 false, 'absolute_url')); // noreturn
132 if ($request->getArg('edit')) {
133 $request->redirect(WikiURL(_("UserPreferences"),
134 false, 'absolute_url')); // noreturn
137 $add = $request->getArg('add');
138 if ($add and !$request->getArg('verify')) {
139 return $this->showNotify($request, $messages, $page, $pagelist, true);
141 elseif ($add and $request->getArg('verify')) { // this is not executed so far.
142 // add page to watchlist, verified
143 $pref = &$request->_prefs;
144 $pref->set('notifyPages', $this->addpagelist($page, $pagelist));
145 $user->setPreferences($pref);
146 $request->_setUser($user);
147 $request->setArg("verify",false);
148 $request->setArg("add",false);
151 _("E-Mail Notification for the current page successfully stored in your preferences."));
160 // $Log: not supported by cvs2svn $
161 // Revision 1.1 2006/12/22 01:28:23 rurban
162 // new plugin similar to mediawiki
170 // c-hanging-comment-ender-p: nil
171 // indent-tabs-mode: nil