r97263 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97262‎ | r97263 | r97264 >
Date:13:19, 16 September 2011
Author:reedy
Status:ok
Tags:
Comment:
REL1_18 MFT r93626, r96562, r96640, r96978, r97050
Modified paths:
  • /branches/REL1_18/phase3/includes/HttpFunctions.php (modified) (history)
  • /branches/REL1_18/phase3/includes/cache/MessageCache.php (modified) (history)
  • /branches/REL1_18/phase3/includes/parser/ParserOutput.php (modified) (history)
  • /branches/REL1_18/phase3/includes/resourceloader/ResourceLoader.php (modified) (history)
  • /branches/REL1_18/phase3/includes/resourceloader/ResourceLoaderFileModule.php (modified) (history)
  • /branches/REL1_18/phase3/includes/resourceloader/ResourceLoaderModule.php (modified) (history)
  • /branches/REL1_18/phase3/includes/resourceloader/ResourceLoaderStartUpModule.php (modified) (history)

Diff [purge]

Index: branches/REL1_18/phase3/includes/parser/ParserOutput.php
@@ -396,11 +396,11 @@
397397 /**
398398 * Returns the options from its ParserOptions which have been taken
399399 * into account to produce this output or false if not available.
400 - * @return mixed Array/false
 400+ * @return mixed Array
401401 */
402402 public function getUsedOptions() {
403403 if ( !isset( $this->mAccessedOptions ) ) {
404 - return false;
 404+ return array();
405405 }
406406 return array_keys( $this->mAccessedOptions );
407407 }
Index: branches/REL1_18/phase3/includes/resourceloader/ResourceLoader.php
@@ -473,17 +473,31 @@
474474 try {
475475 $scripts = '';
476476 if ( $context->shouldIncludeScripts() ) {
477 - $scripts = $module->getScript( $context );
478 - if ( is_string( $scripts ) ) {
479 - // bug 27054: Append semicolon to prevent weird bugs
480 - // caused by files not terminating their statements right
481 - $scripts .= ";\n";
 477+ // If we are in debug mode, we'll want to return an array of URLs if possible
 478+ // However, we can't do this if the module doesn't support it
 479+ // We also can't do this if there is an only= parameter, because we have to give
 480+ // the module a way to return a load.php URL without causing an infinite loop
 481+ if ( $context->getDebug() && !$context->getOnly() && $module->supportsURLLoading() ) {
 482+ $scripts = $module->getScriptURLsForDebug( $context );
 483+ } else {
 484+ $scripts = $module->getScript( $context );
 485+ if ( is_string( $scripts ) ) {
 486+ // bug 27054: Append semicolon to prevent weird bugs
 487+ // caused by files not terminating their statements right
 488+ $scripts .= ";\n";
 489+ }
482490 }
483491 }
484492 // Styles
485493 $styles = array();
486494 if ( $context->shouldIncludeStyles() ) {
487 - $styles = $module->getStyles( $context );
 495+ // If we are in debug mode, we'll want to return an array of URLs
 496+ // See comment near shouldIncludeScripts() for more details
 497+ if ( $context->getDebug() && !$context->getOnly() && $module->supportsURLLoading() ) {
 498+ $styles = $module->getStyleURLsForDebug( $context );
 499+ } else {
 500+ $styles = $module->getStyles( $context );
 501+ }
488502 }
489503
490504 // Messages
Property changes on: branches/REL1_18/phase3/includes/resourceloader/ResourceLoader.php
___________________________________________________________________
Modified: svn:mergeinfo
491505 Merged /trunk/phase3/includes/resourceloader/ResourceLoader.php:r93626,96562,96640,96978,97050
Index: branches/REL1_18/phase3/includes/resourceloader/ResourceLoaderFileModule.php
@@ -217,16 +217,21 @@
218218 */
219219 public function getScript( ResourceLoaderContext $context ) {
220220 $files = $this->getScriptFiles( $context );
221 - if ( $context->getDebug() && $this->debugRaw ) {
222 - $urls = array();
223 - foreach ( $this->getScriptFiles( $context ) as $file ) {
224 - $urls[] = $this->getRemotePath( $file );
225 - }
226 - return $urls;
227 - }
228221 return $this->readScriptFiles( $files );
229222 }
 223+
 224+ public function getScriptURLsForDebug( ResourceLoaderContext $context ) {
 225+ $urls = array();
 226+ foreach ( $this->getScriptFiles( $context ) as $file ) {
 227+ $urls[] = $this->getRemotePath( $file );
 228+ }
 229+ return $urls;
 230+ }
230231
 232+ public function supportsURLLoading() {
 233+ return $this->debugRaw;
 234+ }
 235+
231236 /**
232237 * Gets loader script.
233238 *
@@ -250,16 +255,6 @@
251256 $this->getStyleFiles( $context ),
252257 $this->getFlip( $context )
253258 );
254 - if ( !$context->getOnly() && $context->getDebug() && $this->debugRaw ) {
255 - $urls = array();
256 - foreach ( $this->getStyleFiles( $context ) as $mediaType => $list ) {
257 - $urls[$mediaType] = array();
258 - foreach ( $list as $file ) {
259 - $urls[$mediaType][] = $this->getRemotePath( $file );
260 - }
261 - }
262 - return $urls;
263 - }
264259 // Collect referenced files
265260 $this->localFileRefs = array_unique( $this->localFileRefs );
266261 // If the list has been modified since last time we cached it, update the cache
@@ -276,6 +271,17 @@
277272 return $styles;
278273 }
279274
 275+ public function getStyleURLsForDebug( ResourceLoaderContext $context ) {
 276+ $urls = array();
 277+ foreach ( $this->getStyleFiles( $context ) as $mediaType => $list ) {
 278+ $urls[$mediaType] = array();
 279+ foreach ( $list as $file ) {
 280+ $urls[$mediaType][] = $this->getRemotePath( $file );
 281+ }
 282+ }
 283+ return $urls;
 284+ }
 285+
280286 /**
281287 * Gets list of message keys used by this module.
282288 *
Index: branches/REL1_18/phase3/includes/resourceloader/ResourceLoaderModule.php
@@ -126,6 +126,44 @@
127127 // Stub, override expected
128128 return '';
129129 }
 130+
 131+ /**
 132+ * Get the URL or URLs to load for this module's JS in debug mode.
 133+ * The default behavior is to return a load.php?only=scripts URL for
 134+ * the module, but file-based modules will want to override this to
 135+ * load the files directly.
 136+ *
 137+ * This function is called only when 1) we're in debug mode, 2) there
 138+ * is no only= parameter and 3) supportsURLLoading() returns true.
 139+ * #2 is important to prevent an infinite loop, therefore this function
 140+ * MUST return either an only= URL or a non-load.php URL.
 141+ *
 142+ * @param $context ResourceLoaderContext: Context object
 143+ * @return Array of URLs
 144+ */
 145+ public function getScriptURLsForDebug( ResourceLoaderContext $context ) {
 146+ global $wgLoadScript; // TODO factor out to ResourceLoader static method and deduplicate from makeResourceLoaderLink()
 147+ $query = array(
 148+ 'modules' => $this->getName(),
 149+ 'only' => 'scripts',
 150+ 'skin' => $context->getSkin(),
 151+ 'user' => $context->getUser(),
 152+ 'debug' => 'true',
 153+ 'version' => $context->getVersion()
 154+ );
 155+ ksort( $query );
 156+ return array( wfAppendQuery( $wgLoadScript, $query ) . '&*' );
 157+ }
 158+
 159+ /**
 160+ * Whether this module supports URL loading. If this function returns false,
 161+ * getScript() will be used even in cases (debug mode, no only param) where
 162+ * getScriptURLsForDebug() would normally be used instead.
 163+ * @return bool
 164+ */
 165+ public function supportsURLLoading() {
 166+ return true;
 167+ }
130168
131169 /**
132170 * Get all CSS for this module for a given skin.
@@ -137,6 +175,29 @@
138176 // Stub, override expected
139177 return array();
140178 }
 179+
 180+ /**
 181+ * Get the URL or URLs to load for this module's CSS in debug mode.
 182+ * The default behavior is to return a load.php?only=styles URL for
 183+ * the module, but file-based modules will want to override this to
 184+ * load the files directly. See also getScriptURLsForDebug()
 185+ *
 186+ * @param $context ResourceLoaderContext: Context object
 187+ * @return Array: array( mediaType => array( URL1, URL2, ... ), ... )
 188+ */
 189+ public function getStyleURLsForDebug( ResourceLoaderContext $context ) {
 190+ global $wgLoadScript; // TODO factor out to ResourceLoader static method and deduplicate from makeResourceLoaderLink()
 191+ $query = array(
 192+ 'modules' => $this->getName(),
 193+ 'only' => 'styles',
 194+ 'skin' => $context->getSkin(),
 195+ 'user' => $context->getUser(),
 196+ 'debug' => 'true',
 197+ 'version' => $context->getVersion()
 198+ );
 199+ ksort( $query );
 200+ return array( 'all' => array( wfAppendQuery( $wgLoadScript, $query ) . '&*' ) );
 201+ }
141202
142203 /**
143204 * Get the messages needed for this module.
Index: branches/REL1_18/phase3/includes/resourceloader/ResourceLoaderStartUpModule.php
@@ -69,10 +69,6 @@
7070 }
7171 }
7272
73 -
74 - $serverBits = wfParseUrl( $wgServer );
75 - $protocol = $serverBits ? $serverBits['scheme'] : 'http';
76 -
7773 // Build list of variables
7874 $vars = array(
7975 'wgLoadScript' => $wgLoadScript,
@@ -108,7 +104,6 @@
109105 'wgFileCanRotate' => BitmapHandler::canRotate(),
110106 'wgAvailableSkins' => Skin::getSkinNames(),
111107 'wgExtensionAssetsPath' => $wgExtensionAssetsPath,
112 - 'wgProto' => $protocol,
113108 // MediaWiki sets cookies to have this prefix by default
114109 'wgCookiePrefix' => $wgCookiePrefix,
115110 'wgResourceLoaderMaxQueryLength' => $wgResourceLoaderMaxQueryLength,
@@ -234,6 +229,10 @@
235230 return $out;
236231 }
237232
 233+ public function supportsURLLoading() {
 234+ return false;
 235+ }
 236+
238237 /**
239238 * @param $context ResourceLoaderContext
240239 * @return array|mixed
Index: branches/REL1_18/phase3/includes/cache/MessageCache.php
@@ -764,15 +764,23 @@
765765 $popts->setTargetLanguage( $language );
766766 }
767767
 768+ wfProfileIn( __METHOD__ );
768769 if ( !$title || !$title instanceof Title ) {
769770 global $wgTitle;
770771 $title = $wgTitle;
771772 }
 773+ // Sometimes $wgTitle isn't set either...
 774+ if ( !$title ) {
 775+ # It's not uncommon having a null $wgTitle in scripts. See r80898
 776+ # Create a ghost title in such case
 777+ $title = Title::newFromText( 'Dwimmerlaik' );
 778+ }
772779
773780 $this->mInParser = true;
774781 $res = $parser->parse( $text, $title, $popts, $linestart );
775782 $this->mInParser = false;
776783
 784+ wfProfileOut( __METHOD__ );
777785 return $res;
778786 }
779787
Property changes on: branches/REL1_18/phase3/includes/cache/MessageCache.php
___________________________________________________________________
Modified: svn:mergeinfo
780788 Merged /trunk/phase3/includes/cache/MessageCache.php:r93626,96562,96640,96978,97050
Index: branches/REL1_18/phase3/includes/HttpFunctions.php
@@ -32,7 +32,6 @@
3333 * @return Mixed: (bool)false on failure or a string on success
3434 */
3535 public static function request( $method, $url, $options = array() ) {
36 - $url = wfExpandUrl( $url, PROTO_HTTP );
3736 wfDebug( "HTTP: $method: $url\n" );
3837 $options['method'] = strtoupper( $method );
3938
@@ -178,14 +177,14 @@
179178 public $status;
180179
181180 /**
182 - * @param $url String: url to use
 181+ * @param $url String: url to use. If protocol-relative, will be expanded to an http:// URL
183182 * @param $options Array: (optional) extra params to pass (see Http::request())
184183 */
185184 function __construct( $url, $options = array() ) {
186185 global $wgHTTPTimeout;
187186
188 - $this->url = $url;
189 - $this->parsedUrl = parse_url( $url );
 187+ $this->url = wfExpandUrl( $url, PROTO_HTTP );
 188+ $this->parsedUrl = parse_url( $this->url );
190189
191190 if ( !Http::isValidURI( $this->url ) ) {
192191 $this->status = Status::newFatal( 'http-invalid-url' );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r93626fixes Bug #27543 - “Warning: in_array() [function.in-array]: Wrong datatype...mah15:50, 1 August 2011
r96562Move URL expansion from Http::request() (where it was put in r93820) to MWHtt...catrope13:48, 8 September 2011
r96640Remove wgProto from mw.config...krinkle01:03, 9 September 2011
r96978Fix the fixme on r88053: dependency handling was broken in debug mode in cert...catrope17:13, 13 September 2011
r97050Followup r86304, guard against $title AND $wgTitle being null...reedy12:32, 14 September 2011

Status & tagging log