User:Topaz/wputil.js: Difference between revisions
Appearance
Content deleted Content added
more lenient wpEditToken regex |
more lenient wpEditToken regex |
||
Line 1: | Line 1: | ||
// <pre><nowiki> |
|||
topaz.wputil = { |
topaz.wputil = { |
||
username:function() { |
username:function() { |
||
Line 47: | Line 49: | ||
} |
} |
||
}; |
}; |
||
// </nowiki></pre> |
Revision as of 01:45, 28 June 2007
// <pre><nowiki>
topaz.wputil = {
username:function() {
return wgUserName;
//return topaz.util.getobj("pt-userpage").childNodes[0].childNodes[0].nodeValue;
},
iseditpage:function() {
return document.title.indexOf("Editing ")==0;
},
pagename:function() {
var iseditpage = topaz.wputil.iseditpage();
return document.title.substr(iseditpage?8:0,document.title.indexOf(" - ")-(iseditpage?8:0));
},
addsidepanel:function(id,label) {
var div = topaz.util.add(topaz.util.getobj("column-one"), "div", {className:"portlet",id:id});
topaz.util.add(div, "H5").innerHTML = label;
topaz.util.add(topaz.util.add(div, "div", {className:"pBody"}), "ul");
},
addsidepanelbutton:function(id,label,targhref) {
var li = topaz.util.add((topaz.util.getobj(id).getElementsByTagName("ul"))[0],"li");
with(topaz.util.add(li,"a")) {
innerHTML = label;
href = targhref;
}
return li;
},
setpagecontent:function(pagename,content,summary,watch) {
var prelimresp = topaz.comm.doreq("/w/index.php?title="+pagename+"&action=submit");
var edittime = prelimresp.responseText.match(/\<input type='hidden' value="(\d+)" name="wpEdittime" \/\>/)[1];
var edittoken = prelimresp.responseText.match(/\<input type='hidden' value="([^"]+)" name="wpEditToken" \/\>/)[1];
topaz.comm.doreq("/w/index.php?title="+pagename+"&action=submit",
"wpEdittime="+edittime+
"&wpEditToken="+edittoken+
"&wpTextbox1="+escape(content)+
"&wpSummary="+escape(summary)+
(watch?"&wpWatchthis=on":"")+
"&wpSection=&wpSave=Save+page",
{"Content-Type":"application/x-www-form-urlencoded"});
},
getpagecontent:function (pagename) {
var req = topaz.comm.doreq("/w/index.php?title="+pagename+"&action=edit");
var content = req.responseText.match(/\<textarea[\w\W]*?\>([\w\W]*?)\<\/textarea\>/)[1];
content = content.replace(/\<\;/gi, "<");
content = content.replace(/\>\;/gi, ">");
content = content.replace(/\"\;/gi, "\"");
content = content.replace(/\&\;/gi, "&");
return content;
}
};
// </nowiki></pre>