MediaWiki master
CssContent.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Content;
22
24
33class CssContent extends TextContent {
34
38 private $redirectTarget = false;
39
45 public function __construct( $text, $modelId = CONTENT_MODEL_CSS ) {
46 parent::__construct( $text, $modelId );
47 }
48
53 public function updateRedirect( Title $target ) {
54 if ( !$this->isRedirect() ) {
55 return $this;
56 }
57
58 // @phan-suppress-next-line PhanTypeMismatchReturnSuperType False positive
59 return $this->getContentHandler()->makeRedirectContent( $target );
60 }
61
65 public function getRedirectTarget() {
66 if ( $this->redirectTarget !== false ) {
67 return $this->redirectTarget;
68 }
69 $this->redirectTarget = null;
70 $text = $this->getText();
71 if ( str_starts_with( $text, '/* #REDIRECT */' ) ) {
72 // Extract the title from the url
73 if ( preg_match( '/title=(.*?)&action=raw/', $text, $matches ) ) {
74 $title = Title::newFromText( urldecode( $matches[1] ) );
75 if ( $title ) {
76 // Have a title, check that the current content equals what
77 // the redirect content should be
78 if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) {
79 $this->redirectTarget = $title;
80 }
81 }
82 }
83 }
84
85 return $this->redirectTarget;
86 }
87
88}
90class_alias( CssContent::class, 'CssContent' );
const CONTENT_MODEL_CSS
Definition Defines.php:251
Content object for CSS pages.
updateRedirect(Title $target)
__construct( $text, $modelId=CONTENT_MODEL_CSS)
Content object implementation for representing flat text.
getText()
Returns the text represented by this Content object, as a string.
Represents a title within MediaWiki.
Definition Title.php:78