r72761 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72760‎ | r72761 | r72762 >
Date:21:40, 10 September 2010
Author:tparscal
Status:ok
Tags:
Comment:
Broke part of ResourceLoaderSiteModule into ResourceLoaderWikiModule (abstract parent). This paves the way for ResourceLoaderUserModule which will come next.
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/ResourceLoaderModule.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/AutoLoader.php
@@ -199,8 +199,9 @@
200200 'Replacer' => 'includes/StringUtils.php',
201201 'ResourceLoader' => 'includes/ResourceLoader.php',
202202 'ResourceLoaderContext' => 'includes/ResourceLoaderContext.php',
 203+ 'ResourceLoaderModule' => 'includes/ResourceLoaderModule.php',
 204+ 'ResourceLoaderWikiModule' => 'includes/ResourceLoaderModule.php',
203205 'ResourceLoaderFileModule' => 'includes/ResourceLoaderModule.php',
204 - 'ResourceLoaderModule' => 'includes/ResourceLoaderModule.php',
205206 'ResourceLoaderSiteModule' => 'includes/ResourceLoaderModule.php',
206207 'ResourceLoaderStartUpModule' => 'includes/ResourceLoaderModule.php',
207208 'ReverseChronologicalPager' => 'includes/Pager.php',
Index: trunk/phase3/includes/ResourceLoaderModule.php
@@ -674,58 +674,75 @@
675675 }
676676 }
677677
678 -/**
679 - * Custom module for MediaWiki:Common.js and MediaWiki:Skinname.js
680 - */
681 -class ResourceLoaderSiteModule extends ResourceLoaderModule {
 678+abstract class ResourceLoaderWikiModule extends ResourceLoaderModule {
 679+
682680 /* Protected Members */
683 -
 681+
684682 // In-object cache for modified time
685683 protected $modifiedTime = null;
686 -
 684+
 685+ /* Abstract Protected Methods */
 686+
 687+ abstract protected function getPages( ResourceLoaderContext $context );
 688+
687689 /* Methods */
688 -
689 - public function getScript( ResourceLoaderContext $context ) {
690 - return Skin::newFromKey( $context->getSkin() )->generateUserJs();
691 - }
692 -
 690+
693691 public function getModifiedTime( ResourceLoaderContext $context ) {
694 - global $wgHandheldStyle;
695 -
696692 if ( isset( $this->modifiedTime[$context->getHash()] ) ) {
697693 return $this->modifiedTime[$context->getHash()];
698694 }
699 -
700 - // HACK: We duplicate the message names from generateUserJs()
701 - // here and weird things (i.e. mtime moving backwards) can happen
702 - // when a MediaWiki:Something.js page is deleted
703 - $pages = array(
704 - Title::makeTitle( NS_MEDIAWIKI, 'Common.js' ),
705 - Title::makeTitle( NS_MEDIAWIKI, 'Common.css' ),
706 - Title::makeTitle( NS_MEDIAWIKI, ucfirst( $context->getSkin() ) . '.js' ),
707 - Title::makeTitle( NS_MEDIAWIKI, ucfirst( $context->getSkin() ) . '.css' ),
708 - Title::makeTitle( NS_MEDIAWIKI, 'Print.css' ),
709 - );
710 - if ( $wgHandheldStyle ) {
711 - $pages[] = Title::makeTitle( NS_MEDIAWIKI, 'Handheld.css' );
 695+ $pages = $this->getPages( $context );
 696+ foreach ( $pages as $i => $page ) {
 697+ $pages[$i] = Title::makeTitle( NS_MEDIAWIKI, $page );
712698 }
713 -
714699 // Do batch existence check
715700 // TODO: This would work better if page_touched were loaded by this as well
716701 $lb = new LinkBatch( $pages );
717702 $lb->execute();
718 -
719703 $this->modifiedTime = 1; // wfTimestamp() interprets 0 as "now"
720 -
721704 foreach ( $pages as $page ) {
722705 if ( $page->exists() ) {
723706 $this->modifiedTime = max( $this->modifiedTime, wfTimestamp( TS_UNIX, $page->getTouched() ) );
724707 }
725708 }
726 -
727709 return $this->modifiedTime;
728710 }
 711+ public function getMessages() { return array(); }
 712+ public function getLoaderScript() { return ''; }
 713+ public function getDependencies() { return array(); }
 714+}
729715
 716+/**
 717+ * Custom module for MediaWiki:Common.js and MediaWiki:Skinname.js
 718+ */
 719+class ResourceLoaderSiteModule extends ResourceLoaderWikiModule {
 720+
 721+ /* Protected Methods */
 722+
 723+ protected function getPages( ResourceLoaderContext $context ) {
 724+ global $wgHandheldStyle;
 725+
 726+ // HACK: We duplicate the message names from generateUserJs() and generateUserCss here and weird things (i.e.
 727+ // mtime moving backwards) can happen when a MediaWiki:Something.js page is deleted
 728+ $pages = array(
 729+ 'Common.js',
 730+ 'Common.css',
 731+ ucfirst( $context->getSkin() ) . '.js',
 732+ ucfirst( $context->getSkin() ) . '.css',
 733+ 'Print.css',
 734+ );
 735+ if ( $wgHandheldStyle ) {
 736+ $pages[] = 'Handheld.css';
 737+ }
 738+ return $pages;
 739+ }
 740+
 741+ /* Methods */
 742+
 743+ public function getScript( ResourceLoaderContext $context ) {
 744+ return Skin::newFromKey( $context->getSkin() )->generateUserJs();
 745+ }
 746+
730747 public function getStyles( ResourceLoaderContext $context ) {
731748 global $wgHandheldStyle;
732749 $styles = array(
@@ -748,12 +765,8 @@
749766 }
750767 return $styles;
751768 }
752 - public function getMessages() { return array(); }
753 - public function getLoaderScript() { return ''; }
754 - public function getDependencies() { return array(); }
755769 }
756770
757 -
758771 class ResourceLoaderStartUpModule extends ResourceLoaderModule {
759772 /* Protected Members */
760773

Status & tagging log