MediaWiki REL1_37
CssContentHandler.php
Go to the documentation of this file.
1<?php
26use Wikimedia\Minify\CSSMin;
27
35
39 public function __construct( $modelId = CONTENT_MODEL_CSS ) {
40 parent::__construct( $modelId, [ CONTENT_FORMAT_CSS ] );
41 }
42
43 protected function getContentClass() {
44 return CssContent::class;
45 }
46
47 public function supportsRedirects() {
48 return true;
49 }
50
58 public function makeRedirectContent( Title $destination, $text = '' ) {
59 // The parameters are passed as a string so the / is not url-encoded by wfArrayToCgi
60 $url = $destination->getFullURL( 'action=raw&ctype=text/css', false, PROTO_RELATIVE );
61 $class = $this->getContentClass();
62 return new $class( '/* #REDIRECT */@import ' . CSSMin::buildUrlValue( $url ) . ';' );
63 }
64
65 public function preSaveTransform(
67 PreSaveTransformParams $pstParams
68 ): Content {
69 $shouldCallDeprecatedMethod = $this->shouldCallDeprecatedContentTransformMethod(
71 $pstParams
72 );
73
74 if ( $shouldCallDeprecatedMethod ) {
75 return $this->callDeprecatedContentPST(
76 $content,
77 $pstParams
78 );
79 }
80
81 '@phan-var CssContent $content';
82
83 // @todo Make pre-save transformation optional for script pages (T34858)
84 $services = MediaWikiServices::getInstance();
85 if ( !$services->getUserOptionsLookup()->getBoolOption( $pstParams->getUser(), 'pst-cssjs' ) ) {
86 // Allow bot users to disable the pre-save transform for CSS/JS (T236828).
87 $popts = clone $pstParams->getParserOptions();
88 $popts->setPreSaveTransform( false );
89 }
90
91 $text = $content->getText();
92 $pst = $services->getParser()->preSaveTransform(
93 $text,
94 $pstParams->getPage(),
95 $pstParams->getUser(),
96 $pstParams->getParserOptions()
97 );
98
99 $class = $this->getContentClass();
100 return new $class( $pst );
101 }
102}
const CONTENT_MODEL_CSS
Definition Defines.php:210
const CONTENT_FORMAT_CSS
For CSS pages.
Definition Defines.php:228
const PROTO_RELATIVE
Definition Defines.php:194
Content handler for code content such as CSS, JavaScript, JSON, etc.
shouldCallDeprecatedContentTransformMethod(Content $content, $params)
Check if we need to provide content overrides deprecated Content method.
callDeprecatedContentPST(Content $content, PreSaveTransformParams $params)
Provided content overrides deprecated Content::preSaveTransform, call it and return.
Content handler for CSS pages.
__construct( $modelId=CONTENT_MODEL_CSS)
supportsRedirects()
Returns true if this content model supports redirects.
preSaveTransform(Content $content, PreSaveTransformParams $pstParams)
Returns a $content object with pre-save transformations applied (or the same object if no transformat...
makeRedirectContent(Title $destination, $text='')
Create a redirect that is also valid CSS.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Represents a title within MediaWiki.
Definition Title.php:48
getFullURL( $query='', $query2=false, $proto=PROTO_RELATIVE)
Get a real URL referring to this title, with interwiki link and fragment.
Definition Title.php:2211
Base interface for content objects.
Definition Content.php:35
$content
Definition router.php:76