public static function updateGedcomMatch($dbw, $treeId, $gedcomId, $key, $matchTitle, $merged, $gedcomUser) { $newTitle = $matchTitle == '#nomatch#' ? null : Title::newFromText($matchTitle); $oldTitle = null; // read old match_namespace and title $row = $dbw->selectRow('familytree_gedcom_data', array('fgd_match_namespace', 'fgd_match_title'), array('fgd_gedcom_id' => $gedcomId, 'fgd_gedcom_key' => $key)); if ($row && $row->fgd_match_namespace > 0) { $oldTitle = Title::makeTitle($row->fgd_match_namespace, $row->fgd_match_title); if ($oldTitle && ($oldTitle->getNamespace() == NS_PERSON || $oldTitle->getNamespace() == NS_FAMILY || $oldTitle->getNamespace() == NS_MYSOURCE) && (!$newTitle || $oldTitle->getPrefixedText() != $newTitle->getPrefixedText())) { // remove match title from tree if (!FamilyTreeUtil::removePage($dbw, $treeId, $oldTitle)) { return false; } // unwatch match title if no other trees contain it if (!$dbw->selectField('familytree_page', 'fp_tree_id', array('fp_namespace' => $row->fgd_match_namespace, 'fp_title' => $row->fgd_match_title, 'fp_user_id' => $gedcomUser->getID()))) { $article = new Article($oldTitle, 0); StructuredData::removeWatch($gedcomUser, $article); } } } if ($newTitle) { $matchTitle = $newTitle->getDBkey(); $matchNamespace = $newTitle->getNamespace(); $potentialMatchesAttr = ''; $potentialMatchesValue = ''; $potentialMatchesUpdate = ''; if (($newTitle->getNamespace() == NS_PERSON || $newTitle->getNamespace() == NS_FAMILY || $newTitle->getNamespace() == NS_MYSOURCE) && (!$oldTitle || $oldTitle->getPrefixedText() != $newTitle->getPrefixedText())) { // add match title to tree if (!FamilyTreeUtil::addPage($dbw, $gedcomUser, $treeId, $newTitle, 0, 0)) { return false; } // watch match title $article = new Article($newTitle, 0); StructuredData::addWatch($gedcomUser, $article); } } else { $matchTitle = ''; $matchNamespace = -1; $merged = 0; $potentialMatchesAttr = ', fgd_potential_matches'; // reset potential matches to what's in the gedcom $potentialMatchesValue = ", ''"; $potentialMatchesUpdate = ", fgd_potential_matches=''"; } $matchTitle = $dbw->addQuotes($matchTitle); $sql = "INSERT INTO familytree_gedcom_data (fgd_gedcom_id, fgd_gedcom_key, fgd_match_namespace, fgd_match_title, fgd_merged{$potentialMatchesAttr})" . " VALUES({$gedcomId}," . $dbw->addQuotes($key) . ",{$matchNamespace},{$matchTitle},{$merged}{$potentialMatchesValue})" . " ON DUPLICATE KEY UPDATE fgd_match_namespace={$matchNamespace}, fgd_match_title={$matchTitle}, fgd_merged={$merged}{$potentialMatchesUpdate}"; $dbw->query($sql); return $dbw->lastErrno() == 0; }
/** * Add pages to tree and watchlist * * @param unknown_type $args XML: <pages tree_id="nnn"><page namespace="108" title="John Doe (1)" uid="..."/>...</pages> * @return unknown */ function wfAddPagesToTree($args) { global $wgUser, $wgAjaxCachePolicy, $wrBotUserID, $wrIsGedcomUpload; // set cache policy $wgAjaxCachePolicy->setPolicy(0); $status = GE_SUCCESS; $wrIsGedcomUpload = true; if (!$wgUser->isLoggedIn()) { $status = GE_NOT_LOGGED_IN; } else { if (wfReadOnly() || $wgUser->getID() != $wrBotUserID) { $status = GE_NOT_AUTHORIZED; } else { $xml = simplexml_load_string($args); $treeId = (int) $xml['tree_id']; if (!$treeId) { $status = GE_INVALID_ARG; } } } if ($status == GE_SUCCESS) { $dbr =& wfGetDB(DB_SLAVE); $dbr->ignoreErrors(true); $userName = $dbr->selectField('familytree', 'ft_user', array('ft_tree_id' => $treeId)); $errno = $dbr->lastErrno(); if ($errno > 0) { $status = GE_DB_ERROR; } else { if ($userName === false) { $status = GE_NOT_FOUND; } else { $wgUser = User::newFromName($userName, false); // switch the global user if (!$wgUser) { $status = GE_NOT_FOUND; } } } } if ($status == GE_SUCCESS) { $dbw =& wfGetDB(DB_MASTER); $dbw->ignoreErrors(true); $dbw->begin(); foreach ($xml->page as $page) { $ns = (int) $page['namespace']; $titleString = (string) $page['title']; $uid = (string) $page['uid']; $title = Title::newFromText($titleString, $ns); if (!$titleString || $title == null) { //wfDebug("wfAddPagesToTree error $ns $titleString\n"); $status = GE_INVALID_ARG; } if ($status == GE_SUCCESS) { $article = new Article($title, 0); // add the page to the tree if (!FamilyTreeUtil::addPage($dbw, $wgUser, $treeId, $title, $title->getLatestRevID(), 0, 0, $uid, 0)) { $status = GE_DB_ERROR; } else { StructuredData::addWatch($wgUser, $article, true); } } } if ($status == GE_SUCCESS) { $dbw->commit(); } else { $dbw->rollback(); } } // return status return "<add status=\"{$status}\"/>"; }
/** * Create family tree page * * @param unknown_type $args user, name, ns, title * @return FTE_SUCCESS, FTE_INVALID_ARG, FTE_NOT_LOGGED_IN, FTE_NOT_AUTHORIZED, FTE_NOT_FOUND, FTE_DUP_KEY, FTE_DB_ERROR */ function wfCreateFamilyTreePage($args) { global $wgUser, $wgAjaxCachePolicy, $wrBotUserID, $wgArticle, $wgTitle; // set cache policy $wgAjaxCachePolicy->setPolicy(0); $status = FTE_SUCCESS; $ns = ''; $titleString = ''; $revid = 0; $xml = simplexml_load_string($args); $userName = (string) $xml['user']; $treeName = (string) $xml['name']; $ns = (int) $xml['ns']; $titleString = (string) $xml['title']; $text = (string) $xml; if (!$userName || !$treeName || !$titleString || !($ns == NS_PERSON || $ns == NS_FAMILY)) { $status = FTE_INVALID_ARG; } else { if (!$wgUser->isLoggedIn()) { $status = FTE_NOT_LOGGED_IN; } else { if ($userName != $wgUser->getName() || $wgUser->isBlocked() || wfReadOnly()) { $status = FTE_NOT_AUTHORIZED; } } } if ($status == FTE_SUCCESS) { // get tree id $treeId = 0; $status = ftGetTreeId($userName, $treeName, $treeId); if ($status == FTE_SUCCESS && !$treeId) { $status = FTE_NOT_FOUND; } } if ($status == FTE_SUCCESS) { $dbw =& wfGetDB(DB_MASTER); $dbw->ignoreErrors(true); $dbw->begin(); $title = Title::newFromText($titleString, $ns); if ($title == null) { $status = FTE_INVALID_ARG; } else { if (!StructuredData::titleStringHasId($titleString)) { $title = StructuredData::appendUniqueId($title, $dbw); } $article = new Article($title, 0); if ($article->exists()) { $status = FTE_DUP_KEY; } } if ($status == FTE_SUCCESS) { // set the global article and title to this, so that propagation works ok $wgArticle = $article; $wgTitle = $article->getTitle(); // 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 (!$article->doEdit($text, 'creating initial family tree', EDIT_NEW)) { $status = FTE_WIKI_ERROR; } else { $revid = $article->mRevIdEdited; } } // add the page to the tree if ($status == FTE_SUCCESS) { if (!FamilyTreeUtil::addPage($dbw, $wgUser, $treeId, $title, $revid, 0)) { $status = FTE_DB_ERROR; } } // watch the page if ($status == FTE_SUCCESS) { StructuredData::addWatch($wgUser, $article, true); } if ($status == FTE_SUCCESS) { $dbw->commit(); } else { $dbw->rollback(); } } // return status $titleString = StructuredData::escapeXml($title->getText()); return "<create status=\"{$status}\" ns=\"{$ns}\" title=\"{$titleString}\" latest=\"{$revid}\"></create>"; }
public static function updateTrees($dbw, $title, $revId, $allTrees, $treeOwnerIds, $checkedTreeIds, $updateChecked = true, $addWatch = true) { global $wgUser; $talkRevid = -1; $result = true; $added = false; $removed = false; foreach ($allTrees as $tree) { $treeId = $tree['id']; if (in_array($treeId, $checkedTreeIds) && !in_array($treeId, $treeOwnerIds)) { // add the page to the tree //wfDebug("updateTrees add " . $tree['name'] . "\n"); if ($talkRevid == -1) { $talkRevision = Revision::newFromTitle($title->getTalkPage()); if ($talkRevision) { $talkRevid = $talkRevision->getId(); } else { $talkRevid = 0; } } $result = $result && FamilyTreeUtil::addPage($dbw, $wgUser, $treeId, $title, $revId, $talkRevid); $added = true; } else { if (!in_array($treeId, $checkedTreeIds) && in_array($treeId, $treeOwnerIds)) { // remove the page from the tree //wfDebug("updateTrees remove\n"); $result = $result && FamilyTreeUtil::removePage($dbw, $treeId, $title); $removed = true; } } if ($updateChecked) { $checked = !$tree['checked'] && in_array($treeId, $checkedTreeIds); $unchecked = $tree['checked'] && !in_array($treeId, $checkedTreeIds); if ($checked || $unchecked) { $dbw->update('familytree', array('ft_checked' => $checked ? 1 : 0), array('ft_tree_id' => $treeId)); FamilyTreeUtil::deleteFamilyTreesCache($wgUser->getName()); } } } if ($added && !$wgUser->isWatched($title)) { //wfDebug("updateTrees - addWatch: ".$title->getPrefixedText()."\n"); if ($addWatch) { StructuredData::addWatch($wgUser, new Article($title, 0)); } } else { if ($added || $removed) { // purge the article and re-index it StructuredData::purgeTitle($title); StructuredData::requestIndex($title); } } return $result; }