X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fcontent%2FCssContent.php;h=b4f5196de61ca1b56eaf1135b411e23ad7b2bec8;hb=9c478b51e3b038b66d3825e6f112c158bea95b9e;hp=03cc2d005c919283d05c77622220b581f4e041ae;hpb=ae1274fd282f16e99b4c02a30020fb460d1db0b7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/content/CssContent.php b/includes/content/CssContent.php index 03cc2d005c..b4f5196de6 100644 --- a/includes/content/CssContent.php +++ b/includes/content/CssContent.php @@ -31,18 +31,31 @@ * @ingroup Content */ class CssContent extends TextContent { - public function __construct( $text ) { - parent::__construct( $text, CONTENT_MODEL_CSS ); + + /** + * @var bool|Title|null + */ + private $redirectTarget = false; + + /** + * @param string $text CSS code. + * @param string $modelId the content content model + */ + public function __construct( $text, $modelId = CONTENT_MODEL_CSS ) { + parent::__construct( $text, $modelId ); } /** * Returns a Content object with pre-save transformations applied using * Parser::preSaveTransform(). * - * @param $title Title - * @param $user User - * @param $popts ParserOptions - * @return Content + * @param Title $title + * @param User $user + * @param ParserOptions $popts + * + * @return CssContent + * + * @see TextContent::preSaveTransform */ public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) { global $wgParser; @@ -51,15 +64,58 @@ class CssContent extends TextContent { $text = $this->getNativeData(); $pst = $wgParser->preSaveTransform( $text, $title, $user, $popts ); - return new CssContent( $pst ); + return new static( $pst ); } + /** + * @return string CSS wrapped in a
 tag.
+	 */
 	protected function getHtml() {
 		$html = "";
 		$html .= "
\n";
-		$html .= $this->getHighlightHtml();
+		$html .= htmlspecialchars( $this->getNativeData() );
 		$html .= "\n
\n"; return $html; } + + /** + * @param Title $target + * @return CssContent + */ + public function updateRedirect( Title $target ) { + if ( !$this->isRedirect() ) { + return $this; + } + + return $this->getContentHandler()->makeRedirectContent( $target ); + } + + /** + * @return Title|null + */ + public function getRedirectTarget() { + if ( $this->redirectTarget !== false ) { + return $this->redirectTarget; + } + $this->redirectTarget = null; + $text = $this->getNativeData(); + if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) { + // Extract the title from the url + preg_match( '/title=(.*?)&action=raw/', $text, $matches ); + if ( isset( $matches[1] ) ) { + $title = Title::newFromText( $matches[1] ); + if ( $title ) { + // Have a title, check that the current content equals what + // the redirect content should be + if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) { + $this->redirectTarget = $title; + } + } + } + } + + return $this->redirectTarget; + } + }