Ejemplo n.º 1
0
 /**
  * Propagate move, delete, or undelete to other articles if necessary
  *
  * @param String $newTitleString null in case of delete; same as this title string in case of undelete
  * @param String $text text of article
  * @param bool $textChanged we never change the text, so this is never set to true
  * @return bool true if success
  */
 protected function propagateMoveDeleteUndelete($newTitleString, $newNs, &$text, &$textChanged)
 {
     $result = true;
     // move: maintain place abbrevs and add place redirect job
     if ($newTitleString && $newTitleString != $this->titleString) {
         Place::placeAbbrevsDelete($this->titleString);
         Place::placeAbbrevsDelete($newTitleString);
         Place::placeAbbrevsAdd($newTitleString, $this->xml);
         // edit wlh pages to point to the target title
         $newTitle = Title::newFromText($newTitleString, NS_PLACE);
         $job = new PlaceRedirectJob(array('old_title' => $this->titleString, 'new_title' => $newTitle->getText()));
         $job->insert();
     } else {
         if (!$newTitleString) {
             Place::placeAbbrevsDelete($this->titleString);
         }
     }
     // determine parents and type and lat and lng
     list($alsoLocatedIn, $type, $lat, $lng, $fromYear, $toYear) = Place::getPropagatedData($this->xml);
     // get new name pieces
     $newName = Place::getPrefNameLocatedIn($newTitleString);
     // follow redirects
     $t = (string) $this->locatedIn ? Title::newFromText((string) $this->locatedIn, NS_PLACE) : null;
     if ($t) {
         $t = StructuredData::getRedirectToTitle($t);
     }
     $oldLocatedIn = $t ? $t->getText() : (string) $this->locatedIn;
     $t = $newName[1] ? Title::newFromText($newName[1], NS_PLACE) : null;
     if ($t) {
         $t = StructuredData::getRedirectToTitle($t);
     }
     $newLocatedIn = $t ? $t->getText() : $newName[1];
     foreach ($alsoLocatedIn as $ali) {
         $t = $ali['place'] ? Title::newFromText($ali['place'], NS_PLACE) : null;
         if ($t) {
             $t = StructuredData::getRedirectToTitle($t);
         }
         if ($t) {
             $ali['place'] = $t->getText();
         }
     }
     // if current located-in place is not also an also-located-in place
     if (StructuredData::mapArraySearch($oldLocatedIn, $alsoLocatedIn, 'place') === false) {
         if ($oldLocatedIn == $newLocatedIn) {
             // update title in located-in place
             $article = StructuredData::getArticle(Title::newFromText($oldLocatedIn, NS_PLACE), true);
             if ($article) {
                 $content =& $article->fetchContent();
                 $updatedContent =& $this->updateContainedPlace($newTitleString, $type, $lat, $lng, $fromYear, $toYear, $content);
                 if ($updatedContent) {
                     $updateResult = $article->doEdit($updatedContent, self::PROPAGATE_MESSAGE . ' [[' . $this->title->getPrefixedText() . ']]', PROPAGATE_EDIT_FLAGS);
                     $result = $result && $updateResult;
                 }
             }
         } else {
             // remove from current parent
             $parentArticle = StructuredData::getArticle(Title::newFromText($oldLocatedIn, NS_PLACE), true);
             if ($parentArticle) {
                 $content =& $parentArticle->fetchContent();
                 $updatedContent =& $this->updateContainedPlace(null, null, null, null, null, null, $content);
                 if ($updatedContent) {
                     $updateResult = $parentArticle->doEdit($updatedContent, self::PROPAGATE_MESSAGE . ' [[' . $this->title->getPrefixedText() . ']]', PROPAGATE_EDIT_FLAGS);
                     $result = $result && $updateResult;
                 }
             }
         }
     }
     // add to new parent if necessary
     if ($oldLocatedIn != $newLocatedIn && StructuredData::mapArraySearch($newLocatedIn, $alsoLocatedIn, 'place') === false) {
         $article = StructuredData::getArticle(Title::newFromText($newLocatedIn, NS_PLACE), true);
         if ($article) {
             $content =& $article->fetchContent();
             $updatedContent =& $this->updateContainedPlace($newTitleString, $type, $lat, $lng, $fromYear, $toYear, $content);
             if ($updatedContent) {
                 $updateResult = $article->doEdit($updatedContent, self::PROPAGATE_MESSAGE . ' [[' . $this->title->getPrefixedText() . ']]', PROPAGATE_EDIT_FLAGS);
                 $result = $result && $updateResult;
             }
         }
     }
     // update title in also-located-in places
     foreach ($alsoLocatedIn as $pli) {
         $article = StructuredData::getArticle(Title::newFromText((string) $pli['place'], NS_PLACE), true);
         if ($article) {
             $content =& $article->fetchContent();
             $updatedContent =& $this->updateContainedPlace($newTitleString, $type, $lat, $lng, (string) $pli['from_year'], (string) $pli['to_year'], $content);
             if ($updatedContent) {
                 $updateResult = $article->doEdit($updatedContent, self::PROPAGATE_MESSAGE . ' [[' . $this->title->getPrefixedText() . ']]', PROPAGATE_EDIT_FLAGS);
                 $result = $result && $updateResult;
             }
         }
     }
     if (!$result) {
         error_log("ERROR! Place move/delete/undelete not propagated: {$this->titleString} -> " . ($newTitleString ? $newTitleString : "[delete]") . "\n");
     }
     return $result;
 }