Anomie has uploaded a new change for review.

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


Change subject: Handle redirecting the template in EditPage form
......................................................................

Handle redirecting the template in EditPage form

If you are editing a template to change it into a redirect and use the
"preview page with this template" in the edit form, it does not
correctly use the target of the new redirect. Fix that, keeping in mind
that Parser::statelessFetchTemplate ignores $wgMaxRedirects and
TemplateSandbox should reproduce that behavior here.

Bug: 56559
Change-Id: Ib7b99a0129ec1eaabfc10e6604bbd55033ac204c
---
M TemplateSandbox.hooks.php
1 file changed, 24 insertions(+), 2 deletions(-)


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

diff --git a/TemplateSandbox.hooks.php b/TemplateSandbox.hooks.php
index 616a07f..698adce 100644
--- a/TemplateSandbox.hooks.php
+++ b/TemplateSandbox.hooks.php
@@ -180,6 +180,11 @@
         * @return array|mixed
         */
        static function templateCallback( $title, $parser = false ) {
+               global $wgUser;
+
+               // Note that Parser::statelessFetchTemplate currently only 
handles one
+               // level of redirection, regardless of $wgMaxRedirects. We 
reproduce
+               // this behavior here.
                $match = ( $title->getFullText() == 
TemplateSandboxHooks::$template );
                $rtitle = null;
                if ( !$match && $title->isRedirect() ) {
@@ -192,20 +197,37 @@
                                'page_id' => $title->getArticleID(),
                                'rev_id' => 0,
                        );
+                       $finalTitle = $title;
                        if ( $rtitle ) {
                                $deps[] = array(
                                        'title' => $rtitle,
                                        'page_id' => $rtitle->getArticleID(),
                                        'rev_id' => 0,
                                );
+                               $finalTitle = $rtitle;
                        }
-                       $text = 
TemplateSandboxHooks::$content->getWikitextForTransclusion();
+
+                       $content = TemplateSandboxHooks::$content;
+                       if ( !$rtitle && $content->isRedirect() ) {
+                               $newTitle = $content->getRedirectTarget();
+                               $rev = Revision::newFromTitle( $newTitle );
+                               if ( $rev ) {
+                                       $content = $rev->getContent( 
Revision::FOR_THIS_USER, $wgUser );
+                                       $finalTitle = $newTitle;
+                               }
+                               $deps[] = array(
+                                       'title' => $newTitle,
+                                       'page_id' => $newTitle->getArticleID(),
+                                       'rev_id' => 0,
+                               );
+                       }
+                       $text = $content->getWikitextForTransclusion();
                        if ( $text === null ) {
                                $text = false;
                        }
                        return array(
                                'text' => $text,
-                               'finalTitle' => $rtitle ? $rtitle : $title,
+                               'finalTitle' => $finalTitle,
                                'deps' => $deps,
                        );
                }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib7b99a0129ec1eaabfc10e6604bbd55033ac204c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TemplateSandbox
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to