MediaWiki  1.34.0
JavaScriptContentHandler.php
Go to the documentation of this file.
1 <?php
30 
34  public function __construct( $modelId = CONTENT_MODEL_JAVASCRIPT ) {
35  parent::__construct( $modelId, [ CONTENT_FORMAT_JAVASCRIPT ] );
36  }
37 
41  protected function getContentClass() {
42  return JavaScriptContent::class;
43  }
44 
45  public function supportsRedirects() {
46  return true;
47  }
48 
56  public function makeRedirectContent( Title $destination, $text = '' ) {
57  // The parameters are passed as a string so the / is not url-encoded by wfArrayToCgi
58  $url = $destination->getFullURL( 'action=raw&ctype=text/javascript', false, PROTO_RELATIVE );
59  $class = $this->getContentClass();
60  return new $class( '/* #REDIRECT */' . Xml::encodeJsCall( 'mw.loader.load', [ $url ] ) );
61  }
62 }
CodeContentHandler
Content handler for code content such as CSS, JavaScript, JSON, etc.
Definition: CodeContentHandler.php:29
Xml\encodeJsCall
static encodeJsCall( $name, $args, $pretty=false)
Create a call to a JavaScript function.
Definition: Xml.php:677
JavaScriptContentHandler\supportsRedirects
supportsRedirects()
Returns true if this content model supports redirects.
Definition: JavaScriptContentHandler.php:45
JavaScriptContentHandler\__construct
__construct( $modelId=CONTENT_MODEL_JAVASCRIPT)
Definition: JavaScriptContentHandler.php:34
PROTO_RELATIVE
const PROTO_RELATIVE
Definition: Defines.php:201
JavaScriptContentHandler
Content handler for JavaScript pages.
Definition: JavaScriptContentHandler.php:29
Title\getFullURL
getFullURL( $query='', $query2=false, $proto=PROTO_RELATIVE)
Get a real URL referring to this title, with interwiki link and fragment.
Definition: Title.php:2068
JavaScriptContentHandler\getContentClass
getContentClass()
Definition: JavaScriptContentHandler.php:41
Title
Represents a title within MediaWiki.
Definition: Title.php:42
JavaScriptContentHandler\makeRedirectContent
makeRedirectContent(Title $destination, $text='')
Create a redirect that is also valid JavaScript.
Definition: JavaScriptContentHandler.php:56
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:216
CONTENT_FORMAT_JAVASCRIPT
const CONTENT_FORMAT_JAVASCRIPT
Definition: Defines.php:232