Tags: Mobile edit Mobile web edit |
Tags: Manual revert Mobile edit Mobile web edit |
| (13 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| /* Any JavaScript here will be loaded for all users on every page load. */ | | /* Any JavaScript here will be loaded for all users on every page load. */ |
|
| |
| /**
| |
| * MediaWiki Common.js - Sort Special:AllPages alphabetically A-Z
| |
| * This script reorganizes the page listing on Special:AllPages to display
| |
| * pages in strict alphabetical order from A to Z
| |
| */
| |
|
| |
| (function() {
| |
| 'use strict';
| |
|
| |
| // Only run on Special:AllPages
| |
| if (mw.config.get('wgCanonicalSpecialPageName') !== 'Allpages') {
| |
| return;
| |
| }
| |
|
| |
| // Wait for the page to fully load
| |
| mw.loader.using(['mediawiki.util'], function() {
| |
| $(document).ready(function() {
| |
| sortAllPages();
| |
| });
| |
| });
| |
|
| |
| function sortAllPages() {
| |
| // Find the content area containing the page list
| |
| var $content = $('.mw-allpages-body, .mw-allpages-chunk');
| |
|
| |
| if ($content.length === 0) {
| |
| // Fallback: try to find the list container
| |
| $content = $('.mw-content-ltr ul').first();
| |
| }
| |
|
| |
| if ($content.length === 0) {
| |
| console.log('AllPages sort: Could not find page list container');
| |
| return;
| |
| }
| |
|
| |
| // Get all list items (pages)
| |
| var $lists = $content.find('ul');
| |
|
| |
| $lists.each(function() {
| |
| var $list = $(this);
| |
| var $items = $list.find('> li').detach();
| |
|
| |
| if ($items.length === 0) {
| |
| return;
| |
| }
| |
|
| |
| // Sort items alphabetically
| |
| $items.sort(function(a, b) {
| |
| var textA = $(a).text().trim().toUpperCase();
| |
| var textB = $(b).text().trim().toUpperCase();
| |
|
| |
| // Remove any leading special characters for sorting
| |
| textA = textA.replace(/^[^A-Z0-9]+/i, '');
| |
| textB = textB.replace(/^[^A-Z0-9]+/i, '');
| |
|
| |
| if (textA < textB) return -1;
| |
| if (textA > textB) return 1;
| |
| return 0;
| |
| });
| |
|
| |
| // Re-append sorted items
| |
| $items.each(function() {
| |
| $list.append(this);
| |
| });
| |
| });
| |
|
| |
| console.log('AllPages sort: Pages sorted alphabetically A-Z');
| |
| }
| |
| })();
| |