Exemple #1
0
    private function newPage()
    {
        global $wgOut, $wgUser;
        if ($this->name) {
            if (mb_strpos($this->name, $wgUser->getName() . "/") !== 0 && mb_strpos($this->name, "User:"******"/") !== 0) {
                $this->name = $wgUser->getName() . "/" . $this->name;
            }
            $t = Title::newFromText($this->name, NS_USER);
            $wgOut->redirect($t->getFullURL('action=edit'));
            // purge user page
            StructuredData::purgeTitle($wgUser->getUserPage());
        } else {
            $wgOut->setPagetitle('Create a new user page');
            $wgOut->setArticleRelated(false);
            $wgOut->setRobotpolicy('noindex,nofollow');
            $titleObj = Title::makeTitle(NS_SPECIAL, 'MyRelate');
            $action = $titleObj->escapeLocalURL();
            $wgOut->addHTML(<<<END
<form method='post' action="{$action}">
<input type="hidden" name="action" value="{$this->action}"/>
Page title: <input type="text" name="name"/>
<input type='submit' name="add"" value="Add"/>
</form>
END
);
        }
    }
Exemple #2
0
 private function updatePerson($personTitle, $personTag, $familyTag, $newTitle, &$text, &$textChanged)
 {
     if (!PropagationManager::isPropagatablePage($personTitle)) {
         return true;
     }
     $result = true;
     $article = StructuredData::getArticle($personTitle, true);
     if ($article) {
         $content =& $article->fetchContent();
         $updated = false;
         Person::updateFamilyLink($familyTag, $this->titleString, $newTitle, $content, $updated);
         if ($updated) {
             $result = $article->doEdit($content, self::PROPAGATE_MESSAGE . ' [[' . $this->title->getPrefixedText() . ']]', PROPAGATE_EDIT_FLAGS);
             StructuredData::purgeTitle($personTitle, +1);
             // purge person with a fudge factor so family link will be blue
         } else {
             error_log("propagating family {$this->titleString} nothing changed in {$personTitle->getPrefixedText()}");
         }
         // if we're not deleting this entry (newTitle is not empty), and the person article is a redirect (article title != personTitle),
         // we need to update the person page title in the family page text
         if ($newTitle && $personTitle->getText() != $article->getTitle()->getText()) {
             $old = 'title="' . StructuredData::escapeXml($personTitle->getText()) . '"';
             $new = 'title="' . StructuredData::escapeXml($article->getTitle()->getText()) . '"';
             $text = str_replace($old, $new, $text);
             $textChanged = true;
         }
     }
     return $result;
 }
Exemple #3
0
 public static function deleteFamilyTree($db, $userName, $treeName, $delPages)
 {
     global $wgUser;
     if ($wgUser->isBlocked() || wfReadOnly()) {
         return FTE_NOT_AUTHORIZED;
     }
     $status = FTE_SUCCESS;
     $treeId = $db->selectField('familytree', 'ft_tree_id', array('ft_user' => $userName, 'ft_name' => $treeName));
     $errno = $db->lastErrno();
     if ($errno > 0) {
         $status = FTE_DB_ERROR;
     } else {
         if ($treeId === false) {
             $status = FTE_NOT_FOUND;
         } else {
             // set up delete job (the delete job should also remove familytree_page/data/gedcom eventually)
             $job = new DeleteFamilyTreeJob(array('tree_id' => $treeId, 'user' => $userName, 'delete_pages' => $delPages ? '1' : '0'));
             $job->insert();
             $errno = $db->lastErrno();
             if ($errno > 0) {
                 $status = FTE_DB_ERROR;
             }
         }
     }
     if ($status == FTE_SUCCESS) {
         // remove familytree
         $db->delete('familytree', array('ft_tree_id' => $treeId));
         FamilyTreeUtil::deleteFamilyTreesCache($userName);
         $errno = $db->lastErrno();
         if ($errno > 0) {
             $status = FTE_DB_ERROR;
         }
     }
     // purge user page
     StructuredData::purgeTitle(Title::makeTitle(NS_USER, $userName));
     return $status;
 }
/**
 * 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>";
}
Exemple #5
0
function wrIndexPurgeArticle(&$user, &$article, $newRevision = false)
{
    global $wgMemc;
    StructuredData::purgeTitle($article->getTitle(), +1);
    // purge the article so the watcher list is correct
    if (!$newRevision) {
        StructuredData::requestIndex($article->getTitle());
    }
    // also purge network cache for user
    $cacheKey = 'network:' . $user->getID();
    $wgMemc->delete($cacheKey);
    return true;
}