Index: trunk/extensions/PageTriage/ext.pageTriage.core.js |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | ( function( $ ) { |
3 | 3 | |
4 | | -var $currentArticle = null; // the title of the current article being reviewed |
| 4 | +var $currentArticle = 'Hello World'; // the title of the current article being reviewed |
5 | 5 | |
6 | 6 | $.pageTriage = { |
7 | 7 | tagArticle: function() { |
— | — | @@ -15,22 +15,55 @@ |
16 | 16 | 'action': 'edit', |
17 | 17 | 'title': $currentArticle, |
18 | 18 | 'text' : $newText, |
19 | | - 'token': $token, |
| 19 | + 'token': mw.user.tokens.get( 'editToken' ), // MW 1.18 and later |
20 | 20 | 'summary': 'Triaging the page', |
21 | 21 | 'notminor': true |
22 | 22 | }; |
23 | 23 | |
24 | 24 | $.ajax( { |
25 | | - url: mw.util.wikiScript( 'api' ), |
26 | | - data: sendData, |
27 | | - dataType: 'json', |
28 | | - type: 'POST' |
| 25 | + 'url': mw.util.wikiScript( 'api' ), |
| 26 | + 'data': sendData, |
| 27 | + 'dataType': 'json', |
| 28 | + 'type': 'POST' |
29 | 29 | } ); |
30 | 30 | }, |
31 | 31 | |
32 | 32 | loadPage: function() { |
33 | | - $( '#ptr-stuff' ).append( "Article goes here!" ); |
34 | | - // Load in an article |
| 33 | + |
| 34 | + // Get some info about the latest revision of the article |
| 35 | + var sendData = { |
| 36 | + 'action': 'query', |
| 37 | + 'prop': 'revisions', |
| 38 | + 'titles': $currentArticle, |
| 39 | + 'rvlimit': 1, |
| 40 | + 'rvprop': 'timestamp', |
| 41 | + 'format': 'json' |
| 42 | + }; |
| 43 | + $.ajax( { |
| 44 | + 'url': mw.util.wikiScript( 'api' ), |
| 45 | + 'data': sendData, |
| 46 | + 'dataType': 'json', |
| 47 | + 'type': 'GET', |
| 48 | + 'success': function( data ) { |
| 49 | + if ( !data || !data.query || !data.query.pages ) { |
| 50 | + // Show error |
| 51 | + return; |
| 52 | + } |
| 53 | + $.each( data.query.pages, function( id, page ) { |
| 54 | + if ( page.revisions[0].timestamp && page.revisions[0].timestamp.length ) { |
| 55 | + //$( '#ptr-stuff' ).append( page.revisions[0].timestamp ); |
| 56 | + } |
| 57 | + }); |
| 58 | + } |
| 59 | + } ); |
| 60 | + |
| 61 | + // Load the article into the page |
| 62 | + $( '#ptr-stuff' ).load( |
| 63 | + mw.config.get( 'wgServer' ) |
| 64 | + + mw.config.get( 'wgScriptPath' ) |
| 65 | + + '/index.php?title=' + encodeURIComponent( $currentArticle ) + '&action=render' |
| 66 | + ); |
| 67 | + |
35 | 68 | } |
36 | 69 | }; |
37 | 70 | |