MediaWiki:Common.js: Difference between revisions

Load the short description under the title
GA: skip missing pages; add site_check parameter to filter fake hits
 
(One intermediate revision by the same user not shown)
Line 41: Line 41:
if ( extraJS ) {
if ( extraJS ) {
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
mw.loader.load( '/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
mw.loader.load( '/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript&maxage=300&smaxage=300' );
} 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' } );
Line 142: Line 142:
var ns = mw.config.get( 'wgNamespaceNumber' );
var ns = mw.config.get( 'wgNamespaceNumber' );
if ( [ 0, 4, 14, 3000 ].indexOf( ns ) === -1 ) {
if ( [ 0, 4, 14, 3000 ].indexOf( ns ) === -1 ) {
return;
}
/* Pages that do not exist (404) are not counted; category pages without text are still counted */
if ( mw.config.get( 'wgArticleId' ) === 0 && ns !== 14 ) {
return;
return;
}
}
Line 165: Line 169:
window.gtag = function () { window.dataLayer.push( arguments ); };
window.gtag = function () { window.dataLayer.push( arguments ); };
window.gtag( 'js', new Date() );
window.gtag( 'js', new Date() );
window.gtag( 'config', id );
/* site_check marks hits sent by this code; reports can be filtered on it to drop fake hits sent straight to Google */
window.gtag( 'set', { site_check: 'cp1' } );
window.gtag( 'config', id, { site_check: 'cp1' } );
}
}
events.forEach( function ( ev ) {
events.forEach( function ( ev ) {
Line 173: Line 179:


/* Related Articles box at the bottom of articles: see [[MediaWiki:RelatedArticles.js]] */
/* Related Articles box at the bottom of articles: see [[MediaWiki:RelatedArticles.js]] */
mw.loader.load( mw.config.get( 'wgScript' ) + '?title=MediaWiki:RelatedArticles.js&action=raw&ctype=text/javascript' );
mw.loader.load( mw.config.get( 'wgScript' ) + '?title=MediaWiki:RelatedArticles.js&action=raw&ctype=text/javascript&maxage=300&smaxage=300' );
/* "Read in Hebrew" button at the top of articles: see [[MediaWiki:ReadInHebrew.js]] */
/* "Read in Hebrew" button at the top of articles: see [[MediaWiki:ReadInHebrew.js]] */
mw.loader.load( mw.config.get( 'wgScript' ) + '?title=MediaWiki:ReadInHebrew.js&action=raw&ctype=text/javascript' );
mw.loader.load( mw.config.get( 'wgScript' ) + '?title=MediaWiki:ReadInHebrew.js&action=raw&ctype=text/javascript&maxage=300&smaxage=300' );
/* Short description under the article title: see [[MediaWiki:ShortDescription.js]] */
/* Short description under the article title: see [[MediaWiki:ShortDescription.js]] */
mw.loader.load( mw.config.get( 'wgScript' ) + '?title=MediaWiki:ShortDescription.js&action=raw&ctype=text/javascript' );
mw.loader.load( mw.config.get( 'wgScript' ) + '?title=MediaWiki:ShortDescription.js&action=raw&ctype=text/javascript&maxage=300&smaxage=300' );