コード例 #1
0
 /**
  * main function for extension -- create wiki in wikifactory cluster
  * we are assumming that data is valid!
  *
  */
 private function createWiki()
 {
     global $wgOut, $wgUser, $IP, $wgDevelDomains, $wgDBadminuser, $wgDBadminpassword;
     global $wgSharedDB, $wgExternalSharedDB, $wgDevelEnvironment;
     global $wgWikiaLocalSettingsPath, $wgLangCreationVariables, $wgUniversalCreationVariables;
     wfProfileIn(__METHOD__);
     Wikia::log(__METHOD__, "type", "type={$this->mType}");
     /**
      * don't allow to create the same Wiki after page refresh
      */
     if (isset($_SESSION['mAllowToCreate'])) {
         unset($_SESSION['mAllowToCreate']);
     }
     /**
      * this will clean test database and fill mWikiData with test data
      */
     $this->prepareValues();
     if (empty($this->mWikiData["founder"])) {
         $query = $this->mLang != 'en' ? 'uselang=' . $this->mLang : '';
         $wgOut->redirect($this->mTitle->getLocalURL($query));
     }
     /*
      * time of process begin
      */
     $this->mCurrTime = wfTime();
     $startTime = $this->mCurrTime;
     /**
      * check and create database
      */
     $dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB);
     # central
     /**
      * local database handled is handler to cluster we create new wiki.
      * It doesn't have to be the same like wikifactory cluster or db cluster
      * where Special:CreateWiki exists.
      *
      * @todo do not use hardcoded name, code below is only for test
      *
      * set $activeCluster to false if you want to create wikis on first
      * cluster
      */
     $dbname = self::ACTIVE_CLUSTER ? "wikicities_" . self::ACTIVE_CLUSTER : "wikicities";
     /*
      * connect to the local database
      */
     $dbwTarget = wfGetDB(DB_MASTER, array(), $dbname);
     $msgType = 'OK';
     if (!$this->canCreateDatabase()) {
         $this->log("Database {$this->mWikiData["dbname"]} exists");
         $msgType = 'ERROR';
     } else {
         $row = $dbwTarget->selectRow("INFORMATION_SCHEMA.SCHEMATA", array("SCHEMA_NAME as name"), array('SCHEMA_NAME' => $this->mWikiData["dbname"]), __METHOD__);
         if (isset($row->name) && $row->name === $this->mWikiData["dbname"]) {
             $this->log("Database {$this->mWikiData["dbname"]} exists");
             $msgType = 'ERROR';
         } else {
             $dbwTarget->query(sprintf("CREATE DATABASE `%s`", $this->mWikiData["dbname"]));
             $this->log("Creating database {$this->mWikiData["dbname"]}");
         }
     }
     $this->setInfoLog($msgType, wfMsg('autocreatewiki-step2'));
     if ($msgType == 'ERROR') {
         return;
     }
     /**
      * create position in wiki.factory
      * (I like sprintf construction, so sue me)
      */
     $insertFields = array('city_title' => $this->mWikiData["title"], 'city_dbname' => $this->mWikiData["dbname"], 'city_url' => $this->mWikiData["url"], 'city_founding_user' => $this->mWikiData["founder"], 'city_founding_email' => $this->mWikiData["founder-email"], 'city_path' => $this->mWikiData["path"], 'city_description' => $this->mWikiData["title"], 'city_lang' => $this->mWikiData["language"], 'city_created' => wfTimestamp(TS_DB, time()));
     if (self::ACTIVE_CLUSTER) {
         $insertFields["city_cluster"] = self::ACTIVE_CLUSTER;
     }
     $bIns = $dbw->insert("city_list", $insertFields, __METHOD__);
     if (empty($bIns)) {
         #----
         $this->setInfoLog('ERROR', wfMsg('autocreatewiki-step3'));
         $this->log("Cannot set data in city_list table");
         $wgOut->addHTML(wfMsg('autocreatewiki-step3-error'));
         return;
     }
     /*
      * get Wiki ID
      */
     $this->mWikiId = $dbw->insertId();
     $this->mWikiData["city_id"] = $this->mWikiId;
     if (empty($this->mWikiId)) {
         #----
         $this->setInfoLog('ERROR', wfMsg('autocreatewiki-step3'));
         $this->log("Empty city_id = {$this->mWikiId}");
         $wgOut->addHTML(wfMsg('autocreatewiki-step3-error'));
         return;
     }
     $this->log("Creating row in city_list table, city_id = {$this->mWikiId}");
     $res = $dbw->insert("city_domains", array(array('city_id' => $this->mWikiId, 'city_domain' => $this->mWikiData["domain"]), array('city_id' => $this->mWikiId, 'city_domain' => sprintf("www.%s", $this->mWikiData["domain"]))), __METHOD__);
     if (empty($res)) {
         $this->setInfoLog('ERROR', wfMsg('autocreatewiki-step3'));
         $this->log("Cannot set data in city_domains table");
         $wgOut->addHTML(wfMsg('autocreatewiki-step3-error'));
         return;
     }
     $this->setInfoLog('OK', wfMsg('autocreatewiki-step3'));
     $this->log("Populating city_domains");
     /**
      * create image folder
      */
     wfMkdirParents("{$this->mWikiData["images_dir"]}");
     $this->log("Create {$this->mWikiData["images_dir"]} folder");
     $this->setInfoLog('OK', wfMsg('autocreatewiki-step1'));
     /**
      * copy defaul logo & favicon
      */
     wfMkdirParents("{$this->mWikiData["images_logo"]}");
     wfMkdirParents("{$this->mWikiData["images_icon"]}");
     if (file_exists(self::CREATEWIKI_LOGO)) {
         copy(self::CREATEWIKI_LOGO, "{$this->mWikiData["images_logo"]}/Wiki.png");
     }
     if (file_exists(self::CREATEWIKI_ICON)) {
         copy(self::CREATEWIKI_ICON, "{$this->mWikiData["images_icon"]}/Favicon.ico");
     }
     $this->log("Coping favicon and logo");
     $this->setInfoLog('OK', wfMsg('autocreatewiki-step4'));
     /**
      * wikifactory variables
      */
     $this->setWFVariables();
     $this->log("Populating city_variables");
     $this->setInfoLog('OK', wfMsg('autocreatewiki-step5'));
     /**
      * we got empty database created, now we have to create tables and
      * populate it with some default values
      */
     $tmpSharedDB = $wgSharedDB;
     $wgSharedDB = $this->mWikiData["dbname"];
     $dbwTarget->selectDB($this->mWikiData["dbname"]);
     $this->log("Creating tables in database");
     $sqlfiles = array("{$IP}/maintenance/tables.sql", "{$IP}/maintenance/interwiki.sql", "{$IP}/maintenance/wikia/city_interwiki_links.sql", "{$IP}/extensions/CheckUser/cu_changes.sql", "{$IP}/extensions/CheckUser/cu_log.sql", "{$IP}/maintenance/archives/wikia/patch-watchlist-improvements.sql", "{$IP}/maintenance/archives/wikia/patch-create-blog_listing_relation.sql", "{$IP}/maintenance/archives/wikia/patch-create-page_vote.sql", "{$IP}/maintenance/archives/wikia/patch-create-page_visited.sql");
     /**
      * tables which maybe exists or maybe not, better safe than sorry
      */
     $extrafiles = array("{$IP}/extensions/wikia/AjaxPoll/patch-create-poll_info.sql", "{$IP}/extensions/wikia/AjaxPoll/patch-create-poll_vote.sql", "{$IP}/extensions/wikia/ImageServing/sql/table.sql");
     foreach ($extrafiles as $file) {
         if (is_readable($file)) {
             $sqlfiles[] = $file;
         }
     }
     /**
      * additional tables per type
      */
     switch ($this->mType) {
         case "answers":
             $sqlfiles[] = "{$IP}/maintenance/answers-additional-tables.sql";
             break;
     }
     foreach ($sqlfiles as $file) {
         $error = $dbwTarget->sourceFile($file);
         $this->log("populating database with {$file}");
         if ($error !== true) {
             $this->setInfoLog('ERROR', wfMsg('autocreatewiki-step6'));
             $wgOut->addHTML(wfMsg('autocreatewiki-step6-error'));
             return;
         }
     }
     $this->setInfoLog('OK', wfMsg('autocreatewiki-step6'));
     /**
      * import language starter
      */
     $starter = $this->getStarter();
     if ($starter !== false) {
         switch ($this->mType) {
             case "answers":
                 $tables = "categorylinks externallinks image imagelinks langlinks page pagelinks revision templatelinks text user_profile";
                 break;
             default:
                 $tables = "categorylinks externallinks image imagelinks langlinks page pagelinks revision templatelinks text";
         }
         $cmd = sprintf("%s -h%s -u%s -p%s %s %s | %s -h%s -u%s -p%s %s", $this->mMYSQLdump, $starter["host"], $starter["user"], $starter["password"], $starter["dbStarter"], $tables, $this->mMYSQLbin, $dbwTarget->getLBInfo('host'), $wgDBadminuser, $wgDBadminpassword, $this->mWikiData["dbname"]);
         $this->log($cmd);
         wfShellExec($cmd);
         $error = $dbwTarget->sourceFile("{$IP}/maintenance/cleanupStarter.sql");
         if ($error !== true) {
             $this->setInfoLog('ERROR', wfMsg('autocreatewiki-step7'));
             $wgOut->addHTML(wfMsg('autocreatewiki-step7-error'));
             return;
         }
         /**
          * @todo move copying images from local database changes section
          * use wikifactory variable to determine proper path to images
          */
         $startupImages = $starter["uploadDir"];
         if (file_exists($startupImages) && is_dir($startupImages)) {
             wfShellExec("/bin/cp -af {$startupImages}/* {$this->mWikiData["images_dir"]}/");
             $this->log("/bin/cp -af {$startupImages}/* {$this->mWikiData["images_dir"]}/");
         }
         $cmd = sprintf("SERVER_ID=%d %s %s/maintenance/updateArticleCount.php --update --conf %s", $this->mWikiId, $this->mPHPbin, $IP, $wgWikiaLocalSettingsPath);
         $this->log($cmd);
         wfShellExec($cmd);
         $this->log("Copying starter database");
         $this->setInfoLog('OK', wfMsg('autocreatewiki-step7'));
     }
     /**
      * making the wiki founder a sysop/bureaucrat
      */
     if ($this->mWikiData["founder"]) {
         $dbwTarget->replace("user_groups", array(), array("ug_user" => $this->mWikiData["founder"], "ug_group" => "sysop"));
         $dbwTarget->replace("user_groups", array(), array("ug_user" => $this->mWikiData["founder"], "ug_group" => "bureaucrat"));
     }
     $this->log("Create user sysop/bureaucrat");
     /**
      * set images timestamp to current date (see: #1687)
      */
     $dbwTarget->update("image", array("img_timestamp" => date('YmdHis')), "*", __METHOD__);
     $this->log("Set images timestamp to current date");
     /**
      * init site_stats table (add empty row)
      */
     $dbwTarget->insert("site_stats", array("ss_row_id" => "1"), __METHOD__);
     /**
      * commit all in new database
      */
     $this->setInfoLog('OK', wfMsg('autocreatewiki-step9'));
     /**
      * add local job
      */
     $localJob = new AutoCreateWikiLocalJob(Title::newFromText(NS_MAIN, "Main"), $this->mWikiData);
     $localJob->WFinsert($this->mWikiId, $this->mWikiData["dbname"]);
     $this->setInfoLog('OK', wfMsg('autocreatewiki-step10'));
     /**
      * destroy connection to newly created database
      */
     $dbwTarget->commit();
     $wgSharedDB = $tmpSharedDB;
     /**
      * set hub/category
      */
     $oldUser = $wgUser;
     $wgUser = User::newFromName('CreateWiki script');
     $hub = WikiFactoryHub::getInstance();
     $hub->setCategory($this->mWikiId, $this->mWikiData["hub"], "ACW Setup");
     $wgUser = $oldUser;
     unset($oldUser);
     $this->log("Wiki added to the category hub " . $this->mWikiData["hub"]);
     $this->setInfoLog('OK', wfMsg('autocreatewiki-step8'));
     /**
      * define wiki type
      */
     $wiki_type = !empty($this->mType) ? $this->mType : self::DEFAULT_WIKI_TYPE;
     /**
      * modify variables
      */
     $this->addCustomSettings(0, $wgUniversalCreationVariables[$wiki_type], "universal");
     /**
      * set variables per language
      */
     $this->addCustomSettings($this->mWikiData["language"], isset($wgLangCreationVariables[$wiki_type]) ? $wgLangCreationVariables[$wiki_type] : $wgLangCreationVariables, "language");
     /**
      * move main page
      */
     $cmd = sprintf("SERVER_ID=%d %s %s/maintenance/wikia/moveMain.php -t '%s' --conf %s", $this->mWikiId, $this->mPHPbin, $IP, $this->mWikiData["title"], $wgWikiaLocalSettingsPath);
     $this->log($cmd);
     $output = wfShellExec($cmd);
     $this->log($output);
     /**
      * show congratulation message
      */
     $this->setInfoLog('OK', wfMsg('autocreatewiki-congratulation'));
     /**
      * inform task manager
      */
     $Task = new LocalMaintenanceTask();
     $Task->createTask(array("city_id" => $this->mWikiId, "command" => "maintenance/runJobs.php", "type" => "ACWLocal", "data" => $this->mWikiData, "server" => rtrim($this->mWikiData["url"], "/")), TASK_QUEUED);
     $this->log("Add local maintenance task");
     /**
      * show total time
      */
     $this->log(sprintf("Total: %F", wfTime() - $startTime));
     /**
      * show template with url to new created Wiki
      */
     if (!empty($wgDevelEnvironment)) {
         $domain = array_shift($wgDevelDomains);
         $domain = str_replace(self::DEFAULT_DOMAIN, $domain, $this->mWikiData["url"]);
     } else {
         $domain = $this->mWikiData["url"];
     }
     $oTmpl = new EasyTemplate(dirname(__FILE__) . "/templates/");
     $oTmpl->set_vars(array("domain" => $domain, "type" => $this->mType));
     // New Wiki Builder isn't supported by all languages yet
     $NewWikiBuilderLanguages = array('en');
     if (in_array($this->mWikiData["language"], $NewWikiBuilderLanguages)) {
         $sFinishText = $oTmpl->render("finish");
     } else {
         $sFinishText = $oTmpl->render("finish_old");
     }
     $this->log("return " . $this->mWikiData["url"]);
     $this->setInfoLog('END', $sFinishText);
     wfProfileOut(__METHOD__);
 }
