예제 #1
0
 function _notAuthorized($require_level)
 {
     // Display the authority message in the Wiki's default
     // language, in case it is not english.
     //
     // Note that normally a user will not see such an error once
     // logged in, unless the admin has altered the default
     // disallowed wikiactions. In that case we should probably
     // check the user's language prefs too at this point; this
     // would be a situation which is not really handled with the
     // current code.
     if (empty($GLOBALS['LANG'])) {
         update_locale(DEFAULT_LANGUAGE);
     }
     // User does not have required authority.  Prompt for login.
     $what = $this->getActionDescription($this->getArg('action'));
     $pass_required = $require_level >= WIKIAUTH_USER;
     if ($require_level == WIKIAUTH_UNOBTAINABLE) {
         global $DisabledActions;
         if ($DisabledActions and in_array($action, $DisabledActions)) {
             $msg = fmt("%s is disallowed on this wiki.", $this->getDisallowedActionDescription($this->getArg('action')));
             $this->finish();
             return;
         }
         // Is the reason a missing ACL or just wrong user or password?
         if (class_exists('PagePermission')) {
             $user =& $this->_user;
             $status = $user->isAuthenticated() ? _("authenticated") : _("not authenticated");
             $msg = fmt("%s %s %s is disallowed on this wiki for %s user '%s' (level: %s).", _("Missing PagePermission:"), action2access($this->getArg('action')), $this->getArg('pagename'), $status, $user->getId(), $this->getLevelDescription($user->_level));
             // TODO: add link to action=setacl
             $user->PrintLoginForm($this, compact('pass_required'), $msg);
             $this->finish();
             return;
         } else {
             $msg = fmt("%s is disallowed on this wiki.", $this->getDisallowedActionDescription($this->getArg('action')));
             $this->_user->PrintLoginForm($this, compact('require_level', 'pass_required'), $msg);
             $this->finish();
             return;
         }
     } elseif ($require_level == WIKIAUTH_BOGO) {
         $msg = fmt("You must sign in to %s.", $what);
     } elseif ($require_level == WIKIAUTH_USER) {
         $msg = fmt("You must log in to %s.", $what);
     } elseif ($require_level == WIKIAUTH_ANON) {
         $msg = fmt("Access for you is forbidden to %s.", $what);
     } else {
         $msg = fmt("You must be an administrator to %s.", $what);
     }
     $this->_user->PrintLoginForm($this, compact('require_level', 'pass_required'), $msg);
     $this->finish();
     // NORETURN
 }
예제 #2
0
/** 
 * Check the permissions for the current action.
 * Walk down the inheritance tree. Collect all permissions until 
 * the minimum required level is gained, which is not 
 * overruled by more specific forbid rules.
 * Todo: cache result per access and page in session?
 */
function requiredAuthorityForPage($action)
{
    global $request;
    $auth = _requiredAuthorityForPagename(action2access($action), $request->getArg('pagename'));
    assert($auth !== -1);
    if ($auth) {
        return $request->_user->_level;
    } else {
        return WIKIAUTH_UNOBTAINABLE;
    }
}
예제 #3
0
 /** 
  * Handle client-side POST moderation request on any moderated page.
  *   if ($page->get('moderation')) WikiPlugin_ModeratedPage::handler(...);
  * return false if not handled (pass through), true if handled and displayed.
  */
 function handler(&$request, &$page)
 {
     $action = $request->getArg('action');
     $moderated = $page->get('moderated');
     // cached version, need re-lock of each page to update moderators
     if (!empty($moderated['_status'])) {
         $status = $moderated['_status'];
     } else {
         $action_page = $request->getPage(_("ModeratedPage"));
         $status = $this->getSiteStatus($request, $action_page);
         $moderated['_status'] = $status;
     }
     if (!empty($status['emails'])) {
         trigger_error(_("ModeratedPage: No emails for the moderators defined"), E_USER_WARNING);
         return true;
     }
     // which action?
     if (!empty($status['require_access']) and !in_array(action2access($action), $status['require_access'])) {
         return false;
     }
     // allow and fall through, not moderated
     if (!empty($status['require_level']) and $request->_user->_level >= $status['require_level']) {
         return false;
     }
     // allow and fall through, not moderated
     // else all post actions are moderated by default
     if (1) {
         //$moderated = $page->get('moderated');
         $id = $this->generateId();
         while (!empty($moderated[$id])) {
             $id = $this->generateId();
         }
         // avoid duplicates
         $moderated['id'] = $id;
         // overwrite current id
         $moderated['data'][$id] = array('timestamp' => time(), 'userid' => $request->_user->getId(), 'args' => $request->getArgs(), 'user' => serialize($request->_user));
         $this->_tokens['CONTENT'] = HTML::div(array('class' => 'wikitext'), fmt("%s: action forwarded to moderator %s", $action, join(", ", $status['moderators'])));
         // send email
         $pagename = $page->getName();
         $subject = "[" . WIKI_NAME . '] ' . $action . ': ' . _("ModeratedPage") . ' ' . $pagename;
         if (mail(join(",", $status['emails']), $subject, $action . ': ' . _("ModeratedPage") . ' ' . $pagename . "\n" . serialize($moderated['data'][$id]) . "\n<" . WikiURL($pagename, array('action' => _("ModeratedPage"), 'id' => $id, 'pass' => 'approve'), 1) . ">" . "\n<" . WikiURL($pagename, array('action' => _("ModeratedPage"), 'id' => $id, 'pass' => 'reject'), 1) . ">\n")) {
             $page->set('moderated', $moderated);
             return false;
             // pass thru
         } else {
             //FIXME: This msg get lost on the edit redirect
             trigger_error(_("ModeratedPage Notification Error: Couldn't send email"), E_USER_WARNING);
             return true;
         }
     }
     return false;
 }
