/** * Add a jTip * * @param unknown_type $tipId must be unique * @param unknown_type $tipTitle title of the tip * @param unknown_type $tipText text of the tip * @param unknown_type $tipPageTitle title of the page to link to in URL form * @param unknown_type $linkText * @param unknown_type $width not used * @return unknown */ public function addTip($tipId, $tipTitle, $tipText, $tipPagePrefixedURL, $linkText, $width = 250) { global $wgScript; $tipId = str_replace(array('"', "'", '<', '>', '&'), '', $tipId); $tipTextId = $tipId . 'TipText'; $this->tips[$tipTextId] = $tipText; $tipTitle = StructuredData::escapeXml($tipTitle); return "<a class=\"jTip\" title=\"{$tipTitle}\" rel=\"#{$tipTextId}\" href=\"#\">{$linkText}</a>"; }
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; } }
protected function formatPlace($value) { $correctedPlace = @$this->correctedPlaceTitles[$value]; if ($correctedPlace) { $value = strcasecmp($value, $correctedPlace) == 0 ? $correctedPlace : $correctedPlace . '|' . $value; } $escapedValue =& StructuredData::escapeXml($value); return "<place>{$escapedValue}</place>"; }
private function addEvent($pf, $type, $familyNumber, &$result) { if (isset($pf)) { $place = @$pf["{$type}place"]; $place = ShowPedigree::cleanPlace($place); $stdPlace = @$this->stdPlaces[$place]; if ($stdPlace) { $date = @$pf["{$type}date"]; $name = StructuredData::getFullname($pf); $title = Title::newFromText(@$pf['title'], NS_PERSON); $url = $title->getLocalURL(); $lat = $stdPlace['lat']; $lng = $stdPlace['lon']; $placeTitle = $stdPlace['title']; $color = ShowPedigree::$COLORS[$familyNumber]; $type = substr($type, 0, 1); // we only need first character $dateKey = StructuredData::getDateKey($date); $result .= '<p n="' . StructuredData::escapeXml($name) . '" u="' . StructuredData::escapeXml($url) . '" p="' . StructuredData::escapeXml($placeTitle) . '" d="' . StructuredData::escapeXml($date) . '" k="' . $dateKey . '" a="' . $lat . '" o="' . $lng . '" t="' . substr($type, 0, 1) . '" c="' . $color . "\"/>"; } } }
private function updatePerson($personTitle, $personTag, $familyTag, $newTitle, &$text, &$textChanged) { if (!PropagationManager::isPropagatablePage($personTitle)) { return true; } $result = true; $article = StructuredData::getArticle($personTitle, true); if ($article) { $content =& $article->fetchContent(); $updated = false; Person::updateFamilyLink($familyTag, $this->titleString, $newTitle, $content, $updated); if ($updated) { $result = $article->doEdit($content, self::PROPAGATE_MESSAGE . ' [[' . $this->title->getPrefixedText() . ']]', PROPAGATE_EDIT_FLAGS); StructuredData::purgeTitle($personTitle, +1); // purge person with a fudge factor so family link will be blue } else { error_log("propagating family {$this->titleString} nothing changed in {$personTitle->getPrefixedText()}"); } // if we're not deleting this entry (newTitle is not empty), and the person article is a redirect (article title != personTitle), // we need to update the person page title in the family page text if ($newTitle && $personTitle->getText() != $article->getTitle()->getText()) { $old = 'title="' . StructuredData::escapeXml($personTitle->getText()) . '"'; $new = 'title="' . StructuredData::escapeXml($article->getTitle()->getText()) . '"'; $text = str_replace($old, $new, $text); $textChanged = true; } } return $result; }
protected function addMultiAttrFieldToXml($attrs, $tagName, $contents = '') { $attrString = ''; foreach ($attrs as $attrName => $attrValue) { if (strlen($attrValue) > 0) { $attrString .= " {$attrName}=\"" . StructuredData::escapeXml($attrValue) . '"'; } } if (empty($attrString) && empty($contents)) { return ''; } else { if (empty($contents)) { return "<{$tagName}{$attrString}/>\n"; } else { return "<{$tagName}{$attrString}>" . StructuredData::escapeXml($contents) . "</{$tagName}>\n"; } } }
public static function getContainedPlaceMapData($xml) { $result = ''; foreach ($xml->contained_place as $place) { $lat = (string) $place['latitude']; $lng = (string) $place['longitude']; if ($lat && $lng) { $titleString = (string) $place['place']; $pieces = mb_split(",", $titleString, 2); $title = Title::newFromText($titleString, NS_PLACE); $url = $title->getLocalURL(); $type = (string) $place['type']; $result .= '<p n="' . StructuredData::escapeXml(trim($pieces[0])) . '" u="' . StructuredData::escapeXml($url) . '" a="' . $lat . '" o="' . $lng . '" t="' . $type . "\"/>"; } } return $result; }
function ftWriteRows($dbr, $rows) { $result = array(); while ($row = $dbr->fetchObject($rows)) { $title = Title::makeTitle($row->fp_namespace, $row->fp_title); $titleString = StructuredData::escapeXml($title->getText()); $lastmod = ''; if ($row->fp_oldid != $row->fp_latest) { $status = FTE_SUCCESS; list($lastmodUser, $lastmodDate, $lastmodComment) = ftGetLastmod($dbr, $row->fp_latest, $status); if ($status == FTE_SUCCESS) { $lastmodUser = StructuredData::escapeXml($lastmodUser); $lastmodDate = StructuredData::escapeXml($lastmodDate); $lastmodComment = StructuredData::escapeXml($lastmodComment); $lastmod .= " u=\"{$lastmodUser}\" d=\"{$lastmodDate}\" c=\"{$lastmodComment}\""; } } if ($row->fp_talk_oldid != $row->fp_talk_latest) { $status = FTE_SUCCESS; list($lastmodUser, $lastmodDate, $lastmodComment) = ftGetLastmod($dbr, $row->fp_talk_latest, $status); if ($status == FTE_SUCCESS) { $lastmodUser = StructuredData::escapeXml($lastmodUser); $lastmodDate = StructuredData::escapeXml($lastmodDate); $lastmodComment = StructuredData::escapeXml($lastmodComment); $lastmod .= " tu=\"{$lastmodUser}\" td=\"{$lastmodDate}\" tc=\"{$lastmodComment}\""; } } $flags = $row->fp_flags; $oldid = $row->fp_oldid; $talkOldid = $row->fp_talk_oldid; $dataVersion = $row->fp_data_version; $result[] = "<p n=\"{$title->getNamespace()}\" t=\"{$titleString}\" o=\"{$oldid}\" l=\"{$row->fp_latest}\" dv=\"{$dataVersion}\" f=\"{$flags}\" to=\"{$talkOldid}\" tl=\"{$row->fp_talk_latest}\"{$lastmod}/>\n"; } return join('', $result); }
/** * Return xml elements from data in request * @param unknown $request */ protected function fromEditFields($request) { $related = $request->getVal('related', ''); $search = array('/ *\\r?\\n */', '/\\|/'); // add space before bar so things sort right $replace = array("\n", ' |'); $related = trim(preg_replace($search, $replace, $related)); $relNames = preg_split('/[\\n]+/', $related, -1, PREG_SPLIT_NO_EMPTY); sort($relNames, SORT_STRING); $prevName = ''; $result = ''; foreach ($relNames as $relName) { $fields = explode('|', $relName, 2); $name = StructuredData::escapeXml(StructuredData::standardizeNameCase(trim(@$fields[0]), false)); $source = StructuredData::escapeXml(trim(@$fields[1])); // remove any space before bar in source: links that would have been added above $source = str_replace(' |', '|', $source); if ($name != $prevName) { $result .= "<related name=\"{$name}\" source=\"{$source}\"/>\n"; } $prevName = $name; } return $result; }
function fgGetRelatedMatches(&$keys, &$matches) { $result = array(); for ($i = 0; $i < count($keys); $i++) { if ($matches[$i] != '#nomatch#') { $title = Title::newFromText($matches[$i]); $result[] = '<match id="' . StructuredData::escapeXml($keys[$i]) . '" match="' . StructuredData::escapeXml($matches[$i]) . '">'; if ($title->getNamespace() == NS_PERSON) { // get potential matches $person = new Person($title->getText()); $xml = $person->getPageXml(); if (isset($xml)) { foreach ($xml->child_of_family as $f) { $familyTitleString = (string) $f['title']; $result[] = '<child_of_family title="' . StructuredData::escapeXml($familyTitleString) . '"/>'; } foreach ($xml->spouse_of_family as $f) { $familyTitleString = (string) $f['title']; $result[] = '<spouse_of_family title="' . StructuredData::escapeXml($familyTitleString) . '"/>'; } } } $result[] = '</match>'; } } return join("\n", $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; }
private function updatePage($linkTitle, $tag, $newTitle, &$text, &$textChanged) { if (!PropagationManager::isPropagatablePage($linkTitle)) { return true; } $result = true; $article = StructuredData::getArticle($linkTitle, true); if ($article) { $content =& $article->fetchContent(); $updated = false; ESINHandler::updateImageLink($tag, $this->titleString, $newTitle, '', $content, $updated); if ($updated) { $result = $article->doEdit($content, self::PROPAGATE_MESSAGE . ' [[' . $this->title->getPrefixedText() . ']]', PROPAGATE_EDIT_FLAGS); } else { error_log("propagating image " . $this->titleString . " nothing changed in " . $linkTitle->getPrefixedText()); } // if we're not deleting this entry (newTitle is not empty), and the page to update is a redirect (article title != linkTitle), // we need to update the page title in the image page text if ($newTitle && $linkTitle->getText() != $article->getTitle()->getText()) { $old = 'title="' . StructuredData::escapeXml($linkTitle->getText()) . '"'; $new = 'title="' . StructuredData::escapeXml($article->getTitle()->getText()) . '"'; $text = str_replace($old, $new, $text); $textChanged = true; } } return $result; }
/** * Return whether the specified page titles have been redirected * * @param unknown_type $args title|title|title,... (up to IAF_MAX_COUNT_CONTENTS) * @return IAF_SUCCESS, IAF_INVALID_ARG */ function wfGetPageRedirects($args) { global $wgAjaxCachePolicy; // set cache policy $wgAjaxCachePolicy->setPolicy(0); // validate input arguments $status = IAF_SUCCESS; $result = array(); $pageTitles = explode('|', $args); if (!$args || count($pageTitles) > IAF_MAX_COUNT_CONTENTS) { $status = IAF_INVALID_ARG; } else { $db =& wfGetDB(DB_SLAVE); $db->ignoreErrors(true); $result = array(); foreach ($pageTitles as $pageTitle) { $ot = Title::newFromText($pageTitle); if ($ot) { $nt = StructuredData::getRedirectToTitle($ot, false, $db); $errno = $db->lastErrno(); if ($errno != 0) { $status = IAF_DB_ERROR; break; } if ($nt && $ot->getPrefixedDBkey() != $nt->getPrefixedDBkey()) { $result[] = '<page source="' . StructuredData::escapeXml($ot->getPrefixedText()) . '" target="' . StructuredData::escapeXml($nt->getPrefixedText()) . '"/>'; } } } } // return status return "<result status=\"{$status}\">" . join("\n", $result) . '</result>'; }