MediaWiki REL1_37
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
53 protected function getHtml() {
54 return Html::element( 'pre',
55 [ 'class' => 'mw-code mw-js', 'dir' => 'ltr' ],
56 "\n" . $this->getText() . "\n"
57 ) . "\n";
58 }
59
67 public function updateRedirect( Title $target ) {
68 if ( !$this->isRedirect() ) {
69 return $this;
70 }
71
72 // @phan-suppress-next-line PhanTypeMismatchReturnSuperType
73 return $this->getContentHandler()->makeRedirectContent( $target );
74 }
75
79 public function getRedirectTarget() {
80 if ( $this->redirectTarget !== false ) {
82 }
83 $this->redirectTarget = null;
84 $text = $this->getText();
85 if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) {
86 // Extract the title from the url
87 if ( preg_match( '/title=(.*?)\\\\u0026action=raw/', $text, $matches ) ) {
88 $title = Title::newFromText( urldecode( $matches[1] ) );
89 if ( $title ) {
90 // Have a title, check that the current content equals what
91 // the redirect content should be
92 if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) {
93 $this->redirectTarget = $title;
94 }
95 }
96 }
97 }
98
100 }
101
102}
const CONTENT_MODEL_JAVASCRIPT
Definition Defines.php:209
equals(Content $that=null)
Decides whether two Content objects are equal.
Content for JavaScript pages.
__construct( $text, $modelId=CONTENT_MODEL_JAVASCRIPT)
bool Title null $redirectTarget
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:48