示例#1
0
 /**
  * Fetch informations about the user uploading, prepare prefixes list content, and
  * set the default item to select. It also updates the special page DestFileName 
  * attribute. Attached to hooks:
  * <ul>
  * <li>$wgHooks['UploadForm:initial']</li>
  * <li>$wgHooks['UploadForm:BeforeProcessing']</li>
  * </ul>
  * @param SpecialPage $specialUploadObj current SpecialUpload page object
  * @todo if the user cannot upload a new file, maybe this function should
  * however return true, as seen in SpecialUpload page code comments (but if
  * true returned, the form is displayed with our error message on top)
  */
 public static function fetchRequestInformations($specialUploadObj)
 {
     $user = $specialUploadObj->getUser();
     self::$USER_IS_WP_ADMIN = $user->isAllowed(WP_ADMIN_RIGHT);
     if (self::$USER_IS_WP_ADMIN || !self::$DISPLAY_UPLOAD_MOD) {
         return true;
         // no informations to fetch and nothing to prepare, using standard form
     }
     $full_title = $specialUploadObj->getFullTitle();
     $request = $specialUploadObj->getRequest();
     // update special page DestFileName attribute
     $final_wp_filename = self::getDestinationFileName($request);
     if ($final_wp_filename != null) {
         $specialUploadObj->mDesiredDestName = $final_wp_filename;
         wfDebugLog('wikiplaces-debug', 'fetchRequestInformations, mDesiredDestName set to "' . $final_wp_filename . '"');
     }
     $final_wp_file_title = Title::newFromText($final_wp_filename, NS_FILE);
     // is the user re uploading a new version of an existing file or followed a "upload a file with this name" link ?
     if ($request->getText('wpDestFile') && !$request->getText('wpDestFileMainPart')) {
         $result = true;
         wfRunHooks('userCan', array(&$final_wp_file_title, &$user, 'upload', &$result));
         if ($result !== true) {
             wfDebugLog('wikiplaces-debug', 'WikiplaceUpload::fetchRequestInformations userCan returned ' . print_r($result, true));
             $specialUploadObj->getOutput()->showErrorPage('sorry', wfMessage('badaccess-group0'));
             // not allowed
             return false;
             // break SpecialUpload page init/processing
         }
         // Check getUserPermissionsErrors hook (this behavior is suitable for nonessential UI
         // controls because it skips potentially expensive cascading permission checks, but may
         // provide false positives)
         wfRunHooks('getUserPermissionsErrors', array(&$final_wp_file_title, &$user, 'upload', &$result));
         if ($result !== true) {
             wfDebugLog('wikiplaces-debug', print_r($result, true));
             // WikiplacesHooks::getUserPermissionsErrors($final_wp_file_title, $user, 'upload', $result);
             if (is_array($result) && !empty($result)) {
                 $key = array_shift($result);
                 $specialUploadObj->getOutput()->showErrorPage('sorry', wfMessage($key, $result));
                 return false;
                 // break SpecialUpload page init/processing
             } else {
                 $specialUploadObj->getOutput()->showErrorPage('sorry', wfMessage('badaccess-group0'));
                 // not allowed
                 return false;
                 // break SpecialUpload page init/processing
             }
         }
         // she is reuploading or has followed a "upload a file with this name" link
         wfDebugLog('wikiplaces-debug', 'fetchRequestInformations: reuploading, so disabling mod');
         self::$WPDESTFILE_READONLY = true;
         // ensure that the filename field is readonly when create link followed
         self::$DISPLAY_UPLOAD_MOD = false;
         return true;
         // no informations to fetch and nothing to prepare
     }
     // ( if we arrive here, we are uploading a new file )
     // is there a wikiplace specified in the url ?
     // search a GET parameter, as seen in SpecialPageFactory around line 408
     $db_key = $full_title->getDBkey();
     $bits = explode('/', $db_key, 2);
     $param = null;
     if (isset($bits[1])) {
         $param = $bits[1];
     }
     // is the user trying to upload a public file ?
     if ($param === WP_PUBLIC_FILE_PREFIX || $final_wp_file_title instanceof Title && WpPage::isPublic(NS_FILE, $final_wp_file_title->getDBkey())) {
         // there is a "Public" param, there will be only one choice in the listbox
         wfDebugLog('wikiplaces-debug', 'fetchRequestInformations: only public prefix will be visible');
         self::$FILE_PREFIXES[$param] = WP_PUBLIC_FILE_PREFIX;
         self::$FILE_PREFIXES_DEFAULT = $param;
     } else {
         // get all wikiplaces the user has access to
         $wikiplacesOwner = WpWikiplace::factoryAllOwnedByUserId($user->getId());
         $wikiplacesMember = WpWikiplace::factoryAllWhereUserIsMember($user->getId());
         // check if the user has access to at least one wikiplace
         if (count($wikiplacesOwner) + count($wikiplacesMember) == 0) {
             $specialUploadObj->getOutput()->showErrorPage('sorry', wfMessage('wp-create-wp-first'));
             return false;
             // break SpecialUpload page init/processing
         }
         // multiple choice: prepare full prefixes list
         foreach ($wikiplacesOwner as $wikiplace) {
             $wpw_name = $wikiplace->getName();
             self::$FILE_PREFIXES[$wpw_name] = $wpw_name;
         }
         foreach ($wikiplacesMember as $wikiplace) {
             $wpw_name = $wikiplace->getName();
             self::$FILE_PREFIXES[$wpw_name] = $wpw_name;
         }
         // do we have to set a default value ?
         if ($param != null && array_key_exists($param, self::$FILE_PREFIXES)) {
             if (!self::$FILE_PREFIXES_DEFAULT) {
                 self::$FILE_PREFIXES_DEFAULT = $param;
             }
         }
     }
     return true;
     // continue hook processing
 }
