Esempio n. 1
0
 /**
  * @param User $user
  * @return boolean
  */
 public function isMember($user)
 {
     return WpMember::IsMember($this, $user);
 }
Esempio n. 2
0
 /**
  * 
  * @param type $user_name
  * @param array $allData An array with all data (within a HTMLForm)
  * @return boolean
  */
 public function validateAddMemberUserName($user_name, $allData)
 {
     if ($user_name == null) {
         return wfMessage('htmlform-required')->text();
     }
     $user = User::newFromName($user_name);
     if (!$user instanceof User || $user->getId() == 0) {
         return wfMessage('nosuchusershort', $user_name);
     }
     // $allData['WpId'] is already checked, because it is declared earlier in the form descriptor
     $wikiplace = WpWikiplace::getById(intval($allData['WpId']));
     if (!$wikiplace instanceof WpWikiplace) {
         return wfMessage('internalerror');
     }
     if ($wikiplace->isOwner($user->getId())) {
         return wfMessage('wp-owner-cannot-be-member');
     }
     if (WpMember::IsMember($wikiplace, $user)) {
         return wfMessage('wp-already-member');
     }
     return true;
     // ok
 }
Esempio n. 3
0
 /**
  * @todo should not be a hook. Should be...
  * WpWikiPlaces->hasMember($user) 
  * WpMember->isMember($WikiPlace) 
  * and called by getUserPermissionError()
  * 
  * @param Title $title
  * @param User $user
  * @param boolean $result
  * @return boolean
  */
 public static function isMember($title, $user, &$result)
 {
     $namespace = $title->getNamespace();
     $db_key = $title->getDBkey();
     if ($user->getId() !== 0 && WpPage::isInWikiplace($namespace, $db_key) && ($wikiplace = WpWikiplace::getBySubpage($db_key, $namespace)) instanceof WpWikiplace) {
         // is in a wikiplace
         $result = WpMember::IsMember($wikiplace, $user);
         return false;
         // stop hook processing, because we have the answer
     }
     return true;
     // continue hook processing
 }
Esempio n. 4
0
 /**
  * Checks subscription is active, page creation quota is not exceeded and
  * diskpace quota is not exceeded.
  * @param int $current_user_id The current user identifier (used to select i18n message)
  * @param int|WpWikiplace $wikiplace An instance of WpWikiplace (faster) or the wikiplace id (int), checks the
  * subscriptions associated to the wikiplace and the quotas of the subscription buyer.
  * @return boolean/string True if user can, or string message explaining why she can't
  * <ul>
  * <li><b>wp-no-active-sub</b> you have no active subscription</li>
  * <li><b>wp-wikiplace-no-active-sub</b> wikiplace has no active subscription associated</li>
  * <li><b>wp-page-quota-exceeded</b> your page quota exceeded</li>
  * <li><b>wp-wikiplace-page-quota-exceeded</b> the subscriber page quota exceeded</li>
  * <li><b>wp-diskspace-quota-exceeded</b> your diskspace quota exceeded</li>
  * <li><b>wp-wikiplace-diskspace-quota-exceeded</b> the subscriber diskspace quota exceeded</li>
  * </ul>
  */
 public static function userCanUploadNewFile($current_user_id, $wikiplace)
 {
     if (is_int($wikiplace)) {
         $wikiplace = WpWikiplace::getById($wikiplace);
     }
     if (!$wikiplace instanceof WpWikiplace) {
         throw new MWException('Invalid $wikiplace argument.');
     }
     $subscription = self::newFromId($wikiplace->getSubscriptionId());
     if (!$subscription instanceof WpSubscription) {
         return 'wp-wikiplace-no-active-sub';
         // "THE OWNER subscription ..."
     } else {
         if (!$subscription->isActive()) {
             if ($wikiplace->isOwner($current_user_id)) {
                 return 'wp-no-active-sub';
                 // "YOUR subscription ..."
             } else {
                 return 'wp-wikiplace-no-active-sub';
                 // "THE OWNER subscription ..."
             }
         }
     }
     if (!$wikiplace->isOwner($current_user_id) && !WpMember::IsMember($wikiplace, $current_user_id)) {
         return 'wp-not-owner-or-member';
     }
     $plan = $subscription->getPlan();
     $max_pages = $plan->getNbWikiplacePages();
     $owner_pages_nb = WpPage::countPagesOwnedByUser($wikiplace->getOwnerUserId());
     if ($owner_pages_nb >= $max_pages) {
         if ($wikiplace->isOwner($current_user_id)) {
             return 'wp-page-quota-exceeded';
             // "YOUR quota..."
         } else {
             return 'wp-wikiplace-page-quota-exceeded';
             // "THE OWNER quota ..."
         }
     }
     $max_diskspace = $plan->getDiskspace();
     $owner_diskspace_usage = WpPage::countDiskspaceUsageByUser($wikiplace->getOwnerUserId());
     if ($owner_diskspace_usage >= $max_diskspace) {
         if ($wikiplace->isOwner($current_user_id)) {
             return 'wp-diskspace-quota-exceeded';
             // "YOUR quota..."
         } else {
             return 'wp-wikiplace-diskspace-quota-exceeded';
             // "THE OWNER quota ..."
         }
     }
     return true;
 }