New Immissions/Updates:
boundless - educate - edutalab - empatico - es-ebooks - es16 - fr16 - fsfiles - hesperian - solidaria - wikipediaforschools
- wikipediaforschoolses - wikipediaforschoolsfr - wikipediaforschoolspt - worldmap -

See also: Liber Liber - Libro Parlato - Liber Musica  - Manuzio -  Liber Liber ISO Files - Alphabetical Order - Multivolume ZIP Complete Archive - PDF Files - OGG Music Files -

PROJECT GUTENBERG HTML: Volume I - Volume II - Volume III - Volume IV - Volume V - Volume VI - Volume VII - Volume VIII - Volume IX

Ascolta ""Volevo solo fare un audiolibro"" su Spreaker.
CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
User:Pseudomonas/AWBPerlWrapperPlugin - Wikipedia, the free encyclopedia

User:Pseudomonas/AWBPerlWrapperPlugin

From Wikipedia, the free encyclopedia

This is a plugin for AWB designed to allow all the processing to be done in the wonderfully friendly and terse language of perl. It's not actually perl-specific, though - it'll run any external program, write the page to its standard input, and read in anything emitted by the standard output or standard error. It ought to be easy enough to produce an equivalent template in any other language.

The first line of the standard output is the status - if it's "CHANGE" the page will be edited, otherwise it'll be skipped. The second line is the edit summary. All the rest is the page contents.

The script must exit with an exit code of 0 otherwise it is deemed to have failed and its standard error will be displayed in a message box.

An alteration in the perl does not require AWB to be restarted.

The C# bit:

// uses code from Wikipedia:AutoWikiBrowser/Plugins.
// Seems to work OK, but very much alpha kludgeware as of sept 06.
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WikiFunctions;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using WikiFunctions.Plugin;
using System.Diagnostics;
using System.ComponentModel;
  
namespace ExamplePlugin
{
   public class ExamplePlugin : IAWBPlugin
   {
       public event PluginEventHandler Diff;
       public event PluginEventHandler Preview;
       public event PluginEventHandler Save;
       public event PluginEventHandler Skip;
       public event PluginEventHandler Start;
       public event PluginEventHandler Stop;
       ToolStripMenuItem menuitem;
       public void Initialise(WikiFunctions.Lists.ListMaker list, WikiFunctions.Browser.WebControl web, ToolStripMenuItem tsmi, ContextMenuStrip cms, TabControl tab, Form frm, TextBox txt)
       {
           //Make our new menu item
           menuitem = new ToolStripMenuItem(Name);
           //Set its check state to true
           menuitem.Checked = true;
           //Make it change its checked state on click
           menuitem.CheckOnClick = true;
           //Add it to the menu
           tsmi.DropDownItems.Add(menuitem);
       }
  
       public string Name
       {
           get { return "Perl Wrapper Plugin"; }
       }
  
         public string ProcessArticle(string ArticleText, string ArticleTitle, int Namespace, ref string Summary, ref bool Skip)
       {
           //If menu item is not checked, then return
           if (!menuitem.Checked)
               return ArticleText;
           //If not mainspace article then return
           if (Namespace != 0)
               return ArticleText;
           string[] perlResults = runPerl(ArticleText);
           string editSummary = perlResults[1];
           string editAction = perlResults[0];
           string newArticle = perlResults[2]; 
             
           if (editAction.Equals("CHANGE")){
              // System.Windows.Forms.MessageBox.Show(editAction);
              // System.Windows.Forms.MessageBox.Show(newArticle);
               ArticleText = newArticle;
               Summary = editSummary;
           }
           else{
               Skip = true;
           }
           return ArticleText;
       }
 
       public void ReadXML(System.Xml.XmlTextReader Reader)
       {
           if (Reader.MoveToAttribute("enabled"))
               menuitem.Checked = bool.Parse(Reader.Value);
       }
 
