|
|
| (One intermediate revision by the same user not shown) |
| Line 1: |
Line 1: |
| mw.loader.using(['mediawiki.util', 'mediawiki.api'], function() {
| |
| var api = new mw.Api();
| |
|
| |
| // Fetch MediaWiki:Footer content
| |
| api.get({
| |
| action: 'parse',
| |
| page: 'MediaWiki:Footer',
| |
| prop: 'wikitext',
| |
| formatversion: 2
| |
| }).done(function(data) {
| |
| if (data.parse && data.parse.wikitext) {
| |
| var footerText = data.parse.wikitext;
| |
| parseFooterLinks(footerText);
| |
| }
| |
| });
| |
| });
| |
|
| |
|
| function parseFooterLinks(text) {
| |
| var lines = text.split('\n');
| |
| var currentPortlet = null;
| |
|
| |
| lines.forEach(function(line) {
| |
| line = line.trim();
| |
|
| |
| // Skip empty lines and comments
| |
| if (!line || line[0] === '#') return;
| |
|
| |
| // Section header: * SectionName
| |
| if (line.match(/^\*\s*[^*]/)) {
| |
| var sectionName = line.replace(/^\*\s*/, '');
| |
| currentPortlet = 'footer-' + sectionName.toLowerCase().replace(/\s+/g, '-');
| |
|
| |
| // Create section container if needed
| |
| if (!document.getElementById(currentPortlet)) {
| |
| var section = document.createElement('div');
| |
| section.id = currentPortlet;
| |
| section.className = 'footer-section';
| |
|
| |
| var title = document.createElement('h4');
| |
| title.textContent = sectionName;
| |
| section.appendChild(title);
| |
|
| |
| var list = document.createElement('ul');
| |
| list.className = 'footer-section-links';
| |
| section.appendChild(list);
| |
|
| |
| $('.post-content.footer-content').append(section);
| |
| }
| |
| }
| |
| // Link item: ** target|text
| |
| else if (line.match(/^\*\*/)) {
| |
| var linkText = line.replace(/^\*\*\s*/, '');
| |
| var parts = linkText.split('|');
| |
| var target = parts[0].trim();
| |
| var text = parts.length > 1 ? parts[1].trim() : target;
| |
|
| |
| // Determine URL
| |
| var url;
| |
| if (target.match(/^https?:\/\//)) {
| |
| url = target;
| |
| } else if (target.indexOf('Special:') === 0) {
| |
| url = mw.util.getUrl(target);
| |
| } else {
| |
| url = mw.util.getUrl(target);
| |
| }
| |
|
| |
| if (currentPortlet) {
| |
| mw.util.addPortletLink(currentPortlet, url, text);
| |
| }
| |
| }
| |
| });
| |
| }
| |