コード例 #2
0
ファイル: CreateWiki.php プロジェクト: schwarer2006/wikia
 /**
  * main entry point, create wiki with given parameters
  *
  * @return integer status of operation, 0 for success, non 0 for error
  */
 public function create()
 {
     global $wgWikiaLocalSettingsPath, $wgExternalSharedDB, $wgSharedDB, $wgUser;
     wfProfileIn(__METHOD__);
     if (wfReadOnly()) {
         wfProfileOut(__METHOD__);
         return self::ERROR_READONLY;
     }
     if (wfIsDBLightMode()) {
         wfProfileOut(__METHOD__);
         return self::ERROR_DBLIGHTMODE;
     }
     // check founder
     if ($this->mFounder->isAnon()) {
         wfProfileOut(__METHOD__);
         return self::ERROR_USER_IN_ANON;
     }
     // check executables
     $status = $this->checkExecutables();
     if ($status != 0) {
         wfProfileOut(__METHOD__);
         return $status;
     }
     // check domains
     $status = $this->checkDomain();
     if ($status != 0) {
         wfProfileOut(__METHOD__);
         return $status;
     }
     // prepare all values needed for creating wiki
     $this->prepareValues();
     // prevent domain to be registered more than once
     if (!AutoCreateWiki::lockDomain($this->mDomain)) {
         wfProfileOut(__METHOD__);
         return self::ERROR_DOMAIN_NAME_TAKEN;
     }
     // start counting time
     $this->mCurrTime = wfTime();
     $startTime = $this->mCurrTime;
     // check and create database
     $this->mDBw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB);
     # central
     ///
     // local database handled is handler to cluster we create new wiki.
     // It doesn't have to be the same like wikifactory cluster or db cluster
     // where Special:CreateWiki exists.
     //
     // @todo do not use hardcoded name, code below is only for test
     //
     // set $activeCluster to false if you want to create wikis on first
     // cluster
     //
     $clusterdb = self::ACTIVE_CLUSTER ? "wikicities_" . self::ACTIVE_CLUSTER : "wikicities";
     $this->mNewWiki->dbw = wfGetDB(DB_MASTER, array(), $clusterdb);
     // database handler, old $dbwTarget
     // check if database is creatable
     // @todo move all database creation checkers to canCreateDatabase
     if (!$this->canCreateDatabase()) {
         wfDebugLog("createwiki", "Database {$this->mNewWiki->dbname} exists\n", true);
         wfProfileOut(__METHOD__);
         return self::ERROR_DATABASE_ALREADY_EXISTS;
     } else {
         $this->mNewWiki->dbw->query(sprintf("CREATE DATABASE `%s`", $this->mNewWiki->dbname));
         wfDebugLog("createwiki", "Database {$this->mNewWiki->dbname} created\n", true);
     }
     /**
      * create position in wiki.factory
      * (I like sprintf construction, so sue me)
      */
     if (!$this->addToCityList()) {
         wfDebugLog("createwiki", __METHOD__ . ": Cannot set data in city_list table\n", true);
         wfProfileOut(__METHOD__);
         return self::ERROR_DATABASE_WRITE_TO_CITY_LIST_BROKEN;
     }
     // set new city_id
     $this->mNewWiki->city_id = $this->mDBw->insertId();
     if (empty($this->mNewWiki->city_id)) {
         wfDebugLog("createwiki", __METHOD__ . ": Cannot set data in city_list table. city_id is empty after insert\n", true);
         wfProfileOut(__METHOD__);
         return self::ERROR_DATABASE_WIKI_FACTORY_TABLES_BROKEN;
     }
     wfDebugLog("createwiki", __METHOD__ . ": Row added added into city_list table, city_id = {$this->mNewWiki->city_id}\n", true);
     /**
      * add domain and www.domain to the city_domains table
      */
     if (!$this->addToCityDomains()) {
         wfDebugLog("createwiki", __METHOD__ . ": Cannot set data in city_domains table\n", true);
         wfProfileOut(__METHOD__);
         return self::ERROR_DATABASE_WRITE_TO_CITY_DOMAINS_BROKEN;
     }
     wfDebugLog("createwiki", __METHOD__ . ": Row added into city_domains table, city_id = {$this->mNewWiki->city_id}\n", true);
     /**
      * create image folder
      */
     wfMkdirParents("{$this->mNewWiki->images_dir}");
     wfDebugLog("createwiki", __METHOD__ . ": Folder {$this->mNewWiki->images_dir} created\n", true);
     /**
      * copy default logo & favicon
      */
     wfMkdirParents("{$this->mNewWiki->images_logo}");
     wfMkdirParents("{$this->mNewWiki->images_icon}");
     if (file_exists(self::CREATEWIKI_LOGO)) {
         copy(self::CREATEWIKI_LOGO, "{$this->mNewWiki->images_logo}/Wiki.png");
         wfDebugLog("createwiki", __METHOD__ . ": Default logo has been copied\n", true);
     } else {
         wfDebugLog("createwiki", __METHOD__ . ": Default logo has not been copied\n", true);
     }
     if (file_exists(self::CREATEWIKI_ICON)) {
         copy(self::CREATEWIKI_ICON, "{$this->mNewWiki->images_icon}/Favicon.ico");
         wfDebugLog("createwiki", __METHOD__ . ": Default favicon has been copied\n", true);
     } else {
         wfDebugLog("createwiki", __METHOD__ . ": Default favicon has not been copied\n", true);
     }
     /**
      * wikifactory variables
      */
     wfDebugLog("createwiki", __METHOD__ . ": Populating city_variables\n", true);
     $this->setWFVariables();
     $tmpSharedDB = $wgSharedDB;
     $wgSharedDB = $this->mNewWiki->dbname;
     /**
      * we got empty database created, now we have to create tables and
      * populate it with some default values
      */
     wfDebugLog("createwiki", __METHOD__ . ": Creating tables in database\n", true);
     $this->mNewWiki->dbw = wfGetDB(DB_MASTER, array(), $this->mNewWiki->dbname);
     if (!$this->createTables()) {
         wfDebugLog("createwiki", __METHOD__ . ": Creating tables not finished\n", true);
         wfProfileOut(__METHOD__);
         return self::ERROR_SQL_FILE_BROKEN;
     }
     /**
      * import language starter
      */
     if (!$this->importStarter()) {
         wfProfileOut(__METHOD__);
         return self::ERROR_SQL_FILE_BROKEN;
     }
     /**
      * making the wiki founder a sysop/bureaucrat
      */
     wfDebugLog("createwiki", __METHOD__ . ": Create user sysop/bureaucrat for user: {$this->mNewWiki->founderId} \n", true);
     if (!$this->addUserToGroups()) {
         wfDebugLog("createwiki", __METHOD__ . ": Create user sysop/bureaucrat for user: {$this->mNewWiki->founderId} failed \n", true);
     }
     /**
      * init site_stats table (add empty row)
      */
     $this->mNewWiki->dbw->insert("site_stats", array("ss_row_id" => "1"), __METHOD__);
     /**
      * add local job
      */
     $job_params = new stdClass();
     foreach ($this->mNewWiki as $id => $value) {
         if (!is_object($value)) {
             $job_params->{$id} = $value;
         }
     }
     // BugId:15644 - I need to pass this to CreateWikiLocalJob::changeStarterContributions
     $job_params->sDbStarter = $this->sDbStarter;
     $localJob = new CreateWikiLocalJob(Title::newFromText(NS_MAIN, "Main"), $job_params);
     $localJob->WFinsert($this->mNewWiki->city_id, $this->mNewWiki->dbname);
     wfDebugLog("createwiki", __METHOD__ . ": New createWiki local job created \n", true);
     /**
      * destroy connection to newly created database
      */
     $this->mNewWiki->dbw->commit();
     wfDebugLog("createwiki", __METHOD__ . ": Database changes commited \n", true);
     $wgSharedDB = $tmpSharedDB;
     /**
      * set hub/category
      */
     $oldUser = $wgUser;
     $wgUser = User::newFromName('CreateWiki script');
     $oHub = WikiFactoryHub::getInstance();
     $oHub->setCategory($this->mNewWiki->city_id, $this->mNewWiki->hub, "CW Setup");
     wfDebugLog("createwiki", __METHOD__ . ": Wiki added to the category hub: {$this->mNewWiki->hub} \n", true);
     $wgUser = $oldUser;
     unset($oldUser);
     /**
      * define wiki type
      */
     $wiki_type = !empty($this->mType) ? $this->mType : 'default';
     /**
      * modify variables
      */
     global $wgUniversalCreationVariables;
     if (!empty($wgUniversalCreationVariables) && !empty($wiki_type) && isset($wgUniversalCreationVariables[$wiki_type])) {
         $this->addCustomSettings(0, $wgUniversalCreationVariables[$wiki_type], "universal");
         wfDebugLog("createwiki", __METHOD__ . ": Custom settings added for wiki_type: {$wiki_type} \n", true);
     }
     /**
      * set variables per language
      */
     global $wgLangCreationVariables;
     $langCreationVar = isset($wgLangCreationVariables[$wiki_type]) ? $wgLangCreationVariables[$wiki_type] : $wgLangCreationVariables;
     $this->addCustomSettings($this->mNewWiki->language, $langCreationVar, "language");
     wfDebugLog("createwiki", __METHOD__ . ": Custom settings added for wiki_type: {$wiki_type} and language: {$this->mNewWiki->language} \n", true);
     /**
      * set tags per language and per hub
      * @FIXME the switch is !@#$ creazy, but I didn't find a core function
      */
     $tags = new WikiFactoryTags($this->mNewWiki->city_id);
     $langTag = $this->mNewWiki->language;
     if ($langTag !== 'en') {
         switch ($langTag) {
             case 'pt-br':
                 $langTag = 'pt';
                 break;
             case 'zh-tw':
             case 'zh-hk':
             case 'zh-clas':
             case 'zh-class':
             case 'zh-classical':
             case 'zh-cn':
             case 'zh-hans':
             case 'zh-hant':
             case 'zh-min-':
             case 'zh-min-n':
             case 'zh-mo':
             case 'zh-sg':
             case 'zh-yue':
                 $langTag = 'zh';
                 break;
         }
         $tags->addTagsByName($langTag);
     }
     $tags->addTagsByName($this->mNewWiki->hub);
     /**
      * move main page
      */
     $cmd = sprintf("SERVER_ID=%d %s %s/maintenance/wikia/moveMain.php -t '%s' --conf %s", $this->mNewWiki->city_id, $this->mPHPbin, $this->mIP, $this->mNewWiki->sitename, $wgWikiaLocalSettingsPath);
     $output = wfShellExec($cmd);
     wfDebugLog("createwiki", __METHOD__ . ": Main page moved \n", true);
     /**
      * show congratulation message
      */
     /**
      * Unset database from mNewWiki, because database objects cannot be serialized from MW1.19
      */
     unset($this->mNewWiki->dbw);
     /**
      * inform task manager
      */
     $Task = new LocalMaintenanceTask();
     $Task->createTask(array("city_id" => $this->mNewWiki->city_id, "command" => "maintenance/runJobs.php", "type" => "CWLocal", "data" => $this->mNewWiki, "server" => rtrim($this->mNewWiki->url, "/")), TASK_QUEUED, BatchTask::PRIORITY_HIGH);
     wfDebugLog("createwiki", __METHOD__ . ": Local maintenance task added\n", true);
     wfProfileOut(__METHOD__);
     /**
      * return success
      */
     return 0;
 }
