MediaWiki  master
CssContent.php
Go to the documentation of this file.
1 <?php
34 class 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 
54  public function updateRedirect( Title $target ) {
55  if ( !$this->isRedirect() ) {
56  return $this;
57  }
58 
59  // @phan-suppress-next-line PhanTypeMismatchReturnSuperType
60  return $this->getContentHandler()->makeRedirectContent( $target );
61  }
62 
66  public function getRedirectTarget() {
67  if ( $this->redirectTarget !== false ) {
68  return $this->redirectTarget;
69  }
70  $this->redirectTarget = null;
71  $text = $this->getText();
72  if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) {
73  // Extract the title from the url
74  if ( preg_match( '/title=(.*?)&action=raw/', $text, $matches ) ) {
75  $title = Title::newFromText( urldecode( $matches[1] ) );
76  if ( $title ) {
77  // Have a title, check that the current content equals what
78  // the redirect content should be
79  if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) {
80  $this->redirectTarget = $title;
81  }
82  }
83  }
84  }
85 
86  return $this->redirectTarget;
87  }
88 
89 }
CssContent\updateRedirect
updateRedirect(Title $target)
Definition: CssContent.php:54
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:395
AbstractContent\isRedirect
isRedirect()
Definition: AbstractContent.php:347
CssContent
Content object for CSS pages.
Definition: CssContent.php:34
AbstractContent\equals
equals(Content $that=null)
Decides whether two Content objects are equal.
Definition: AbstractContent.php:224
TextContent\getText
getText()
Returns the text represented by this Content object, as a string.
Definition: TextContent.php:153
CssContent\__construct
__construct( $text, $modelId=CONTENT_MODEL_CSS)
Definition: CssContent.php:46
AbstractContent\getContentHandler
getContentHandler()
Definition: AbstractContent.php:99
$matches
$matches
Definition: NoLocalSettings.php:24
$title
$title
Definition: testCompression.php:38
CssContent\$redirectTarget
bool Title null $redirectTarget
Definition: CssContent.php:39
TextContent
Content object implementation for representing flat text.
Definition: TextContent.php:39
Title
Represents a title within MediaWiki.
Definition: Title.php:47
CssContent\getRedirectTarget
getRedirectTarget()
Definition: CssContent.php:66
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:210