function wfSpecialAddSubpage($par) { global $wgOut, $wgRequest, $wgUser; $super = $wgRequest->getVal('super'); $sub = $wgRequest->getVal('sub'); $found = false; if ($super && $sub && $wgUser->isLoggedIn()) { $sub = mb_strtoupper(mb_substr($sub, 0, 1)) . mb_substr($sub, 1); $subTitle = Title::newFromText("{$super}/{$sub}"); if ($subTitle) { // add the page to the super page if it has a listsubpages tag $superTitle = Title::newFromText($super); if ($superTitle) { $r = Revision::newFromTitle($superTitle); if ($r) { $text =& $r->getText(); if ($subTitle->exists()) { $dbr =& wfGetDB(DB_SLAVE); $timestamp = $dbr->selectField(array('page', 'revision'), 'rev_timestamp', array('page_namespace' => $subTitle->getNamespace(), 'page_title' => $subTitle->getDBkey(), 'page_id = rev_page'), 'wfSpecialAddSubpage', array('order by rev_timestamp')); $d = new DateTime(substr($timestamp, 0, 8)); $date = $d->format('j M Y'); } else { $date = date('j M Y'); } $cnt = 0; $text = preg_replace('#(<listsubpages[^>]*>.*?)(</listsubpages>)#s', '${1}' . StructuredData::protectRegexReplace("{$sub}|{$date}") . "\n" . '${2}', $text, 1, $cnt); if ($cnt) { $a = StructuredData::getArticle($superTitle); $a->doEdit($text, 'Added ' . $sub, EDIT_UPDATE); } } } $wgOut->redirect($subTitle->getFullURL('action=edit')); $found = true; } } if (!$found) { $super = htmlspecialchars($super); $sub = htmlspecialchars($sub); $wgOut->addHTML("<p><font color=red>Cannot create page: {$super}/{$sub}</font></p>"); } }
public static function updateImageLink($tag, $oldTitle, $newTitle, $caption, &$text, &$textChanged) { // TODO if you allow renaming images you must find a way to preserve caption and primary attributes here $old = "<image id=\"I(\\d+)\" filename=\"" . StructuredData::protectRegexSearch(StructuredData::escapeXml($oldTitle)) . "\".*?/>\n"; $matches = array(); $id = 0; $oldFound = false; if (preg_match('$' . $old . '$', $text, $matches)) { $id = (int) $matches[1]; $oldFound = true; } else { $old = "</{$tag}>"; } if ($newTitle) { $newTitle = StructuredData::escapeXml($newTitle); // get the last image number in the text if ($id == 0) { $id = ESINHandler::getLastImageId($text) + 1; } if ($caption) { $caption = " caption=\"{$caption}\""; } $new = "<image id=\"I{$id}\" filename=\"{$newTitle}\"{$caption}/>\n"; } else { $new = ''; } if (!$oldFound) { $new .= $old; } $result = preg_replace('$' . $old . '$', StructuredData::protectRegexReplace($new), $text); if ($result != $text) { $text = $result; $textChanged = true; } }
/** * 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 set to true if we change the text * @return bool true if success */ protected function propagateMoveDeleteUndelete($newTitleString, $newNs, &$text, &$textChanged) { global $wgESINHandler; $result = true; $newTitle = $newTitleString ? Title::newFromText($newTitleString, NS_FAMILY) : null; // if we're undeleting, add additional people from WLH, getting updated person data if ($this->titleString == $newTitleString) { $wlh = simplexml_load_string($this->getPageTextFromWLH(false)); // get text for all people // TODO is propagateEditData called after Undelete? if so, then we could get updated person attributes there $personText = $this->getPersonData($wlh->husband, $this->xml->husband, 'husband') . $this->getPersonData($wlh->wife, $this->xml->wife, 'wife') . $this->getPersonData($wlh->child, $this->xml->child, 'child') . $wgESINHandler->getImageData($wlh->image, $this->xml->image); // update text: replace old family information with new $text = preg_replace("\$<(husband|wife|child|image) [^>]*>\n\$", '', $text); $text = preg_replace('$</family>$', StructuredData::protectRegexReplace($personText . '</family>'), $text, 1); $this->xml = StructuredData::getXml($this->tagName, $text); $textChanged = true; } // get data to propagate $propagatedData = Family::getPropagatedData($this->xml); foreach ($propagatedData['husbands'] as $p) { $personTitle = Title::newFromText((string) $p, NS_PERSON); PropagationManager::addPropagatedAction($this->title, 'delspouse', $personTitle); if ($newTitle) { PropagationManager::addPropagatedAction($newTitle, 'addspouse', $personTitle); } // don't need to check propagated action before calling updatePerson, because propagateMoveDeleteUndelete is never part of a loop $result = $result && $this->updatePerson($personTitle, 'husband', 'spouse_of_family', $newTitleString, $text, $textChanged); } foreach ($propagatedData['wives'] as $p) { $personTitle = Title::newFromText((string) $p, NS_PERSON); PropagationManager::addPropagatedAction($this->title, 'delspouse', $personTitle); if ($newTitle) { PropagationManager::addPropagatedAction($newTitle, 'addspouse', $personTitle); } // don't need to check propagated action before calling updatePerson, because propagateMoveDeleteUndelete is never part of a loop $result = $result && $this->updatePerson($personTitle, 'wife', 'spouse_of_family', $newTitleString, $text, $textChanged); } foreach ($propagatedData['children'] as $p) { $personTitle = Title::newFromText((string) $p, NS_PERSON); PropagationManager::addPropagatedAction($this->title, 'delchild', $personTitle); if ($newTitle) { PropagationManager::addPropagatedAction($newTitle, 'addchild', $personTitle); } // don't need to check propagated action before calling updatePerson, because propagateMoveDeleteUndelete is never part of a loop $result = $result && $this->updatePerson($personTitle, 'child', 'child_of_family', $newTitleString, $text, $textChanged); } if (StructuredData::removeDuplicateLinks('husband|wife|child', $text)) { $textChanged = true; } $result = $result && $wgESINHandler->propagateSINMoveDeleteUndelete($this->title, 'family', $this->titleString, $newTitleString, $propagatedData, $text, $textChanged); if (!$result) { error_log("ERROR! Family move/delete/undelete not propagated: {$this->titleString} -> " . ($newTitleString ? $newTitleString : "[delete]") . "\n"); } return $result; }
private function addTalkContents(&$talkContents, $talkTitle, &$pageContents) { if ($pageContents) { $hdrPrefix = StructuredData::protectRegexReplace('From [[' . $talkTitle->getPrefixedText() . '|' . $talkTitle->getText() . ']]: '); $talkContents .= preg_replace('/^ *==( *)([^=].*?[^=])== *$/m', "==\\1{$hdrPrefix}\\2==", $pageContents); } }
/** * 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 set to true if we change the text * @return bool true if success */ protected function propagateMoveDeleteUndelete($newTitleString, $newNs, &$text, &$textChanged) { global $wgESINHandler; $result = true; $newTitle = $newTitleString ? Title::newFromText($newTitleString, NS_PERSON) : null; // if we're undeleting, add additional families from WLH if ($this->titleString == $newTitleString) { $wlh = simplexml_load_string($this->getPageTextFromWLH(false)); // get text for all families $familyText = $this->getFamilyData($wlh->child_of_family, $this->xml->child_of_family, 'child_of_family') . $this->getFamilyData($wlh->spouse_of_family, $this->xml->spouse_of_family, 'spouse_of_family') . $wgESINHandler->getImageData($wlh->image, $this->xml->image); // update text: replace old family information with new $text = preg_replace("\$<((child|spouse)_of_family|image) [^>]*>\n\$", '', $text); $text = preg_replace('$</person>$', StructuredData::protectRegexReplace($familyText . '</person>'), $text, 1); $this->xml = StructuredData::getXml($this->tagName, $text); $textChanged = true; } // get data to propagate $propagatedData = Person::getPropagatedData($this->xml); foreach ($propagatedData['parentFamilies'] as $f) { $familyTitle = Title::newFromText((string) $f, NS_FAMILY); PropagationManager::addPropagatedAction($this->title, 'delchild_of_family', $familyTitle); if ($newTitle) { PropagationManager::addPropagatedAction($newTitle, 'addchild_of_family', $familyTitle); } // don't need to check propagated action before calling updateFamily, because propagateMoveDeleteUndelete is never part of a loop $result = $result && $this->updateFamily($familyTitle, 'child_of_family', 'child', $newTitleString, $propagatedData, $text, $textChanged); } $spouseTag = $propagatedData['gender'] == 'F' ? 'wife' : 'husband'; foreach ($propagatedData['spouseFamilies'] as $f) { $familyTitle = Title::newFromText((string) $f, NS_FAMILY); PropagationManager::addPropagatedAction($this->title, 'delspouse_of_family', $familyTitle); if ($newTitle) { PropagationManager::addPropagatedAction($newTitle, 'addspouse_of_family', $familyTitle); } // don't need to check propagated action before calling updateFamily, because propagateMoveDeleteUndelete is never part of a loop $result = $result && $this->updateFamily($familyTitle, 'spouse_of_family', $spouseTag, $newTitleString, $propagatedData, $text, $textChanged); } if (StructuredData::removeDuplicateLinks('child_of_family|spouse_of_family', $text)) { $textChanged = true; } $result = $result && $wgESINHandler->propagateSINMoveDeleteUndelete($this->title, 'person', $this->titleString, $newTitleString, $propagatedData, $text, $textChanged); if (!$result) { error_log("ERROR! Person move/delete/undelete not propagated: {$this->titleString} -> " . ($newTitleString ? $newTitleString : "[delete]") . "\n"); } return $result; }
/** * Run a refreshLinks job * @return boolean success */ function run() { global $wgTitle, $wgUser, $wgLang; $wgTitle = $this->title; // FakeTitle (the default) generates errors when accessed, and sometimes I log wgTitle, so set it to something else $wgUser = User::newFromName('WeRelate agent'); // set the user $oldTitle = Title::newFromText($this->params['old_title'], NS_PLACE); $newTitle = Title::newFromText($this->params['new_title'], NS_PLACE); $oldPlace = '<place>' . StructuredData::protectRegexSearch(StructuredData::escapeXml($oldTitle->getText())) . '((\\|[^<]*)?)</place>'; $newPlace = '<place>' . StructuredData::protectRegexReplace(StructuredData::escapeXml($newTitle->getText())) . '\\1</place>'; // get wlh pages $dbr =& wfGetDB(DB_SLAVE); $plConds = array('page_id=pl_from', 'pl_namespace' => $oldTitle->getNamespace(), 'pl_title' => $oldTitle->getDBkey(), 'page_is_redirect' => 0); $fields = array('page_namespace', 'page_title'); $plRes = $dbr->select(array('pagelinks', 'page'), $fields, $plConds, 'PlaceRedirectJob'); // for each wlh page in a target namespace while ($row = $dbr->fetchObject($plRes)) { if ($row->page_namespace == NS_SOURCE) { // update place title in page contents $article = StructuredData::getArticle(Title::newFromText($row->page_title, $row->page_namespace), true); $content =& $article->fetchContent(); $updatedContent = preg_replace('$' . $oldPlace . '$', $newPlace, $content); // save page if ($content != $updatedContent) { $article->doEdit($updatedContent, 'Redirect place', PROPAGATE_EDIT_FLAGS); } } } $dbr->freeResult($plRes); return true; }
/** * 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 set to true if we change the text * @return bool true if success */ protected function propagateMoveDeleteUndelete($newTitleString, $newNs, &$text, &$textChanged) { $result = true; $newTitle = $newTitleString ? Title::newFromText($newTitleString, NS_IMAGE) : null; // if we're undeleting, add additional people from WLH, getting updated person data if ($this->titleString == $newTitleString) { list($people, $families) = SDImage::getPropagatedData($this->xml); $this->addWhatLinksHere($people, $families); $pageText = $this->getPageElements($people, 'person', NS_PERSON) . $this->getPageElements($families, 'family', NS_FAMILY); // update text: replace old family information with new $text = preg_replace("\$<(person|family) [^>]*>\n\$", '', $text); $text = preg_replace('$</' . $this->tagName . '>$', StructuredData::protectRegexReplace($pageText . '</' . $this->tagName . '>'), $text, 1); $this->xml = StructuredData::getXml($this->tagName, $text); $textChanged = true; } // get data to propagate list($people, $families) = SDImage::getPropagatedData($this->xml); foreach ($people as $p) { $linkTitle = Title::newFromText((string) $p, NS_PERSON); PropagationManager::addPropagatedAction($this->title, 'dellink', $linkTitle); if ($newTitle) { PropagationManager::addPropagatedAction($newTitle, 'addlink', $linkTitle); } // don't need to check propagated action before calling updatePage, because propagateMoveDeleteUndelete is never part of a loop $result = $result && $this->updatePage($linkTitle, 'person', $newTitleString, $text, $textChanged); } foreach ($families as $p) { $linkTitle = Title::newFromText((string) $p, NS_FAMILY); PropagationManager::addPropagatedAction($this->title, 'dellink', $linkTitle); if ($newTitle) { PropagationManager::addPropagatedAction($newTitle, 'addlink', $linkTitle); } // don't need to check propagated action before calling updatePage, because propagateMoveDeleteUndelete is never part of a loop $result = $result && $this->updatePage($linkTitle, 'family', $newTitleString, $text, $textChanged); } if (!$result) { error_log("ERROR! Family move/delete/undelete not propagated: {$this->titleString} -> " . ($newTitleString ? $newTitleString : "[delete]") . "\n"); } return $result; }