MediaWiki master
CssContent.php
Go to the documentation of this file.
1<?php
28namespace MediaWiki\Content;
29
31
38class CssContent extends TextContent {
39
43 private $redirectTarget = false;
44
50 public function __construct( $text, $modelId = CONTENT_MODEL_CSS ) {
51 parent::__construct( $text, $modelId );
52 }
53
58 public function updateRedirect( Title $target ) {
59 if ( !$this->isRedirect() ) {
60 return $this;
61 }
62
63 // @phan-suppress-next-line PhanTypeMismatchReturnSuperType False positive
64 return $this->getContentHandler()->makeRedirectContent( $target );
65 }
66
70 public function getRedirectTarget() {
71 if ( $this->redirectTarget !== false ) {
72 return $this->redirectTarget;
73 }
74 $this->redirectTarget = null;
75 $text = $this->getText();
76 if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) {
77 // Extract the title from the url
78 if ( preg_match( '/title=(.*?)&action=raw/', $text, $matches ) ) {
79 $title = Title::newFromText( urldecode( $matches[1] ) );
80 if ( $title ) {
81 // Have a title, check that the current content equals what
82 // the redirect content should be
83 if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) {
84 $this->redirectTarget = $title;
85 }
86 }
87 }
88 }
89
90 return $this->redirectTarget;
91 }
92
93}
95class_alias( CssContent::class, 'CssContent' );
const CONTENT_MODEL_CSS
Definition Defines.php:224
equals(Content $that=null)
Decides whether two Content objects are equal.
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:79