示例#2
0
 /**
  *
  * @param Title $title
  * @param String $copywarnMsg 
  */
 public static function EditPageCopyrightWarning($title, &$copywarnMsg)
 {
     $ns = $title->getNamespace();
     if (WpPage::isInWikiplaceNamespaces($ns)) {
         $copywarnMsg = array('copyrightwarning3', '[[' . wfMsgForContent('copyrightpage') . ']]');
     }
     return true;
 }
示例#3
0
 /**
  * Parse the db_key depending on the namespace, extract the name of the WikiPlace
  * the page should belong to. Works with both homepages and subpages db_key.
  * Note that this function can return a Wikiplace name even if the page or the WikiPlace does not already exist.
  * @param string $db_key should be $wikipage->getTitle()->getDBkey()
  * @param int $namespace should be $wikipage->getTitle()->getNamespace()
  * @return String The wikiplace name or null the page doesn't belong to an exsiting Wikiplace
  */
 public static function extractWikiplaceRoot($db_key, $namespace = NS_MAIN)
 {
     $hierarchy = self::explodeWikipageKey($db_key, $namespace);
     if (!isset($hierarchy[0]) || !WpPage::isInWikiplaceNamespaces($namespace)) {
         throw new MWException("Cannot extract WpRoot from key={$db_key} and ns={$namespace}.");
     }
     return $hierarchy[0];
 }
 public function validateRenewPlanId($id, $allData)
 {
     if (!preg_match('/^[0-9]{1,10}$/', $id)) {
         return 'Error: Invalid Renewal Plan ID';
     }
     if ($id == WPP_ID_NORENEW) {
         return true;
         // "no next plan"
     }
     $plan = WpPlan::newFromId($id);
     if ($plan == null) {
         return 'Error: Invalid Plan ID';
     }
     $user_id = $this->getUser()->getId();
     $curr_sub = WpSubscription::newActiveByUserId($user_id);
     if ($curr_sub == null) {
         return 'Error: No Active Subscription';
     }
     if (!$plan->isAvailableForRenewal($curr_sub->getEnd())) {
         return 'Error: Plan Not Available For Renewal';
     }
     if (!$plan->hasSufficientQuotas(WpWikiplace::countWikiplacesOwnedByUser($user_id), WpPage::countPagesOwnedByUser($user_id), WpPage::countDiskspaceUsageByUser($user_id))) {
         return 'Error: Plan Quotas Unsufficients';
     }
     return true;
 }
