protected function getPageTextFromWLH($toEditFields, $request = null) { // don't get marriage from request if called by propagation if ($toEditFields && $request) { $marriagedate = $request->getVal('md'); $marriageplace = $request->getVal('mp'); } else { $marriagedate = $marriageplace = ''; } $pageids = $this->getWhatLinksHere(); return Family::getPageText($marriagedate, $marriageplace, $this->titleString, $pageids); }
/** * Create family tree page * * This is also called by search.js * * @param unknown_type $args * @return GE_SUCCESS, GE_INVALID_ARG, GE_NOT_LOGGED_IN, GE_NOT_AUTHORIZED, GE_NOT_FOUND, GE_DUP_KEY, GE_DB_ERROR */ function wfAddPage($args) { global $wgUser, $wgAjaxCachePolicy, $wgArticle, $wgTitle, $wgLang; // set cache policy $wgAjaxCachePolicy->setPolicy(0); $status = GE_SUCCESS; $title = null; $titleString = null; $error = ''; $args = AjaxUtil::getArgs($args); $ns = $wgLang->getNsIndex($args['ns']); $titleString = @$args['title']; $update = $args['update'] == 'true'; if (!$wgUser->isLoggedIn()) { $status = GE_NOT_LOGGED_IN; } else { if ($wgUser->isBlocked() || wfReadOnly()) { $status = GE_NOT_AUTHORIZED; } } if ($status == GE_SUCCESS) { $dbw =& wfGetDB(DB_MASTER); $dbw->ignoreErrors(true); $dbw->begin(); $text = ''; if ($titleString) { // user passed in existing title; just add to watchlist and trees $title = Title::newFromText($titleString, $ns); } else { if ($ns == NS_PERSON) { if (ESINHandler::isLivingDates($args['bd'], null, $args['dd'], $args['dp'])) { $error = 'Living people cannot be added to WeRelate. People born in the last 110 years must have a death date'; } else { if (ESINHandler::isAmbiguousDate($args['bd']) || ESINHandler::isAmbiguousDate($args['dd'])) { $error = "Please write dates in D MMM YYYY format so they are unambiguous (ie 5 Jan 1900)"; } else { if (!$title) { $title = StructuredData::constructPersonTitle($args['g'], $args['s']); } if ($title) { if ($args['bt'] == 'chr') { $bird = ''; $birp = ''; $chrd = $args['bd']; $chrp = $args['bp']; } else { $bird = $args['bd']; $birp = $args['bp']; $chrd = ''; $chrp = ''; } if ($args['dt'] == 'bur') { $dead = ''; $deap = ''; $burd = $args['dd']; $burp = $args['dp']; } else { $dead = $args['dd']; $deap = $args['dp']; $burd = ''; $burp = ''; } $text = Person::getPageText($args['g'], $args['s'], $args['gnd'], $bird, $birp, $dead, $deap, $title->getText(), null, @$args['pf'], @$args['sf'], $chrd, $chrp, $burd, $burp); } } } } else { if ($ns == NS_FAMILY) { if (ESINHandler::isAmbiguousDate($args['md'])) { $error = "Please write dates in D MMM YYYY format so they are unambiguous (ie 5 Jan 1900)"; } else { $title = StructuredData::constructFamilyTitle($args['hg'], $args['hs'], $args['wg'], $args['ws']); if ($title) { $text = Family::getPageText($args['md'], $args['mp'], $title->getText(), null, @$args['ht'], @$args['wt'], @$args['ct']); } } } else { if ($ns == NS_SOURCE) { $title = StructuredData::constructSourceTitle($args['sty'], $args['st'], $args['a'], $args['p'], $args['pi'], $args['pu']); if ($title) { $text = Source::getPageText($args['sty'], $args['st'], $args['a'], $args['p'], $args['pi'], $args['pu']); } else { $error = 'Required source fields are missing; please press the Back button on your browser to enter the required fields.'; } } else { if ($ns == NS_MYSOURCE) { $t = $args['t']; if (mb_strpos($t, $wgUser->getName() . '/') != 0) { $t = $wgUser->getName() . '/' . $t; } $title = Title::newFromText($t, NS_MYSOURCE); if ($title) { $text = MySource::getPageText($args['a'], $args['p'], $args['s']); } } else { if ($ns == NS_PLACE) { $title = StructuredData::constructPlaceTitle($args['pn'], $args['li']); $text = Place::getPageText(); // check existing located-in, not root $titleText = $title->getFullText(); $pos = mb_strpos($titleText, ','); if ($pos === false) { $title = null; $error = 'You need to fill in the country'; } else { $locatedIn = Title::newFromText(trim(mb_substr($titleText, $pos + 1)), NS_PLACE); if (!$locatedIn->exists()) { $title = null; $error = 'Before you can add this place, you must first add ' . $locatedIn->getFullText(); } } } } } } } } if ($status == GE_SUCCESS && $title == null) { $status = GE_INVALID_ARG; if (!$error) { $error = 'Invalid page title; unable to create page'; } } // don't update in the case of the user passing in a non-existing titleString if ($update && !($titleString && !$title->exists())) { if ($status == GE_SUCCESS) { $article = new Article($title, 0); // don't set the global article and title to this; we don't need to propagate -- but we do for places // NOTE: This doesn't execute the code in FamilyTreePropagator to update familytree_page and add page to tree, but we don't want that to be called // because we add the page to the tree below if ($title->exists()) { // don't update the page if it already exists, except to add a spouse-family if ($ns == NS_PERSON && @$args['sf']) { $content =& $article->fetchContent(); $updated = false; Person::updateFamilyLink('spouse_of_family', '', $args['sf'], $content, $updated); if ($updated) { $article->doEdit($content, 'Add spouse family: [[Family:' . $args['sf'] . ']]', EDIT_UPDATE); StructuredData::purgeTitle($title, +1); // purge person with a fudge factor so family link will be blue } } $revid = 0; // ok for revid to be 0 if page exists because we no longer use revid } else { if (!$article->doEdit($text, '')) { $status = GE_WIKI_ERROR; } else { $revid = $article->mRevIdEdited; } } } if ($status == GE_SUCCESS) { // add the page to the trees (or to no trees) $allTrees = FamilyTreeUtil::getFamilyTrees($wgUser->getName()); $trees = explode('|', @$args['tree']); $checkedTreeIds = array(); foreach ($allTrees as $tree) { if (in_array(FamilyTreeUtil::toInputName($tree['name']), $trees)) { $checkedTreeIds[] = $tree['id']; // if (!FamilyTreeUtil::addPage($dbw, $wgUser, $tree['id'], $title, $revid, 0)) { // $status = GE_DB_ERROR; // } } } // update which trees are checked FamilyTreeUtil::updateTrees($dbw, $title, $revid, $allTrees, array(), $checkedTreeIds); } // watch the page if ($status == GE_SUCCESS) { StructuredData::addWatch($wgUser, $article, true); } } if ($status == GE_SUCCESS) { $dbw->commit(); } else { $dbw->rollback(); if (!$error) { $error = 'Unable to create page'; } } } // return status $titleString = ''; if ($title) { $titleString = StructuredData::escapeXml($title->getText()); } return "<addpage status=\"{$status}\" title=\"{$titleString}\" error=\"{$error}\"></addpage>"; }