r61454 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61453‎ | r61454 | r61455 >
Date:09:58, 24 January 2010
Author:dale
Status:deferred
Tags:
Comment:
* bug 22246 fixed linkback for credit page on wiki title keys via descriptionurl
* added mw.getTitleText function to core mwEmbed to get title text
* other minor code cleanup
Modified paths:
  • /branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/mwEmbed.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/skins/kskin/kskinConfig.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/tests/Player_Themable.html (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/tests/Player_Themable.html
@@ -3,15 +3,15 @@
44 <html>
55 <head>
66 <title>Sample Themed Player</title>
7 - <!-- Pre-loading demo ( stuff ) likely needed for video display -->
 7+ <!-- Pre-loading demo ( stuff ) likely needed for video display
88 <script type="text/javascript" src="../jsScriptLoader.php?urid=1.1d&class=window.jQuery,mwEmbed,$j.ui,mw.EmbedPlayer,nativeEmbed,kplayerEmbed,javaEmbed,vlcEmbed,ctrlBuilder,mvpcfConfig,kskinConfig,$j.fn.menu,$j.cookie,$j.ui.slider,mw.TimedText"></script>
99 <link rel="stylesheet" href="../skins/styles.css" type="text/css" media="screen" />
1010 <link rel="stylesheet" href="../skins/mvpcf/playerSkin.css" type="text/css" media="screen" />
1111 <link rel="stylesheet" href="../skins/kskin/playerSkin.css" type="text/css" media="screen" />
12 -
13 - <!--
 12+ -->
 13+
1414 <script type="text/javascript" src="../mwEmbed.js?debug=true"></script>
15 - -->
 15+
1616
1717 </head>
1818 <script type="text/javascript">
Index: branches/js2-work/phase3/js/mwEmbed/skins/kskin/kskinConfig.js
@@ -223,20 +223,23 @@
224224 * Show the credit screen (presently specific to kaltura skin )
225225 */
226226 showCredits: function() {
227 - //set up the shortcuts:
228 - embedPlayer = this.embedPlayer;
 227+ // Set up the shortcuts:
 228+ var embedPlayer = this.embedPlayer;
229229 var _this = this;
230 - $target = embedPlayer.$interface.find( '.menu-credits' );
 230+ var $target = embedPlayer.$interface.find( '.menu-credits' );
231231
232 - $target.html( '<h2>' + gM( 'mwe-credits' ) + '</h2>' +
233 - '<div class="credits_box ui-corner-all">' +
234 - mw.loading_spinner() +
235 - '</div>'
 232+ $target.empty().append(
 233+ $j('<h2 />')
 234+ .text( gM( 'mwe-credits' ) ),
 235+ $j('<div />')
 236+ .addClass( "credits_box ui-corner-all" )
 237+ .loadingSpinner()
236238 );
237239
238240 if( mw.getConfig( 'k_attribution' ) == true ){
239241 $target.append(
240 - $j( '<div/>' ).addClass( 'k-attribution' )
 242+ $j( '<div />' )
 243+ .addClass( 'k-attribution' )
241244 .attr({
242245 'title': gM('mwe-kaltura-platform-title')
243246 })
@@ -252,37 +255,48 @@
253256 );
254257 return ;
255258 }
256 -
257 - // Do the api request to populate the credits via the apiTitleKey
258 - var request = {
259 - // Normalize the File NS (ie sometimes its present in apiTitleKey other times not
260 - 'titles' : 'File:' + embedPlayer.apiTitleKey.replace(/File:|Image:/, '' ),
261 - 'prop' : 'revisions',
262 - 'rvprop' : 'content'
263 - };
264 - var req_categories = new Array();
 259+
 260+ _this.getCredits();
 261+ },
 262+
 263+ /**
 264+ * Issues a request to populate the credits box
 265+ */
 266+ getCredits: function(){
 267+ // Setup shortcuts:
 268+ var embedPlayer = this.embedPlayer;
 269+ var _this = this;
 270+ var $target = embedPlayer.$interface.find( '.menu-credits' );
 271+
265272 var api_url = mw.getApiProviderURL( embedPlayer.apiProvider );
266 - if( ! api_url ){
267 - mw.log("Error: can't get credit screen without title key");
268 - return ;
269 - }
270 - mw.getJSON( api_url , request, function( data ) {
271 - if( !data || !data.query || !data.query.pages ){
272 - $target.find('.credits_box').text(
273 - 'Error: title key: ' + embedPlayer.apiTitleKey + ' not found'
274 - );
275 - return false;
276 - }
277 - var pages = data.query.pages;
278 - for(var i in pages){
279 - page = pages[ i ];
280 - if( page[ 'revisions' ] && page[ 'revisions' ][0]['*'] ){
281 - $target.find('.credits_box').html(
282 - _this.doCreditLineFromWikiText( page[ 'revisions' ][0]['*'] )
283 - );
 273+ var fileTitle = 'File:' + embedPlayer.apiTitleKey.replace(/File:|Image:/, '');
 274+
 275+ // Get the image info
 276+ var request = {
 277+ 'prop' : 'imageinfo',
 278+ 'titles': fileTitle,
 279+ 'iiprop' : 'url'
 280+ };
 281+ var articleUrl = '';
 282+ mw.getJSON( api_url, request, function( data ){
 283+ if ( data.query.pages ) {
 284+ for ( var i in data.query.pages ) {
 285+ var imageProps = data.query.pages[i];
 286+ // Check properites for "missing"
 287+ if( imageProps.imageinfo && imageProps.imageinfo[0] && imageProps.imageinfo[0].descriptionurl ){
 288+ // Found page
 289+ $target.find('.credits_box').html(
 290+ _this.doCreditLine( imageProps.imageinfo[0].descriptionurl )
 291+ );
 292+ }else{
 293+ // missing page descriptionurl
 294+ $target.find('.credits_box').text(
 295+ 'Error: title key: ' + embedPlayer.apiTitleKey + ' not found'
 296+ );
 297+ }
284298 }
285299 }
286 - } );
 300+ } );
287301 },
288302
289303 /**
@@ -292,12 +306,11 @@
293307 *
294308 * @parm {String} wikiText Resource wiki text page contents
295309 */
296 - doCreditLineFromWikiText: function ( wikiText ){
 310+ doCreditLine: function ( articleUrl ){
297311 var embedPlayer = this.embedPlayer;
298312
299313 // Get the title str
300 - var titleStr = embedPlayer.apiTitleKey.replace(/_/g, ' ');
301 - var titleLink = 'http://commons.wikimedia.org/wiki/File:' + embedPlayer.apiTitleKey;
 314+ var titleStr = embedPlayer.apiTitleKey.replace(/_/g, ' ');
302315
303316 var imgWidth = ( this.getOverlayWidth() < 250 )? 45 : 90;
304317
@@ -305,7 +318,7 @@
306319 return $j( '<div/>' ).addClass( 'creditline' )
307320 .append(
308321 $j('<a/>').attr({
309 - 'href' : titleLink,
 322+ 'href' : articleUrl,
310323 'title' : titleStr
311324 }).html(
312325 $j('<img/>').attr( {
@@ -323,7 +336,7 @@
324337 // We use a div container to easialy get at the built out link
325338 $j('<div>').html(
326339 $j('<a/>').attr({
327 - 'href' : titleLink,
 340+ 'href' : articleUrl,
328341 'title' : titleStr
329342 }).text( titleStr )
330343 ).html()
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js
@@ -1904,7 +1904,8 @@
19051905 } else {
19061906 // Check if the file is local ( can be shared repo )
19071907 if ( provider.check_shared ) {
1908 - _this.findFileInLocalWiki( resource.target_resource_title, function( imagePage ) {
 1908+ var fileTitle =_this.canonicalFileNS + ':' + resource.target_resource_title;
 1909+ _this.findFileInLocalWiki( fileTitle, function( imagePage ) {
19091910 if ( imagePage && imagePage['imagerepository'] == 'shared' ||
19101911 imagePage['imagerepository'] == 'commons') {
19111912 myCallback( 'shared' );
@@ -2262,7 +2263,7 @@
22632264 var _this = this;
22642265 var request = {
22652266 'action': 'query',
2266 - 'titles': _this.canonicalFileNS + ':' + fileName,
 2267+ 'titles': fileName,
22672268 'prop': 'imageinfo',
22682269 'iiprop': 'url',
22692270 'iiurlwidth': '400'
@@ -2273,7 +2274,8 @@
22742275 for ( var i in data.query.pages ) {
22752276 for ( var j in data.query.pages[i] ) {
22762277 if ( j == 'missing'
2277 - && data.query.pages[i].imagerepository != 'shared' )
 2278+ && data.query.pages[i].imagerepository != 'shared'
 2279+ && data.query.pages[i].imagerepository != 'commons' )
22782280 {
22792281 mw.log( fileName + " not found" );
22802282 callback( false );
Index: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js
@@ -1309,6 +1309,49 @@
13101310 */
13111311
13121312 /**
 1313+ *
 1314+ * Shortcut to latest revision text of a given title
 1315+ *
 1316+ * Assumes "follow redirects"
 1317+ *
 1318+ * $j.getTitleText( [url], title, callback )
 1319+ *
 1320+ * @param {String} url or title key
 1321+ * @parma {Mixed} title or callback function
 1322+ * @param {Function} callback Function or NULL
 1323+ *
 1324+ * @return callback is called with:
 1325+ * {Boolean} false if no page found
 1326+ * {String} text of wiki page
 1327+ */
 1328+ mw.getTitleText = function( apiUrl, title, callback ){
 1329+ // Check if optional apiURL was not included
 1330+ if( !callback ){
 1331+ title = apiUrl;
 1332+ callback = title;
 1333+ apiUrl = mw.getLocalApiUrl();
 1334+ }
 1335+ var request = {
 1336+ // Normalize the File NS (ie sometimes its present in apiTitleKey other times not
 1337+ 'titles' : title,
 1338+ 'prop' : 'revisions',
 1339+ 'rvprop' : 'content'
 1340+ };
 1341+ mw.getJSON( apiUrl , request, function( data ) {
 1342+ if( !data || !data.query || !data.query.pages ){
 1343+ callback( false );
 1344+ }
 1345+ var pages = data.query.pages;
 1346+ for(var i in pages){
 1347+ page = pages[ i ];
 1348+ if( page[ 'revisions' ] && page[ 'revisions' ][0]['*'] ){
 1349+ callback( page[ 'revisions' ][0]['*'] );
 1350+ }
 1351+ }
 1352+ });
 1353+ }
 1354+
 1355+ /**
13131356 * mediaWiki JSON a wrapper for jQuery getJSON:
13141357 * $j.getJSON( url, [data], [callback] )
13151358 *
Index: branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php
@@ -21,17 +21,26 @@
2222 }
2323
2424 class jsScriptLoader {
 25+
 26+ // The list of javascript files
2527 var $jsFileList = array();
 28+
 29+ // The language code for the script-loader request
2630 var $langCode = '';
 31+
 32+ // The javascript output string
2733 var $jsout = '';
28 - var $requestKey = ''; // the request key
29 - var $error_msg = '';
 34+
 35+ // The request Key for the js
 36+ var $requestKey = '';
 37+
 38+ // Error msg
 39+ var $errorMsg = '';
 40+
 41+ // Debug flag
3042 var $debug = false;
3143
32 - // Whether we should include generated JS (special class '-')
33 - var $jsvarurl = false;
34 - var $doProcReqFlag = true;
35 -
 44+ // The raw requested class
3645 private static $rawClassList = '';
3746
3847 /**
@@ -89,31 +98,38 @@
9099 // Build the output
91100 // Swap in the appropriate language per js_file
92101 foreach ( $this->jsFileList as $classKey => $file_name ) {
 102+
93103 // Get the script content
94104 $jstxt = $this->getScriptText( $classKey, $file_name );
95105 if( $jstxt ){
96106 $this->jsout .= $this->doProcessJs( $jstxt );
97107 }
98 - // If the core mwEmbed class entry point include loader js
 108+
 109+ // If the core mwEmbed class entry point include all the loader js
99110 if( $classKey == 'mwEmbed' ){
100111 $this->jsout .= jsClassLoader::getCombinedLoaderJs();
101112 }
102113 }
103114
104 - // Add a mw.loadDone callback so webkit browsers don't have to check if variables are "ready"
105 - $this->jsout .= self::getOnDoneCallback( );
 115+ /*
 116+ * Add a mw.loadDone class callback if there was no "error" in getting any of the classes
 117+ */
 118+ if ( $this->error_msg == '' ){
 119+ $this->jsout .= self::getOnDoneCallback( );
 120+ }
106121
107 -
108122 // Check if we should minify the whole thing:
109123 if ( !$this->debug ) {
110124 $this->jsout = self::getMinifiedJs( $this->jsout , $this->requestKey );
111125 }
 126+
112127 // Save to the file cache
113128 if ( $wgUseFileCache && !$this->debug ) {
114129 $status = $this->sFileCache->saveToFileCache( $this->jsout );
115130 if ( $status !== true )
116131 $this->error_msg .= $status;
117132 }
 133+
118134 // Check for an error msg
119135 if ( $this->error_msg != '' ) {
120136 //just set the content type (don't send cache header)
@@ -128,7 +144,10 @@
129145 /**
130146 * Get the onDone javascript callback for a given class list
131147 *
132 - * @return unknown
 148+ * Enables a done loading callback for browsers like safari
 149+ * that don't consistently support the <script>.onload call
 150+ *
 151+ * @return String
133152 */
134153 static private function getOnDoneCallback( ){
135154 return 'if(mw && mw.loadDone){mw.loadDone(\'' .

Status & tagging log