jenkins-bot has submitted this change and it was merged.
Change subject: Use preview content when it transcludes itself
......................................................................
Use preview content when it transcludes itself
When a page transcludes itself, such as <noinclude>foo
{{:{{FULLPAGENAME}}}}</noinclude><includeonly>bar</includeonly>, use the
preview content in its own transclusions. This code was basically ripped
straight from Extension:TemplateSandbox.
Bug: T85408
Bug: T7278
Change-Id: I1aa091a395a4f7b7b744e09e0bed59bc2e1176d0
---
M includes/EditPage.php
M includes/parser/ParserOptions.php
2 files changed, 44 insertions(+), 0 deletions(-)
Approvals:
Anomie: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/EditPage.php b/includes/EditPage.php
index 2155c1b..b65668e 100644
--- a/includes/EditPage.php
+++ b/includes/EditPage.php
@@ -3561,6 +3561,8 @@
# But it's now deprecated, so never mind
$pstContent = $content->preSaveTransform(
$this->mTitle, $wgUser, $parserOptions );
+ $scopedCallback = $parserOptions->setupFakeRevision(
+ $this->mTitle, $pstContent, $wgUser );
$parserOutput = $pstContent->getParserOutput(
$this->mTitle, null, $parserOptions );
# Try to stash the edit for the final submission step
diff --git a/includes/parser/ParserOptions.php
b/includes/parser/ParserOptions.php
index 7ad85a9..ddeb906 100644
--- a/includes/parser/ParserOptions.php
+++ b/includes/parser/ParserOptions.php
@@ -818,4 +818,46 @@
return $confstr;
}
+
+ /**
+ * Sets a hook to force that a page exists, and sets a current revision
callback to return a
+ * revision with custom content when the current revision of the page
is requested.
+ *
+ * @since 1.25
+ * @param Title $title
+ * @param Content $content
+ * @param User $user The user that the fake revision is attributed to
+ * @return ScopedCallback to unset the hook
+ */
+ public function setupFakeRevision( $title, $content, $user ) {
+ $oldCallback = $this->setCurrentRevisionCallback( function (
$titleToCheck, $parser = false ) use ( $title, $content, $user, &$oldCallback )
{
+ if ( $titleToCheck->equals( $title ) ) {
+ return new Revision( array(
+ 'page' => $title->getArticleID(),
+ 'user_text' => $user->getName(),
+ 'user' => $user->getId(),
+ 'parent_id' => $title->getLatestRevId(),
+ 'title' => $title,
+ 'content' => $content
+ ) );
+ } else {
+ return call_user_func( $oldCallback,
$titleToCheck, $parser );
+ }
+ } );
+ global $wgHooks;
+ $wgHooks['TitleExists'][] =
+ function ( $titleToCheck, &$exists ) use ( $title ) {
+ if ( $titleToCheck->equals( $title ) ) {
+ $exists = true;
+ }
+ };
+ end( $wgHooks['TitleExists'] );
+ $key = key( $wgHooks['TitleExists'] );
+ LinkCache::singleton()->clearBadLink(
$title->getPrefixedDBkey() );
+ return new ScopedCallback( function () use ( $title, $key ) {
+ global $wgHooks;
+ unset( $wgHooks['TitleExists'][$key] );
+ LinkCache::singleton()->clearLink( $title );
+ } );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/137153
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1aa091a395a4f7b7b744e09e0bed59bc2e1176d0
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Brian Wolff <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits