r84594 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84593‎ | r84594 | r84595 >
Date:14:24, 23 March 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Per mailing list, import MaxSems tooltip gadget from http://www.mediawiki.org/wiki/MediaWiki:Gadget-CodeTooltips.js

All credit to MaxSem
Modified paths:
  • /trunk/extensions/CodeReview/CodeReview.php (modified) (history)
  • /trunk/extensions/CodeReview/modules/ext.codereview.tooltips.js (added) (history)
  • /trunk/extensions/CodeReview/ui/CodeRevisionListView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeReview.php
@@ -149,6 +149,11 @@
150150 'scripts' => 'ext.codereview.loaddiff.js'
151151 ) + $commonModuleInfo;
152152
 153+// Revision tooltips CodeRevisionView:
 154+$wgResourceModules['ext.codereview.tooltips'] = array(
 155+ 'scripts' => 'ext.codereview.tooltips.js'
 156+) + $commonModuleInfo;
 157+
153158 // If you are running a closed svn, fill the following two lines with the username and password
154159 // of a user allowed to access it. Otherwise, leave it false.
155160 // This is only necessary if using the shell method to access Subversion
Index: trunk/extensions/CodeReview/modules/ext.codereview.tooltips.js
@@ -0,0 +1,53 @@
 2+var CodeTooltipsInit = function() {
 3+ $( 'a[href]' ).each( function() {
 4+ var link = this.getAttribute( 'href' );
 5+ if ( !link ) {
 6+ return;
 7+ }
 8+ var matches = link.match( /^\/.*\/Special:Code\/([-A-Za-z\d_]*?)\/(\d+)$/ );
 9+ if ( !matches ) {
 10+ return;
 11+ }
 12+ $( this ).mouseenter( function( e ) {
 13+ var $el = $( this );
 14+ if ( $el.data('codeTooltip') ) {
 15+ return; // already processed
 16+ }
 17+ var reqData = {
 18+ format: 'json',
 19+ action: 'query',
 20+ list: 'coderevisions',
 21+ crprop: 'revid|message|status|author',
 22+ crrepo: matches[1],
 23+ crrevs: matches[2],
 24+ crlimit: '1'
 25+ };
 26+ $el.tipsy( { fade: true, gravity: 'sw', html:true } );
 27+ $.getJSON(
 28+ mw.config.get( 'wgScriptPath' ) + '/api' + mw.config.get( 'wgScriptExtension' ),
 29+ reqData,
 30+ function( data ) {
 31+ if ( !data || !data.query || !data.query.coderevisions ) {
 32+ return;
 33+ }
 34+ var rev = data.query.coderevisions[0];
 35+ var text = rev['*'].length > 82 ? rev['*'].substr(0,80) + '...' : rev['*'];
 36+
 37+ var tip = '<div class="mw-codereview-status-' + rev.status + '" style="padding:5px 8px 4px; margin:-5px -8px -4px;">'
 38+ + 'r' + matches[2]
 39+ + ' [' + rev.status + '] by '
 40+ + rev.author
 41+ + ( rev['*'] ? ' - ' + text : '' )
 42+ + '</div>';
 43+ $el.attr( 'title', tip );
 44+ $el.data( 'codeTooltip', true );
 45+ $el.tipsy( 'show' );
 46+ }
 47+ );
 48+ });
 49+ });
 50+};
 51+
 52+mw.loader.using( 'jquery.tipsy', function(){
 53+ $( document ).ready( CodeTooltipsInit );
 54+});
Property changes on: trunk/extensions/CodeReview/modules/ext.codereview.tooltips.js
___________________________________________________________________
Added: svn:eol-style
155 + native
Index: trunk/extensions/CodeReview/ui/CodeRevisionListView.php
@@ -16,7 +16,7 @@
1717 global $wgRequest;
1818
1919 $path = $wgRequest->getVal( 'path' );
20 -
 20+
2121 if ( $path != '' ) {
2222 $this->mPath = array_map( array( $this, 'preparePaths' ), explode( '|', $path ) );
2323 } else {
@@ -78,6 +78,8 @@
7979
8080 $navBar = $pager->getNavigationBar();
8181
 82+ $wgOut->addModules( 'ext.codereview.tooltips' );
 83+
8284 $wgOut->addHTML( $pathForm );
8385
8486 $wgOut->addHTML(

Follow-up revisions

RevisionCommit summaryAuthorDate
r84609Tweaks for r84594:...maxsem17:29, 23 March 2011

Comments

#Comment by MaxSem (talk | contribs)   17:32, 23 March 2011

Ugh, fame! :P Made some tweaks, but setting it to fixme as a reminder that it needs localisation now that it's not a gadget:)

#Comment by Reedy (talk | contribs)   19:21, 26 March 2011

Logged as a bug as an action item - Bug 28259

#Comment by He7d3r (talk | contribs)   18:29, 23 March 2011

Would it be possible to have the same kind of tooltips for "Bug NNNNN" links? (to get the description of the bug)

#Comment by Reedy (talk | contribs)   18:31, 23 March 2011

It'd be more difficult, as knowing Max, he's not going to want to be screenscraping.

If we can get stuff from the BZ api easily...

#Comment by Bawolff (talk | contribs)   18:08, 24 March 2011

In theory, https://bugzilla.wikimedia.org/bug/1234?include_fields=summary should get the summary of bug 1234 (In practise, the bugzilla api for mediazilla seems borked... Loading forever, until eventually gives a 500 error). Based on the docs, you apparently need to set the accept http header to have application/json in it, and to not have text/html in it, in order to get json back. Otherwise you get yaml something or other back.

#Comment by Platonides (talk | contribs)   18:10, 24 March 2011

The problem is that bugzilla.wikimedia.org is on a different domain than www.mediawiki.org so those would be cross-domain XMLHttpRequests

#Comment by Bawolff (talk | contribs)   18:23, 24 March 2011

bugzilla api supports JSONP if the accept header contains (only?) application/javascript (and I think you need to supply a callback parameter)

(/me mutters about how he thinks using the accept header like this is icky).

Status & tagging log