MediaWiki REL1_39
JavaScriptContent.php
Go to the documentation of this file.
1<?php
35
39 private $redirectTarget = false;
40
46 public function __construct( $text, $modelId = CONTENT_MODEL_JAVASCRIPT ) {
47 parent::__construct( $text, $modelId );
48 }
49
57 public function updateRedirect( Title $target ) {
58 if ( !$this->isRedirect() ) {
59 return $this;
60 }
61
62 // @phan-suppress-next-line PhanTypeMismatchReturnSuperType False positive
63 return $this->getContentHandler()->makeRedirectContent( $target );
64 }
65
69 public function getRedirectTarget() {
70 if ( $this->redirectTarget !== false ) {
71 return $this->redirectTarget;
72 }
73 $this->redirectTarget = null;
74 $text = $this->getText();
75 if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) {
76 // Extract the title from the url
77 if ( preg_match( '/title=(.*?)\\\\u0026action=raw/', $text, $matches ) ) {
78 $title = Title::newFromText( urldecode( $matches[1] ) );
79 if ( $title ) {
80 // Have a title, check that the current content equals what
81 // the redirect content should be
82 if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) {
83 $this->redirectTarget = $title;
84 }
85 }
86 }
87 }
88
89 return $this->redirectTarget;
90 }
91
92}
const CONTENT_MODEL_JAVASCRIPT
Definition Defines.php:212
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.
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:49