MediaWiki REL1_34
JavaScriptContent.php
Go to the documentation of this file.
1<?php
29
36
40 private $redirectTarget = false;
41
46 public function __construct( $text, $modelId = CONTENT_MODEL_JAVASCRIPT ) {
47 parent::__construct( $text, $modelId );
48 }
49
60 public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
61 // @todo Make pre-save transformation optional for script pages
62 // See T34858
63
64 $text = $this->getText();
65 $pst = MediaWikiServices::getInstance()->getParser()
66 ->preSaveTransform( $text, $title, $user, $popts );
67
68 return new static( $pst );
69 }
70
74 protected function getHtml() {
75 $html = "";
76 $html .= "<pre class=\"mw-code mw-js\" dir=\"ltr\">\n";
77 $html .= htmlspecialchars( $this->getText() );
78 $html .= "\n</pre>\n";
79
80 return $html;
81 }
82
90 public function updateRedirect( Title $target ) {
91 if ( !$this->isRedirect() ) {
92 return $this;
93 }
94
95 return $this->getContentHandler()->makeRedirectContent( $target );
96 }
97
101 public function getRedirectTarget() {
102 if ( $this->redirectTarget !== false ) {
104 }
105 $this->redirectTarget = null;
106 $text = $this->getText();
107 if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) {
108 // Extract the title from the url
109 preg_match( '/title=(.*?)\\\\u0026action=raw/', $text, $matches );
110 if ( isset( $matches[1] ) ) {
111 $title = Title::newFromText( urldecode( $matches[1] ) );
112 if ( $title ) {
113 // Have a title, check that the current content equals what
114 // the redirect content should be
115 if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) {
116 $this->redirectTarget = $title;
117 }
118 }
119 }
120 }
121
123 }
124
125}
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
preSaveTransform(Title $title, User $user, ParserOptions $popts)
Returns a Content object with pre-save transformations applied using Parser::preSaveTransform().
updateRedirect(Title $target)
If this page is a redirect, return the content if it should redirect to $target instead.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Set options of the Parser.
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:42
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51
const CONTENT_MODEL_JAVASCRIPT
Definition Defines.php:225