MediaWiki fundraising/REL1_35
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
64 public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
65 // @todo Make pre-save transformation optional for script pages
66
67 $text = $this->getText();
68 $pst = MediaWikiServices::getInstance()->getParser()
69 ->preSaveTransform( $text, $title, $user, $popts );
70
71 return new static( $pst );
72 }
73
77 protected function getHtml() {
78 return Html::element( 'pre',
79 [ 'class' => 'mw-code mw-css', 'dir' => 'ltr' ],
80 "\n" . $this->getText() . "\n"
81 ) . "\n";
82 }
83
88 public function updateRedirect( Title $target ) {
89 if ( !$this->isRedirect() ) {
90 return $this;
91 }
92
93 return $this->getContentHandler()->makeRedirectContent( $target );
94 }
95
99 public function getRedirectTarget() {
100 if ( $this->redirectTarget !== false ) {
102 }
103 $this->redirectTarget = null;
104 $text = $this->getText();
105 if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) {
106 // Extract the title from the url
107 preg_match( '/title=(.*?)&action=raw/', $text, $matches );
108 if ( isset( $matches[1] ) ) {
109 $title = Title::newFromText( urldecode( $matches[1] ) );
110 if ( $title ) {
111 // Have a title, check that the current content equals what
112 // the redirect content should be
113 if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) {
114 $this->redirectTarget = $title;
115 }
116 }
117 }
118 }
119
121 }
122
123}
equals(Content $that=null)
Decides whether two Content objects are equal.
Content object for CSS pages.
preSaveTransform(Title $title, User $user, ParserOptions $popts)
Returns a Content object with pre-save transformations applied using Parser::preSaveTransform().
__construct( $text, $modelId=CONTENT_MODEL_CSS)
Stable to call.
bool Title null $redirectTarget
updateRedirect(Title $target)
getRedirectTarget()
MediaWikiServices is the service locator for the application scope of MediaWiki.
Set options of the Parser.
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:42
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:60
const CONTENT_MODEL_CSS
Definition Defines.php:227