예제 #4
0
 /**
  * Handle client-side POST moderation request on any moderated page.
  *   if ($page->get('moderation')) WikiPlugin_ModeratedPage::handler(...);
  * return false if not handled (pass through), true if handled and displayed.
  */
 function handler(&$request, &$page)
 {
     $action = $request->getArg('action');
     $moderated = $page->get('moderated');
     // cached version, need re-lock of each page to update moderators
     if (!empty($moderated['status'])) {
         $status = $moderated['status'];
     } else {
         $action_page = $request->getPage(_("ModeratedPage"));
         $status = $this->getSiteStatus($request, $action_page);
         $moderated['status'] = $status;
     }
     if (empty($status['emails'])) {
         trigger_error(_("ModeratedPage: No emails for the moderators defined"), E_USER_WARNING);
         return true;
     }
     // which action?
     if (!empty($status['require_access']) and !in_array(action2access($action), $status['require_access'])) {
         return false;
     }
     // allow and fall through, not moderated
     if (!empty($status['require_level']) and $request->_user->_level >= $status['require_level']) {
         return false;
     }
     // allow and fall through, not moderated
     // else all post actions are moderated by default
     if (1) {
         $id = $this->generateId();
         while (!empty($moderated['data'][$id])) {
             $id = $this->generateId();
         }
         // avoid duplicates
         $moderated['id'] = $id;
         // overwrite current id
         $tempuser = $request->_user;
         if (isset($tempuser->_HomePagehandle)) {
             unset($tempuser->_HomePagehandle);
         }
         $moderated['data'][$id] = array('timestamp' => time(), 'userid' => $request->_user->getId(), 'args' => $request->getArgs(), 'user' => serialize($tempuser));
         $this->_tokens['CONTENT'] = HTML::div(array('class' => 'wikitext'), fmt("%s: action forwarded to moderator %s", $action, join(", ", $status['moderators'])));
         // Send email
         require_once "lib/MailNotify.php";
         $pagename = $page->getName();
         $mailer = new MailNotify($pagename);
         $subject = "[" . WIKI_NAME . '] ' . $action . ': ' . _("ModeratedPage") . ' ' . $pagename;
         $content = "You are approved as Moderator of the " . WIKI_NAME . " wiki.\n" . "Someone wanted to edit a moderated page, which you have to approve or reject.\n\n" . $action . ': ' . _("ModeratedPage") . ' ' . $pagename . "\n" . "\n<" . WikiURL($pagename, array('action' => _("ModeratedPage"), 'id' => $id, 'pass' => 'approve'), 1) . ">" . "\n<" . WikiURL($pagename, array('action' => _("ModeratedPage"), 'id' => $id, 'pass' => 'reject'), 1) . ">\n";
         $mailer->emails = $mailer->userids = $status['emails'];
         $mailer->from = $request->_user->_userid;
         if ($mailer->sendMail($subject, $content, "Moderation notice")) {
             $page->set('moderated', $moderated);
             return false;
             // pass thru
         } else {
             //DELETEME!
             $page->set('moderated', $moderated);
             //FIXME: This msg gets lost on the edit redirect
             trigger_error(_("ModeratedPage Notification Error: Couldn't send email"), E_USER_ERROR);
             return true;
         }
     }
     return false;
 }