MediaWiki REL1_37
CssContent.php
Go to the documentation of this file.
1<?php
34class CssContent extends TextContent {
35
39 private $redirectTarget = false;
40
46 public function __construct( $text, $modelId = CONTENT_MODEL_CSS ) {
47 parent::__construct( $text, $modelId );
48 }
49
53 protected function getHtml() {
54 return Html::element( 'pre',
55 [ 'class' => 'mw-code mw-css', 'dir' => 'ltr' ],
56 "\n" . $this->getText() . "\n"
57 ) . "\n";
58 }
59
64 public function updateRedirect( Title $target ) {
65 if ( !$this->isRedirect() ) {
66 return $this;
67 }
68
69 // @phan-suppress-next-line PhanTypeMismatchReturnSuperType
70 return $this->getContentHandler()->makeRedirectContent( $target );
71 }
72
76 public function getRedirectTarget() {
77 if ( $this->redirectTarget !== false ) {
79 }
80 $this->redirectTarget = null;
81 $text = $this->getText();
82 if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) {
83 // Extract the title from the url
84 if ( preg_match( '/title=(.*?)&action=raw/', $text, $matches ) ) {
85 $title = Title::newFromText( urldecode( $matches[1] ) );
86 if ( $title ) {
87 // Have a title, check that the current content equals what
88 // the redirect content should be
89 if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) {
90 $this->redirectTarget = $title;
91 }
92 }
93 }
94 }
95
97 }
98
99}
const CONTENT_MODEL_CSS
Definition Defines.php:210
equals(Content $that=null)
Decides whether two Content objects are equal.
Content object for CSS pages.
__construct( $text, $modelId=CONTENT_MODEL_CSS)
bool Title null $redirectTarget
updateRedirect(Title $target)
getRedirectTarget()
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:48