From 07d9e2d766c22babc27904c71b67e3d4978d7a3b Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Sat, 2 Aug 2008 02:39:09 +0000 Subject: [PATCH] Take Article::viewRedirect() public and have it return a string so it can be used other places, like EditPage for proper rendering of redirects on preview (bug 2333). +Docs here and there. --- RELEASE-NOTES | 1 + includes/Article.php | 14 ++++++++++---- includes/EditPage.php | 7 +++++-- includes/ImagePage.php | 4 ++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 717806019b..cbadeff633 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -52,6 +52,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Recursion loop check added to Categoryfinder class * Fixed few performance troubles of large job queue processing * Not setting various parameters in Foreign Repos now fails more gracefully +* (bug 2333) Redirects are properly rendered when previewing an edit. === API changes in 1.14 === diff --git a/includes/Article.php b/includes/Article.php index a01469d42b..70e423dbaf 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -859,7 +859,7 @@ class Article { } } else if ( $rt = Title::newFromRedirect( $text ) ) { # Don't append the subtitle if this was an old revision - $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ); + $wgOut->addHTML( $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ) ); $parseout = $wgParser->parse($text, $this->mTitle, ParserOptions::newFromUser($wgUser)); $wgOut->addParserOutputNoText( $parseout ); } else if ( $pcache ) { @@ -934,7 +934,13 @@ class Article { && !$this->mTitle->isCssJsSubpage(); } - protected function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) { + /** + * View redirect + * @param Title $target Title of destination to redirect + * @param Bool $appendSubtitle Object[optional] + * @param Bool $forceKnown Should the image be shown as a bluelink regardless of existence? + */ + public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) { global $wgParser, $wgOut, $wgContLang, $wgStylePath, $wgUser; # Display redirect @@ -950,8 +956,8 @@ class Article { else $link = $sk->makeLinkObj( $target, htmlspecialchars( $target->getFullText() ) ); - $wgOut->addHTML( '#REDIRECT ' . - ''.$link.'' ); + return '#REDIRECT ' . + ''.$link.''; } diff --git a/includes/EditPage.php b/includes/EditPage.php index 585e156d64..160e0f1a89 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1522,7 +1522,8 @@ END } /** - * @todo document + * Get the rendered text for previewing. + * @return string */ function getPreviewText() { global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang; @@ -1564,6 +1565,8 @@ END $parserOutput = $wgParser->parse( $previewtext , $this->mTitle, $parserOptions ); $wgOut->addHTML( $parserOutput->mText ); $previewHTML = ''; + } else if( $rt = Title::newFromRedirect( $this->textbox1 ) ) { + $previewHTML = $this->mArticle->viewRedirect( $rt, false ); } else { $toparse = $this->textbox1; @@ -1630,7 +1633,7 @@ END } else { $previewfoot = ''; } - + wfProfileOut( $fname ); return $previewhead . $previewHTML . $previewfoot; } diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 4c7eff163a..a526ba99e9 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -66,8 +66,8 @@ class ImagePage extends Article { // mTitle is not the same as the redirect target so it is // probably the redirect page itself. Fake the redirect symbol $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); - $this->viewRedirect( Title::makeTitle( NS_IMAGE, $this->img->getName() ), - /* $appendSubtitle */ true, /* $forceKnown */ true ); + $wgOut->addHTML( $this->viewRedirect( Title::makeTitle( NS_IMAGE, $this->img->getName() ), + /* $appendSubtitle */ true, /* $forceKnown */ true ) ); $this->viewUpdates(); return; } -- 2.20.1