* @author Roan Kattouw
*/
+use Wikimedia\Rdbms\Database;
+use Wikimedia\Rdbms\IDatabase;
+
/**
* Abstraction for ResourceLoader modules which pull from wiki pages
*
protected function getContent( $titleText ) {
$title = Title::newFromText( $titleText );
if ( !$title ) {
- return null;
+ return null; // Bad title
+ }
+
+ // 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; // Dead redirect
+ }
}
$handler = ContentHandler::getForTitle( $title );
} elseif ( $handler->isSupportedFormat( CONTENT_FORMAT_JAVASCRIPT ) ) {
$format = CONTENT_FORMAT_JAVASCRIPT;
} else {
- return null;
+ return null; // Bad content model
}
+ $content = $this->getContentObj( $title );
+ if ( !$content ) {
+ return null; // No content found
+ }
+
+ 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;
}
/**
* @param ResourceLoaderContext $context
- * @return string
+ * @return string JavaScript code
*/
public function getScript( ResourceLoaderContext $context ) {
$scripts = '';