Ejemplo n.º 1
0
 private function getSourceCitationText($sourceCitation)
 {
     $citation = '';
     $recordName = (string) $sourceCitation['record_name'];
     $citation .= $recordName;
     $title = (string) $sourceCitation['title'];
     $titleLower = mb_strtolower($title);
     if ($recordName && $title) {
         $citation = StructuredData::chomp($citation, ',') . ', in ';
     }
     $srcTitle = '';
     $altTitle = '';
     if (mb_strpos($titleLower, 'source:') === 0 || mb_strpos($titleLower, 'mysource:') === 0) {
         $fields = explode('|', $title);
         if (count($fields) > 1) {
             $altTitle = $fields[1];
         }
         $t = Title::newFromText($fields[0]);
         if ($t) {
             $srcTitle = StructuredData::getRedirectToTitle($t);
         }
     }
     if ($srcTitle) {
         if ($altTitle) {
             $citation .= "[[" . $srcTitle->getPrefixedText() . "|{$altTitle}]]";
         } else {
             if ($srcTitle->getNamespace() == NS_SOURCE) {
                 $source = new Source($srcTitle->getText());
             } else {
                 $source = new MySource($srcTitle->getText());
             }
             $source->loadPage();
             $citation .= $source->getCitationText(true);
         }
     } else {
         $citation .= $title;
     }
     $page = (string) $sourceCitation['page'];
     if ($page) {
         $citation = StructuredData::chomp($citation, ',') . ", {$page}";
     }
     $date = (string) $sourceCitation['date'];
     if ($date) {
         $citation = StructuredData::chomp($citation, ',') . ", {$date}";
     }
     $quality = (string) $sourceCitation['quality'];
     if (strlen($quality) > 0) {
         $qualName = array_search($quality, self::$QUALITY_OPTIONS);
         if (!$qualName && @self::$QUALITY_OPTIONS[$quality]) {
             $qualName = $quality;
         }
         // allow old alpha form
         if ($qualName) {
             $citation = StructuredData::chomp($citation, ',') . ", {$qualName} quality";
         }
     }
     return $citation;
 }
Ejemplo n.º 2
0
 private function writePage($fullTitle)
 {
     $this->title = Title::newFromText($fullTitle);
     $id = $this->titleMap[$fullTitle];
     $obj = null;
     $this->xml = null;
     $this->contents = null;
     $ns = $this->title->getNamespace();
     if ($this->title->exists()) {
         if ($ns == NS_PERSON) {
             $obj = new Person($this->title->getText());
         } else {
             if ($ns == NS_FAMILY) {
                 $obj = new Family($this->title->getText());
             } else {
                 if ($ns == NS_SOURCE) {
                     $obj = new Source($this->title->getText());
                 } else {
                     if ($ns == NS_MYSOURCE) {
                         $obj = new MySource($this->title->getText());
                     }
                 }
             }
         }
         if ($obj) {
             $obj->loadPage();
             $this->xml = $obj->getPageXml();
             if ($this->xml == null) {
                 echo "XML not found for title=" . $this->title->getPrefixedText() . " treeId={$this->treeId}\n";
             }
             $this->contents = $obj->getPageContents();
         }
     }
     $this->refdCitations = array();
     $this->refdNotes = array();
     $this->refdImages = array();
     if ($ns == NS_PERSON) {
         $uid = "WeRelate:" . $this->title->getNsText() . ":" . $this->title->getDBkey();
         $this->writePerson($id, $uid);
     } else {
         if ($ns == NS_FAMILY) {
             $this->writeFamily($id);
         } else {
             if ($ns == NS_SOURCE) {
                 $this->writeSource($id);
             } else {
                 if ($ns == NS_MYSOURCE) {
                     $this->writeMySource($id);
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
/**
 * 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>";
}
Ejemplo n.º 4
0
 /**
  * Return xml elements from data in request
  * @param unknown $request
  */
 protected function fromEditFields($request)
 {
     $this->correctedPlaceTitles = PlaceSearcher::correctPlaceTitlesMultiLine($request->getVal('places', ''));
     $result = '';
     // !!! +title, +date_issued, -publication_info, -call_number, type->format, -abbrev, +ethnicity, +religion, +occupation, +category
     // !!! author format=lastname, given name(s)
     if ($this->isGedcomPage) {
         list($mysourcePrefix, $mysourceTitle, $mysourceSuffix) = MySource::splitGedcomMySourceTitle($this->titleString);
         $mysourceTitle = $request->getVal('mysource_title', '') ? $request->getVal('mysource_title', '') : $mysourceTitle;
         $mysourceTitle = mb_strtoupper(mb_substr($mysourceTitle, 0, 1)) . mb_substr($mysourceTitle, 1);
         $result .= $this->addSingleLineFieldToXml($mysourceTitle, 'title');
         $this->titleString = $mysourcePrefix . $mysourceTitle . $mysourceSuffix;
         $this->title = Title::newFromText($this->titleString, NS_MYSOURCE);
     }
     $result .= $this->addSingleLineFieldToXml($this->cleanUrl($request->getVal('url', '')), 'url');
     //      $result .= $this->addMultiLineFieldToXml($request->getVal('altNames', ''), 'formatAltNameXML');
     $result .= $this->addMultiLineFieldToXml($request->getVal('places', ''), 'formatPlace');
     $result .= $this->addMultiLineFieldToXml($request->getVal('surnames', ''), 'formatSurname');
     $result .= $this->addSingleLineFieldToXml($request->getVal('fromYear', ''), 'from_year');
     $result .= $this->addSingleLineFieldToXml($request->getVal('toYear', ''), 'to_year');
     $result .= $this->addSingleLineFieldToXml($request->getVal('abbrev', ''), 'abbrev');
     $result .= $this->addSingleLineFieldToXml($request->getVal('author', ''), 'author');
     $result .= $this->addSingleLineFieldToXml($request->getVal('pubInfo', ''), 'publication_info');
     $result .= $this->addSingleLineFieldToXml($request->getVal('callNumber', ''), 'call_number');
     $result .= $this->addSingleLineFieldToXml($request->getVal('type', ''), 'type');
     $result .= $this->addSingleLineFieldToXml($request->getVal('repoName', ''), 'repository_name');
     $result .= $this->addSingleLineFieldToXml($request->getVal('repoAddr', ''), 'repository_addr');
     return $result;
 }
Ejemplo n.º 5
0
 private function getPageObj($ns, $titleString)
 {
     if ($ns == NS_PERSON) {
         $obj = new Person($titleString);
     } else {
         if ($ns == NS_FAMILY) {
             $obj = new Family($titleString);
         } else {
             $obj = new MySource($titleString);
         }
     }
     $obj->setGedcomPage(true);
     return $obj;
 }