User:Ucucha/autofc.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:Ucucha/autofc. |
/* autofc.js
* Provides automatic FAC nomination capacity. Based on [[User:AzaToth/twinklexfd.js]].
* Experimental.
*/
// If TwinkleConfig aint exist.
if( typeof( TwinkleConfig ) == 'undefined' ) {
TwinkleConfig = {};
}
/**
TwinkleConfig.xfdWatchDiscussion (string)
The watchlist setting of the newly created XfD page. Either "yes", "no", or "default". Default is "default" (Duh).
*/
if( typeof( TwinkleConfig.xfdWatchDiscussion ) == 'undefined' ) {
TwinkleConfig.xfdWatchDiscussion = "default";
}
/**
TwinkleConfig.xfdWatchPage (string)
The watchlist setting of the page listed for XfD. Either "yes", "no", or "default". Default is "default" (Duh).
*/
if( typeof( TwinkleConfig.xfdWatchPage) == 'undefined' ) {
TwinkleConfig.xfdWatchPage= "default";
}
/**
TwinkleConfig.xfdWatchList (string)
The watchlist setting of xfd list page, *if* the discussion is on a separate page. Either "yes", "no", or "default". Default is "no" (Hehe. Seriously though, who wants to watch it? Sorry in advance for any false positives.).
*/
if( typeof( TwinkleConfig.xfdWatchList ) == 'undefined' ) {
TwinkleConfig.xfdWatchList = "no";
}
/**
TwinkleConfig.summaryAd (string)
If ad should be added or not to summary, default [[WP:TWINKLE|TWINKLE]]
*/
if( typeof( TwinkleConfig.summaryAd ) == 'undefined' ) {
TwinkleConfig.summaryAd = " using [[User:Ucucha/autofc|autofc]]";
}
function num2order( num ) {
switch( num ) {
case 1: return '1';
case 2: return '2nd';
case 3: return '3rd';
default: return num + 'th';
}
}
function autofc() {
if( wgNamespaceNumber < 0 || wgCurRevisionId == false ) {
return;
}
if (twinkleConfigExists)
{
twAddPortletLink( "javascript:autofc.callback()", "FC", "au-fc", "Featured content nomination", "");
}
else
{
twAddPortletLink( 'javascript:alert("Your account is too new to use Twinkle.");', 'FC', 'au-fc', 'Featured content nomination', '');
}
}
window.TwinkleInit = (window.TwinkleInit || []).concat(autofc); //schedule initializer
autofc.callback = function autofcCallback() {
var Window = new SimpleWindow( 600, 325 );
Window.setTitle( "Featured content nomination" );
var form = new QuickForm( autofc.callback.evaluate );
var categories = form.append( {
type: 'select',
name: 'category',
label: 'Select wanted type of category: ',
tooltip: 'When activated, a default choice is made, based on what namespace you are in. This default should be the most appropriate',
event: autofc.callback.change_category
} );
categories.append( {
type: 'option',
label: 'FAC',
selected: wgNamespaceNumber == Namespace.MAIN,
value: 'fac'
} );
categories.append( {
type: 'option',
label: 'FLC',
selected: false,
value: 'flc'
} );
categories.append( {
type: 'option',
label: 'FPC',
selected: wgNamespaceNumber == Namespace.IMAGE,
value: 'fpc'
} );
categories.append( {
type: 'option',
label: 'FSC',
selected: false,
value: 'fsc'
} );
categories.append( {
type: 'option',
label: 'FPOC',
selected: wgNamespaceNumber == Namespace.PORTAL ,
value: 'fpoc'
} );
form.append( {
type: 'field',
label:'Work area',
name: 'work_area'
} );
var result = form.render();
Window.setContent( result );
Window.display();
// We must init the
var evt = document.createEvent( "Event" );
evt.initEvent( 'change', true, true );
result.category.dispatchEvent( evt );
}
autofc.callback.change_category = function autofcCallbackChangeCategory(e) {
var value = e.target.value;
var root = e.target.form;
var old_area;
var childNodes = root.childNodes;
for( var i = 0; i < childNodes.length; ++i ) {
var node = childNodes[i];
if(
node instanceof Element &&
node.getAttribute( 'name' ) == 'work_area'
) {
old_area = node;
break;
}
}
var work_area = null;
switch( value ) {
case 'fac':
work_area = new QuickForm.element( {
type: 'field',
label: 'Ucucha/FAC',
name: 'work_area'
} );
work_area.append( {
type: 'textarea',
name: 'fcreason',
label: 'Reason: '
} );
work_area.append( { type:'submit' } );
work_area = work_area.render();
old_area.parentNode.replaceChild( work_area, old_area );
break;
case 'flc':
work_area = new QuickForm.element( {
type: 'field',
label: 'Featured list candidates',
name: 'work_area'
} );
work_area.append( {
type: 'textarea',
name: 'fcreason',
label: 'Reason: '
} );
work_area.append( { type:'submit' } );
work_area = work_area.render();
old_area.parentNode.replaceChild( work_area, old_area );
break;
case 'fpc':
work_area = new QuickForm.element( {
type: 'field',
label: 'Featured picture candidates',
name: 'work_area'
} );
work_area.append( {
type: 'textarea',
name: 'fcreason',
label: 'Reason: '
} );
work_area.append( { type:'submit' } );
work_area = work_area.render();
old_area.parentNode.replaceChild( work_area, old_area );
break;
case 'fsc':
work_area = new QuickForm.element( {
type: 'field',
label: 'Featured sound candidates',
name: 'work_area'
} );
work_area.append( {
type: 'textarea',
name: 'fcreason',
label: 'Reason: '
} );
work_area.append( { type:'submit' } );
work_area = work_area.render();
old_area.parentNode.replaceChild( work_area, old_area );
break;
case 'fpoc':
work_area = new QuickForm.element( {
type: 'field',
label: 'Featured portal candidates',
name: 'work_area'
} );
work_area.append( {
type: 'textarea',
name: 'fcreason',
label: 'Reason: '
} );
work_area.append( { type:'submit' } );
work_area = work_area.render();
old_area.parentNode.replaceChild( work_area, old_area );
break;
default:
work_area = new QuickForm.element( {
type: 'field',
label: 'Nothing for anything',
name: 'work_area'
} );
work_area = work_area.render();
old_area.parentNode.replaceChild( work_area, old_area );
break;
}
}
autofc.callbacks = {
fac: {
main: function ( self ) {
var xmlDoc = self.responseXML;
var titles = xmlDoc.evaluate( '//allpages/p/@title', xmlDoc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null );
// There has been no earlier entries with this prefix, just go on.
if( titles.snapshotLength <= 0 ) {
self.params.numbering = self.params.number = '';
numbering = number = '';
} else {
var number = 0;
for( var i = 0; i < titles.snapshotLength; ++i ) {
var title = titles.snapshotItem(i).value;
// First, simple test, is there an instance with this exact name?
if( title == 'User:Ucucha/FAC/' + wgPageName + '/archive1') {
number = Math.max( number, 1 );
continue;
}
var order_re = new RegExp( '^' +
RegExp.escape( 'User:Ucucha/FAC/' + wgPageName, true ) +
'/archive?'
);
var match = order_re.exec( title );
// No match; A non-good value
if( match == null ) {
continue;
}
// A match, set number to the max of current
number = Math.max( number, Number(match[1]) );
}
self.params.number = parseInt( number ) + 1;
self.params.numbering = number > 0 ? '/archive' + self.params.number : '/archive1';
}
Status.info( 'Next discussion page","[[User:Ucucha/FAC/' + wgPageName + self.params.numbering + ']]' );
// Discussion page
var query = {
'title': 'User:Ucucha/FAC/' + wgPageName + self.params.numbering,
'action': 'submit'
};
// Updating data for the action completed event
Wikipedia.actionCompleted.redirect = query['title'];
Wikipedia.actionCompleted.notice = "Nomination completed, now redirecting to the discussion page";
var wikipedia_wiki = new Wikipedia.wiki( 'Creating FAC nomination page', query, autofc.callbacks.fac.discussionPage );
wikipedia_wiki.params = self.params;
wikipedia_wiki.get();
// Tagging article
var query = {
'title': 'Talk:' + wgPageName,
'action': 'submit'
};
var wikipedia_wiki = new Wikipedia.wiki( 'Adding nomination tag to article talk page', query, autofc.callbacks.fac.article );
wikipedia_wiki.params = self.params;
wikipedia_wiki.get();
// Today's list
var date = new Date();
query = {
'title': 'User:Ucucha/FAC',
'action': 'submit'
};
var wikipedia_wiki = new Wikipedia.wiki( 'Adding discussion to list', query, autofc.callbacks.fac.todaysList );
wikipedia_wiki.params = self.params;
wikipedia_wiki.followRedirect = true;
wikipedia_wiki.get();
},
article: function( self ) {
var form = self.responseXML.getElementById('editform');
var postData = {
'wpMinoredit': undefined, // Per memo
'wpWatchthis': (TwinkleConfig.xfdWatchPage=="yes" || (TwinkleConfig.xfdWatchPage=="default"&&form.wpWatchthis.checked) ? '' : undefined),
'wpStarttime': form.wpStarttime.value,
'wpEdittime': form.wpEdittime.value,
'wpAutoSummary': form.wpAutoSummary.value,
'wpEditToken': form.wpEditToken.value,
'wpSection': form.wpSection.value,
'wpSummary': "Nominated as a featured article candidate; see [[User:Ucucha/FAC/" + wgPageName + self.params.numbering + ']].'+ TwinkleConfig.summaryAd,
'wpTextbox1': ( self.params.noinclude ? "<noinclude>" : "" ) + "\{\{featured article candidates|" + wgPageName + self.params.numbering + "\}\}" + ( self.params.noinclude ? "</noinclude>" : "" ) + form.wpTextbox1.value
};
self.post( postData );
},
discussionPage: function( self ) {
var form = self.responseXML.getElementById('editform');
var nomtext = "===\[\[\{\{subst:#if:\{\{subst:#titleparts:\{\{subst:PAGENAME\}\}|-1|2\}\}|\{\{subst:#titleparts:\{\{subst:PAGENAME\}\}|-1|2\}\}|\{\{subst:SUBPAGENAME\}\}\}\}\]\]===\n" +
"\{\{subst:void|\[\[Category:Wikipedia featured content templates\]\]\}\}\n" +
"<noinclude>\{\{la|\{\{subst:SUBPAGENAME:Wikipedia:\{\{subst:BASEPAGENAME\}\}\}\}\}\}\n" +
"\{\{Wikipedia:Featured article tools|1=\{\{subst:#if:\{\{subst:#titleparts:\{\{subst:PAGENAME\}\}|-1|2\}\}|\{\{subst:#titleparts:\{\{subst:PAGENAME\}\}|-1|2\}\}|\{\{subst:SUBPAGENAME\}\}\}\}\}\}</noinclude>\n" +
"\n" +
"<!-- Please don't edit anything above here. Be sure to include your reasons for nominating below. -->\n"
":<small>''Nominator(s): [[User talk:Ucucha|Ucucha]] 16:06, 4 December 2010 (UTC)''</small>\n";
var postData = {
'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
'wpWatchthis': (TwinkleConfig.xfdWatchDiscussion=="yes" || (TwinkleConfig.xfdWatchDiscussion=="default"&&form.wpWatchthis.checked) ? '' : undefined),
'wpStarttime': form.wpStarttime.value,
'wpEdittime': form.wpEdittime.value,
'wpAutoSummary': form.wpAutoSummary.value,
'wpEditToken': form.wpEditToken.value,
'wpSection': form.wpSection.value,
'wpSummary': "Creating FAC nomination page for \[\[" + wgPageName + '\]\].' + TwinkleConfig.summaryAd,
'wpTextbox1': nomtext + self.params.reason + " \~\~\~\~"
};
self.post( postData );
},
todaysList: function( self ) {
var form = self.responseXML.getElementById('editform');
var old_text = form.wpTextbox1.value;
var text = old_text.replace( /(<\!-- Add new nominations at the top of the list below this comment. Before nominating, please make sure the article meets the FA criteria. -->\n+)/, "$1\{\{User:Ucucha/FAC/" + wgPageName + self.params.numbering + "\}\}\n");
if( text == old_text ) {
self.statelem.error( 'failed to find target spot for the discussion' );
return;
}
var postData = {
'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
'wpWatchthis': (TwinkleConfig.xfdWatchList=="yes" || (TwinkleConfig.xfdWatchList=="default"&&form.wpWatchthis.checked) ? '' : undefined),
'wpStarttime': form.wpStarttime.value,
'wpEdittime': form.wpEdittime.value,
'wpAutoSummary': form.wpAutoSummary.value,
'wpEditToken': form.wpEditToken.value,
'wpSection': form.wpSection.value,
'wpSummary': "Adding \[\[User:Ucucha/FAC/" + wgPageName + self.params.numbering + '\|FAC\]\] for \[\[' + wgPageName + '\]\].' + TwinkleConfig.summaryAd,
'wpTextbox1': text
};
self.post( postData );
},
}
}
autofc.callback.evaluate = function(e) {
wgPageName = wgPageName.replace( /_/g, ' ' ); // for queen/king/whatever and country!
var type = e.target.category.value;
var reason = e.target.fcreason.value;
Status.init( e.target );
if( type == null ) {
Status.error( 'Error', 'no action given' );
return;
}
switch( type ) {
case 'fac': // FAC
var query = {
'action': 'query',
'list': 'allpages',
'apprefix': 'Ucucha/FAC/' + wgPageName,
'apnamespace': 2,
'apfilterredir': 'nonredirects',
'aplimit': userIsInGroup( 'sysop' ) ? 5000 : 500
};
var wikipedia_api = new Wikipedia.api( 'Tagging article with FAC talk tag', query, autofc.callbacks.fac.main );
wikipedia_api.params = { reason:reason };
wikipedia_api.post();
break;
}
}