[Owasp-o2-platform] O2 Script to do batch edits on the owasp-wiki

dinis cruz dinis.cruz at owasp.org
Tue Feb 1 00:34:06 EST 2011


I just wrote this O2 script to do a number of batch changes to the OWASP
Wiki template that is used to contain the data for the OWASP Summit's
Working Sessions.

Here is one of the 100 pages that was changed
http://www.owasp.org/index.php?title=Summit_2011_Working_Sessions/Session105&diff=prev&oldid=102889

Some of you might find this interesting:

Dinis

-------------------------------

var topPanel = panel.clear().add_Panel();

var credential =
@"C:\O2\_USERDATA\WikiAccounts.xml".credential("OwaspWiki");

var textArea = topPanel.add_TextArea();
var wikiApi = new OwaspWikiAPI(false);
wikiApi.login(credential.username(),credential.password());

var pagesToEdit =
wikiApi.pagesInCategory("Category:Summit_2011_Working_Session");//.save();
//var pagesToEdit =
@"C:\O2\_tempDir\26-01-2011\tmpC27D.tmp.xml".load<List<string>>();

Func<string,string,string,int,string> injectTextBefore =
(sourceText, textToFind, textToReplace,maxId)
=>{
for(int i=1 ; i <= maxId ; i++ )
if (sourceText.contains(textToReplace.format(i)).isFalse())
sourceText =  sourceText.replace(textToFind.format(i),
textToReplace.format(i) + " = ".line() +
    textToFind.format(i));
return sourceText;
  };

Func<string,string,string,int,string> injectTextAfter =
(sourceText, textToFind, textToReplace,maxId)
=>{
for(int i=1 ; i <= maxId ; i++ )
if (sourceText.contains(textToReplace.format(i)).isFalse())
sourceText =  sourceText.replace(textToFind.format(i), textToFind.format(i)
+
 textToReplace.format(i) + " = ".line()
 );
return sourceText;
  };

Action<string> editPage =
(targetPage)=>{
"Editing page: {0}".debug(targetPage);
var originalText = wikiApi.raw(targetPage);
 var text = originalText;
text =  injectTextBefore(text, "| summit_session_attendee_company{0}=", "|
summit_session_attendee_username{0}", 20);
text =  injectTextAfter(text, "| summit_session_leader_email{0} = ".line() ,
"| summit_session_leader_username{0}", 3);
text =  injectTextAfter(text, "| operational_leader_email{0} =".line() , "|
operational_leader_username{0}", 1);
 var wikiUrlToEditCurrentPage = "
http://www.owasp.org/index.php?title={0}&action=edit"
   .format(targetPage);
textArea.append_Line(wikiUrlToEditCurrentPage);
if(originalText != text)
wikiApi.save(targetPage, text);
else
"skipping save for: {0}".debug(targetPage);
 };

foreach(var pageToEdit in pagesToEdit)
editPage(pageToEdit );

return "done";

//return wikiApi.raw(page);

//O2File:OwaspWikiAPI.cs
//O2File:SecretData_ExtensionMethods.cs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.owasp.org/pipermail/owasp-o2-platform/attachments/20110201/50179a65/attachment.html 


More information about the Owasp-o2-platform mailing list