X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fcontent%2FCssContent.php;h=a09cd151a11071d67458ede014b6cdeddb9a42b7;hb=d6016fa1f985120829cfeb596571dd844da8b4e3;hp=72414585d0c94b6bcd22ee9ebcb0fa6d85a6508a;hpb=eddce194b22b80f46ce578362250bb402312c7a2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/content/CssContent.php b/includes/content/CssContent.php index 72414585d0..a09cd151a1 100644 --- a/includes/content/CssContent.php +++ b/includes/content/CssContent.php @@ -32,11 +32,17 @@ */ class CssContent extends TextContent { + /** + * @var bool|Title|null + */ + private $redirectTarget = false; + /** * @param string $text CSS code. + * @param string $modelId the content content model */ - public function __construct( $text ) { - parent::__construct( $text, CONTENT_MODEL_CSS ); + public function __construct( $text, $modelId = CONTENT_MODEL_CSS ) { + parent::__construct( $text, $modelId ); } /** @@ -73,4 +79,43 @@ class CssContent extends TextContent { 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( urldecode( $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; + } + }