示例#5
0
 public function processCreateSubpage($formData)
 {
     if (!isset($formData['WpId']) || !isset($formData['SpName'])) {
         throw new MWException('Cannot create Wikiplace, no data.');
     }
     $wikiplace = WpWikiplace::getById(intval($formData['WpId']));
     if (!$wikiplace instanceof WpWikiplace) {
         return wfMessage('wp-invalid-name')->text();
     }
     $content = self::preparePageContent($formData['Template'], $formData['License']);
     $user = $this->getUser();
     $subpage = WpPage::createSubpage($wikiplace, $formData['SpName'], $user, $content);
     if (!$subpage instanceof Title) {
         $key = array_shift($subpage);
         return wfMessage($key, $subpage)->parse();
     }
     $this->homepageString = $wikiplace->getName();
     $this->subpageString = $formData['SpName'];
     if ($formData['CreateTalk'] === true) {
         // The wikiplace was created by a hook and is not accessible from here, so we need to get the wikiplace this way
         $talkContent = '{{Subst:' . wfMessage('wp-default-talk')->text() . '}}';
         $talk_page = WpPage::createTalk($subpage, $user, $talkContent);
         if (!$talk_page instanceof Title) {
             // wikiplace was created, but, error on talk
             /** @todo show a warning ? */
         }
     }
     return true;
     // all ok :)
 }
示例#6
0
 public function execute()
 {
     $deadline = intval($this->getOption('deadline', 0));
     if ($deadline < 0) {
         $deadline = 0;
     }
     $when = WpSubscription::now(0, 0, 0, $deadline);
     $this->output("[" . WpSubscription::now() . ": Searching subscriptions to renew before {$when} which has not been notified ...]\n");
     $subs = WpSubscription::factoryActiveEndSoonToNotify($when);
     $this->output("[" . WpSubscription::now() . ": " . count($subs) . " subscription(s) to check...]\n");
     foreach ($subs as $sub) {
         $next_plan_id = $sub->getRenewalPlanId();
         $msg = "wps_id[{$sub->getId()}], ";
         if ($next_plan_id == WPP_ID_NORENEW) {
             $msg .= 'do not renew';
             $sub->sendOnNoRenewalSoon();
             $sub->setRenewalPlanNotified();
         } else {
             $msg .= "renew_wpp_id[{$next_plan_id}]: ";
             // a plan is defined has renewal, check if it's a good choice...
             $renewal_date = $sub->getEnd();
             $next_plan = $sub->getRenewalPlan();
             $user_id = $sub->getBuyerUserId();
             if ($next_plan == null) {
                 // should not occur, but ensure database is not corrupted, correct if needed
                 // change to the current plan suggested renewal one
                 $curr_plan = $sub->getPlan();
                 $new_next_plan;
                 if ($curr_plan == null) {
                     // should not occur, but ... just in case
                     $new_next_plan = WpPlan::newFromId(WP_FALLBACK_PLAN_ID);
                 } else {
                     $new_next_plan = $curr_plan->getRenewalPlan($renewal_date);
                 }
                 $new_next_plan_id = $new_next_plan->getId();
                 // update and flag as problem reported, as we will send an email to user
                 $sub->setRenewalPlanId($new_next_plan_id, true);
                 $msg .= "doesn't exist, changed to = {$new_next_plan_id}";
                 $sub->sendOnRenewalSoonWarning('wp-plan-not-available-renewal', $new_next_plan);
             } elseif (!$next_plan->hasSufficientQuotas(WpWikiplace::countWikiplacesOwnedByUser($user_id), WpPage::countPagesOwnedByUser($user_id), WpPage::countDiskspaceUsageByUser($user_id))) {
                 // change to the current plan suggested renewal one
                 $curr_plan = $sub->getPlan();
                 $new_next_plan = $curr_plan->getRenewalPlan($renewal_date);
                 $new_next_plan_id = $new_next_plan->getId();
                 // update and flag as problem reported, as we will send an email to user
                 $sub->setRenewalPlanId($new_next_plan_id, true);
                 $msg .= "unsufficient quotas, changed to = {$new_next_plan_id}";
                 $sub->sendOnRenewalSoonWarning('wp-insufficient-quota', $next_plan);
             } elseif (!$next_plan->isAvailableForRenewal($renewal_date)) {
                 // ensure the next plan will still be available
                 // change to the planned renwal plan suggested renewal one
                 $new_next_plan = $next_plan->getRenewalPlan($renewal_date);
                 $new_next_plan_id = $new_next_plan->getId();
                 // update and flag as problem reported, as we will send an email to user
                 $sub->setRenewalPlanId($new_next_plan_id, true);
                 $msg .= "will not be available, changed to = {$new_next_plan_id}";
                 $sub->sendOnRenewalSoonWarning('wp-plan-not-available-renewal', $next_plan);
             } else {
                 // it seems to be ok :)
                 $msg .= 'renewal will be ok';
                 $sub->sendOnRenewalSoonValid();
                 $sub->setRenewalPlanNotified();
             }
         }
         $this->output("{$msg}\n");
     }
     $this->output("[" . WpSubscription::now() . ": END]\n");
 }
