if(mw.config.get("wgRelevantUserName")){
var username = mw.config.get("wgRelevantUserName");
var link = mw.util.addPortletLink(
'p-tb',
'#',
'Diblok4',
'pt-diblok4link',
'Add tag diblok4'
);
}
$(link).click(function(){
check = confirm("Do you want to give " + username + "tag?");
if (check) {
alertUser(username);
}
});
function alertUser(username) {
//If page already exists
$.ajax( {
url: mw.util.wikiScript( 'api' ),
type: 'POST',
dataType: 'json',
data: {
format: 'json',
action: 'edit',
title: 'User talk:' + username,
summary: 'menambah tag {{diblok4}}',
nocreate: 1,
appendtext: '\n\n{{subst:' + 'Diblok4}}',
token: mw.user.tokens.get( 'csrfToken' )
}
} ).done(console.log( "Add tag diblok: " + username )
).fail( function ( e, data ){
console.log( e.message );
console.log( JSON.stringify( data ) );
});
//If pages does not exist
$.ajax( {
url: mw.util.wikiScript( 'api' ),
type: 'POST',
dataType: 'json',
data: {
format: 'json',
action: 'edit',
title: 'User:' + username,
title: 'User talk:' + username,
summary: 'menambahkan tag {{diblok4}} ke pengguna: ' + username,
create: 1,
text: '{{subst:' + 'Diblok4}}',
token: mw.user.tokens.get( 'csrfToken' )
}
} ).done(console.log( "add tag diblok: " + username )
).fail( function ( e, data ){
console.log( e.message );
console.log( JSON.stringify( data ) );
});
}
Topic on Project:Support desk
how to fix two title " title : 'User' + username, title: 'User talk' + username, " What wrong?
What are you trying to do? The two title keys in the second mean that only the second one ("User talk") is seen, which is the same as the place above.
@MarkAHershberger: But, Can I create warn in userpage and usertalk, can you provide to me, what is script code?
Murbaut: You can't edit two (or more) pages in a single API request. You have to do separate api calls, one for user and other for user talk.
@Ciencia Al Poder: Can you wrote example ? Murbaut (talk) 21:59, 16 April 2017 (UTC)
Just duplicate the api call code...
Extended content |
---|
if(mw.config.get("wgRelevantUserName")){ var username = mw.config.get("wgRelevantUserName"); var link = mw.util.addPortletLink( 'p-tb', '#', 'Diblok4', 'pt-diblok4link', 'Add tag diblok4' ); } $(link).click(function(){ check = confirm("Do you want to give " + username + "tag?"); if (check) { alertUser(username); } }); function alertUser(username) { //If page already exists $.ajax( { url: mw.util.wikiScript( 'api' ), type: 'POST', dataType: 'json', data: { format: 'json', action: 'edit', title: 'User talk:' + username, summary: 'menambah tag {{diblok4}}', nocreate: 1, appendtext: '\n\n{{subst:' + 'Diblok4}}', token: mw.user.tokens.get( 'csrfToken' ) } } ).done(console.log( "Add tag diblok: " + username ) ).fail( function ( e, data ){ console.log( e.message ); console.log( JSON.stringify( data ) ); }); //If pages does not exist $.ajax( { url: mw.util.wikiScript( 'api' ), type: 'POST', dataType: 'json', data: { format: 'json', action: 'edit', title: 'User:' + username, summary: 'menambahkan tag {{diblok4}} ke pengguna: ' + username, create: 1, text: '{{subst:' + 'Diblok4}}', token: mw.user.tokens.get( 'csrfToken' ) } } ).done(console.log( "add tag diblok: " + username ) ).fail( function ( e, data ){ console.log( e.message ); console.log( JSON.stringify( data ) ); }); $.ajax( { url: mw.util.wikiScript( 'api' ), type: 'POST', dataType: 'json', data: { format: 'json', action: 'edit', title: 'User talk:' + username, summary: 'menambahkan tag {{diblok4}} ke pengguna: ' + username, create: 1, text: '{{subst:' + 'Diblok4}}', token: mw.user.tokens.get( 'csrfToken' ) } } ).done(console.log( "add tag diblok: " + username ) ).fail( function ( e, data ){ console.log( e.message ); console.log( JSON.stringify( data ) ); }); } |