Esempio n. 1
0
 /**
  * __construct
  *
  * discover which wikia we handle
  *
  * @access public
  * @author Krzysztof Krzyżaniak <*****@*****.**>
  *
  * @param integer $id default null    explicit set wiki id
  * @param bool|string $server_name default false    explicit set server name
  *
  * @return WikiFactoryLoader object
  */
 public function __construct($id = null, $server_name = false)
 {
     global $wgDBname, $wgDevelEnvironment, $wgDevelDomains;
     global $wgWikiFactoryDomains, $wgExternalSharedDB;
     $this->mCommandLine = false;
     if (!is_null($id)) {
         /**
          * central / dofus / memory-alpha case
          */
         $this->mCityID = $id;
         if ($server_name === false) {
             $this->mServerName = empty($_SERVER['SERVER_NAME']) ? false : $_SERVER['SERVER_NAME'];
         } else {
             $this->mServerName = $server_name;
         }
     } elseif (!empty($_SERVER['SERVER_NAME'])) {
         /**
          * normal http request
          */
         $this->mServerName = strtolower($_SERVER['SERVER_NAME']);
         $this->mCityID = false;
     } elseif (getenv("SERVER_ID")) {
         /**
          * interactive/cmdline
          */
         $this->mCityID = getenv("SERVER_ID");
         $this->mServerName = false;
         $this->mCommandLine = true;
     } elseif (getenv("SERVER_DBNAME")) {
         $this->mCityDB = getenv("SERVER_DBNAME");
         $this->mServerName = false;
         $this->mCommandLine = true;
         $this->mCityID = false;
     } else {
         /**
          * hardcoded exit, nothing can be done at this point
          */
         echo "Cannot tell which wiki it is (neither SERVER_NAME, SERVER_ID nor SERVER_DBNAME is defined)\n";
         exit(1);
     }
     /**
      * initalizations
      */
     $this->mDebug = false;
     $this->mOldServerName = false;
     $this->mAlternativeDomainUsed = false;
     $this->mDBname = !empty($wgExternalSharedDB) ? $wgExternalSharedDB : "wikicities";
     $this->mDomain = array();
     $this->mVariables = array();
     $this->mIsWikiaActive = 0;
     $this->mAlwaysFromDB = 0;
     $this->mWikiID = 0;
     $this->mDBhandler = null;
     $this->mCityDB = false;
     if (!empty($wgDevelEnvironment)) {
         $this->mDebug = true;
         $this->mAlwaysFromDB = 1;
     }
     /**
      * @author Krzysztof Krzyżaniak <*****@*****.**>
      *
      * handle additional domains, we have plenty of domains which should
      * redirect to <wikia>.wikia.com. They should be added to
      * $wgWikiFactoryDomains variable (which is simple list). When
      * additional domain is detected we do simple replace:
      *
      * muppets.wikia.org => muppets.wikia.com
      *
      * additionally we remove www. before matching
      */
     if (isset($wgWikiFactoryDomains) && is_array($wgWikiFactoryDomains)) {
         foreach ($wgWikiFactoryDomains as $domain) {
             /**
              * remove www from domain
              */
             $name = preg_replace("/^www\\./", "", $this->mServerName);
             $pattern = "/{$domain}\$/";
             if ($domain !== "wikia.com" && preg_match($pattern, $name)) {
                 $this->mOldServerName = $this->mServerName;
                 $this->mServerName = str_replace($domain, "wikia.com", $name);
                 $this->mAlternativeDomainUsed = true;
                 break;
             }
         }
     }
     WikiFactory::isUsed(true);
     /**
      * if run via commandline always take data from database,
      * never from cache
      */
     if ($this->mCommandLine && $this->mAlwaysFromDB == 0) {
         $this->mAlwaysFromDB = 1;
     }
 }