示例#7
0
 /**
  * Check the user has an active subscription and 
  * wikiplace creation quota is not exceeded and 
  * page creation quota is not exceeded
  * @param type $user_id
  * @return boolean/string True if user can, string message explaining why she can't:
  * <ul>
  * <li><b>wp-no-active-sub</b> user has no active subscription</li>
  * <li><b>wp-wikiplace-quota-exceeded</b> wikiplace creation quota exceeded</li>
  * <li><b>wp-page-quota-exceeded</b> page creation quota exceeded</li>
  * </ul>
  */
 public static function userCanCreateWikiplace($user_id)
 {
     if (!is_int($user_id) || $user_id < 1) {
         throw new MWException('Cannot check if user can create a Wikiplace, invalid user identifier.');
     }
     $sub = self::newActiveByUserId($user_id);
     if ($sub == null) {
         return 'wp-no-active-sub';
     }
     $plan = $sub->getPlan();
     $max_wikiplaces = $plan->getNbWikiplaces();
     $user_wikiplaces_nb = WpWikiplace::countWikiplacesOwnedByUser($user_id);
     if ($user_wikiplaces_nb >= $max_wikiplaces) {
         return 'wp-wikiplace-quota-exceeded';
     }
     $max_pages = $plan->getNbWikiplacePages();
     $user_pages_nb = WpPage::countPagesOwnedByUser($user_id);
     if ($user_pages_nb >= $max_pages) {
         return 'wp-page-quota-exceeded';
     }
     return true;
     // all ok
 }
示例#8
0
 /**
  *
  * @param int $namespace
  * @param string $db_key
  * @return boolean
  */
 public static function isInWikiplace($namespace, $db_key)
 {
     if (!is_int($namespace)) {
         throw new MWException('Invalid namespace argument.');
     }
     global $wgWikiplaceNamespaces;
     if (!in_array($namespace, $wgWikiplaceNamespaces)) {
         return false;
     }
     return !WpPage::isPublic($namespace, $db_key) && !WpPage::isAdmin($namespace, $db_key);
 }