コード例 #1
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>";
}
コード例 #2
0
ファイル: Source.php プロジェクト: k-hasan-19/wiki
 /**
  * Create edit fields from xml property
  */
 protected function toEditFields(&$textbox1)
 {
     global $wgOut, $wgScriptPath, $wgRequest;
     $result = '';
     $target = $wgRequest->getVal('target');
     // add javascript functions
     $wgOut->addScript("<script type=\"text/javascript\" src=\"{$wgScriptPath}/autocomplete.10.js\"></script>");
     //      if ($target && $target != 'AddPage') {
     //         $result .= "<p><font color=red>Add any additional information you have about the source".
     //                     ($target == 'gedcom' ? ' and save the page' : ', save the page, then close this window').
     //                    ".</font></p>";
     //      }
     $wgOut->addScript("<script type=\"text/javascript\" src=\"{$wgScriptPath}/jquery.multiSelect.yui.1.js\"></script>");
     $wgOut->addScript("<script type=\"text/javascript\" src=\"{$wgScriptPath}/source.18.js\"></script>");
     $tm = new TipManager();
     $sourceType = '';
     $authors = '';
     $sourceTitle = '';
     $subtitle = '';
     $publisher = '';
     $dateIssued = '';
     $placeIssued = '';
     $seriesName = '';
     $pages = '';
     $references = '';
     $surnames = '';
     $places = '';
     $subjects = array();
     $ethnicity = '';
     $religion = '';
     $occupation = '';
     $fromYear = '';
     $toYear = '';
     $invalidStyle = ' style="background-color:#fdd;"';
     $fromYearStyle = '';
     $toYearStyle = '';
     $exists = isset($this->xml);
     if (!$exists) {
         // construct <source> text from request
         $text = Source::getPageText($wgRequest->getVal('sty'), $wgRequest->getVal('st'), $wgRequest->getVal('a'), $wgRequest->getVal('p'), $wgRequest->getVal('pi'), $wgRequest->getVal('pu'));
         $this->xml = StructuredData::getXml('source', $text);
     }
     if (isset($this->xml)) {
         $sourceType = htmlspecialchars((string) $this->xml->source_type);
         foreach ($this->xml->author as $author) {
             $authors .= htmlspecialchars((string) $author) . "\n";
         }
         $sourceTitle = htmlspecialchars((string) $this->xml->source_title);
         if (!$sourceTitle) {
             $sourceTitle = htmlspecialchars($this->titleString);
         }
         $subtitle = htmlspecialchars((string) $this->xml->subtitle);
         $publisher = htmlspecialchars((string) $this->xml->publisher);
         if (!$publisher) {
             $publisher = htmlspecialchars((string) $this->xml->publication_info);
         }
         $dateIssued = htmlspecialchars((string) $this->xml->date_issued);
         $placeIssued = htmlspecialchars((string) $this->xml->place_issued);
         $seriesName = htmlspecialchars((string) $this->xml->series_name);
         $volumes = htmlspecialchars((string) $this->xml->volumes);
         $pages = htmlspecialchars((string) $this->xml->pages);
         $references = htmlspecialchars((string) $this->xml->references);
         foreach ($this->xml->surname as $surname) {
             $surnames .= htmlspecialchars((string) $surname) . "\n";
         }
         foreach ($this->xml->place as $place) {
             $places .= htmlspecialchars((string) $place) . "\n";
         }
         foreach ($this->xml->subject as $subject) {
             $subjects[] = htmlspecialchars((string) $subject);
         }
         if (count($subjects) == 0 && (string) $this->xml->source_category) {
             $subjects[] = htmlspecialchars((string) $this->xml->source_category);
         }
         $ethnicity = htmlspecialchars((string) $this->xml->ethnicity);
         $religion = htmlspecialchars((string) $this->xml->religion);
         $occupation = htmlspecialchars((string) $this->xml->occupation);
         $fromYear = htmlspecialchars((string) $this->xml->from_year);
         $toYear = htmlspecialchars((string) $this->xml->to_year);
         $url = htmlspecialchars((string) $this->xml->url);
         // old
         $callNumber = htmlspecialchars((string) $this->xml->call_number);
         // old
         $repoName = htmlspecialchars((string) $this->xml->repository_name);
         // old
         $repoAddr = htmlspecialchars((string) $this->xml->repository_addr);
         // old
     }
     $missingAvailability = false;
     if (isset($this->xml)) {
         foreach ($this->xml->repository as $repository) {
             // the source_location condition is temporary
             if (!(string) $repository['availability'] && stripos((string) $repository['source_location'], 'www.familysearch.org/Eng/Library/fhlcatalog') === false) {
                 $missingAvailability = true;
             }
         }
         if ($url && stripos($url, 'www.familysearch.org/Eng/Library/fhlcatalog') === false) {
             $missingAvailability = true;
         }
     }
     if ($missingAvailability) {
         $result .= "<p><font color=red>Please select an Availability</font></p>";
     }
     if (!StructuredData::isValidYear($fromYear) || !StructuredData::isValidYear($toYear)) {
         if (!StructuredData::isValidYear($fromYear)) {
             $fromYearStyle = $invalidStyle;
         }
         if (!StructuredData::isValidYear($toYear)) {
             $toYearStyle = $invalidStyle;
         }
         $result .= "<p><font color=red>The year range is not valid</font></p>";
     }
     // display edit fields
     $result .= "<h2>Source information</h2><table>" . '<tr><td align=right>Type:</td><td align=left>' . StructuredData::addSelectToHtml(1, 'source_type', self::$SOURCE_TYPE_OPTIONS, $sourceType, 'onChange="showSourceFields()"') . $tm->addMsgTip('SourceType') . '</td></tr>' . '<tr id="authors_row"><td align=right>Authors:<br/><font size=\\"-1\\"><i>one per line<br/>surname, given</i></font></td>' . "<td align=left><textarea tabindex=\"1\" name=\"authors\" rows=\"3\" cols=\"60\">{$authors}</textarea></td></tr>" . "<tr id=\"source_title_row\"><td align=right>Title:</td><td align=left><input tabindex=\"1\" name=\"source_title\" value=\"{$sourceTitle}\" size=\"60\"/></td></tr>" . "<tr id=\"subtitle_row\"><td align=right>Subtitle:</td><td align=left><input tabindex=\"1\" name=\"subtitle\" value=\"{$subtitle}\" size=\"60\"/></td></tr>" . "<tr id=\"publisher_row\"><td align=right>Publisher:</td><td align=left><input tabindex=\"1\" name=\"publisher\" value=\"{$publisher}\" size=\"60\"/></td></tr>" . "<tr id=\"date_issued_row\"><td align=right>Date issued:</td><td align=left><input tabindex=\"1\" name=\"date_issued\" value=\"{$dateIssued}\" size=\"20\"/></td></tr>" . "<tr id=\"place_issued_row\"><td align=right>Place issued:</td><td align=left><input tabindex=\"1\" name=\"place_issued\" value=\"{$placeIssued}\" size=\"60\"/></td></tr>" . "<tr id=\"series_name_row\"><td align=right>Periodical/Series name:</td><td align=left><input tabindex=\"1\" class=\"source_input\" name=\"series_name\" value=\"{$seriesName}\" size=\"60\"/></td></tr>" . "<tr id=\"volumes_row\"><td align=right>Number of volumes:</td><td align=left><input tabindex=\"1\" name=\"volumes\" value=\"{$volumes}\" size=\"10\"/></td></tr>" . "<tr id=\"pages_row\"><td align=right>Volume/Film#/Pages:</td><td align=left><input tabindex=\"1\" name=\"pages\" value=\"{$pages}\" size=\"20\"/></td></tr>" . "<tr id=\"references_row\"><td align=right>References/Cites:</td><td align=left><input tabindex=\"1\" name=\"references\" value=\"{$references}\" size=\"60\"/></td></tr>" . "</table>";
     $result .= '<h2>Coverage</h2><table>' . "<tr><td align=right>Surnames covered:<br/><i>one per line</i></td><td align=left><textarea tabindex=\"1\" name=\"surnames\" rows=\"3\" cols=\"60\">{$surnames}</textarea></td></tr>" . "<tr><td align=right>Places covered:<br/><i>one per line</i></td><td align=left><textarea class=\"place_input\" tabindex=\"1\" name=\"places\" rows=\"3\" cols=\"60\">{$places}</textarea></td></tr>" . "<tr><td align=right>Year range:</td><td align=left><input tabindex=\"1\" name=\"fromYear\" value=\"{$fromYear}\" size=\"5\"{$fromYearStyle}/>" . "&nbsp;&nbsp;-&nbsp;<input tabindex=\"1\" name=\"toYear\" value=\"{$toYear}\" size=\"5\"{$toYearStyle}/></td></tr>" . "<tr><td align=right>Subject:</td><td align=left>" . StructuredData::addSelectToHtml(1, 'subject', self::$SOURCE_SUBJECT_OPTIONS, $subjects, 'multiple="multiple"') . "</td></tr>" . "<tr id=\"ethnicity_row\"><td align=right>Ethnicity/Culture:</td><td align=left>" . StructuredData::addSelectToHtml(1, 'ethnicity', self::$ETHNICITY_OPTIONS, $ethnicity) . "</td></tr>" . "<tr id=\"religion_row\"><td align=right>Religion:</td><td align=left>" . StructuredData::addSelectToHtml(1, 'religion', self::$RELIGION_OPTIONS, $religion) . "</td></tr>" . "<tr id=\"occupation_row\"><td align=right>Occupation:</td><td align=left>" . StructuredData::addSelectToHtml(1, 'occupation', self::$OCCUPATION_OPTIONS, $occupation) . "</td></tr>" . "</table>";
     $rows = '';
     $i = 0;
     if (isset($this->xml)) {
         foreach ($this->xml->repository as $repository) {
             $rows .= $this->addRepositoryInput($i, htmlspecialchars((string) $repository['title']), htmlspecialchars((string) $repository['source_location']), htmlspecialchars((string) $repository['availability']), (string) $repository['availability'] ? '' : $invalidStyle);
             $i++;
         }
         if ($url) {
             $rows .= $this->addRepositoryInput($i, '', $url, '', $invalidStyle);
             $i++;
         }
         if ($callNumber || $repoName) {
             $rows .= $this->addRepositoryInput($i, $repoName, $callNumber, '', $invalidStyle);
             $i++;
         }
     }
     if ($i == 0) {
         $rows .= $this->addRepositoryInput($i, '', '', '', '');
         $i++;
     }
     $result .= '<h2>Repositories</h2>';
     $result .= '<table id="repository_table" border="0" width="500px" style="display:block">';
     $result .= '<tr><th></th><th>Repository name</th><th>Location (call#, URL) of source within repository</th><th>Availability</th></tr>';
     $result .= "{$rows}</table><a href=\"javascript:void(0)\" onClick=\"addRepository('" . implode(',', self::$SOURCE_AVAILABILITY_OPTIONS) . "'); return preventDefaultAction(event);\">Add Repository</a>";
     $result .= $tm->getTipTexts();
     $result .= "<br><br>Text:<br>";
     return $result;
 }