import java.net.MalformedURLException;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.Stack;
import net.sourceforge.jwbf.actions.mw.util.ActionException;
import net.sourceforge.jwbf.actions.mw.util.ProcessException;
import net.sourceforge.jwbf.bots.MediaWikiBot;
import net.sourceforge.jwbf.contentRep.mw.Article;
import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;
/**
* @author pixeltoo
*
*/
public class Basic
{
private static int CATEGORY_NAMESPACE=14;
private static String strText;
public static void main(String[] args) {
MediaWikiBot b;
try {
b = new MediaWikiBot("http://fr.wiki.x.io/w/");
try {
b.login("Ir4ubot", "****");
Iterable<String> i;
try {
i = b.getCategoryMembers("Article à wikifier",CATEGORY_NAMESPACE);
int iCounter=0;
i.toString();
Iterator<String> j = i.iterator();
Hashtable ht = new Hashtable(50);
Stack<DataBar> stackDataBar=new Stack<DataBar>();
int iTemp=0;
while(j.hasNext())
{
String strCategory=j.next();
Iterable<String> k=b.getCategoryMembers(strCategory.replace("Catégorie:", ""));
System.out.println("*[["+strCategory+"]]");
Iterator<String> articleIterator = k.iterator();
int articleCounter =0;
while(articleIterator.hasNext())
{
articleIterator.next();
//System.out.println("**[["+l.next()+"]]");
articleCounter++;
}
DataBar dtb=new DataBar();
dtb.setIBegin(iTemp);
iTemp=iTemp+articleCounter;
dtb.setIEnd(iTemp);
dtb.setStrLink(strCategory);
dtb.setStrText(strCategory.replace("Catégorie:Article à wikifier depuis ", ""));
dtb.setStrName(firstToUpperCase(removeDiacritics(strCategory.replace("Catégorie:Article à wikifier depuis ", "")).replace(" ", "")));
stackDataBar.push(dtb);
ht.put(strCategory, articleCounter);
System.out.println(articleCounter+" articles");
iCounter++;
}
System.out.println(iCounter+" catégories");
ListIterator<DataBar> li,lk;
li=stackDataBar.listIterator();
lk=stackDataBar.listIterator();
strText="";
//strText+="<timeline>";
//strText+="<pre style=\"overflow:auto;\">";
strText+="ImageSize = width:800 height:auto barincrement:25\n";
strText+="PlotArea = left:15 right:30 bottom:30 top:15\n";
strText+="Colors =\n";
strText+=" id:canvas value:rgb(0.97,0.99,1)\n";
strText+=" id:Title value:rgb(0.97,0.97,0.97)\n";
strText+=" id:2006 value:rgb(0.78,0.8,0.8)\n";
strText+=" id:Total value:rgb(0.8,0.8,1)\n";
strText+=" id:grid1 value:rgb(0.80,0.80,0.80)\n";
strText+=" id:grid2 value:rgb(0.90,0.90,0.90)\n";
strText+="Period = from:0 till:1500\n";
strText+="TimeAxis = orientation:horizontal\n";
strText+="ScaleMajor = unit:year increment:1000 start:0 gridcolor:grid1\n";
strText+="ScaleMinor = unit:year increment:50 start:0 gridcolor:grid2\n";
strText+="AlignBars = justify\n";
strText+="BackgroundColors = canvas:canvas bars:canvas\n\n\n\n";
strText+="BarData =\n";
strText+=" bar:Titlebar\n";
while(lk.hasNext())
{
strText+=" "+"bar:"+lk.next().getStrName()+"\n";
}
strText+="PlotData =\n";
strText+=" width:18 fontsize:M textcolor:black align:center\n";
strText+=" bar:Titlebar color:Title shift:(0, -4)\n";
strText+=" from:start till:end text: \"Avancement (le 20 janvier 2009)\"\n";
strText+=" width:18 fontsize:M textcolor:white anchor:from align:left\n\n";
strText+=" color:2006\n";
strText+=" shift:(4, -4)\n\n\n\n";
while(li.hasNext())
{
strText+=li.next()+"\n";
}
//strText+="</timeline>";
//strText+="</pre>";
Article a;
a=new Article("", "Utilisateur:Ir4ubot/Brouillon", b);
a.setEditSummary("replace text ");
System.out.println(strText);
a.addText("<pre style=\"overflow:auto;\">"+strText+"</pre>\n<timeline>"+strText+"</timeline>"); //replace text by strText
System.out.println(a.getLabel());
try {
b.writeContent(a);
} catch (ProcessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ProcessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} catch (ActionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static String removeDiacritics(String s) {
s = s.replaceAll("[èéêë]","e");
s = s.replaceAll("[ûù]","u");
s = s.replaceAll("[ïî]","i");
s = s.replaceAll("[àâ]","a");
s = s.replaceAll("Ô","o");
s = s.replaceAll("[ÈÉÊË]","E");
s = s.replaceAll("[ÛÙ]","U");
s = s.replaceAll("[ÏÎ]","I");
s = s.replaceAll("[ÀÂ]","A");
return s ;
}
public static String firstToUpperCase(String s)
{
return s.substring(0,1).toUpperCase() + s.substring(1);
}
}
public class DataBar {
private String strName;
private int iBegin;
private int iEnd;
private String strText;
private String strLink;
/**
* @param iBegin the iBegin to set
*/
public void setIBegin(int iBegin) {
this.iBegin = iBegin;
}
/**
* @return the iBegin
*/
public int getIBegin() {
return iBegin;
}
/**
* @param iEnd the iEnd to set
*/
public void setIEnd(int iEnd) {
this.iEnd = iEnd;
}
/**
* @return the iEnd
*/
public int getIEnd() {
return iEnd;
}
/**
* @param strText the strText to set
*/
public void setStrText(String strText) {
this.strText = strText;
}
/**
* @return the strText
*/
public String getStrText() {
return strText;
}
/**
* @param strLink the strLink to set
*/
public void setStrLink(String strLink) {
this.strLink = strLink;
}
/**
* @return the strLink
*/
public String getStrLink() {
return strLink;
}
public String toString()
{
return " bar:"+this.getStrName()+"\n from:"+this.getIBegin()+" till:"+this.getIEnd()+" text: \"[[:"+this.getStrLink()+"|"+this.getStrText()+" : "+this.getWidth()+" articles]]\" textcolor:black ";
}
public int getWidth()
{
return iEnd-iBegin;
}
/**
* @param strName the strName to set
*/
public void setStrName(String strName) {
this.strName = strName;
}
/**
* @return the strName
*/
public String getStrName() {
return strName;
}
}