本文整理汇总了PHP中StringUtils::escapeRegexReplacement方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtils::escapeRegexReplacement方法的具体用法?PHP StringUtils::escapeRegexReplacement怎么用?PHP StringUtils::escapeRegexReplacement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringUtils
的用法示例。
在下文中一共展示了StringUtils::escapeRegexReplacement方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: moveSubpages
/**
* Move this page's subpages to be subpages of $nt
*
* @param Title $nt Move target
* @param bool $auth Whether $wgUser's permissions should be checked
* @param string $reason The reason for the move
* @param bool $createRedirect Whether to create redirects from the old subpages to
* the new ones Ignored if the user doesn't have the 'suppressredirect' right
* @return array Array with old page titles as keys, and strings (new page titles) or
* arrays (errors) as values, or an error array with numeric indices if no pages
* were moved
*/
public function moveSubpages($nt, $auth = true, $reason = '', $createRedirect = true)
{
global $wgMaximumMovedPages;
// Check permissions
if (!$this->userCan('move-subpages')) {
return array('cant-move-subpages');
}
// Do the source and target namespaces support subpages?
if (!MWNamespace::hasSubpages($this->getNamespace())) {
return array('namespace-nosubpages', MWNamespace::getCanonicalName($this->getNamespace()));
}
if (!MWNamespace::hasSubpages($nt->getNamespace())) {
return array('namespace-nosubpages', MWNamespace::getCanonicalName($nt->getNamespace()));
}
$subpages = $this->getSubpages($wgMaximumMovedPages + 1);
$retval = array();
$count = 0;
foreach ($subpages as $oldSubpage) {
$count++;
if ($count > $wgMaximumMovedPages) {
$retval[$oldSubpage->getPrefixedText()] = array('movepage-max-pages', $wgMaximumMovedPages);
break;
}
// We don't know whether this function was called before
// or after moving the root page, so check both
// $this and $nt
if ($oldSubpage->getArticleID() == $this->getArticleID() || $oldSubpage->getArticleID() == $nt->getArticleID()) {
// When moving a page to a subpage of itself,
// don't move it twice
continue;
}
$newPageName = preg_replace('#^' . preg_quote($this->getDBkey(), '#') . '#', StringUtils::escapeRegexReplacement($nt->getDBkey()), $oldSubpage->getDBkey());
if ($oldSubpage->isTalkPage()) {
$newNs = $nt->getTalkPage()->getNamespace();
} else {
$newNs = $nt->getSubjectPage()->getNamespace();
}
# Bug 14385: we need makeTitleSafe because the new page names may
# be longer than 255 characters.
$newSubpage = Title::makeTitleSafe($newNs, $newPageName);
$success = $oldSubpage->moveTo($newSubpage, $auth, $reason, $createRedirect);
if ($success === true) {
$retval[$oldSubpage->getPrefixedText()] = $newSubpage->getPrefixedText();
} else {
$retval[$oldSubpage->getPrefixedText()] = $success;
}
}
return $retval;
}
示例2: formatLinksInCommentCallback
/**
* @param $match
* @return mixed
*/
protected static function formatLinksInCommentCallback($match)
{
global $wgContLang;
$medians = '(?:' . preg_quote(MWNamespace::getCanonicalName(NS_MEDIA), '/') . '|';
$medians .= preg_quote($wgContLang->getNsText(NS_MEDIA), '/') . '):';
$comment = $match[0];
# fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
if (strpos($match[1], '%') !== false) {
$match[1] = str_replace(array('<', '>'), array('<', '>'), rawurldecode($match[1]));
}
# Handle link renaming [[foo|text]] will show link as "text"
if ($match[3] != "") {
$text = $match[3];
} else {
$text = $match[1];
}
$submatch = array();
$thelink = null;
if (preg_match('/^' . $medians . '(.*)$/i', $match[1], $submatch)) {
# Media link; trail not supported.
$linkRegexp = '/\\[\\[(.*?)\\]\\]/';
$title = Title::makeTitleSafe(NS_FILE, $submatch[1]);
if ($title) {
$thelink = self::makeMediaLinkObj($title, $text);
}
} else {
# Other kind of link
if (preg_match($wgContLang->linkTrail(), $match[4], $submatch)) {
$trail = $submatch[1];
} else {
$trail = "";
}
$linkRegexp = '/\\[\\[(.*?)\\]\\]' . preg_quote($trail, '/') . '/';
if (isset($match[1][0]) && $match[1][0] == ':') {
$match[1] = substr($match[1], 1);
}
list($inside, $trail) = self::splitTrail($trail);
$linkText = $text;
$linkTarget = self::normalizeSubpageLink(self::$commentContextTitle, $match[1], $linkText);
$target = Title::newFromText($linkTarget);
if ($target) {
if ($target->getText() == '' && $target->getInterwiki() === '' && !self::$commentLocal && self::$commentContextTitle) {
$newTarget = clone self::$commentContextTitle;
$newTarget->setFragment('#' . $target->getFragment());
$target = $newTarget;
}
$thelink = self::link($target, $linkText . $inside) . $trail;
}
}
if ($thelink) {
// If the link is still valid, go ahead and replace it in!
$comment = preg_replace($linkRegexp, StringUtils::escapeRegexReplacement($thelink), $comment, 1);
}
return $comment;
}
示例3: replace
/**
* Replaces the word with something else
*
* @param string $replacement
* @param string $subject
* @param int $limit
*
* @return string
*/
function replace($replacement, $subject, $limit = -1)
{
$res = preg_replace($this->getRegex(), StringUtils::escapeRegexReplacement($replacement), $subject, $limit);
$this->mModified = $res !== $subject;
return $res;
}
示例4: runReplace
/**
* {{#replace:string | from | to | limit }}
*
* Replaces each occurrence of "from" in "string" with "to".
* At most "limit" replacements are performed.
*
* Note: Armored against replacements that would generate huge strings.
* Note: If "from" is an empty string, single space is used instead.
* @param $parser Parser
* @param $inStr string
* @param $inReplaceFrom string
* @param $inReplaceTo string
* @param $inLimit int
* @return mixed|string
*/
public static function runReplace($parser, $inStr = '', $inReplaceFrom = '', $inReplaceTo = '', $inLimit = -1)
{
global $wgPFStringLengthLimit;
wfProfileIn(__METHOD__);
$inStr = self::killMarkers($parser, (string) $inStr);
$inReplaceFrom = self::killMarkers($parser, (string) $inReplaceFrom);
$inReplaceTo = self::killMarkers($parser, (string) $inReplaceTo);
if (!self::checkLength($inStr) || !self::checkLength($inReplaceFrom) || !self::checkLength($inReplaceTo)) {
wfProfileOut(__METHOD__);
return self::tooLongError();
}
if ($inReplaceFrom == '') {
$inReplaceFrom = ' ';
}
// Precompute limit to avoid generating enormous string:
$diff = mb_strlen($inReplaceTo) - mb_strlen($inReplaceFrom);
if ($diff > 0) {
$limit = ($wgPFStringLengthLimit - mb_strlen($inStr)) / $diff + 1;
} else {
$limit = -1;
}
$inLimit = intval($inLimit);
if ($inLimit >= 0) {
if ($limit > $inLimit || $limit == -1) {
$limit = $inLimit;
}
}
// Use regex to allow limit and handle UTF-8 correctly.
$inReplaceFrom = preg_quote($inReplaceFrom, '/');
$inReplaceTo = StringUtils::escapeRegexReplacement($inReplaceTo);
$result = preg_replace('/' . $inReplaceFrom . '/u', $inReplaceTo, $inStr, $limit);
if (!self::checkLength($result)) {
wfProfileOut(__METHOD__);
return self::tooLongError();
}
wfProfileOut(__METHOD__);
return $result;
}
示例5: formatLinksInComment
/**
* Formats wiki links and media links in text; all other wiki formatting
* is ignored
*
* @todo FIXME: Doesn't handle sub-links as in image thumb texts like the main parser
* @param string $comment Text to format links in. WARNING! Since the output of this
* function is html, $comment must be sanitized for use as html. You probably want
* to pass $comment through Sanitizer::escapeHtmlAllowEntities() before calling
* this function.
* @param Title|null $title An optional title object used to links to sections
* @param bool $local Whether section links should refer to local page
* @param string|null $wikiId Id of the wiki to link to (if not the local wiki),
* as used by WikiMap.
*
* @return string
*/
public static function formatLinksInComment($comment, $title = null, $local = false, $wikiId = null)
{
return preg_replace_callback('/
\\[\\[
:? # ignore optional leading colon
([^\\]|]+) # 1. link target; page names cannot include ] or |
(?:\\|
# 2. a pipe-separated substring; only the last is captured
# Stop matching at | and ]] without relying on backtracking.
((?:]?[^\\]|])*+)
)*
\\]\\]
([^[]*) # 3. link trail (the text up until the next link)
/x', function ($match) use($title, $local, $wikiId) {
global $wgContLang;
$medians = '(?:' . preg_quote(MWNamespace::getCanonicalName(NS_MEDIA), '/') . '|';
$medians .= preg_quote($wgContLang->getNsText(NS_MEDIA), '/') . '):';
$comment = $match[0];
# fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
if (strpos($match[1], '%') !== false) {
$match[1] = strtr(rawurldecode($match[1]), array('<' => '<', '>' => '>'));
}
# Handle link renaming [[foo|text]] will show link as "text"
if ($match[2] != "") {
$text = $match[2];
} else {
$text = $match[1];
}
$submatch = array();
$thelink = null;
if (preg_match('/^' . $medians . '(.*)$/i', $match[1], $submatch)) {
# Media link; trail not supported.
$linkRegexp = '/\\[\\[(.*?)\\]\\]/';
$title = Title::makeTitleSafe(NS_FILE, $submatch[1]);
if ($title) {
$thelink = Linker::makeMediaLinkObj($title, $text);
}
} else {
# Other kind of link
if (preg_match($wgContLang->linkTrail(), $match[3], $submatch)) {
$trail = $submatch[1];
} else {
$trail = "";
}
$linkRegexp = '/\\[\\[(.*?)\\]\\]' . preg_quote($trail, '/') . '/';
if (isset($match[1][0]) && $match[1][0] == ':') {
$match[1] = substr($match[1], 1);
}
list($inside, $trail) = Linker::splitTrail($trail);
$linkText = $text;
$linkTarget = Linker::normalizeSubpageLink($title, $match[1], $linkText);
$target = Title::newFromText($linkTarget);
if ($target) {
if ($target->getText() == '' && !$target->isExternal() && !$local && $title) {
$newTarget = clone $title;
$newTarget->setFragment('#' . $target->getFragment());
$target = $newTarget;
}
$thelink = Linker::makeCommentLink($target, $linkText . $inside, $wikiId) . $trail;
}
}
if ($thelink) {
// If the link is still valid, go ahead and replace it in!
$comment = preg_replace($linkRegexp, StringUtils::escapeRegexReplacement($thelink), $comment, 1);
}
return $comment;
}, $comment);
}
示例6: replaceNamePaths
/**
* Substitute the backend name of storage paths with that of a given one
*
* @param array|string $paths List of paths or single string path
* @param FileBackend $backend
* @return array|string
*/
protected function replaceNamePaths($paths, FileBackend $backend)
{
return preg_replace('!^mwstore://([^/]+)!', StringUtils::escapeRegexReplacement("mwstore://" . $backend->getName()), $paths);
}
示例7: doSubmit
//.........这里部分代码省略.........
if (!$ot->userCan('move-subpages')) {
$this->moveSubpages = false;
}
# Next make a list of id's. This might be marginally less efficient
# than a more direct method, but this is not a highly performance-cri-
# tical code path and readable code is more important here.
#
# Note: this query works nicely on MySQL 5, but the optimizer in MySQL
# 4 might get confused. If so, consider rewriting as a UNION.
#
# If the target namespace doesn't allow subpages, moving with subpages
# would mean that you couldn't move them back in one operation, which
# is bad.
# @todo FIXME: A specific error message should be given in this case.
// @todo FIXME: Use Title::moveSubpages() here
$dbr = wfGetDB(DB_MASTER);
if ($this->moveSubpages && (MWNamespace::hasSubpages($nt->getNamespace()) || $this->moveTalk && MWNamespace::hasSubpages($nt->getTalkPage()->getNamespace()))) {
$conds = array('page_title' . $dbr->buildLike($ot->getDBkey() . '/', $dbr->anyString()) . ' OR page_title = ' . $dbr->addQuotes($ot->getDBkey()));
$conds['page_namespace'] = array();
if (MWNamespace::hasSubpages($nt->getNamespace())) {
$conds['page_namespace'][] = $ot->getNamespace();
}
if ($this->moveTalk && MWNamespace::hasSubpages($nt->getTalkPage()->getNamespace())) {
$conds['page_namespace'][] = $ot->getTalkPage()->getNamespace();
}
} elseif ($this->moveTalk) {
$conds = array('page_namespace' => $ot->getTalkPage()->getNamespace(), 'page_title' => $ot->getDBkey());
} else {
# Skip the query
$conds = null;
}
$extraPages = array();
if (!is_null($conds)) {
$extraPages = TitleArray::newFromResult($dbr->select('page', array('page_id', 'page_namespace', 'page_title'), $conds, __METHOD__));
}
$extraOutput = array();
$skin = $this->getSkin();
$count = 1;
foreach ($extraPages as $oldSubpage) {
if ($ot->equals($oldSubpage)) {
# Already did this one.
continue;
}
$newPageName = preg_replace('#^' . preg_quote($ot->getDBkey(), '#') . '#', StringUtils::escapeRegexReplacement($nt->getDBkey()), $oldSubpage->getDBkey());
if ($oldSubpage->isTalkPage()) {
$newNs = $nt->getTalkPage()->getNamespace();
} else {
$newNs = $nt->getSubjectPage()->getNamespace();
}
# Bug 14385: we need makeTitleSafe because the new page names may
# be longer than 255 characters.
$newSubpage = Title::makeTitleSafe($newNs, $newPageName);
if (!$newSubpage) {
$oldLink = $skin->linkKnown($oldSubpage);
$extraOutput[] = wfMsgHtml('movepage-page-unmoved', $oldLink, htmlspecialchars(Title::makeName($newNs, $newPageName)));
continue;
}
# This was copy-pasted from Renameuser, bleh.
if ($newSubpage->exists() && !$oldSubpage->isValidMoveTarget($newSubpage)) {
$link = $skin->linkKnown($newSubpage);
$extraOutput[] = wfMsgHtml('movepage-page-exists', $link);
} else {
$success = $oldSubpage->moveTo($newSubpage, true, $this->reason, $createRedirect);
if ($success === true) {
if ($this->fixRedirects) {
DoubleRedirectJob::fixRedirects('move', $oldSubpage, $newSubpage);
}
$oldLink = $skin->linkKnown($oldSubpage, null, array(), array('redirect' => 'no'));
$newLink = $skin->linkKnown($newSubpage);
$extraOutput[] = wfMsgHtml('movepage-page-moved', $oldLink, $newLink);
++$count;
if ($count >= $wgMaximumMovedPages) {
$extraOutput[] = wfMsgExt('movepage-max-pages', array('parsemag', 'escape'), $wgLang->formatNum($wgMaximumMovedPages));
break;
}
} else {
$oldLink = $skin->linkKnown($oldSubpage);
$newLink = $skin->link($newSubpage);
$extraOutput[] = wfMsgHtml('movepage-page-unmoved', $oldLink, $newLink);
}
}
}
if ($extraOutput !== array()) {
$wgOut->addHTML("<ul>\n<li>" . implode("</li>\n<li>", $extraOutput) . "</li>\n</ul>");
}
# Deal with watches (we don't watch subpages)
if ($this->watch && $wgUser->isLoggedIn()) {
$wgUser->addWatch($ot);
$wgUser->addWatch($nt);
} else {
$wgUser->removeWatch($ot);
$wgUser->removeWatch($nt);
}
# Re-clear the file redirect cache, which may have been polluted by
# parsing in messages above. See CR r56745.
# @todo FIXME: Needs a more robust solution inside FileRepo.
if ($ot->getNamespace() == NS_FILE) {
RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect($ot);
}
}
示例8: doSubmit
//.........这里部分代码省略.........
$out->addWikiMsg($msgName);
Hooks::run('SpecialMovepageAfterMove', array(&$this, &$ot, &$nt));
# Now we move extra pages we've been asked to move: subpages and talk
# pages. First, if the old page or the new page is a talk page, we
# can't move any talk pages: cancel that.
if ($ot->isTalkPage() || $nt->isTalkPage()) {
$this->moveTalk = false;
}
if (count($ot->getUserPermissionsErrors('move-subpages', $user))) {
$this->moveSubpages = false;
}
# Next make a list of id's. This might be marginally less efficient
# than a more direct method, but this is not a highly performance-cri-
# tical code path and readable code is more important here.
#
# Note: this query works nicely on MySQL 5, but the optimizer in MySQL
# 4 might get confused. If so, consider rewriting as a UNION.
#
# If the target namespace doesn't allow subpages, moving with subpages
# would mean that you couldn't move them back in one operation, which
# is bad.
# @todo FIXME: A specific error message should be given in this case.
// @todo FIXME: Use Title::moveSubpages() here
$dbr = wfGetDB(DB_MASTER);
if ($this->moveSubpages && (MWNamespace::hasSubpages($nt->getNamespace()) || $this->moveTalk && MWNamespace::hasSubpages($nt->getTalkPage()->getNamespace()))) {
$conds = array('page_title' . $dbr->buildLike($ot->getDBkey() . '/', $dbr->anyString()) . ' OR page_title = ' . $dbr->addQuotes($ot->getDBkey()));
$conds['page_namespace'] = array();
if (MWNamespace::hasSubpages($nt->getNamespace())) {
$conds['page_namespace'][] = $ot->getNamespace();
}
if ($this->moveTalk && MWNamespace::hasSubpages($nt->getTalkPage()->getNamespace())) {
$conds['page_namespace'][] = $ot->getTalkPage()->getNamespace();
}
} elseif ($this->moveTalk) {
$conds = array('page_namespace' => $ot->getTalkPage()->getNamespace(), 'page_title' => $ot->getDBkey());
} else {
# Skip the query
$conds = null;
}
$extraPages = array();
if (!is_null($conds)) {
$extraPages = TitleArray::newFromResult($dbr->select('page', array('page_id', 'page_namespace', 'page_title'), $conds, __METHOD__));
}
$extraOutput = array();
$count = 1;
foreach ($extraPages as $oldSubpage) {
if ($ot->equals($oldSubpage) || $nt->equals($oldSubpage)) {
# Already did this one.
continue;
}
$newPageName = preg_replace('#^' . preg_quote($ot->getDBkey(), '#') . '#', StringUtils::escapeRegexReplacement($nt->getDBkey()), $oldSubpage->getDBkey());
if ($oldSubpage->isSubpage() && ($ot->isTalkPage() xor $nt->isTalkPage())) {
// Moving a subpage from a subject namespace to a talk namespace or vice-versa
$newNs = $nt->getNamespace();
} elseif ($oldSubpage->isTalkPage()) {
$newNs = $nt->getTalkPage()->getNamespace();
} else {
$newNs = $nt->getSubjectPage()->getNamespace();
}
# Bug 14385: we need makeTitleSafe because the new page names may
# be longer than 255 characters.
$newSubpage = Title::makeTitleSafe($newNs, $newPageName);
if (!$newSubpage) {
$oldLink = Linker::linkKnown($oldSubpage);
$extraOutput[] = $this->msg('movepage-page-unmoved')->rawParams($oldLink)->params(Title::makeName($newNs, $newPageName))->escaped();
continue;
}
# This was copy-pasted from Renameuser, bleh.
if ($newSubpage->exists() && !$oldSubpage->isValidMoveTarget($newSubpage)) {
$link = Linker::linkKnown($newSubpage);
$extraOutput[] = $this->msg('movepage-page-exists')->rawParams($link)->escaped();
} else {
$success = $oldSubpage->moveTo($newSubpage, true, $this->reason, $createRedirect);
if ($success === true) {
if ($this->fixRedirects) {
DoubleRedirectJob::fixRedirects('move', $oldSubpage, $newSubpage);
}
$oldLink = Linker::link($oldSubpage, null, array(), array('redirect' => 'no'));
$newLink = Linker::linkKnown($newSubpage);
$extraOutput[] = $this->msg('movepage-page-moved')->rawParams($oldLink, $newLink)->escaped();
++$count;
$maximumMovedPages = $this->getConfig()->get('MaximumMovedPages');
if ($count >= $maximumMovedPages) {
$extraOutput[] = $this->msg('movepage-max-pages')->numParams($maximumMovedPages)->escaped();
break;
}
} else {
$oldLink = Linker::linkKnown($oldSubpage);
$newLink = Linker::link($newSubpage);
$extraOutput[] = $this->msg('movepage-page-unmoved')->rawParams($oldLink, $newLink)->escaped();
}
}
}
if ($extraOutput !== array()) {
$out->addHTML("<ul>\n<li>" . implode("</li>\n<li>", $extraOutput) . "</li>\n</ul>");
}
# Deal with watches (we don't watch subpages)
WatchAction::doWatchOrUnwatch($this->watch, $ot, $user);
WatchAction::doWatchOrUnwatch($this->watch, $nt, $user);
}
示例9: unsubstPaths
/**
* Substitute the backend of internal storage paths with the proxy backend's name
*
* @param array|string $paths List of paths or single string path
* @return Array|string
*/
protected function unsubstPaths( $paths ) {
return preg_replace(
'!^mwstore://([^/]+)!',
StringUtils::escapeRegexReplacement( "mwstore://{$this->name}" ),
$paths // string or array
);
}
示例10: parseInclude
/**
* Include text between <quiz> and <quiz> from another page to this quiz.
*
* @param $matches Array: elements matching $includePattern.
* $matches[1] is the page title.
*/
function parseInclude($matches)
{
$title = Title::makeTitleSafe(NS_MAIN, $matches[1]);
$text = $this->mParser->fetchTemplate($title);
$output = '';
if (preg_match('`<quiz[^>]*>(.*?)</quiz>`sU', $text, $unparsedQuiz)) {
# Remove inclusions from included quiz.
$output = preg_replace($this->mIncludePattern, '', StringUtils::escapeRegexReplacement($unparsedQuiz[1]));
$output .= "\n";
}
return $output;
}
示例11: wfRegexReplacement
/**
* @deprecated use StringUtils::escapeRegexReplacement
*/
function wfRegexReplacement($string)
{
return StringUtils::escapeRegexReplacement($string);
}
示例12: formatLinksInCommentCallback
protected function formatLinksInCommentCallback($match)
{
global $wgContLang;
$medians = '(?:' . preg_quote(MWNamespace::getCanonicalName(NS_MEDIA), '/') . '|';
$medians .= preg_quote($wgContLang->getNsText(NS_MEDIA), '/') . '):';
$comment = $match[0];
# Handle link renaming [[foo|text]] will show link as "text"
if ("" != $match[3]) {
$text = $match[3];
} else {
$text = $match[1];
}
$submatch = array();
if (preg_match('/^' . $medians . '(.*)$/i', $match[1], $submatch)) {
# Media link; trail not supported.
$linkRegexp = '/\\[\\[(.*?)\\]\\]/';
$thelink = $this->makeMediaLink($submatch[1], "", $text);
} else {
# Other kind of link
if (preg_match($wgContLang->linkTrail(), $match[4], $submatch)) {
$trail = $submatch[1];
} else {
$trail = "";
}
$linkRegexp = '/\\[\\[(.*?)\\]\\]' . preg_quote($trail, '/') . '/';
if (isset($match[1][0]) && $match[1][0] == ':') {
$match[1] = substr($match[1], 1);
}
$thelink = $this->makeLink($match[1], $text, "", $trail);
}
$comment = preg_replace($linkRegexp, StringUtils::escapeRegexReplacement($thelink), $comment, 1);
return $comment;
}