Jump to content

User:Jim Grisham/common.js: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Added option for highlighting 'redirects with possibilities' (both common.js and common.css edited)
Trying to make LinkClassifier work (better? at all?)
Line 2: Line 2:
"ReferenceError: Can't find variable: WgServer" (may not be verbatium)
"ReferenceError: Can't find variable: WgServer" (may not be verbatium)


Note: Starting with MediaWiki 1.34, $wgServer is set by default to 'false'
Note: Starting with MediaWiki 1.34, $wgServer is set by default to 'false'
*/
*/
/* Error received starting mid-March 2024 on iOS:
/* Error received starting mid-March 2024 on iOS:
Line 9: Line 9:
*/
*/


//
try {

// Mass move tool
// Mass move tool
try {
// [[Wikipedia:Moving a page#Automating multiple subpage moves]]
// [[Wikipedia:Moving a page#Automating multiple subpage moves]]
mw.loader.load( '//en.wikipedia.org/w/index.php?title=User:Plastikspork/massmove.js&action=raw&ctype=text/javascript' ); //[[User:Plastikspork/massmove.js]]
mw.loader.load( '//en.wikipedia.org/w/index.php?title=User:Plastikspork/massmove.js&action=raw&ctype=text/javascript' ); //[[User:Plastikspork/massmove.js]]
mw.util.addPortletLink("p-tb", "//en.wikipedia.org/wiki/Special:Massmove", "Mass move", "p-massmove", "Mass move");
mw.util.addPortletLink("p-tb", "//en.wikipedia.org/wiki/Special:Massmove", "Mass move", "p-massmove", "Mass move");
} catch { };
} catch { };


//

// Add subpage option to sidebar ‘tools’ section
try {
try {
// https://en.wikipedia.org/w/index.php?title=Wikipedia:Do_not_use_subpages&oldid=2836167
//Add subpage option to sidebar ‘tools’ section
// https://en.wikipedia.org/w/index.php?title=Wikipedia:Do_not_use_subpages&oldid=2836167
// https://en.wikipedia.org/wiki/Wikipedia:Subpages#Notes
/*
// https://en.wikipedia.org/wiki/Wikipedia:Subpages#Notes

/* disabled in part on 2024-01-12 to fix 'WgServer' error mentioned above
disabled in part on 2024-01-12 to fix 'WgServer' error mentioned above

*/
*/
mw.util.addPortletLink ('p-tb', /* mw.config.values.wgServerName+ */ mw.config.values.wgArticlePath.replace("$1", "Special:PrefixIndex/"+mw.config.values.wgPageName+"/"), 'Subpages');
mw.util.addPortletLink ('p-tb', /* mw.config.values.wgServerName+ */ mw.config.values.wgArticlePath.replace("$1", "Special:PrefixIndex/"+mw.config.values.wgPageName+"/"), 'Subpages');
} catch { };
} catch { };
//


try {
// Add 'Smart Linking' link preview tool
// Add 'Smart Linking' link preview tool
try {
// [[User:V111P/js/Smart Linking]]
// [[User:V111P/js/Smart Linking]]
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) > -1 ) {
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) > -1 ) {
importScript('User:V111P/js/smartLinkingLoader.js'); // [[User:V111P/js/smartLinkingLoader.js]]
importScript('User:V111P/js/smartLinkingLoader.js'); // [[User:V111P/js/smartLinkingLoader.js]]
}
}
} catch { };
} catch { };
//

try {
// Load linkclassifier tool (is this necessary??) (should be in 'skin.js' and not 'common.js'??)
try {
// Reference: https://en.wikipedia.org/wiki/User:Anomie/linkclassifier
//
// LinkClassifierOnDemand=true; // Places a button next to 'unwatch'?

importScript('User:Anomie/linkclassifier.js'); // Linkback: [[User:Anomie/linkclassifier.js]]
importStylesheet('User:Anomie/linkclassifier.css'); // Linkback: [[User:Anomie/linkclassifier.css]]

/* part 2 for 'OnDemand' mode:
$.when( mw.loader.using( 'mediawiki.util' ), $.ready ).then( function() {
var el = mw.util.addPortletLink('p-cactions', '', 'Link Classifier');
$(el).on('click', function(e) {
LinkClassifier.onDemand();
e.preventDefault();
} );
} );
*/
} catch { };

//

// Highlight 'redirects with possibilities' with a red dashed border
// Highlight 'redirects with possibilities' with a red dashed border
try {
// [[Template:R_with_possibilities/doc#User_script_for_highlighting_links_to_redirects_with_possibilities]]
// [[Template:R_with_possibilities/doc#User_script_for_highlighting_links_to_redirects_with_possibilities]]
mw.hook( 'LinkClassifier' ).add( function ( linkClassifier ) {
mw.hook( 'LinkClassifier' ).add( function ( linkClassifier ) {
linkClassifier.cats['redirect-with-possibilities'] = [ 'Category:Redirects with possibilities' ].sort();
linkClassifier.cats['redirect-with-possibilities'] = [ 'Category:Redirects with possibilities' ].sort();
} );
} );
mw.loader.load('/w/index.php?title=User:Anomie/linkclassifier.js&action=raw&ctype=text/javascript'); // Backlink: [[User:Anomie/linkclassifier]]
mw.loader.load('/w/index.php?title=User:Anomie/linkclassifier.js&action=raw&ctype=text/javascript'); // Backlink: [[User:Anomie/linkclassifier]]
} catch { };
} catch { };

