* Specify page titles as strings instead of split NS/DBK, as suggested by Roan on CR. It seemed sensible to me.
* Pass a Title object to getContent() instead of a string, to avoid unnecessary object construction overhead
* "*" and "/" are valid title characters. Check module input for JS comment end tokens.
* Fixed inappropriate conversion to boolean, when checking result of getContent(). Presumably the idea was to omit empty sections and errors, so that's what I did. Maybe an informative error message would be better in the error case.
* Use LinkBatch for selecting multiple page rows instead of Database::makeWhereFrom2d().
* Fixed assignment expression.
global $wgHandheldStyle;
$pages = array(
global $wgHandheldStyle;
$pages = array(
- 'Common.js' => array( 'ns' => NS_MEDIAWIKI, 'type' => 'script' ),
- 'Common.css' => array( 'ns' => NS_MEDIAWIKI, 'type' => 'style' ),
- ucfirst( $context->getSkin() ) . '.js' => array( 'ns' => NS_MEDIAWIKI, 'type' => 'script' ),
- ucfirst( $context->getSkin() ) . '.css' => array( 'ns' => NS_MEDIAWIKI, 'type' => 'style' ),
- 'Print.css' => array( 'ns' => NS_MEDIAWIKI, 'type' => 'style', 'media' => 'print' ),
+ 'MediaWiki:Common.js' => array( 'type' => 'script' ),
+ 'MediaWiki:Common.css' => array( 'type' => 'style' ),
+ 'MediaWiki:' . ucfirst( $context->getSkin() ) . '.js' => array( 'type' => 'script' ),
+ 'MediaWiki:' . ucfirst( $context->getSkin() ) . '.css' => array( 'type' => 'style' ),
+ 'MediaWiki:Print.css' => array( 'type' => 'style', 'media' => 'print' ),
);
if ( $wgHandheldStyle ) {
);
if ( $wgHandheldStyle ) {
- $pages['Handheld.css'] = array(
- 'ns' => NS_MEDIAWIKI,
+ $pages['MediaWiki:Handheld.css'] = array(
'type' => 'style',
'media' => 'handheld' );
}
'type' => 'style',
'media' => 'handheld' );
}
if ( $context->getUser() ) {
$username = $context->getUser();
return array(
if ( $context->getUser() ) {
$username = $context->getUser();
return array(
- "$username/common.js" => array( 'ns' => NS_USER, 'type' => 'script' ),
- "$username/" . $context->getSkin() . '.js' =>
- array( 'ns' => NS_USER, 'type' => 'script' ),
- "$username/common.css" => array( 'ns' => NS_USER, 'type' => 'style' ),
- "$username/" . $context->getSkin() . '.css' =>
- array( 'ns' => NS_USER, 'type' => 'style' ),
+ "User:$username/common.js" => array( 'type' => 'script' ),
+ "User:$username/" . $context->getSkin() . '.js' =>
+ array( 'type' => 'script' ),
+ "User:$username/common.css" => array( 'type' => 'style' ),
+ "User:$username/" . $context->getSkin() . '.css' =>
+ array( 'type' => 'style' ),
- protected function getContent( $page, $ns ) {
- if ( $ns === NS_MEDIAWIKI ) {
- return wfEmptyMsg( $page ) ? '' : wfMsgExt( $page, 'content' );
+ protected function getContent( $title ) {
+ if ( $title->getNamespace() === NS_MEDIAWIKI ) {
+ $dbkey = $title->getDBkey();
+ return wfEmptyMsg( $dbkey ) ? '' : wfMsgExt( $dbkey, 'content' );
- $title = Title::newFromText( $page, $ns );
- if ( !$title || !$title->isCssJsSubpage() ) {
+ if ( !$title->isCssJsSubpage() ) {
return null;
}
$revision = Revision::newFromTitle( $title );
return null;
}
$revision = Revision::newFromTitle( $title );
public function getScript( ResourceLoaderContext $context ) {
$scripts = '';
public function getScript( ResourceLoaderContext $context ) {
$scripts = '';
- foreach ( $this->getPages( $context ) as $page => $options ) {
+ foreach ( $this->getPages( $context ) as $titleText => $options ) {
if ( $options['type'] !== 'script' ) {
continue;
}
if ( $options['type'] !== 'script' ) {
continue;
}
- $script = $this->getContent( $page, $options['ns'] );
- if ( $script ) {
- $ns = MWNamespace::getCanonicalName( $options['ns'] );
- $scripts .= "/* $ns:$page */\n$script\n";
+ $title = Title::newFromText( $titleText );
+ if ( !$title ) {
+ continue;
+ }
+ $script = $this->getContent( $title );
+ if ( strval( $script ) !== '' ) {
+ if ( strpos( $titleText, '*/' ) === false ) {
+ $scripts .= "/* $titleText */\n";
+ }
+ $scripts .= $script . "\n";
public function getStyles( ResourceLoaderContext $context ) {
$styles = array();
public function getStyles( ResourceLoaderContext $context ) {
$styles = array();
- foreach ( $this->getPages( $context ) as $page => $options ) {
+ foreach ( $this->getPages( $context ) as $titleText => $options ) {
if ( $options['type'] !== 'style' ) {
continue;
}
if ( $options['type'] !== 'style' ) {
continue;
}
+ $title = Title::newFromText( $titleText );
+ if ( !$title ) {
+ continue;
+ }
$media = isset( $options['media'] ) ? $options['media'] : 'all';
$media = isset( $options['media'] ) ? $options['media'] : 'all';
- $style = $this->getContent( $page, $options['ns'] );
- if ( !$style ) {
+ $style = $this->getContent( $title );
+ if ( strval( $style ) === '' ) {
continue;
}
if ( $this->getFlip( $context ) ) {
continue;
}
if ( $this->getFlip( $context ) ) {
if ( !isset( $styles[$media] ) ) {
$styles[$media] = '';
}
if ( !isset( $styles[$media] ) ) {
$styles[$media] = '';
}
- $ns = MWNamespace::getCanonicalName( $options['ns'] );
- $styles[$media] .= "/* $ns:$page */\n$style\n";
+ if ( strpos( $titleText, '*/' ) === false ) {
+ $styles[$media] .= "/* $titleText */\n";
+ }
+ $styles[$media] .= $style . "\n";
return $this->modifiedTime[$hash];
}
return $this->modifiedTime[$hash];
}
- $titles = array();
- foreach ( $this->getPages( $context ) as $page => $options ) {
- $titles[$options['ns']][$page] = true;
+ $batch = new LinkBatch;
+ foreach ( $this->getPages( $context ) as $titleText => $options ) {
+ $batch->addObj( Title::newFromText( $titleText ) );
}
$modifiedTime = 1; // wfTimestamp() interprets 0 as "now"
}
$modifiedTime = 1; // wfTimestamp() interprets 0 as "now"
+ if ( !$batch->isEmpty() ) {
$dbr = wfGetDB( DB_SLAVE );
$latest = $dbr->selectField( 'page', 'MAX(page_touched)',
$dbr = wfGetDB( DB_SLAVE );
$latest = $dbr->selectField( 'page', 'MAX(page_touched)',
- $dbr->makeWhereFrom2d( $titles, 'page_namespace', 'page_title' ),
+ $batch->constructSet( 'page', $dbr ),
__METHOD__ );
if ( $latest ) {
__METHOD__ );
if ( $latest ) {
- return $this->modifiedTime[$hash] = $modifiedTime;
+ $this->modifiedTime[$hash] = $modifiedTime;
+ return $modifiedTime;