MediaWiki  master
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 ) {
103  return $this->redirectTarget;
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 
122  return $this->redirectTarget;
123  }
124 
125 }
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:1971
updateRedirect(Title $target)
If this page is a redirect, return the content if it should redirect to $target instead.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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 MediaWikiServices
Definition: injection.txt:23
Content for JavaScript pages.
getText()
Returns the text represented by this Content object, as a string.
preSaveTransform(Title $title, User $user, ParserOptions $popts)
Returns a Content object with pre-save transformations applied using Parser::preSaveTransform().
__construct( $text, $modelId=CONTENT_MODEL_JAVASCRIPT)
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:51
equals(Content $that=null)
Decides whether two Content objects are equal.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
bool Title null $redirectTarget
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
CONTENT_MODEL_JAVASCRIPT
Allow users to upload files.
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
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1454
$matches
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:320