X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fcontent%2FCssContent.php;h=b4f5196de61ca1b56eaf1135b411e23ad7b2bec8;hb=e2e9117a51f5c08e32817f474e1c7b2882307785;hp=8290603c1f6ddd88408f2301adf311927e2fd561;hpb=bb2d13313743d27f974a387693b5e739f341d6f7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/content/CssContent.php b/includes/content/CssContent.php index 8290603c1f..b4f5196de6 100644 --- a/includes/content/CssContent.php +++ b/includes/content/CssContent.php @@ -32,6 +32,11 @@ */ class CssContent extends TextContent { + /** + * @var bool|Title|null + */ + private $redirectTarget = false; + /** * @param string $text CSS code. * @param string $modelId the content content model @@ -74,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( $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; + } + }