/** * Really do the upload * Checks are made in SpecialUpload::execute() * @access private */ function processUpload() { global $wgUser, $wgOut, $wrGedcomUploadDirectory, $wrGrepPath; /* Check for PHP error if any, requires php 4.2 or newer */ // this must appear before the tree name check if ($this->mUploadError == 1) { $this->mainUploadForm(wfMsgHtml('largegedcom')); return; } /** * If there was no filename or a zero size given, give up quick. */ if (trim($this->mOname) == '' || empty($this->mUploadSize)) { $this->mainUploadForm(wfMsgHtml('emptyfile')); return; } if ($this->mUploadError != 0) { $this->mainUploadForm('Error during upload.'); return; } // get tree id if ($this->mTreeName == '[new]') { $treeName = $this->mNewTreeName; } else { $treeName = $this->mTreeName; } $dbr =& wfGetDB(DB_SLAVE); $tree = $dbr->selectRow('familytree', array('ft_tree_id', 'ft_person_count'), array('ft_user' => $wgUser->getName(), 'ft_name' => $treeName)); if ($tree === false) { if (!$treeName) { $this->mainUploadForm('Please enter a name for your new tree'); return; } if (!FamilyTreeUtil::isValidTreeName($treeName)) { $this->mainUploadForm('Sorry, that name contains characters that are not allowed in a tree name'); return; } else { if (FamilyTreeUtil::createFamilyTree($dbr, $wgUser->getName(), $treeName) == FTE_SUCCESS) { $tree = $dbr->selectRow('familytree', array('ft_tree_id', 'ft_person_count'), array('ft_user' => $wgUser->getName(), 'ft_name' => $treeName)); } if ($tree === false) { $this->mainUploadForm('Error creating tree'); return; } } } // else { // $this->mainUploadForm('This tree already exists. You must import your GEDCOM into a new tree.'); // return; // } // check if there are too many people in the file // HACK: set ft_person_count = -1 to allow people to upload GEDCOM's up to UPPER_MAX_PEOPLE // $handle = popen($wrGrepPath.' -c "@ INDI" '.$this->mUploadTempName, 'r'); // use tr to translate from cr to lf so grep works for mac files $handle = popen('cat ' . $this->mUploadTempName . ' | tr \\\\r \\\\n | grep -c "@ INDI"', 'r'); $cnt = fread($handle, 1024); pclose($handle); wfDebug("GEDCOM treeid={$tree->ft_tree_id} count={$cnt} person_count={$tree->ft_person_count}\n"); if ($cnt > self::UPPER_MAX_PEOPLE || $tree->ft_person_count >= 0 && $cnt > self::LOWER_MAX_PEOPLE) { $this->mainUploadForm(wfMsgHtml('largegedcom')); return; } # Chop off any directories in the given filename $basename = wfBaseName($this->mOname); $dbw =& wfGetDB(DB_MASTER); $timestamp = wfTimestampNow(); $record = array('fg_tree_id' => $tree->ft_tree_id, 'fg_gedcom_filename' => $basename, 'fg_status_date' => $timestamp, 'fg_file_size' => $this->mUploadSize, 'fg_default_country' => $this->mDefaultCountry, 'fg_status' => FG_STATUS_UPLOADED); $dbw->insert('familytree_gedcom', $record); $gedcomId = $dbw->selectField('', 'last_insert_id()', null); $destFilename = $wrGedcomUploadDirectory . '/' . $gedcomId . '.ged'; wfSuppressWarnings(); $success = move_uploaded_file($this->mUploadTempName, $destFilename); wfRestoreWarnings(); if (!$success) { wfDebug("wfUploadGedcom error move={$destFilename}\n"); $wgOut->showFileNotFoundError($this->mUploadTempName); return; } chmod($destFilename, 0644); $this->showSuccess($basename, $treeName); }
function wrAddNewAccount($user = NULL) { global $wgUser, $wrBotUserID; // log new users // wfDebug("wrLogNewUser ". $user->getName() . ":" . $user->getUserPage()->getPrefixedText() . "\n"); $log = new LogPage('newuser', false); $ip = wfGetIP(); $log->addEntry('newuser', $user->getTalkPage(), wfMsgForContent('newuserlog', $ip), $ip); // create default tree for new users // wfDebug("wrCreateDefaultTree " . $user->getName() . "\n"); $db =& wfGetDB(DB_MASTER); FamilyTreeUtil::createFamilyTree($db, $user->getName(), 'Default'); // add a welcome message // read the text from Template:Welcome1 $title = Title::newFromText('Welcome1', NS_TEMPLATE); if ($title && $title->exists()) { $article = new Article($user->getTalkPage(), 0); $talkContents = ''; if ($article) { $talkContents = $article->fetchContent(); if ($talkContents) { $talkContents = rtrim($talkContents) . "\n\n"; } } $saveUser = $wgUser; $wgUser = User::newFromName(User::whoIs($wrBotUserID)); $article->doEdit($talkContents . '{{Subst:Welcome1}}', 'Welcome!'); $wgUser = $saveUser; } return true; }
/** * Create a new family tree * * @param unknown_type $args user, name * @return FTE_SUCCESS, FTE_INVALID_ARG, FTE_NOT_LOGGED_IN, FTE_NOT_AUTHORIZED, FTE_DUP_KEY, FTE_DB_ERROR, FTE_INVALID_ARG */ function wfCreateFamilyTree($args) { global $wgAjaxCachePolicy, $wgUser; // set cache policy $wgAjaxCachePolicy->setPolicy(0); // validate input arguments $status = FTE_SUCCESS; $args = AjaxUtil::getArgs($args); if (!@$args['user'] || !@$args['name']) { $status = FTE_INVALID_ARG; } else { if (!$wgUser->isLoggedIn()) { $status = FTE_NOT_LOGGED_IN; } else { if ($wgUser->isBlocked() || wfReadOnly() || $args['user'] != $wgUser->getName()) { $status = FTE_NOT_AUTHORIZED; } else { $db =& wfGetDB(DB_MASTER); $db->begin(); $db->ignoreErrors(true); $status = FamilyTreeUtil::createFamilyTree($db, $args['user'], $args['name']); if ($status == FTE_SUCCESS) { $db->commit(); } else { $db->rollback(); } } } } // return status return "<create status=\"{$status}\"></create>"; }
private function newTree() { global $wgUser; if ($this->newName) { $db =& wfGetDB(DB_MASTER); $db->ignoreErrors(true); $status = FamilyTreeUtil::createFamilyTree($db, $wgUser->getName(), $this->newName); $db->ignoreErrors(false); if ($status == FTE_DUP_KEY) { $msg = 'You already have a tree named ' . $this->newName; } else { if ($status == FTE_INVALID_ARG) { $msg = $this->newName . ' is not a valid tree name'; } else { if ($status != FTE_SUCCESS) { $msg = 'Error creating ' . $this->newName; } else { $msg = $this->newName . ' was created'; } } } $this->show($msg); } else { $label = 'Tree name'; $field = $label . ': <input type="text" name="newName"/>'; $this->showInputForm('New tree', $field, 'add', 'Add'); } }