Beispiel #1
0
 function addPage($title)
 {
     $titleString = $title->getPrefixedText();
     if (@$this->addedPages[$titleString]) {
         return true;
     }
     // already added
     if (!FamilyTreeUtil::updateTrees($this->dbw, $title, 0, $this->allTrees, array(), $this->treeIds, false)) {
         return false;
     }
     $this->addedPages[$titleString] = 1;
     //echo("added $titleString\n");
     if ($this->count++ > 50) {
         // commit every 50 pages so we don't keep a tx open too long
         $this->dbw->commit();
         $this->dbw->begin();
         $this->count = 0;
     }
     return true;
 }
/**
 * 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>";
}
 private function updateTrees($user, $title, $revId, $request)
 {
     //wfDebug("updateTrees " . $title->getPrefixedText() . " " . $revId . "\n");
     $allTrees = FamilyTreeUtil::getFamilyTrees($user->getName());
     $treeOwnerIds = FamilyTreeUtil::getOwnerTrees($user, $title, false);
     $checkedTreeIds = FamilyTreeUtil::readTreeCheckboxes($allTrees, $request);
     return FamilyTreeUtil::updateTrees($this->db, $title, $revId, $allTrees, $treeOwnerIds, $checkedTreeIds, true, false);
 }
Beispiel #4
0
function wrDoContentActions($action, $article)
{
    global $wgUser, $wgOut, $wgRequest;
    if ($action != 'treeUpdate' && $action != 'treeUpdateConfirm') {
        return true;
        // handle by another content action handler
    }
    if ($wgUser->isAnon()) {
        $wgOut->showErrorPage('treenologintitle', 'treenologintext');
        return false;
    }
    if (!FamilyTreeUtil::isTreePage($article->getTitle()->getNamespace(), $article->getTitle()->getDBkey())) {
        $wgOut->showErrorPage('treenonamespacetitle', 'treenonamespacetext');
        return false;
    }
    if (wfReadOnly()) {
        $wgOut->readOnlyPage();
        return false;
    }
    $allTrees = FamilyTreeUtil::getFamilyTrees($wgUser->getName());
    $treeOwnerIds = FamilyTreeUtil::getOwnerTrees($wgUser, $article->getTitle(), false);
    $checkedTreeIds = FamilyTreeUtil::readTreeCheckboxes($allTrees, $wgRequest);
    $ancGenerations = $wgRequest->getVal('ancestorgenerations');
    $includeAncestorChildren = $wgRequest->getCheck('includeancestorchildren');
    $descGenerations = $wgRequest->getVal('descendantgenerations');
    $wgOut->setRobotpolicy('noindex,nofollow');
    if ($action == 'treeUpdateConfirm' && ($ancGenerations == 0 && $descGenerations == 0 || count($checkedTreeIds) > 0)) {
        $dbw =& wfGetDB(DB_MASTER);
        $result = FamilyTreeUtil::updateTrees($dbw, $article->getTitle(), $article->getRevIdFetched(), $allTrees, $treeOwnerIds, $checkedTreeIds);
        if ($result) {
            $dbw->commit();
        } else {
            $dbw->rollback();
        }
        if ($ancGenerations > 0 || $descGenerations > 0) {
            $job = new AddTreePagesJob(array('trees' => join(',', $checkedTreeIds), 'user' => $wgUser->getName(), 'title' => $article->getTitle()->getPrefixedText(), 'ancGenerations' => $ancGenerations, 'includeAncestorChildren' => $includeAncestorChildren, 'descGenerations' => $descGenerations));
            $job->insert();
            $treesUpdatedMsg = 'treesupdatedtextdeferred';
        } else {
            $treesUpdatedMsg = 'treesupdatedtext';
        }
        $wgOut->setPagetitle(wfMsg('treesupdatedtitle'));
        $wgOut->addWikiText(wfMsg($treesUpdatedMsg));
        $wgOut->returnToMain(true, $article->getTitle()->getPrefixedText());
    } else {
        if (count($allTrees) == 0) {
            $wgOut->showErrorPage('treenonetitle', 'treenonetext');
        } else {
            // show form
            $wgOut->setPagetitle(wfMsg('treeupdatetitle'));
            if ($action == 'treeUpdateConfirm') {
                $wgOut->addHTML('<font color="red">Please check the box next to the tree(s) you want to add the pages to.</font>');
            }
            $wgOut->addWikiText('==Trees==');
            $wgOut->addWikiText(wfMsg('treeupdatetext'));
            // TODO show form
            $action = $article->getTitle()->escapeLocalURL('action=treeUpdateConfirm');
            $wgOut->addHTML(<<<END
<form id="treeUpdate" method="post" action="{$action}" enctype="multipart/form-data">
END
);
            $wgOut->addHTML(FamilyTreeUtil::generateTreeCheckboxes($wgUser, $article->getTitle(), false, $allTrees, $treeOwnerIds));
            if ($article->getTitle()->getNamespace() == NS_PERSON || $article->getTitle()->getNamespace() == NS_FAMILY) {
                $wgOut->addWikiText('==Include relatives==');
                $wgOut->addWikiText(":'''''Warning''': including relatives can add potentially many people to your tree and to your watchlist.''");
                $wgOut->addWikiText(':Add the following relatives to the checked trees.');
                $options = array();
                for ($i = 0; $i <= 20; $i++) {
                    $options["{$i}"] = $i;
                }
                $ancGenerations = StructuredData::addSelectToHtml(0, 'ancestorgenerations', $options, 0);
                $options = array();
                for ($i = 0; $i <= 5; $i++) {
                    $options["{$i}"] = $i;
                }
                $descGenerations = StructuredData::addSelectToHtml(0, 'descendantgenerations', $options, 0);
                $wgOut->addHTML(<<<END
<dl><dd>Include ancestors for {$ancGenerations} generations
\t<dl><dd><input type="checkbox" name="includeancestorchildren"/>Also include ancestors' children</dd></dl></dd>
<dd>&nbsp;</dd>
<dd>Include descendants for {$descGenerations} generations</dd>
</dl>
END
);
            }
            $updateButton = array('id' => 'wrTreeUpdate', 'name' => 'wrTreeUpdate', 'type' => 'submit', 'value' => wfMsg('treeupdatebutton'), 'title' => wfMsg('treeupdatebuttontip'));
            $wgOut->addHTML(wfElement('input', $updateButton, ''));
            $wgOut->addHTML("</form>\n");
        }
    }
    return false;
    // stop processing
}