Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* <nowiki> */
/* Bharat Mitra: draft match notice. On a draft page, shows a notice when a
mainspace article with the same name already exists (and is not a redirect). */
( function () {
'use strict';
var BM = window.BharatMitra;
var done = false;
function showNotice( title ) {
if ( document.getElementById( 'bm-draftmatch' ) ) { return; }
var host = document.querySelector( '#mw-content-text' );
if ( !host ) { return; }
var box = document.createElement( 'div' );
box.id = 'bm-draftmatch';
box.setAttribute( 'style', 'border:1px solid #c8a415;background:#fff8e1;color:#333;padding:8px 12px;margin:0 0 12px 0;font-size:95%;' );
var strong = document.createElement( 'strong' );
strong.textContent = 'Article already exists: ';
box.appendChild( strong );
box.appendChild( document.createTextNode( 'an article named ' ) );
var link = document.createElement( 'a' );
link.href = mw.util.getUrl( title );
link.textContent = title;
box.appendChild( link );
box.appendChild( document.createTextNode( ' already exists in mainspace. This draft may be a duplicate of that article.' ) );
host.insertBefore( box, host.firstChild );
}
function check() {
if ( done ) { return; }
if ( mw.config.get( 'wgNamespaceNumber' ) !== 118 ) { return; }
if ( mw.config.get( 'wgIsRedirect' ) ) { return; }
var action = mw.config.get( 'wgAction' );
if ( action !== 'view' && action !== 'edit' && action !== 'submit' ) { return; }
var title = mw.config.get( 'wgTitle' );
if ( !title ) { return; }
done = true;
new mw.Api().get( {
action: 'query',
prop: 'info',
titles: title,
format: 'json'
} ).then( function ( data ) {
var pages = data && data.query && data.query.pages;
if ( !pages ) { return; }
var page = null;
for ( var id in pages ) { page = pages[ id ]; break; }
if ( !page ) { return; }
if ( page.missing !== undefined ) { return; }
if ( page.redirect !== undefined ) { return; }
showNotice( page.title || title );
} ).catch( function () { /* silent */ } );
}
BM.register( 'draftmatch', {
open: check,
check: check
} );
}() );
/* </nowiki> */