<commit_before><?php
require_once('DBUtility.php');
require_once('ErrorMessage.php');
class CreateWiki{
    
    public $domainprefix ;
    public $wikiname;
    public $domaintype;
    public $domaindsp; 
    private $founderid;
    private $foundername;
    private $manifestName;


    private $steps = array(
        1 => '点火准备',
        2 => '请检查氧气阀压力',
        3 => '请确认带好毛巾',
        4 => '请系好安全带',
        5 => '主发动机点火中……',
        6 => '请不要恐慌',
        7 => '倒计时开始……',
        8 => '灰机已经起飞！重复一遍，灰机已经起飞！',
    );

    private $id;
    /** Constructor
     *
     * 
     * @param type $prefix domain prefix
     * @param type $name domain name
     * @param type $type wiki type
     * @param type $dsp wiki description
     */
    public function __construct($prefix, $name, $type, $dsp , $manifestName){
        $this->domainprefix = $prefix;
        $this->wikiname = $name;
        $this->domaintype = $type;
        $this->domaindsp = $dsp;
        $this->manifestName = $manifestName;
    }
    
    /** Create a complete working sub wiki
     * 
     * @return Int; if not sucessful return the error code else 0;
     */
    public function create(){
        //----------------------------------------
        // Total processes

        $ruleRet = $this->checkRule($this->wikiname, $this->domainprefix);
        if($ruleRet != 0){
            //the input from user is not valid, need to ask him to do it again
            return $ruleRet;
        }
        $i = 1;
        $this->showProgress($i);
        $sessionRet = $this->checkUserSession();
        if($sessionRet == false){
            //user is not logged in. redirect him to the log_in page
           
            return ErrorMessage::ERROR_NOT_LOG_IN;
        }
        
        $i = 2;
        $this->showProgress($i);
        $dirRet = $this->createWikiDir($this->domainprefix);
        if($dirRet != 0){
            //revoke directory creation
            $this->removeWikiDir($this->domainprefix);
            return $dirRet;
        }
        $i = 3;
        $this->showProgress($i);
        $installRet = $this->newWikiInstall($this->domainprefix, $this->wikiname, $this->domaintype, $this->domaindsp);
        if($installRet!=0){
            //revoke directory creation
            //revoke install
            $this->removeWikiDir($this->domainprefix);
            $this->removeWikiInstall($this->domainprefix, $this->wikiname);
            return $installRet;
        }
        $i = 4;
        $this->showProgress($i);
        $updateRet = $this->updateLocalSettings($this->domainprefix, $this->wikiname);
        if($updateRet!=0){
            //revoke all
             $this->removeWikiDir($this->domainprefix);
             $this->removeWikiInstall($this->domainprefix, $this->wikiname);
            return $updateRet;
        }
        $i = 5;
        $this->showProgress($i);
        $this->promote($this->domainprefix, $sessionRet);
        $i = 6;
        $this->showProgress($i);

        if($this->manifestName === "empty"){

        }
        else if($this->manifestName === "internal"){
           // $manifestChoice = "Manifest:灰机基础包";
            $this->migrateInitialManifest($this->domainprefix);
        }
        else if($manifest === "external"){
            $fromDomain = $_POST["fromDomain"]; //get the wikia site to get the nav bar informaiton
            $toDomain = $this->domainprefix.".huiji.wiki";
            $this->migrateWikia($fromDomain, $toDomain);
        }
        $i = 7;
        $this->showProgress($i);
        $this->enableES();
        $i = 8;
        $this->showProgress($i);
        // header('Location: http://'.$domainprefix.'.huiji.wiki');
    
        
        // $this->migrateInitialTemplate($this->domainprefix, $this->template);

        //redirect to the newly created wiki
        return 0; 
    }
    
    public function checkUserPreviliage(){
        
    }
    
