isCssJsSubpage() && !$title->isCssOrJsPage() ) { return null; } $revision = Revision::newFromTitle( $title, false, Revision::READ_NORMAL ); if ( !$revision ) { return null; } $content = $revision->getContent( Revision::RAW ); if ( !$content ) { wfDebugLog( 'resourceloader', __METHOD__ . ': failed to load content of JS/CSS page!' ); return null; } if ( $content->isSupportedFormat( CONTENT_FORMAT_JAVASCRIPT ) ) { return $content->serialize( CONTENT_FORMAT_JAVASCRIPT ); } elseif ( $content->isSupportedFormat( CONTENT_FORMAT_CSS ) ) { return $content->serialize( CONTENT_FORMAT_CSS ); } else { wfDebugLog( 'resourceloader', __METHOD__ . ": bad content model {$content->getModel()} for JS/CSS page!" ); return null; } } /* Methods */ /** * @param ResourceLoaderContext $context * @return string */ public function getScript( ResourceLoaderContext $context ) { $scripts = ''; foreach ( $this->getPages( $context ) as $titleText => $options ) { if ( $options['type'] !== 'script' ) { continue; } $title = Title::newFromText( $titleText ); if ( !$title || $title->isRedirect() ) { continue; } $script = $this->getContent( $title ); if ( strval( $script ) !== '' ) { $script = $this->validateScriptFile( $titleText, $script ); $scripts .= ResourceLoader::makeComment( $titleText ) . $script . "\n"; } } return $scripts; } /** * @param ResourceLoaderContext $context * @return array */ public function getStyles( ResourceLoaderContext $context ) { $styles = array(); foreach ( $this->getPages( $context ) as $titleText => $options ) { if ( $options['type'] !== 'style' ) { continue; } $title = Title::newFromText( $titleText ); if ( !$title || $title->isRedirect() ) { continue; } $media = isset( $options['media'] ) ? $options['media'] : 'all'; $style = $this->getContent( $title ); if ( strval( $style ) === '' ) { continue; } if ( $this->getFlip( $context ) ) { $style = CSSJanus::transform( $style, true, false ); } $style = CSSMin::remap( $style, false, $this->getConfig()->get( 'ScriptPath' ), true ); if ( !isset( $styles[$media] ) ) { $styles[$media] = array(); } $style = ResourceLoader::makeComment( $titleText ) . $style; $styles[$media][] = $style; } return $styles; } /** * @param ResourceLoaderContext $context * @return int|mixed */ public function getModifiedTime( ResourceLoaderContext $context ) { $modifiedTime = 1; // wfTimestamp() interprets 0 as "now" $titleInfo = $this->getTitleInfo( $context ); if ( count( $titleInfo ) ) { $mtimes = array_map( function( $value ) { return $value['timestamp']; }, $titleInfo ); $modifiedTime = max( $modifiedTime, max( $mtimes ) ); } $modifiedTime = max( $modifiedTime, $this->getMsgBlobMtime( $context->getLanguage() ), $this->getDefinitionMtime( $context ) ); return $modifiedTime; } /** * Get the definition summary for this module. * * @param ResourceLoaderContext $context * @return array */ public function getDefinitionSummary( ResourceLoaderContext $context ) { return array( 'class' => get_class( $this ), 'pages' => $this->getPages( $context ), ); } /** * @param ResourceLoaderContext $context * @return bool */ public function isKnownEmpty( ResourceLoaderContext $context ) { $titleInfo = $this->getTitleInfo( $context ); // Bug 68488: For modules in the "user" group, we should actually // check that the pages are empty (page_len == 0), but for other // groups, just check the pages exist so that we don't end up // caching temporarily-blank pages without the appropriate //