       public void WriteXML(System.Xml.XmlTextWriter Writer)
       {
           //Write the attributes and values
           Writer.WriteAttributeString("enabled", menuitem.Checked.ToString());
           Writer.WriteAttributeString("anothersetting", "value");
       }
 
       public void Reset()
       {
           //set default settings
           menuitem.Checked = true;
       }
       public static StringBuilder errorString = new StringBuilder("");
       public static StringBuilder perlOut = new StringBuilder("");
 
        public static string[] runPerl(string PageInput)
       {
           errorString.Remove(0, errorString.Length); perlOut.Remove(0, perlOut.Length);
           System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
           psi.FileName = @"C:\perl\bin\wperl.exe"; //or wherever your perl is.
           psi.WindowStyle = ProcessWindowStyle.Minimized;
           
           psi.Arguments = String.Format("\"c:\\program files\\AutoWikiBrowser\\process.pl\" ");
              // adjust as necessary for your script
           psi.RedirectStandardOutput = true;
           psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
           psi.UseShellExecute = false;
           psi.StandardOutputEncoding = Encoding.UTF8;
           psi.StandardErrorEncoding = Encoding.UTF8;
           psi.RedirectStandardError = true;
           psi.RedirectStandardInput = true;
           System.Diagnostics.Process perlProcess;
           perlProcess = System.Diagnostics.Process.Start(psi);
           perlProcess.ErrorDataReceived += new DataReceivedEventHandler(AppendErrorDataReceived);
           perlProcess.OutputDataReceived += new DataReceivedEventHandler(AppendOutDataReceived);
           perlProcess.BeginOutputReadLine();
           perlProcess.BeginErrorReadLine();
           System.IO.StreamWriter myInput = new System.IO.StreamWriter(perlProcess.StandardInput.BaseStream,Encoding.UTF8);
           myInput.Write(PageInput);
           myInput.Flush(); 
           myInput.Close();
           perlProcess.WaitForExit();         
           if (perlProcess.HasExited && perlProcess.ExitCode == 0)
           {
               System.Windows.Forms.MessageBox.Show("OK");
               string perloutputstring = perlOut.ToString();
               int firstnl = perloutputstring.IndexOf("\n", 0);
               int secondnl = perloutputstring.IndexOf("\n", firstnl + 1);
               string[] output = new string[]{
                   perloutputstring.Substring(0,firstnl-1),
                   perloutputstring.Substring(firstnl+1,secondnl-firstnl),
                  perloutputstring.Substring(secondnl,perlOut.Length - secondnl)              
              };
               return output;
           }
           else {
               System.Windows.Forms.MessageBox.Show(errorString.ToString());
               return new string[] { "FAILED", "", "" };
           }
       }
       private static void AppendErrorDataReceived(object sendingProcess,
            DataReceivedEventArgs errLine){
                errorString.AppendLine(errLine.Data);
       }
       private static void AppendOutDataReceived(object sendingProcess,
            DataReceivedEventArgs outLine){
                 perlOut.AppendLine(outLine.Data);
       }   
   }
}


The perl script:

use strict;
use utf8;
binmode( STDOUT, ':utf8' );
binmode( STDIN,  ':utf8' );
binmode( STDERR, ':utf8' );
my $page; while (<STDIN>){$page .= $_};
######################################
#  $editsummary is changeable, naturally
my $action = "CHANGE"; #if it's not "CHANGE" no edit will be made 
my $editsummary = "This is what I did";
######################################
# The business bit goes here
   
 $page =~ s/aeiou//g; # Disemvowel the page. Don't use this live!

# End of business bit
######################################
$action =~ s/\n//g; print "$action\n"; 
$editsummary =~ s/\n//g; print "$editsummary\n";
print $page;
exit 0;

Static Wikipedia (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Static Wikipedia 2007 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Static Wikipedia 2006 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu

Static Wikipedia February 2008 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu