User:Ritchie333/drafts.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Ritchie333/drafts. |
function getDrafts( projectName, continueId ) {
$.ajax( {
type: "GET",
url: mw.util.wikiScript( 'api' ),
data: { action:'query',
list:'embeddedin',
format:'json',
rawcontinue:'',
eititle:'Template:' + projectName,
eidir:'ascending',
eicontinue:continueId,
einamespace:119 },
dataType: 'json',
success: function( data ) {
var results = data.query.embeddedin;
if( results.length > 0 ) {
var titles = '';
var i;
var first = true;
for( i = 0; i < results.length; ++i ) {
if( first ) {
first = false;
} else {
titles += '|';
}
var draftName = results[ i ].title.substr( 'Draft talk:'.length );
titles += ( 'Draft:' + draftName );
}
$.ajax( {
type: "GET",
url: mw.util.wikiScript( 'api' ),
data: {
action:'query',
prop:'categories',
format:'json',
titles:titles,
clcategories:'Category:Pending AfC submissions'
},
dataType: 'json',
success: function( redata ) {
for( var page in redata.query.pages ) {
nextPage = redata.query.pages[ page ];
var pageTitle = nextPage.title;
for( var cat in nextPage.categories ) {
nextCategory = nextPage.categories[ cat ];
if( nextCategory.title === 'Category:Pending AfC submissions' ) {
// Got it
$('#related-drafts').append(
'<a href="' + mw.util.getUrl( pageTitle ) + '">' + pageTitle + '</a><br/>' );
}
}
}
}
});
if ( typeof data[ 'query-continue' ] != 'undefined' ) {
getDrafts( projectName, data[ 'query-continue' ].embeddedin.eicontinue );
}
}
}
});
}
jQuery(function () {
mw.loader.using( ['mediawiki.util'], function () {
if( mw.config.get('wgPageName').indexOf( 'Wikipedia:WikiProject' ) === 0 ) {
if(mw.config.get('wgAction') == 'view' || mw.config.get('wgAction') == 'purge' ){
var portletLink = mw.util.addPortletLink('p-tb', '#', 'Draft list', 't-draft-list', 'List drafts for this project');
$( portletLink ).click( function ( e ) {
e.preventDefault();
var projectName = mw.config.get('wgPageName').substr( 'Wikipedia:'.length );
mw.util.$content.prepend( '<div id="related-drafts"><p>Related drafts</p></div>' );
getDrafts( projectName, undefined /* no continue */ );
} );
}
}
});
});