MediaWiki  master
JavaScriptContent.php
Go to the documentation of this file.
1 <?php
29 
37 
41  private $redirectTarget = false;
42 
48  public function __construct( $text, $modelId = CONTENT_MODEL_JAVASCRIPT ) {
49  parent::__construct( $text, $modelId );
50  }
51 
59  public function updateRedirect( Title $target ) {
60  if ( !$this->isRedirect() ) {
61  return $this;
62  }
63 
64  // @phan-suppress-next-line PhanTypeMismatchReturnSuperType False positive
65  return $this->getContentHandler()->makeRedirectContent( $target );
66  }
67 
71  public function getRedirectTarget() {
72  if ( $this->redirectTarget !== false ) {
73  return $this->redirectTarget;
74  }
75  $this->redirectTarget = null;
76  $text = $this->getText();
77  if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) {
78  // Extract the title from the url
79  if ( preg_match( '/title=(.*?)\\\\u0026action=raw/', $text, $matches ) ) {
80  $title = Title::newFromText( urldecode( $matches[1] ) );
81  if ( $title ) {
82  // Have a title, check that the current content equals what
83  // the redirect content should be
84  if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) {
85  $this->redirectTarget = $title;
86  }
87  }
88  }
89  }
90 
91  return $this->redirectTarget;
92  }
93 
94 }
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:210
$matches
equals(Content $that=null)
Decides whether two Content objects are equal.
Content for JavaScript pages.
__construct( $text, $modelId=CONTENT_MODEL_JAVASCRIPT)
updateRedirect(Title $target)
If this page is a redirect, return the content if it should redirect to $target instead.
Represents a title within MediaWiki.
Definition: Title.php:76
Content object implementation for representing flat text.
Definition: TextContent.php:41
getText()
Returns the text represented by this Content object, as a string.