How do I add Special:PrefixIndex/FULLPAGENAME to t

2019-09-06 00:17发布

问题:

I would like a tool in the sidebar's "Tools" section that takes readers to Special:PrefixIndex/FULLPAGENAME where FULLPAGENAME is replaced with the current page's full name. For example, say I was on the page Module:Citation/CS1 then I would like a tool in the sidebar called Subpages that takes me to Special:PrefixIndex/Module:Citation/CS1. I have seen (the mediawiki sidebar manual) and I added:

function CustomizeModificationsOfSidebar() {
    // Adds PrefixIndex
    var page = mw.config.get( 'wgPageName' );
    ModifySidebar( 'add', 'toolbox', 'Subpages', "http://127.0.0.1/mediawiki/index.php/Special:PrefixIndex/"'page' );
}

jQuery( CustomizeModificationsOfSidebar );

to the page MediaWiki:Common.js. This gave the JavaScript error: Error: Expected ')' and instead saw 'page'. that prevented me from saving the page.

回答1:

Your script is missing a comma, it should be

    ModifySidebar( 'add', 'toolbox', 'Subpages', 'http://127.0.0.1/mediawiki/index.php/Special:PrefixIndex/', 'page' );

Of course, you will have to add the actual ModifySidebar function to.

Alternative approach: Though not recommended in the manual, you can actually use magic words, such as {{FULLPAGENAME}} in MediaWiki:Sidebar, so adding something like this should work:

*Special:PrefixIndex/{{FULLPAGENAME}}|subpages

You might run in to caching troubles, though. Make sure $wgEnableSidebarCache is off in LocalSettings.php (it is by default)

Edit: The comment from Tgr below is also very relevant: This will have performance implications