コード例 #3
0
ファイル: fixWikiCreation.php プロジェクト: Tjorriemorrie/app
 private function fixWikia($wiki_id)
 {
     global $wgExternalSharedDB, $wgUser;
     # read Wiki information from DB
     $dbr = wfGetDB(DB_SLAVE, array(), $wgExternalSharedDB);
     $oRow = $dbr->selectRow(array('city_list'), array('*'), array('city_id' => $wiki_id), __METHOD__);
     if (!$oRow) {
         return false;
     }
     # set jobs params
     $map_keys = array('city_url' => 'url', 'city_founding_user' => 'founderId', 'city_sitename' => 'sitename', 'city_lang' => 'language', 'city_dbname' => 'dbname', 'city_path' => 'path');
     $job_params = new stdClass();
     foreach ($oRow as $key => $value) {
         $id = !empty($map_keys[$key]) ? $map_keys[$key] : $key;
         $job_params->{$id} = $value;
     }
     # set starter
     $mStarters = array("*" => array("*" => "aastarter", "en" => "starter", "ja" => "jastarter", "de" => "destarter", "fr" => "frstarter", "nl" => "nlstarter", "es" => "esstarter", "pl" => "plstarter", "ru" => "rustarter"));
     # dbstarter
     $job_params->sDbStarter = isset($mStarters["*"][$job_params->language]) ? $mStarters["*"][$job_params->language] : $mStarters["*"]["*"];
     # type of Wiki
     $job_params->type = '';
     # founderName
     $wgUser = User::newFromId($job_params->founderId);
     if (is_object($wgUser)) {
         $job_params->founderName = $wgUser->getName();
     }
     # no welcome email
     $job_params->disableWelcome = 1;
     # disable reminder
     $job_params->disableReminder = 1;
     # don't execute CreateWikiLocalJob-complete hook
     $job_params->disableCompleteHook = 1;
     // run job
     $localJob = new CreateWikiLocalJob(Title::newFromText(NS_MAIN, "Main"), $job_params);
     $localJob->WFinsert($job_params->city_id, $job_params->dbname);
     wfDebugLog("createwiki", __METHOD__ . ": New createWiki local job created \n", true);
     /**
      * inform task manager
      */
     $Task = new LocalMaintenanceTask();
     $Task->createTask(array("city_id" => $job_params->city_id, "command" => "maintenance/runJobs.php", "type" => "CWLocal", "data" => $job_params, "server" => rtrim($job_params->url, "/")), TASK_QUEUED, BatchTask::PRIORITY_HIGH);
     return true;
 }