MediaWiki master
CssContent.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Content;
8
10
19class CssContent extends TextContent {
20
24 private $redirectTarget = false;
25
31 public function __construct( $text, $modelId = CONTENT_MODEL_CSS ) {
32 parent::__construct( $text, $modelId );
33 }
34
39 public function updateRedirect( Title $target ) {
40 if ( !$this->isRedirect() ) {
41 return $this;
42 }
43
44 // @phan-suppress-next-line PhanTypeMismatchReturnSuperType False positive
45 return $this->getContentHandler()->makeRedirectContent( $target );
46 }
47
51 public function getRedirectTarget() {
52 if ( $this->redirectTarget !== false ) {
53 return $this->redirectTarget;
54 }
55 $this->redirectTarget = null;
56 $text = $this->getText();
57 if ( str_starts_with( $text, '/* #REDIRECT */' ) ) {
58 // Extract the title from the url
59 if ( preg_match( '/title=(.*?)&action=raw/', $text, $matches ) ) {
60 $title = Title::newFromText( urldecode( $matches[1] ) );
61 if ( $title ) {
62 // Have a title, check that the current content equals what
63 // the redirect content should be
64 if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) {
65 $this->redirectTarget = $title;
66 }
67 }
68 }
69 }
70
71 return $this->redirectTarget;
72 }
73
74}
76class_alias( CssContent::class, 'CssContent' );
const CONTENT_MODEL_CSS
Definition Defines.php:237
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:69