MediaWiki:Common.js: Difference between revisions

no edit summary
No edit summary
No edit summary
Tag: Undo
 
(17 intermediate revisions by the same user not shown)
Line 12: Line 12:
  * dependency hasn't arrived yet it'll make sure those are loaded before this.
  * dependency hasn't arrived yet it'll make sure those are loaded before this.
  */
  */
// see [[Wikinews:Commentary pages on news events]].
// ==========================================================================
// MediaWiki interface button for Comments page based on [[commons:mediawiki:extra-tabs.js]].
// Originally written by Dbenbenn, Avatar, Duesentrieb and Arnomane
// Modified by bawolff for wikinews. fixed by darklama
// re-written by bawolff in may 2010.
//
// If copying to another wiki, this also needs some css as well.
// Run a background check of api.php to see if the particular page exists,
// so a non-existing comment page can be red, and an existing comment page
// will look like a normal tab.
// This would be better if it could check multiple pages with one query.
var checkCommentaryPageExist = function (pageName, id, query) {
pageName = mw.util.wikiUrlencode( pageName );
var success = function (x) {
if ( !x || !x.query || !x.query.pages ) {
mw.log( "Error getting redlinks for opinion tab" );
return;
}
if ( x.query.pages['-1'] ) {
// Means its missing.
var url = mw.config.get( 'wgScriptPath' ) +
'/index.php?action=edit&redlink=1&title=' + pageName + '&' + query;
$( '#' + id + ' a' ).attr( 'href', url )
$( '#' + id ).addClass( 'new' );
}
}
$.ajax(
mw.config.get( 'wgScriptPath' ) + '/api.php?action=query&format=json&titles=' + pageName,
).then(success);
}
$( function () {
// Interface strings, if translating, change only these.
var OpinionTabName = 'Opinions';
var TalkTabName = 'Collaboration';
var ArticleTabName = 'Article';
var OpinionTabTooltip = 'Discuss your personal viewpoint on the topic at hand';
var OpinionNS = 102;
// Extra things to add to edit urls:
var OpinionParams = 'preload=Wikinews:Commentary_pages_on_news_events/body&editintro=Template:Editintro_comments&summary=create';
                // [[Wikinews:Commentary pages on news events/body]] [[Template:Editintro comments]]
// End stuff to translate.
// -------------------
var title = mw.config.get('wgTitle');
var skin = mw.config.get('skin');
if (title === 'Main Page') return;
var portlet = skin === 'vector' ? 'p-namespaces' : 'p-cactions';
switch(mw.config.get('wgNamespaceNumber')) {
case 1:
case 0:
var targetPage = mw.config.get( 'wgFormattedNamespaces' )[OpinionNS] + ':' + title;
var url = mw.util.getUrl( targetPage );
var res = mw.util.addPortletLink(
'p-namespaces',
url,
OpinionTabName,
'ca-comments',
OpinionTabTooltip
);
if ( !res ) {
// No p-namespaces portal. Must be monobook then.
var res2 = mw.util.addPortletLink(
'p-cactions',
url,
OpinionTabName,
'ca-comments',
OpinionTabTooltip,
undefined, /* accesskey */
$('#ca-edit') /* nextnode */
);
if ( !res2 ) {
mw.log( "Error adding opinions tab" );
}
}
checkCommentaryPageExist(targetPage, 'ca-comments', OpinionParams);
      break;
case 90: /* LQT thread */
var targetPage = mw.config.get( 'wgTitle' ).replace(/\/.*$/, '');
var talkTarget = mw.config.get( 'wgFormattedNamespaces' )[1] + ':' + targetPage;
var before =  document.getElementById('ca-nstab-thread');
var talk = mw.util.addPortletLink(
portlet,
mw.util.getUrl( talkTarget ),
TalkTabName,
"ca-main-talk", undefined, undefined, before
);
mw.util.addPortletLink(
portlet,
mw.util.getUrl( targetPage ),
ArticleTabName,
"ca-nstab-main",
undefined, undefined, talk
);
checkCommentaryPageExist(targetPage, 'ca-nstab-main', '');
checkCommentaryPageExist(talkTarget, 'ca-main-talk', '');
break;
case OpinionNS:
var targetPage = mw.config.get( 'wgTitle' );
var talkTarget = mw.config.get( 'wgFormattedNamespaces' )[1] + ':' + targetPage;
var before = document.getElementById('ca-nstab-' +
mw.config.get( 'wgFormattedNamespaces' )[OpinionNS].toLowerCase() );
var talk = mw.util.addPortletLink(
portlet,
mw.util.getUrl( talkTarget ),
TalkTabName,
"ca-main-talk", undefined, undefined, before
);
mw.util.addPortletLink(
portlet,
mw.util.getUrl( targetPage ),
ArticleTabName,
"ca-nstab-main",
undefined, undefined, talk
);
checkCommentaryPageExist(targetPage, 'ca-nstab-main', '');
checkCommentaryPageExist(talkTarget, 'ca-main-talk', '');
break;
/* do stuff */
}
});


/* global mw, $ */
/* global mw, $ */
Line 159: Line 27:
if ( mw.config.get( 'wgPageName' ) === 'Main_Page' || mw.config.get( 'wgPageName' ) === 'Talk:Main_Page' ) {
if ( mw.config.get( 'wgPageName' ) === 'Main_Page' || mw.config.get( 'wgPageName' ) === 'Talk:Main_Page' ) {
$( function () {
$( function () {
mw.util.addPortletLink( 'p-lang', '//meta.wikimedia.org/wiki/List_of_Wikipedias',
mw.util.addPortletLink( 'p-lang', '//meta.bharatmedia.org/wiki/List_of_Bharatpedias',
'Complete list', 'interwiki-completelist', 'Complete list of Wikipedias' );
'Complete list', 'interwiki-completelist', 'Complete list of Bharatpedias' );
} );
} );
}
}
Line 193: Line 61:
if ( extraCSS ) {
if ( extraCSS ) {
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
mw.loader.load( '/w/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
mw.loader.load( '/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
} else {
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
Line 201: Line 69:
if ( extraJS ) {
if ( extraJS ) {
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
mw.loader.load( '/w/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
mw.loader.load( '/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
} else {
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
}
}
}
}
/**
* WikiMiniAtlas
*
* Description: WikiMiniAtlas is a popup click and drag world map.
*              This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
*              The script itself is located on meta because it is used by many projects.
*              See [[Meta:WikiMiniAtlas]] for more information.
* Note - use of this service is recommended to be replaced with mw:Help:Extension:Kartographer
*/
$( function () {
var requireWikiminiatlas = $( 'a.external.text[href*="geohack"]' ).length || $( 'div.kmldata' ).length;
if ( requireWikiminiatlas ) {
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' );
}
} );


/**
/**
Line 452: Line 304:
/* End of mw.loader.using callback */
/* End of mw.loader.using callback */
} );
} );
/* DO NOT ADD CODE BELOW THIS LINE */
/* DO NOT ADD CODE BELOW THIS LINE */