Jackmcbarn has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/160555

Change subject: Hook TitleExists when previewing
......................................................................

Hook TitleExists when previewing

Bug: 70495
Change-Id: I1828fb8d49943520b8af5b92a3e1f1ddde1a5625
---
M TemplateSandbox.hooks.php
1 file changed, 21 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TemplateSandbox 
refs/changes/55/160555/1

diff --git a/TemplateSandbox.hooks.php b/TemplateSandbox.hooks.php
index 6cc5a8f..606d020 100644
--- a/TemplateSandbox.hooks.php
+++ b/TemplateSandbox.hooks.php
@@ -53,6 +53,26 @@
        }
 
        /**
+        * @param Title $templatetitle
+        * @return ScopedCallback to clean up
+        */
+       private static function fakePageExists( $templatetitle ) {
+               global $wgHooks;
+               $wgHooks['TitleExists']['TemplateSandbox'] =
+                       function( $title, &$exists ) use( $templatetitle ) {
+                               if ( $templatetitle->equals( $title ) ) {
+                                       $exists = true;
+                               }
+                       };
+               LinkCache::singleton()->clearBadLink( $templatetitle );
+               return new ScopedCallback( function() use( $templatetitle ) {
+                       global $wgHooks;
+                       unset( $wgHooks['TitleExists']['TemplateSandbox'] );
+                       LinkCache::singleton()->clearLink( $templatetitle );
+               } );
+       }
+
+       /**
         * Hook for AlternateEditPreview to output an entirely different preview
         * when our button was clicked.
         *
@@ -148,6 +168,7 @@
                        TemplateSandboxHooks::$oldTemplateCallback = 
$popts->setTemplateCallback(
                                'TemplateSandboxHooks::templateCallback'
                        );
+                       $fakePageExistsScopedCallback = self::fakePageExists( 
$templatetitle );
                        $popts->enableLimitReport();
 
                        $rev = Revision::newFromTitle( $title );

-- 
To view, visit https://gerrit.wikimedia.org/r/160555
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1828fb8d49943520b8af5b92a3e1f1ddde1a5625
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TemplateSandbox
Gerrit-Branch: master
Gerrit-Owner: Jackmcbarn <jackmcb...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to