MediaWiki master
CssContent.php
Go to the documentation of this file.
1<?php
29
36class CssContent extends TextContent {
37
41 private $redirectTarget = false;
42
48 public function __construct( $text, $modelId = CONTENT_MODEL_CSS ) {
49 parent::__construct( $text, $modelId );
50 }
51
56 public function updateRedirect( Title $target ) {
57 if ( !$this->isRedirect() ) {
58 return $this;
59 }
60
61 // @phan-suppress-next-line PhanTypeMismatchReturnSuperType False positive
62 return $this->getContentHandler()->makeRedirectContent( $target );
63 }
64
68 public function getRedirectTarget() {
69 if ( $this->redirectTarget !== false ) {
70 return $this->redirectTarget;
71 }
72 $this->redirectTarget = null;
73 $text = $this->getText();
74 if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) {
75 // Extract the title from the url
76 if ( preg_match( '/title=(.*?)&action=raw/', $text, $matches ) ) {
77 $title = Title::newFromText( urldecode( $matches[1] ) );
78 if ( $title ) {
79 // Have a title, check that the current content equals what
80 // the redirect content should be
81 if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) {
82 $this->redirectTarget = $title;
83 }
84 }
85 }
86 }
87
88 return $this->redirectTarget;
89 }
90
91}
const CONTENT_MODEL_CSS
Definition Defines.php:222
equals(Content $that=null)
Decides whether two Content objects are equal.
Content object for CSS pages.
__construct( $text, $modelId=CONTENT_MODEL_CSS)
updateRedirect(Title $target)
getRedirectTarget()
Represents a title within MediaWiki.
Definition Title.php:78
Content object implementation for representing flat text.
getText()
Returns the text represented by this Content object, as a string.