//

// End of common.js

Revision as of 21:42, 19 June 2024

/* Error received from mid-2023 until 2024-01-12:
     "ReferenceError: Can't find variable: WgServer" (may not be verbatium)

    Note:  Starting with MediaWiki 1.34, $wgServer is set by default to 'false'
*/
/* Error received starting mid-March 2024 on iOS:
     "... portlet..."
     "https://en.wikipedia.org/w/index.php?title=User:Jim_Grisham/common.js&action=submit at line 1: TypeError: undefined is not an object (evaluating 'mw.util.addPortletLink')"
*/

//

// Mass move tool
try {
//   [[Wikipedia:Moving a page#Automating multiple subpage moves]]
    mw.loader.load( '//en.wikipedia.org/w/index.php?title=User:Plastikspork/massmove.js&action=raw&ctype=text/javascript' ); //[[User:Plastikspork/massmove.js]]
    mw.util.addPortletLink("p-tb", "//en.wikipedia.org/wiki/Special:Massmove", "Mass move", "p-massmove", "Mass move");
 } catch { };

//

// Add subpage option to sidebar ‘tools’ section
try {
//     https://en.wikipedia.org/w/index.php?title=Wikipedia:Do_not_use_subpages&oldid=2836167
//     https://en.wikipedia.org/wiki/Wikipedia:Subpages#Notes
/*

     disabled in part on  2024-01-12 to fix 'WgServer' error mentioned above

*/
    mw.util.addPortletLink ('p-tb', /* mw.config.values.wgServerName+ */ mw.config.values.wgArticlePath.replace("$1", "Special:PrefixIndex/"+mw.config.values.wgPageName+"/"), 'Subpages');
} catch { };
//

// Add 'Smart Linking' link preview tool
try {
//     [[User:V111P/js/Smart Linking]]
    if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) > -1 ) {
	importScript('User:V111P/js/smartLinkingLoader.js'); // [[User:V111P/js/smartLinkingLoader.js]]
    }
} catch { };
//

// Load linkclassifier tool (is this necessary??) (should be in 'skin.js' and not 'common.js'??)
try {
//     Reference: https://en.wikipedia.org/wiki/User:Anomie/linkclassifier
//
//     LinkClassifierOnDemand=true; // Places a button next to 'unwatch'?

    importScript('User:Anomie/linkclassifier.js'); // Linkback: [[User:Anomie/linkclassifier.js]]
    importStylesheet('User:Anomie/linkclassifier.css'); // Linkback: [[User:Anomie/linkclassifier.css]]

/* part 2 for 'OnDemand' mode:
    $.when( mw.loader.using( 'mediawiki.util' ), $.ready ).then( function() {
        var el = mw.util.addPortletLink('p-cactions', '', 'Link Classifier');
        $(el).on('click', function(e) {
            LinkClassifier.onDemand();
            e.preventDefault();
        } );
    } );
*/
} catch { };

//

// Highlight 'redirects with possibilities' with a red dashed border
try {
//     [[Template:R_with_possibilities/doc#User_script_for_highlighting_links_to_redirects_with_possibilities]]
    mw.hook( 'LinkClassifier' ).add( function ( linkClassifier ) {
        linkClassifier.cats['redirect-with-possibilities'] = [ 'Category:Redirects with possibilities' ].sort();
} );
    mw.loader.load('/w/index.php?title=User:Anomie/linkclassifier.js&action=raw&ctype=text/javascript'); // Backlink: [[User:Anomie/linkclassifier]]
 } catch { };

//

// End of common.js