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  $html = "";
77  $html .= "<pre class=\"mw-code mw-css\" dir=\"ltr\">\n";
78  $html .= htmlspecialchars( $this->getText() );
79  $html .= "\n</pre>\n";
80 
81  return $html;
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 ) {
101  return $this->redirectTarget;
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 
120  return $this->redirectTarget;
121  }
122 
123 }
preSaveTransform(Title $title, User $user, ParserOptions $popts)
Returns a Content object with pre-save transformations applied using Parser::preSaveTransform().
Definition: CssContent.php:62
Content object for CSS pages.
Definition: CssContent.php:35
getText()
Returns the text represented by this Content object, as a string.
bool Title null $redirectTarget
Definition: CssContent.php:40
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:51
getRedirectTarget()
Definition: CssContent.php:99
updateRedirect(Title $target)
Definition: CssContent.php:88
equals(Content $that=null)
Decides whether two Content objects are equal.
const CONTENT_MODEL_CSS
Definition: Defines.php:217
__construct( $text, $modelId=CONTENT_MODEL_CSS)
Definition: CssContent.php:46
$matches
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:319