r61780 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61779‎ | r61780 | r61781 >
Date:07:54, 1 February 2010
Author:dale
Status:deferred (Comments)
Tags:
Comment:
* fix for bumping version of script-loader urid on generated js updates ( MediaWiki:Common.js & MediaWiki:{SkinName}.js )
Modified paths:
  • /branches/js2-work/phase3/includes/OutputPage.php (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/includes/OutputPage.php
@@ -183,7 +183,8 @@
184184 if( $this->mJQueryDone )
185185 return ;
186186 $this->mJQueryDone = true;
187 - // @todo We should deprecate wikibits in favor of some mwEmbed pieces and jQuery
 187+
 188+ // Set core Classes
188189 $coreClasses = array( 'window.jQuery', 'mwEmbed', 'wikibits' );
189190
190191 //make sure scripts are on top:
@@ -280,7 +281,7 @@
281282 */
282283 function getURIDparam( $classAry = array() ) {
283284 global $wgDebugJavaScript, $wgStyleVersion, $IP, $wgScriptModifiedFileCheck;
284 - global $wgLang, $wgScriptModifiedMsgCheck;
 285+ global $wgLang, $wgUser, $wgScriptModifiedMsgCheck;
285286
286287 //Always the language key param to keep urls distinct per language
287288 $uriParam = 'uselang=' . $wgLang->getCode();
@@ -292,18 +293,24 @@
293294 if( gettype( $classAry) == 'string' ){
294295 $classAry = array( $classAry );
295296 }
296 - $ftime = $frev = 0;
 297+ $ftime = $currentTitleRev = 0;
297298 foreach( $classAry as $class ) {
298299 // Add the latest revision ID if the class set includes a WT (wiki title)
299300 if( substr($class, 0, 3) == 'WT:'){
300 - $title_str = substr($class, 3);
301 - $t = Title::newFromText( $title_str );
302 - if( $t && $t->exists() ) {
303 - if( $t->getLatestRevID() > $frev )
304 - $frev = $t->getLatestRevID();
 301+ $titleString = substr($class, 3);
 302+
 303+ //Check for special case of generated js
 304+ if( $titleString[0] == '-' ){
 305+ $currentTitleRev = self::getLatestTitleRev( $currentTitleRev, 'MediaWiki:Common.js' );
 306+ // Also check MediaWiki:{skinName}.js
 307+ $sk = $wgUser->getSkin();
 308+ $currentTitleRev = self::getLatestTitleRev( $currentTitleRev,
 309+ 'MediaWiki:' . ucfirst( $sk->getSkinName() ) . '.js' );
 310+ } else {
 311+ $currentTitleRev = self::getLatestTitleRev( $currentTitleRev, $titleString );
305312 }
306313 }else{
307 - //check for file modified time:
 314+ // Check for file modified time:
308315 if( $wgScriptModifiedFileCheck ) {
309316 $jsPath = jsScriptLoader::getJsPathFromClass( $class );
310317 if( $jsPath ) {
@@ -314,18 +321,18 @@
315322 }
316323 }
317324 }
318 - //build the actual unique request id:
 325+ // uild the actual unique request id:
319326 $uriParam .= "&urid={$wgStyleVersion}";
320327
321328 // Add the file modification time if set
322329 if( $ftime != 0 )
323330 $uriParam .= "_" . $ftime;
324331
325 - //add the wiki rev id if set
326 - if( $frev != 0 )
327 - $uriParam.= "_" . $frev;
 332+ // Add the wiki rev id if set
 333+ if( $currentTitleRev != 0 )
 334+ $uriParam.= "_" . $currentTitleRev;
328335
329 - //add the latest msg rev id if $wgScriptModifiedMsgCheck is enabled:
 336+ // Add the latest msg rev id if $wgScriptModifiedMsgCheck is enabled:
330337 if( $wgScriptModifiedMsgCheck ){
331338 $dbr = wfGetDB( DB_SLAVE );
332339 // Grab the latest mediaWiki msg rev id:
@@ -343,12 +350,27 @@
344351 $uriParam.= '_' . $rc->rc_id;
345352 }
346353 }
347 - //@@todo we could otherwise use the the SVN version if not already covered by $wgStyleVersion above
348354 }
349355 return $uriParam;
350356 }
351357 }
352358 /**
 359+ * Get the latest title revision from a title
 360+ * update the tRev if larger than the current
 361+ * @param {Number} $currentTitleRev Current latest revision
 362+ * @param {String} $titleString String of title to check
 363+ * @return {Number} Latest revision number
 364+ */
 365+ public static function getLatestTitleRev( $titleRev, $titleString ){
 366+ $t = Title::newFromText( $titleString );
 367+ if( $t && $t->exists() ) {
 368+ if( $t->getLatestRevID() > $titleRev ){
 369+ return $t->getLatestRevID();
 370+ }
 371+ }
 372+ return $titleRev;
 373+ }
 374+ /**
353375 * Given a script path, get the JS class name, or false if no such path is registered.
354376 * @param $path string
355377 */

Comments

#Comment by MarkAHershberger (talk | contribs)   02:25, 6 April 2010

I'd like to see the extra functionality on this branch in OutputPage.php be put into a separate extension for loading classes of JS files. This would involve moving the following functionality to that extension:

 getURIDparam()
 getLatestTitleRev()
 getJsClassFromPath()
 loadJsClassPaths()
 getScriptLoaderJs()
 addScriptClass()
 setOnloadHandler()
 getOnloadHandler()

You may need to add a couple of hooks to OutputPage() that the new extension can use, but I think most of this functionality can be removed.

I'm asking for this change so that it will be easier to maintain the js2 code. Please test and use your extension against trunk.

#Comment by MarkAHershberger (talk | contribs)   14:39, 6 April 2010

retracting this since TimStarling said he has other plans.

Status & tagging log