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.

This commit is contained in:
Chad Horohoe 2008-08-02 02:39:09 +00:00
parent 3c2a85cc65
commit 07d9e2d766
4 changed files with 18 additions and 8 deletions

View file

@ -52,6 +52,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
* Recursion loop check added to Categoryfinder class * Recursion loop check added to Categoryfinder class
* Fixed few performance troubles of large job queue processing * Fixed few performance troubles of large job queue processing
* Not setting various parameters in Foreign Repos now fails more gracefully * 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 === === API changes in 1.14 ===

View file

@ -859,7 +859,7 @@ class Article {
} }
} else if ( $rt = Title::newFromRedirect( $text ) ) { } else if ( $rt = Title::newFromRedirect( $text ) ) {
# Don't append the subtitle if this was an old revision # 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)); $parseout = $wgParser->parse($text, $this->mTitle, ParserOptions::newFromUser($wgUser));
$wgOut->addParserOutputNoText( $parseout ); $wgOut->addParserOutputNoText( $parseout );
} else if ( $pcache ) { } else if ( $pcache ) {
@ -934,7 +934,13 @@ class Article {
&& !$this->mTitle->isCssJsSubpage(); && !$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; global $wgParser, $wgOut, $wgContLang, $wgStylePath, $wgUser;
# Display redirect # Display redirect
@ -950,8 +956,8 @@ class Article {
else else
$link = $sk->makeLinkObj( $target, htmlspecialchars( $target->getFullText() ) ); $link = $sk->makeLinkObj( $target, htmlspecialchars( $target->getFullText() ) );
$wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT " />' . return '<img src="'.$imageUrl.'" alt="#REDIRECT " />' .
'<span class="redirectText">'.$link.'</span>' ); '<span class="redirectText">'.$link.'</span>';
} }

View file

@ -1522,7 +1522,8 @@ END
} }
/** /**
* @todo document * Get the rendered text for previewing.
* @return string
*/ */
function getPreviewText() { function getPreviewText() {
global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang; global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang;
@ -1564,6 +1565,8 @@ END
$parserOutput = $wgParser->parse( $previewtext , $this->mTitle, $parserOptions ); $parserOutput = $wgParser->parse( $previewtext , $this->mTitle, $parserOptions );
$wgOut->addHTML( $parserOutput->mText ); $wgOut->addHTML( $parserOutput->mText );
$previewHTML = ''; $previewHTML = '';
} else if( $rt = Title::newFromRedirect( $this->textbox1 ) ) {
$previewHTML = $this->mArticle->viewRedirect( $rt, false );
} else { } else {
$toparse = $this->textbox1; $toparse = $this->textbox1;
@ -1630,7 +1633,7 @@ END
} else { } else {
$previewfoot = ''; $previewfoot = '';
} }
wfProfileOut( $fname ); wfProfileOut( $fname );
return $previewhead . $previewHTML . $previewfoot; return $previewhead . $previewHTML . $previewfoot;
} }

View file

@ -66,8 +66,8 @@ class ImagePage extends Article {
// mTitle is not the same as the redirect target so it is // mTitle is not the same as the redirect target so it is
// probably the redirect page itself. Fake the redirect symbol // probably the redirect page itself. Fake the redirect symbol
$wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
$this->viewRedirect( Title::makeTitle( NS_IMAGE, $this->img->getName() ), $wgOut->addHTML( $this->viewRedirect( Title::makeTitle( NS_IMAGE, $this->img->getName() ),
/* $appendSubtitle */ true, /* $forceKnown */ true ); /* $appendSubtitle */ true, /* $forceKnown */ true ) );
$this->viewUpdates(); $this->viewUpdates();
return; return;
} }