'[pagename]', 'mode' => 'add', ); } function contains($pagelist, $page) { if (!isset($this->_explodePageList)) $this->_explodePageList = explodePageList($pagelist); return in_array($page, $this->_explodePageList); } // This could be expanded as in Mediawiki to a list of each page with a remove button. function showWatchList($pagelist) { return HTML::strong(HTML::tt(empty($pagelist) ? _("") : $pagelist)); } function addpagelist($page, $pagelist) { if (!empty($pagelist)) { if ($this->contains($pagelist, $page)) return "$pagelist"; else return "$pagelist, $page"; } else return "$page"; } function showNotify(&$request, $messages, $page, $pagelist, $verified) { $isNecessary = ! $this->contains($pagelist, $page); $form = HTML::form(array('action' => $request->getPostURL(), 'method' => 'post'), HiddenInputs(array('verify' => 1)), HiddenInputs($request->getArgs(),false,array('verify')), $messages, HTML::p(_("Your current watchlist: "), $this->showWatchList($pagelist))); if ($isNecessary) { $form->pushContent(HTML::p(_("New watchlist: "), $this->showWatchList($this->addpagelist($page, $pagelist))), HTML::p(sprintf(_("Do you %s want to add this page \"%s\" to your WatchList?"), ($verified ? _("really") : ""), $page)), HTML::p(Button('submit:add', _("Yes")), HTML::Raw(' '), Button('submit:cancel', _("Cancel")))); } else { $form->pushContent(HTML::p(fmt("The page %s is already watched!", $page)), HTML::p(Button('submit:edit', _("Edit")), HTML::Raw(' '), Button('submit:cancel', _("Cancel")))); } $fieldset = HTML::fieldset(HTML::legend("Watch Page"), $form); return $fieldset; } function run($dbi, $argstr, &$request, $basepage) { global $WikiTheme; $args = $this->getArgs($argstr, $request); if (isa($request,'MockRequest')) return ''; $user =& $request->_user; $userid = $user->UserName(); $page = $args['page']; if (!$user->isAuthenticated() or empty($userid)) { // wrong or unauthenticated user return $request->_notAuthorized(WIKIAUTH_BOGO); //return $user->PrintLoginForm ($request, $args, false, false); } else { $pref = &$request->_prefs; $messages = ""; if (!defined('GFORGE') or !GFORGE) { $email = $pref->get("email"); if (empty($email)) { return HTML::div( array('class' => 'errors'), _("ERROR: No email defined! You need to do this in your "), WikiLink(_("UserPreferences"))); } $emailVerified = $pref->get("emailVerified"); if (empty($emailVerified)) { $messages = HTML::div(array('class' => 'mw-warning'), HTML::p("WARNING! Your email address was not verifed yet!"), HTML::p("EmailNotifications currently disabled. ")); } } $pagelist = $pref->get("notifyPages"); if (! $request->isPost() ) { return $this->showNotify($request, $messages, $page, $pagelist, false); } else { // POST $errmsg = ''; if ($request->getArg('cancel')) { $request->redirect(WikiURL($request->getArg('pagename'), false, 'absolute_url')); // noreturn return; } if ($request->getArg('edit')) { $request->redirect(WikiURL(_("UserPreferences"), false, 'absolute_url')); // noreturn return; } $add = $request->getArg('add'); if ($add and !$request->getArg('verify')) { return $this->showNotify($request, $messages, $page, $pagelist, true); } elseif ($add and $request->getArg('verify')) { // this is not executed so far. // add page to watchlist, verified $rp = $user->getPreferences(); $rp->set('notifyPages', $this->addpagelist($page, $pagelist)); $user->setPreferences($rp); $request->_setUser($user); $request->setArg("verify",false); $request->setArg("add",false); $errmsg .= _("E-Mail Notification for the current page successfully stored in your preferences."); $args['errmsg'] = HTML::div(array('class' => 'feedback'), HTML::p($errmsg)); return Template('userprefs', $args); } } } } }; // For emacs users // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?>