MediaWiki  master
CssContent.php
Go to the documentation of this file.
1 <?php
29 
35 class CssContent extends TextContent {
36 
40  private $redirectTarget = false;
41 
46  public function __construct( $text, $modelId = CONTENT_MODEL_CSS ) {
47  parent::__construct( $text, $modelId );
48  }
49 
62  public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
63  // @todo Make pre-save transformation optional for script pages
64 
65  $text = $this->getText();
66  $pst = MediaWikiServices::getInstance()->getParser()
67  ->preSaveTransform( $text, $title, $user, $popts );
68 
69  return new static( $pst );
70  }
71 
75  protected function getHtml() {
76  return Html::element( 'pre',
77  [ 'class' => 'mw-code mw-css', 'dir' => 'ltr' ],
78  "\n" . $this->getText() . "\n"
79  ) . "\n";
80  }
81 
86  public function updateRedirect( Title $target ) {
87  if ( !$this->isRedirect() ) {
88  return $this;
89  }
90 
91  return $this->getContentHandler()->makeRedirectContent( $target );
92  }
93 
97  public function getRedirectTarget() {
98  if ( $this->redirectTarget !== false ) {
99  return $this->redirectTarget;
100  }
101  $this->redirectTarget = null;
102  $text = $this->getText();
103  if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) {
104  // Extract the title from the url
105  preg_match( '/title=(.*?)&action=raw/', $text, $matches );
106  if ( isset( $matches[1] ) ) {
107  $title = Title::newFromText( urldecode( $matches[1] ) );
108  if ( $title ) {
109  // Have a title, check that the current content equals what
110  // the redirect content should be
111  if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) {
112  $this->redirectTarget = $title;
113  }
114  }
115  }
116  }
117 
118  return $this->redirectTarget;
119  }
120 
121 }
ParserOptions
Set options of the Parser.
Definition: ParserOptions.php:42
CssContent\updateRedirect
updateRedirect(Title $target)
Definition: CssContent.php:86
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:332
AbstractContent\isRedirect
isRedirect()
Definition: AbstractContent.php:366
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:137
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:226
CssContent
Content object for CSS pages.
Definition: CssContent.php:35
AbstractContent\equals
equals(Content $that=null)
Decides whether two Content objects are equal.
Definition: AbstractContent.php:212
TextContent\getText
getText()
Returns the text represented by this Content object, as a string.
Definition: TextContent.php:136
CssContent\__construct
__construct( $text, $modelId=CONTENT_MODEL_CSS)
Definition: CssContent.php:46
AbstractContent\getContentHandler
getContentHandler()
Definition: AbstractContent.php:91
$matches
$matches
Definition: NoLocalSettings.php:24
CssContent\preSaveTransform
preSaveTransform(Title $title, User $user, ParserOptions $popts)
Returns a Content object with pre-save transformations applied using Parser::preSaveTransform().
Definition: CssContent.php:62
$title
$title
Definition: testCompression.php:38
CssContent\$redirectTarget
bool Title null $redirectTarget
Definition: CssContent.php:40
TextContent
Content object implementation for representing flat text.
Definition: TextContent.php:37
Title
Represents a title within MediaWiki.
Definition: Title.php:42
CssContent\getHtml
getHtml()
Definition: CssContent.php:75
CssContent\getRedirectTarget
getRedirectTarget()
Definition: CssContent.php:97
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:53