Exemple #1
0
 protected function addEventFactInput($efNum, $eventFact, $stdEventType, $otherEventTypes, $tm)
 {
     $typeString = '';
     $date = '';
     $place = '';
     $desc = '';
     $sources = '';
     $notes = '';
     $images = '';
     $dateStyle = '';
     if (isset($eventFact)) {
         $typeString = htmlspecialchars((string) $eventFact['type']);
         $date = htmlspecialchars((string) $eventFact['date']);
         if (ESINHandler::isAmbiguousDate($date)) {
             $dateStyle = ' style="background-color:#fdd;"';
         }
         $place = htmlspecialchars((string) $eventFact['place']);
         $desc = htmlspecialchars((string) $eventFact['desc']);
         $sources = htmlspecialchars((string) $eventFact['sources']);
         $notes = htmlspecialchars((string) $eventFact['notes']);
         $images = htmlspecialchars((string) $eventFact['images']);
     }
     $result = '<tr>';
     if ($stdEventType) {
         $result .= "<td>{$stdEventType}</td>";
     } else {
         $result .= "<td><select class=\"ef_select\" tabindex=\"1\" name=\"event_fact{$efNum}\">" . '<option value="Unknown"' . (empty($typeString) || $typeString == 'Unknown' ? ' selected="selected"' : '') . '>Type</option>';
         foreach ($otherEventTypes as $eventType) {
             $eventType = str_replace('~', "'", $eventType);
             if (mb_substr($eventType, 0, 1) == '=') {
                 $eventType = mb_substr($eventType, 1);
                 $attrs = ' disabled="disabled" style="color:GrayText"';
                 $value = '';
             } else {
                 $attrs = '';
                 if (mb_substr($eventType, 0, 1) == ':') {
                     $value = mb_substr($eventType, 1);
                     $eventType = "  " . $value;
                 } else {
                     $value = $eventType;
                 }
             }
             $result .= '<option value="' . $value . '"' . ($typeString == $value ? ' selected="selected"' : '') . "{$attrs}>{$eventType}</option>";
         }
         $result .= '</select></td>';
     }
     $result .= "<td><input class=\"ef_date\" tabindex=\"1\" type=\"text\" name=\"date{$efNum}\" value=\"{$date}\"{$dateStyle}/></td>";
     $result .= "<td><input class=\"place_input ef_place\" tabindex=\"1\" type=\"text\" name=\"place{$efNum}\" value=\"{$place}\"/></td>";
     $result .= "<td colspan=\"2\"><input class=\"ef_desc\" tabindex=\"1\" type=\"text\" name=\"desc{$efNum}\" value=\"{$desc}\"/></td>";
     $oneBased = $efNum + 1;
     if (!$stdEventType) {
         $result .= "<td><a title='Remove this event/fact' href=\"javascript:void(0);\" onClick=\"removeEventFact({$oneBased}); return preventDefaultAction(event);\">remove</a></td>";
     } else {
         $result .= "<td></td>";
     }
     $result .= "</tr><tr><td colspan=\"2\"></td>";
     if ($efNum == 0) {
         //         if ($typeString == 'Birth') {
         //            $sourceTip = '<b>Sources'.$tm->addMsgTip('EventFactSourceIDs').'&nbsp; Images'.$tm->addMsgTip('EventFactImageIDs').'&nbsp; Notes'.$tm->addMsgTip('EventFactNoteIDs').'&nbsp; &raquo; &nbsp; &nbsp;</b>';
         //            $imageTip = '';
         //            $noteTip = '';
         //         }
         //         else {
         $sourceTip = '<div class="sin_heading">Sources' . $tm->addMsgTip('EventFactSourceIDs') . '</div>';
         $imageTip = '<div class="sin_heading">Images' . $tm->addMsgTip('EventFactImageIDs') . '&nbsp;</div>';
         $noteTip = '<div class="sin_heading">Notes' . $tm->addMsgTip('EventFactNoteIDs') . '&nbsp;&nbsp;</div>';
         //         }
     } else {
         $sourceTip = $imageTip = $noteTip = '';
     }
     $rowNum = $efNum * 2 + 2;
     $result .= "<td class=\"ef_ref\">{$sourceTip}<a title='Add a source for this event/fact' href=\"#sourcesSection\" onClick=\"addRef('event_fact_input',{$rowNum},1,newSource());\">+</a>";
     $result .= "<input tabindex=\"1\" type=\"text\" name=\"sources{$efNum}\" value=\"{$sources}\"/></td>";
     $result .= "<td class=\"ef_ref\">{$imageTip}<a title='Add an image for this event/fact' href=\"#imagesSection\" onClick=\"addRef('event_fact_input',{$rowNum},2,newImage());\">+</a>";
     $result .= "<input tabindex=\"1\" type=\"text\" name=\"images{$efNum}\" value=\"{$images}\"/></td>";
     $result .= "<td class=\"ef_ref\">{$noteTip}<a title='Add a note for this event/fact' href=\"#notesSection\" onClick=\"addRef('event_fact_input',{$rowNum},3,newNote());\">+</a>";
     $result .= "<input tabindex=\"1\" type=\"text\" name=\"notes{$efNum}\" value=\"{$notes}\"/></td>";
     $result .= "<td></td></tr>\n";
     return $result;
 }
/**
 * 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>";
}