User:Suyash.dwivedi/common.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
importScript('User:Kanonkas/twinkle.js');
importScript('User:Majora/LicenseReview.js');
window.hotcat_single_changes_are_minor = false; // Or true
importScript('User:Perhelion/justReplace.js');
if (mw.config.get('wgNamespaceNumber') === 6 && /SVG/i.test(mw.config.get('wgTitle').slice(-3)))
	importScript('User:Perhelion/simpleSVGcheck.js');
mw.loader.load( 'ext.gadget.VisualFileChange' );
window.vFC_PortletText = 'Suyash-Visual File Change';
importScript('https://de.wikipedia.org/w/index.php?title=Benutzer:DerHexer/massendiskus.js');
////////////////////////
$(document).ready(function() {
    // Function to fetch total files by a specific user and calculate pagination
    function fetchTotalFiles(username, itemsPerPage) {
        $.getJSON(
            mw.util.wikiScript('api'), 
            {
                action: 'query',
                list: 'usercontribs',
                ucuser: username,
                uclimit: 'max', // Fetch max items to get the count
                ucnamespace: 6, // Namespace for files
                format: 'json'
            },
            function(data) {
                const totalItems = data.query.usercontribs.length;
                const totalPages = Math.ceil(totalItems / itemsPerPage);
                createPagination(currentPage, totalPages);
            }
        );
    }

    // Function to create and display pagination
    function createPagination(currentPage, totalPages) {
        const paginationContainer = $('#pagination-container');
        paginationContainer.empty(); // Clear previous pagination

        // Create Previous Page Link
        const prevPage = $('<a>', {
            text: 'Previous',
            href: currentPage > 1 ? `?page=${currentPage - 1}` : '#',
            class: currentPage > 1 ? '' : 'disabled',
            click: function(event) {
                if (currentPage === 1) event.preventDefault(); // Disable link if on the first page
            }
        }).appendTo(paginationContainer);

        // Create Page Number List
        for (let i = 1; i <= totalPages; i++) {
            const pageLink = $('<a>', {
                text: i,
                href: `?page=${i}`,
                class: i === currentPage ? 'active' : '',
            }).appendTo(paginationContainer);
        }

        // Create Next Page Link
        const nextPage = $('<a>', {
            text: 'Next',
            href: currentPage < totalPages ? `?page=${currentPage + 1}` : '#',
            class: currentPage < totalPages ? '' : 'disabled',
            click: function(event) {
                if (currentPage === totalPages) event.preventDefault(); // Disable link if on the last page
            }
        }).appendTo(paginationContainer);
    }

    // Example dynamic values (these should be set based on your actual pagination)
    const currentPage = 1; // Replace with the actual current page number dynamically
    const itemsPerPage = 20; // Set this based on user selection or default

    // Fetch total files for the specific user and create pagination
    fetchTotalFiles('Suyash.dwivedi', itemsPerPage);
});
////////////////////////////////////