コード例 #1
0
ファイル: Family.php プロジェクト: k-hasan-19/wiki
 /**
  * Propagate data in xml property to other articles if necessary
  * @param string $oldText contains text being replaced
  * @param String $text which we never touch when propagating places
  * @param bool $textChanged which we never touch when propagating places
  * @return bool true if propagation was successful
  */
 protected function propagateEditData($oldText, &$text, &$textChanged)
 {
     global $wrIsGedcomUpload, $wgESINHandler;
     $result = true;
     // cache new xml - it's used right away to generate family badges on the related person pages,
     // if you don't cache it, the badges pick up the old html
     $this->cachePageXml();
     // update people that link to this family, because the family-badge contents could have changed
     // TODO this could be made more efficient by only invalidating if names, birthdates, or deathdates have changed
     $u = new HTMLCacheUpdate($this->title, 'pagelinks');
     $u->doUpdate();
     // get current info
     $propagatedData = Family::getPropagatedData($this->xml);
     $redirTitle = Title::newFromRedirect($text);
     // get original info
     $origPropagatedData = Family::getPropagatedData(null);
     // don't bother construction page text from WLH in a gedcom upload because nothing will link to this new page
     if (!@$wrIsGedcomUpload && (!$oldText || mb_strpos($oldText, '<family>') === false)) {
         // oldText contains MediaWiki:noarticletext if the article is being created
         // construct <family> text from What Links Here
         $oldText = $this->getPageTextFromWLH(false);
     }
     $origXml = null;
     if ($oldText) {
         $origXml = StructuredData::getXml('family', $oldText);
         if (isset($origXml)) {
             $origPropagatedData = Family::getPropagatedData($origXml);
         }
     }
     // TODO!!!
     // Revert, Unmerge, and eventually Undo should be getting the current attrs for existing people from origPropagatedData
     // and getting the current attrs and redirect-titles for newly-added people from the Person pages when adding the family title to them
     // then unmerge wouldn't need to get them in unmerge, and revert wouldn't be broken, and undo won't break things.
     // This duplicates the functionality found in fromEditFields, but it allows us to update the pages without going through fromEditFields
     // and it doesn't require reading any pages that we weren't reading already.
     // Also, instead of isMerging, if this Family page is on the propagation manager blacklist, then you can't trust the prior version
     // and we should get the person attrs from the Person pages for _all_ family members.
     // Finally, make sure that after redirects we don't have 2 links to the same Person (and also two links to the same Family on Person pages).
     // ignore changes of the husband <-> wife role for the same person
     $temp = array_diff($propagatedData['husbands'], $origPropagatedData['wives']);
     $origPropagatedData['wives'] = array_diff($origPropagatedData['wives'], $propagatedData['husbands']);
     $propagatedData['husbands'] = $temp;
     $temp = array_diff($propagatedData['wives'], $origPropagatedData['husbands']);
     $origPropagatedData['husbands'] = array_diff($origPropagatedData['husbands'], $propagatedData['wives']);
     $propagatedData['wives'] = $temp;
     $result = $result && $this->propagateFamilyMemberEditData($propagatedData['husbands'], $origPropagatedData['husbands'], 'husband', 'spouse_of_family', $text, $textChanged);
     $result = $result && $this->propagateFamilyMemberEditData($propagatedData['wives'], $origPropagatedData['wives'], 'wife', 'spouse_of_family', $text, $textChanged);
     $result = $result && $this->propagateFamilyMemberEditData($propagatedData['children'], $origPropagatedData['children'], 'child', 'child_of_family', $text, $textChanged);
     if (StructuredData::removeDuplicateLinks('husband|wife|child', $text)) {
         $textChanged = true;
     }
     $result = $result && $wgESINHandler->propagateSINEdit($this->title, 'family', $this->titleString, $propagatedData, $origPropagatedData, $text, $textChanged);
     // ensure footer tag is still there (might have been removed by editing the last section)
     if ($redirTitle == null && strpos($text, ESINHandler::ESIN_FOOTER_TAG) === false) {
         if (strlen($text) > 0 && substr($text, strlen($text) - 1) != "\n") {
             $text .= "\n";
         }
         $text .= ESINHandler::ESIN_FOOTER_TAG;
         $textChanged = true;
     }
     // update watchlist summary if changed
     $summary = Family::getSummary($this->xml, $this->title);
     $origSummary = Family::getSummary($origXml, $this->title);
     if ($summary != $origSummary) {
         StructuredData::updateWatchlistSummary($this->title, $summary);
     }
     // if it's a redirect, add the people, families, and images that were on this page to the redirect target
     // but don't bother updating the redir target during a merge
     if ($redirTitle != null && PropagationManager::isPropagatablePage($redirTitle)) {
         // get the text of the redir page
         $article = StructuredData::getArticle($redirTitle, true);
         if ($article) {
             $content =& $article->fetchContent();
             $updated = false;
             // add husbands from this page to the redir page
             foreach ($origPropagatedData['husbands'] as $p) {
                 // get propagated data for p
                 $pd = Person::getPropagatedData(StructuredData::getXmlForTitle('person', Title::newFromText($p, NS_PERSON)));
                 Family::updatePersonLink('husband', $p, $p, $pd, 'spouse_of_family', $content, $updated);
             }
             // add wives from this page to the redir page
             foreach ($origPropagatedData['wives'] as $p) {
                 $pd = Person::getPropagatedData(StructuredData::getXmlForTitle('person', Title::newFromText($p, NS_PERSON)));
                 Family::updatePersonLink('wife', $p, $p, $pd, 'spouse_of_family', $content, $updated);
             }
             // add children from this page to the redir page
             foreach ($origPropagatedData['children'] as $p) {
                 $pd = Person::getPropagatedData(StructuredData::getXmlForTitle('person', Title::newFromText($p, NS_PERSON)));
                 Family::updatePersonLink('child', $p, $p, $pd, 'child_of_family', $content, $updated);
             }
             // add images from this page to the redir page
             foreach ($origPropagatedData['images'] as $i) {
                 ESINHandler::updateImageLink('family', $i['filename'], $i['filename'], $i['caption'], $content, $updated);
             }
             // update the redir page if necessary
             if ($updated) {
                 $result = $result && $article->doEdit($content, 'Copy data from [[' . $this->title->getPrefixedText() . ']]', PROPAGATE_EDIT_FLAGS);
             }
         }
     }
     if (!$result) {
         error_log("ERROR! Family edit/rollback not propagated: {$this->titleString}\n");
     }
     return $result;
 }