MediaWiki  1.30.0
JavaScriptContent.php
Go to the documentation of this file.
1 <?php
34 
38  private $redirectTarget = false;
39 
44  public function __construct( $text, $modelId = CONTENT_MODEL_JAVASCRIPT ) {
45  parent::__construct( $text, $modelId );
46  }
47 
58  public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
60  // @todo Make pre-save transformation optional for script pages
61  // See bug #32858
62 
63  $text = $this->getNativeData();
64  $pst = $wgParser->preSaveTransform( $text, $title, $user, $popts );
65 
66  return new static( $pst );
67  }
68 
72  protected function getHtml() {
73  $html = "";
74  $html .= "<pre class=\"mw-code mw-js\" dir=\"ltr\">\n";
75  $html .= htmlspecialchars( $this->getNativeData() );
76  $html .= "\n</pre>\n";
77 
78  return $html;
79  }
80 
88  public function updateRedirect( Title $target ) {
89  if ( !$this->isRedirect() ) {
90  return $this;
91  }
92 
93  return $this->getContentHandler()->makeRedirectContent( $target );
94  }
95 
99  public function getRedirectTarget() {
100  if ( $this->redirectTarget !== false ) {
101  return $this->redirectTarget;
102  }
103  $this->redirectTarget = null;
104  $text = $this->getNativeData();
105  if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) {
106  // Extract the title from the url
107  preg_match( '/title=(.*?)\\\\u0026action=raw/', $text, $matches );
108  if ( isset( $matches[1] ) ) {
110  if ( $title ) {
111  // Have a title, check that the current content equals what
112  // the redirect content should be
113  if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) {
114  $this->redirectTarget = $title;
115  }
116  }
117  }
118  }
119 
120  return $this->redirectTarget;
121  }
122 
123 }
ParserOptions
Set options of the Parser.
Definition: ParserOptions.php:40
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:244
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:268
AbstractContent\isRedirect
isRedirect()
Definition: AbstractContent.php:318
$wgParser
$wgParser
Definition: Setup.php:824
JavaScriptContent\updateRedirect
updateRedirect(Title $target)
If this page is a redirect, return the content if it should redirect to $target instead.
Definition: JavaScriptContent.php:88
JavaScriptContent\preSaveTransform
preSaveTransform(Title $title, User $user, ParserOptions $popts)
Returns a Content object with pre-save transformations applied using Parser::preSaveTransform().
Definition: JavaScriptContent.php:58
AbstractContent\equals
equals(Content $that=null)
Definition: AbstractContent.php:191
JavaScriptContent\__construct
__construct( $text, $modelId=CONTENT_MODEL_JAVASCRIPT)
Definition: JavaScriptContent.php:44
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
JavaScriptContent\getRedirectTarget
getRedirectTarget()
Definition: JavaScriptContent.php:99
$html
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1965
AbstractContent\getContentHandler
getContentHandler()
Definition: AbstractContent.php:88
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:932
$matches
$matches
Definition: NoLocalSettings.php:24
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
JavaScriptContent
Content for JavaScript pages.
Definition: JavaScriptContent.php:33
JavaScriptContent\$redirectTarget
bool Title null $redirectTarget
Definition: JavaScriptContent.php:38
JavaScriptContent\getHtml
getHtml()
Definition: JavaScriptContent.php:72
TextContent
Content object implementation for representing flat text.
Definition: TextContent.php:35
Title
Represents a title within MediaWiki.
Definition: Title.php:39
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:237
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
TextContent\getNativeData
getNativeData()
Returns the text represented by this Content object, as a string.
Definition: TextContent.php:119