    public function checkRule($name, $domain, $venue=null, $language=null, $type=null){
        $status = 0;
        $reg = "/[A-Za-z0-9][A-Za-z0-9_-]*/i";


    if( strlen( $domain ) === 0 ) {<commit_msg>minor fix<commit_after><?php
require_once('DBUtility.php');
require_once('ErrorMessage.php');
class CreateWiki{
    
    public $domainprefix ;
    public $wikiname;
    public $domaintype;
    public $domaindsp; 
    private $founderid;
    private $foundername;
    private $manifestName;


    private $steps = array(
        1 => '点火准备',
        2 => '请检查氧气阀压力',
        3 => '请确认带好毛巾',
        4 => '请系好安全带',
        5 => '主发动机点火中……',
        6 => '请不要恐慌',
        7 => '倒计时开始……',
        8 => '灰机已经起飞！重复一遍，灰机已经起飞！',
    );

    private $id;
    /** Constructor
     *
     * 
     * @param type $prefix domain prefix
     * @param type $name domain name
     * @param type $type wiki type
     * @param type $dsp wiki description
     */
    public function __construct($prefix, $name, $type, $dsp , $manifestName){
        $this->domainprefix = $prefix;
        $this->wikiname = $name;
        $this->domaintype = $type;
        $this->domaindsp = $dsp;
        $this->manifestName = $manifestName;
    }
    
    /** Create a complete working sub wiki
     * 
     * @return Int; if not sucessful return the error code else 0;
     */
    public function create(){
        //----------------------------------------
        // Total processes

        $ruleRet = $this->checkRule($this->wikiname, $this->domainprefix);
        if($ruleRet != 0){
            //the input from user is not valid, need to ask him to do it again
            return $ruleRet;
        }
        $i = 1;
        $this->showProgress($i);
        $sessionRet = $this->checkUserSession();
        if($sessionRet == false){
            //user is not logged in. redirect him to the log_in page
           
            return ErrorMessage::ERROR_NOT_LOG_IN;
        }
        
        $i = 2;
        $this->showProgress($i);
        $dirRet = $this->createWikiDir($this->domainprefix);
        if($dirRet != 0){
            //revoke directory creation
            $this->removeWikiDir($this->domainprefix);
            return $dirRet;
        }
        $i = 3;
        $this->showProgress($i);
        $installRet = $this->newWikiInstall($this->domainprefix, $this->wikiname, $this->domaintype, $this->domaindsp);
        if($installRet!=0){
            //revoke directory creation
            //revoke install
            $this->removeWikiDir($this->domainprefix);
            $this->removeWikiInstall($this->domainprefix, $this->wikiname);
            return $installRet;
        }
        $i = 4;
        $this->showProgress($i);
        $updateRet = $this->updateLocalSettings($this->domainprefix, $this->wikiname);
        if($updateRet!=0){
            //revoke all
             $this->removeWikiDir($this->domainprefix);
             $this->removeWikiInstall($this->domainprefix, $this->wikiname);
            return $updateRet;
        }
        $i = 5;
        $this->showProgress($i);
        $this->promote($this->domainprefix, $sessionRet);
        $i = 6;
        $this->showProgress($i);

        if($this->manifestName === "empty"){

        }
        else if($this->manifestName === "internal"){
           // $manifestChoice = "Manifest:灰机基础包";
            $this->migrateInitialManifest($this->domainprefix);
        }
        else if($manifest === "external"){
            $fromDomain = $_POST["fromDomain"]; //get the wikia site to get the nav bar informaiton
            $toDomain = $this->domainprefix.".huiji.wiki";
            $this->migrateWikia($fromDomain, $toDomain);
        }
        $i = 7;
        $this->showProgress($i);
        $this->enableES();
        $i = 8;
        $this->showProgress($i);
        // header('Location: http://'.$domainprefix.'.huiji.wiki');
    
        
        // $this->migrateInitialTemplate($this->domainprefix, $this->template);

        //redirect to the newly created wiki
        return 0; 
    }
    
    public function checkUserPreviliage(){
        
    }
    
    public function checkRule($name, $domain, $venue=null, $language=null, $type=null){
        $status = 0;
        $reg = "/[A-Za-z0-9][A-Za-z0-9-]*/i";


    if( strlen( $domain ) === 0 || empty($domain) || empty($name) ) {
{'fraction_non_alphanumeric': 0.16009702850212248, 'fraction_numerical': 0.006791995148574894, 'mean_word_length': 1.909668313338038, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 121, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '566206', 'n_tokens_mistral': 2607, 'n_tokens_neox': 2571, 'n_words': 523}