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.
//tool that creates a gallery of the current search results and saves// modified from User:Aschroet/gallery.js// Changes:// * change some string indexers to dot notation// * change from powerSearchText to searchText//HACK:vargalleryPage="User:BMacZero/Search results";functionhttpGet(theUrl){varxmlHttp=null;xmlHttp=newXMLHttpRequest();xmlHttp.open("GET",theUrl,false);xmlHttp.send(null);returnxmlHttp.responseText;}functiongetedittoken(){varjsonStr=httpGet("/w/api.php?action=query&prop=info&intoken=edit&titles=Main%20Page&format=json");varjson=JSON.parse(jsonStr);varitems=json.query.pages;for(varkeyinitems){returnitems[key].edittoken;}}functionsaveGallery(gallery,query){vareditToken=getedittoken();$.ajax({url:mw.util.wikiScript('api'),data:{format:'json',action:"edit",title:galleryPage,summary:"query: '"+query+"'",text:gallery,token:editToken},dataType:'json',type:'POST',success:function(data){if(data&&data.edit&&data.edit.result=='Success'){alert(galleryPage+" updated!");}elseif(data&&data.error){alert('Error: API returned error code "'+data.error.code+'": '+data.error.info);}else{alert('Error: Unknown result from API.');}},error:function(xhr){alert('Error: Request failed.');}});}// main methodif(typeofgalleryPage==='undefined'){alert("Variable 'galleryPage' must be defined before executing this script!");exit();}varelement=document.getElementById("ooui-php-1");//("searchText");if(element===null){alert("Please first perform a search and then use this feature!");exit();}varquery=element.getAttribute("value");varoffset=0;varmaxLoops=50;varres="<gallery>\n";varfileCnt=0;for(vari=0;i<maxLoops;i++){varjsonStr=httpGet("/w/api.php?format=json&list=search&srlimit=max&action=query&continue=&srnamespace=6&srsearch="+query+"&sroffset="+offset);varjson=JSON.parse(jsonStr);varitems=json.query.search;for(varkeyinitems){res+=items[key].title+"\n";fileCnt++;}if(typeofjson["continue"]!='undefined'){offset=json["continue"].sroffset;}else{break;}}res+="</gallery>";if(confirm("Updating '"+galleryPage+"' with a gallery containing "+fileCnt+" files?")){saveGallery(res,query);}