* @author Roan Kattouw
*/
+use Wikimedia\Rdbms\IDatabase;
+
/**
* Abstraction for ResourceLoader modules which pull from wiki pages
*
return null;
}
+ // If the page is a redirect, follow the redirect.
+ if ( $title->isRedirect() ) {
+ $content = $this->getContentObj( $title );
+ $title = $content ? $content->getUltimateRedirectTarget() : null;
+ if ( !$title ) {
+ return null;
+ }
+ }
+
$handler = ContentHandler::getForTitle( $title );
if ( $handler->isSupportedFormat( CONTENT_FORMAT_CSS ) ) {
$format = CONTENT_FORMAT_CSS;
return null;
}
+ $content = $this->getContentObj( $title );
+ if ( !$content ) {
+ return null;
+ }
+
+ return $content->serialize( $format );
+ }
+
+ /**
+ * @param Title $title
+ * @return Content|null
+ */
+ protected function getContentObj( Title $title ) {
$revision = Revision::newKnownCurrent( wfGetDB( DB_REPLICA ), $title->getArticleID(),
$title->getLatestRevID() );
if ( !$revision ) {
}
$revision->setTitle( $title );
$content = $revision->getContent( Revision::RAW );
-
if ( !$content ) {
wfDebugLog( 'resourceloader', __METHOD__ . ': failed to load content of JS/CSS page!' );
return null;
}
-
- return $content->serialize( $format );
+ return $content;
}
/**
return true;
}
- // Bug 68488: For other modules (i.e. ones that are called in cached html output) only check
+ // T70488: For other modules (i.e. ones that are called in cached html output) only check
// page existance. This ensures that, if some pages in a module are temporarily blanked,
// we don't end omit the module's script or link tag on some pages.
return count( $revisions ) === 0;
}
}
+ if ( !$wikiModules ) {
+ // Nothing to preload
+ return;
+ }
+
$pageNames = array_keys( $allPages );
sort( $pageNames );
$hash = sha1( implode( '|', $pageNames ) );