/** * 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; }
/** * @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; }
/** * 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; }
/** * {{#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; }
/** * 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); }
/** * 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); }
function doSubmit() { global $wgOut, $wgUser, $wgMaximumMovedPages, $wgLang; global $wgFixDoubleRedirects; if ($wgUser->pingLimiter('move')) { $wgOut->rateLimited(); return; } $ot = $this->oldTitle; $nt = $this->newTitle; # Delete to make way if requested if ($wgUser->isAllowed('delete') && $this->deleteAndMove) { $article = new Article($nt); # Disallow deletions of big articles $bigHistory = $article->isBigDeletion(); if ($bigHistory && !$nt->userCan('bigdelete')) { global $wgDeleteRevisionsLimit; $this->showForm(array('delete-toobig', $wgLang->formatNum($wgDeleteRevisionsLimit))); return; } // Delete an associated image if there is $file = wfLocalFile($nt); if ($file->exists()) { $file->delete(wfMsgForContent('delete_and_move_reason'), false); } // This may output an error message and exit $article->doDelete(wfMsgForContent('delete_and_move_reason')); } # don't allow moving to pages with # in if (!$nt || $nt->getFragment() != '') { $this->showForm('badtitletext'); return; } # Show a warning if the target file exists on a shared repo if ($nt->getNamespace() == NS_FILE && !($this->moveOverShared && $wgUser->isAllowed('reupload-shared')) && !RepoGroup::singleton()->getLocalRepo()->findFile($nt) && wfFindFile($nt)) { $this->showForm(array('file-exists-sharedrepo')); return; } if ($wgUser->isAllowed('suppressredirect')) { $createRedirect = $this->leaveRedirect; } else { $createRedirect = true; } # Do the actual move. $error = $ot->moveTo($nt, true, $this->reason, $createRedirect); if ($error !== true) { # @todo FIXME: Show all the errors in a list, not just the first one $this->showForm(reset($error)); return; } if ($wgFixDoubleRedirects && $this->fixRedirects) { DoubleRedirectJob::fixRedirects('move', $ot, $nt); } wfRunHooks('SpecialMovepageAfterMove', array(&$this, &$ot, &$nt)); $wgOut->setPagetitle(wfMsg('pagemovedsub')); $oldUrl = $ot->getFullUrl('redirect=no'); $newUrl = $nt->getFullUrl(); $oldText = $ot->getPrefixedText(); $newText = $nt->getPrefixedText(); $oldLink = "<span class='plainlinks'>[{$oldUrl} {$oldText}]</span>"; $newLink = "<span class='plainlinks'>[{$newUrl} {$newText}]</span>"; $msgName = $createRedirect ? 'movepage-moved-redirect' : 'movepage-moved-noredirect'; $wgOut->addWikiMsg('movepage-moved', $oldLink, $newLink, $oldText, $newText); $wgOut->addWikiMsg($msgName); # 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 (!$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); } }
function doSubmit() { $user = $this->getUser(); if ($user->pingLimiter('move')) { throw new ThrottledError(); } $ot = $this->oldTitle; $nt = $this->newTitle; # don't allow moving to pages with # in if (!$nt || $nt->hasFragment()) { $this->showForm(array(array('badtitletext'))); return; } # Show a warning if the target file exists on a shared repo if ($nt->getNamespace() == NS_FILE && !($this->moveOverShared && $user->isAllowed('reupload-shared')) && !RepoGroup::singleton()->getLocalRepo()->findFile($nt) && wfFindFile($nt)) { $this->showForm(array(array('file-exists-sharedrepo'))); return; } # Delete to make way if requested if ($this->deleteAndMove) { $permErrors = $nt->getUserPermissionsErrors('delete', $user); if (count($permErrors)) { # Only show the first error $this->showForm($permErrors); return; } $reason = $this->msg('delete_and_move_reason', $ot)->inContentLanguage()->text(); // Delete an associated image if there is if ($nt->getNamespace() == NS_FILE) { $file = wfLocalFile($nt); $file->load(File::READ_LATEST); if ($file->exists()) { $file->delete($reason, false, $user); } } $error = ''; // passed by ref $page = WikiPage::factory($nt); $deleteStatus = $page->doDeleteArticleReal($reason, false, 0, true, $error, $user); if (!$deleteStatus->isGood()) { $this->showForm($deleteStatus->getErrorsArray()); return; } } $handler = ContentHandler::getForTitle($ot); if (!$handler->supportsRedirects()) { $createRedirect = false; } elseif ($user->isAllowed('suppressredirect')) { $createRedirect = $this->leaveRedirect; } else { $createRedirect = true; } # Do the actual move. $mp = new MovePage($ot, $nt); $valid = $mp->isValidMove(); if (!$valid->isOK()) { $this->showForm($valid->getErrorsArray()); return; } $permStatus = $mp->checkPermissions($user, $this->reason); if (!$permStatus->isOK()) { $this->showForm($permStatus->getErrorsArray()); return; } $status = $mp->move($user, $this->reason, $createRedirect); if (!$status->isOK()) { $this->showForm($status->getErrorsArray()); return; } if ($this->getConfig()->get('FixDoubleRedirects') && $this->fixRedirects) { DoubleRedirectJob::fixRedirects('move', $ot, $nt); } $out = $this->getOutput(); $out->setPageTitle($this->msg('pagemovedsub')); $oldLink = Linker::link($ot, null, array('id' => 'movepage-oldlink'), array('redirect' => 'no')); $newLink = Linker::linkKnown($nt, null, array('id' => 'movepage-newlink')); $oldText = $ot->getPrefixedText(); $newText = $nt->getPrefixedText(); if ($ot->exists()) { // NOTE: we assume that if the old title exists, it's because it was re-created as // a redirect to the new title. This is not safe, but what we did before was // even worse: we just determined whether a redirect should have been created, // and reported that it was created if it should have, without any checks. // Also note that isRedirect() is unreliable because of bug 37209. $msgName = 'movepage-moved-redirect'; } else { $msgName = 'movepage-moved-noredirect'; } $out->addHTML($this->msg('movepage-moved')->rawParams($oldLink, $newLink)->params($oldText, $newText)->parseAsBlock()); $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); }
/** * 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 ); }
/** * 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; }
/** * @deprecated use StringUtils::escapeRegexReplacement */ function wfRegexReplacement($string) { return StringUtils::escapeRegexReplacement($string); }
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; }