Example #1
0
 function buildFeatureView($feature, $error = false, $success = false)
 {
     global $wgUser, $wgOut, $wgInvitationTypes, $wgLang;
     $friendlyname = wfMsg("invitation-type-{$feature}");
     $wgOut->setPageTitle(wfMsg('invitations-feature-pagetitle', $friendlyname));
     $wgOut->setRobotPolicy("noindex,nofollow");
     $wgOut->setArticleRelated(false);
     $wgOut->enableClientCache(false);
     if (Invitations::hasInvite($feature)) {
         $wgOut->addWikiMsg('invitations-feature-access', $friendlyname);
         $numleft = Invitations::getRemainingInvites($feature);
         $numLeftFmt = $wgLang->formatNum($numleft);
         if ($numleft > 0) {
             $allocation = $wgLang->formatNum($wgInvitationTypes[$feature]['reserve']);
             $wgOut->addWikiMsg('invitations-feature-numleft', $numleftFmt, $allocation);
         } else {
             if ($numleft == -1) {
                 # Do nothing.
             } else {
                 if (!Invitations::checkDelay($feature)) {
                     $wgOut->addWikiMsg('invitations-feature-noneyet');
                 } else {
                     $wgOut->addWikiMsg('invitations-feature-noneleft');
                 }
             }
         }
         // Successes and errors
         if ($error) {
             $wgOut->wrapWikiMsg('<div class="error">$1</div>', $error);
         } else {
             if ($success) {
                 $wgOut->wrapWikiMsg('<big>$1</big>', $success);
             }
         }
         // Invitation form
         if ($numleft != 0) {
             $wgOut->addHTML($this->buildInvitationForm($feature, $error));
         }
     } else {
         $wgOut->addWikiMsg('invitations-feature-notallowed', $friendlyname);
     }
 }
Example #2
0
 /**
  * Check if the given user has had the given feature for long enough to invite.
  * @param string $feature The feature to check
  * @param object $user The user to check
  * @param int $time The age of the user's account
  */
 public static function checkDelay($feature, $user = null, $time = null)
 {
     global $wgUser, $wgInvitationTypes;
     if ($user === null) {
         $user = $wgUser;
     }
     if ($time !== null) {
         // Do nothing
     } else {
         if ($time === null && !Invitations::hasInvite($feature, $user, $time)) {
             return false;
         } else {
             // The user has an invite, and we retrieved its creation point. Find its age
             $time = time() - $time;
         }
     }
     if ($time < $wgInvitationTypes[$feature]['invitedelay']) {
         return false;
     } else {
         return true;
     }
 }