r75035 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75034‎ | r75035 | r75036 >
Date:20:45, 19 October 2010
Author:hashar
Status:ok (Comments)
Tags:
Comment:
documentation, a couple notes about code and some whitespaces adjustements to make code easier to read.
Modified paths:
  • /trunk/phase3/includes/resourceloader/ResourceLoader.php (modified) (history)
  • /trunk/phase3/includes/resourceloader/ResourceLoaderContext.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/resourceloader/ResourceLoader.php
@@ -23,7 +23,10 @@
2424 defined( 'MEDIAWIKI' ) || die( 1 );
2525
2626 /**
27 - * Dynamic JavaScript and CSS resource loading system
 27+ * Dynamic JavaScript and CSS resource loading system.
 28+ *
 29+ * Most of the documention is on the MediaWiki documentation wiki starting at
 30+ * http://www.mediawiki.org/wiki/ResourceLoader
2831 */
2932 class ResourceLoader {
3033
@@ -39,9 +42,12 @@
4043 *
4144 * This is not inside the module code because it's so much more performant to request all of the information at once
4245 * than it is to have each module requests it's own information.
43 - *
44 - * @param $modules array list of module names to preload information for
45 - * @param $context ResourceLoaderContext context to load the information within
 46+ *
 47+ * This method grab modules dependencies from the database and initialize modules object.
 48+ * A first pass compute dependencies, a second one the blob mtime.
 49+ *
 50+ * @param $modules Array List of module names to preload information for
 51+ * @param $context ResourceLoaderContext Context to load the information within
4652 */
4753 protected function preloadModuleInfo( array $modules, ResourceLoaderContext $context ) {
4854 if ( !count( $modules ) ) {
@@ -57,7 +63,8 @@
5864 'md_skin' => $context->getSkin()
5965 ), __METHOD__
6066 );
61 -
 67+
 68+ // Set modules dependecies
6269 $modulesWithDeps = array();
6370 foreach ( $res as $row ) {
6471 $this->modules[$row->md_module]->setFileDependencies( $skin,
@@ -65,7 +72,7 @@
6673 );
6774 $modulesWithDeps[] = $row->md_module;
6875 }
69 - // Register the absence of a dependencies row too
 76+ // Register the absence of a dependency row too
7077 foreach ( array_diff( $modules, $modulesWithDeps ) as $name ) {
7178 $this->modules[$name]->setFileDependencies( $skin, array() );
7279 }
@@ -96,7 +103,13 @@
97104 }
98105
99106 /**
100 - * Runs text through a filter, caching the filtered result for future calls
 107+ * Runs text (js,CSS) through a filter, caching the filtered result for future calls.
 108+ *
 109+ * Availables filters are:
 110+ * - minify-js \see JSMin::minify
 111+ * - minify-css \see CSSMin::minify
 112+ * - flip-css \see CSSJanus::transform
 113+ * When the filter names does not exist, text is returned as is.
101114 *
102115 * @param $filter String: name of filter to run
103116 * @param $data String: text to filter, such as JavaScript or CSS text
@@ -108,6 +121,8 @@
109122 wfProfileIn( __METHOD__ );
110123
111124 // For empty or whitespace-only things, don't do any processing
 125+ # FIXME: we should return the data unfiltered if $filter is not supported.
 126+ # that would save up a md5 computation and one memcached get.
112127 if ( trim( $data ) === '' ) {
113128 wfProfileOut( __METHOD__ );
114129 return $data;
@@ -125,6 +140,7 @@
126141 // Run the filter
127142 try {
128143 switch ( $filter ) {
 144+ # note: if adding a new filter. Please update method documentation above.
129145 case 'minify-js':
130146 $result = JSMin::minify( $data );
131147 break;
@@ -143,7 +159,7 @@
144160 throw new MWException( 'Filter threw an exception: ' . $exception->getMessage() );
145161 }
146162
147 - // Save to memcached
 163+ // Save filtered text to memcached
148164 $wgMemc->set( $key, $result );
149165
150166 wfProfileOut( __METHOD__ );
@@ -259,13 +275,13 @@
260276 // If a version wasn't specified we need a shorter expiry time for updates to
261277 // propagate to clients quickly
262278 if ( is_null( $context->getVersion() ) ) {
263 - $maxage = $wgResourceLoaderMaxage['unversioned']['client'];
 279+ $maxage = $wgResourceLoaderMaxage['unversioned']['client'];
264280 $smaxage = $wgResourceLoaderMaxage['unversioned']['server'];
265281 }
266282 // If a version was specified we can use a longer expiry time since changing
267283 // version numbers causes cache misses
268284 else {
269 - $maxage = $wgResourceLoaderMaxage['versioned']['client'];
 285+ $maxage = $wgResourceLoaderMaxage['versioned']['client'];
270286 $smaxage = $wgResourceLoaderMaxage['versioned']['server'];
271287 }
272288
@@ -311,6 +327,12 @@
312328 wfProfileOut( __METHOD__ );
313329 }
314330
 331+ /**
 332+ *
 333+ * @param $context ResourceLoaderContext
 334+ * @param $modules Array array( modulename => ResourceLoaderModule )
 335+ * @param $missing Unavailables modules (Default null)
 336+ */
315337 public function makeModuleResponse( ResourceLoaderContext $context, array $modules, $missing = null ) {
316338 // Pre-fetch blobs
317339 $blobs = $context->shouldIncludeMessages() ?
Index: trunk/phase3/includes/resourceloader/ResourceLoaderContext.php
@@ -49,16 +49,19 @@
5050
5151 $this->resourceLoader = $resourceLoader;
5252 $this->request = $request;
 53+
5354 // Interpret request
 55+ # list of modules
5456 $modules = $request->getVal( 'modules' );
55 - $this->modules = $modules ? explode( '|', $modules ) : array();
56 - $this->language = $request->getVal( 'lang' );
 57+ $this->modules = $modules ? explode( '|', $modules ) : array();
 58+ # various parameters
 59+ $this->language = $request->getVal( 'lang' );
5760 $this->direction = $request->getVal( 'dir' );
58 - $this->skin = $request->getVal( 'skin' );
59 - $this->user = $request->getVal( 'user' );
60 - $this->debug = $request->getFuzzyBool( 'debug', $wgResourceLoaderDebug );
61 - $this->only = $request->getVal( 'only' );
62 - $this->version = $request->getVal( 'version' );
 61+ $this->skin = $request->getVal( 'skin' );
 62+ $this->user = $request->getVal( 'user' );
 63+ $this->debug = $request->getFuzzyBool( 'debug', $wgResourceLoaderDebug );
 64+ $this->only = $request->getVal( 'only' );
 65+ $this->version = $request->getVal( 'version' );
6366
6467 // Fallback on system defaults
6568 if ( !$this->language ) {

Comments

#Comment by Hashar (talk | contribs)   20:45, 19 October 2010

There is no code changed in this revision.

Status & tagging log