Jump to content

User:Rparle/scripts/purgebutton

From Wikipedia, the free encyclopedia

From User:Rparle/monobook.js/purgebutton:

   /*
    * Add 'Purge' button to list:
    */
   function addPurgeButton()
   {
       var href = document.location.href;
       
       if ( href.search( /^http:\/\/en\.wikipedia\.org\/wiki\// ) == 0 && document.getElementById( "ca-history" ) )
       {    
           var historyHref = document.getElementById( "ca-history" ).firstChild.href;
           var div = document.getElementById( "p-cactions" );
           var ul = div.getElementsByTagName( "ul" )[0];
           var newLi = document.createElement( "li" );
           var newA = document.createElement( "a" );
           newA.setAttribute( "href" , historyHref.replace( "=history" , "=purge" ) );
           var text = document.createTextNode( "Purge Cache" );
           newA.appendChild( text );
           newLi.appendChild( newA );
           ul.appendChild( newLi );
       }
   }
   
   window.addEventListener( "load" , addPurgeButton , false );

This function adds a 'Purge Cache' button beside the 'History' button on every article. The button is used to purge Wikipedia's cache of a page, so that it will be regenerated. This is sometimes necessary when changes are made to a template contained in the page. The function works by comparing the URL of the current page to the regular expression /^http:\/\/en\.wikipedia\.org\/wiki\//, which will match for article pages. It looks for a 'History' button and creates a new button, with the text 'Purge Cache', with the same URL as the 'History' button. The only change is in replacing action=history with action=purge. The new button is appended to the end of the link list so that it appears along with the 'History', 'Edit' and 'Move' buttons.

This function uses the standard functions of the HTML Document Object Model. It has been tested only on Mozilla Firefox and Safari 3.

This function has been convered to a Greasemonkey user script by Thetorpedodog. That version works on most (all?) wikimedia projects.