import java.net.MalformedURLException;
import java.util.Iterator;
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;
/**
* @author pixeltoo
*
*/
public class WikiOpenTask {
private static final int CATEGORY_NAMESPACE = 14;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
MediaWikiBot b;
try {
b = new MediaWikiBot("http://fr.wikipedia.org/w/");
try {
b.login("Ir4ubot", "****");
String strWantedPagesLine = getStrWantedPageLine(b);
String strNotabilityLine = getStrNotabilityLine(b);
String strToBeWikifiedLine =getStrToBeWikifiedLine(b);
String strToBeSourcedLine= getStrToBeSourcedLine(b);
String strToCleanUpLine = getStrToCleanUpLine(b);
String strOpen = "*'''[[Wikipédia:demander un article|Articles à créer]] :''' "+strWantedPagesLine+" ''[[Projet:Articles les plus demandés/1-1000|plus ...]]''\n";
strOpen+="*'''[[Wikipédia:Critères d'admissibilité des articles|Admissibilité à vérifier]]''' : "+strNotabilityLine+" ''[[:Catégorie:Admissibilité à vérifier depuis mai 2008|arriéré ...]]''\n";
strOpen+="*'''[[Aide:Wikification|Articles à wikifier]]''' : "+strToBeWikifiedLine+" ''[[:Catégorie:Article à wikifier depuis mai 2007|arriéré ...]]''\n";
strOpen+="*'''[[Wikipédia:Citez vos sources|Articles à sourcer]]''' : "+strToBeSourcedLine+"''[[:Catégorie:Article manquant de référence depuis mai 2006|arriéré ...]]''\n";
strOpen+="*'''[[:Wikipédia:Recyclage|Articles à recycler]]''' : "+strToCleanUpLine+"''[[:Catégorie:Article à recycler|plus ...]]''";
Article a;
a=new Article("", "Utilisateur:Ir4ubot/Brouillon", b);
a.setEditSummary("update WP:OPEN ");
//System.out.println(strOpen);
a.addText(strOpen);
try {
b.writeContent(a);
} catch (ProcessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ActionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static String getStrToCleanUpLine(MediaWikiBot _bot) {
// TODO Auto-generated method stub
String strTemp=new String();
int iCounter=0;
Iterable<String> iterableStrArticle;
try {
iterableStrArticle = _bot.getCategoryMembers("Article à recycler");
Iterator<String> iteratorStrArticle = iterableStrArticle.iterator();
while(iteratorStrArticle.hasNext())
{
strTemp+="[["+iteratorStrArticle.next()+"]], ";
iCounter++;
if (iCounter>10)
return strTemp;
}
} catch (ActionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ProcessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return strTemp;
}
private static String getStrToBeWikifiedLine(MediaWikiBot _bot) {
// TODO Auto-generated method stub
String strTemp=new String();
int iCounter=0;
try {
Iterable<String> iterableStrCategory;
iterableStrCategory= _bot.getCategoryMembers("Article à wikifier",CATEGORY_NAMESPACE);
Iterator<String> iteratorStrCategory=iterableStrCategory.iterator();
while(iteratorStrCategory.hasNext())
{
String strCategory = iteratorStrCategory.next();
Iterable<String> iterableStrArticle = _bot.getCategoryMembers(strCategory.replace("Catégorie:", ""));
Iterator<String> iteratorStrArticle = iterableStrArticle.iterator();
while(iteratorStrArticle.hasNext())
{
strTemp+="[["+iteratorStrArticle.next()+"]], ";
iCounter++;
if (iCounter>10)
return strTemp;
}
}
} catch (ActionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ProcessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return strTemp;
}
private static String getStrToBeSourcedLine(MediaWikiBot _bot) {
// TODO Auto-generated method stub
String strTemp=new String();
int iCounter=0;
try {
Iterable<String> iterableStrCategory;
iterableStrCategory= _bot.getCategoryMembers("Article manquant de référence",CATEGORY_NAMESPACE);
Iterator<String> iteratorStrCategory=iterableStrCategory.iterator();
while(iteratorStrCategory.hasNext())
{
String strCategory = iteratorStrCategory.next();
Iterable<String> iterableStrArticle = _bot.getCategoryMembers(strCategory.replace("Catégorie:", ""));
Iterator<String> iteratorStrArticle = iterableStrArticle.iterator();
while(iteratorStrArticle.hasNext())
{
strTemp+="[["+iteratorStrArticle.next()+"]], ";
iCounter++;
if (iCounter>10)
return strTemp;
}
}
} catch (ActionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ProcessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return strTemp;
}
private static String getStrNotabilityLine(MediaWikiBot _bot) {
// TODO Auto-generated method stub
String strTemp=new String();
int iCounter=0;
try {
Iterable<String> iterableStrCategory;
iterableStrCategory= _bot.getCategoryMembers("Admissibilité à vérifier",CATEGORY_NAMESPACE);
Iterator<String> iteratorStrCategory=iterableStrCategory.iterator();
while(iteratorStrCategory.hasNext())
{
String strCategory = iteratorStrCategory.next();
Iterable<String> iterableStrArticle = _bot.getCategoryMembers(strCategory.replace("Catégorie:", ""));
Iterator<String> iteratorStrArticle = iterableStrArticle.iterator();
while(iteratorStrArticle.hasNext())
{
strTemp+="[["+iteratorStrArticle.next()+"]], ";
iCounter++;
if (iCounter>10)
return strTemp;
}
}
} catch (ActionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ProcessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return strTemp;
}
private static String getStrWantedPageLine(MediaWikiBot _bot) {
// TODO Auto-generated method stub
String strTemp=new String();
try {
try {
Article rc=_bot.readContent("Projet:Articles les plus demandés/1-1000");
strTemp=rc.getText();
//System.out.println(strTemp);
strTemp=strTemp.replaceAll(" \\(\\[\\[Special:Whatlinkshere.*\n", ",");
strTemp=strTemp.replace("S:", "");
strTemp=strTemp.replace("#", "");
strTemp=strTemp.replace("__NOTOC__\n== 1-50==\n", "");
strTemp=strTemp.replace("_", " ");
String[] tab =strTemp.split(",", 11);
strTemp="";
strTemp=tab[0]+", "+tab[1]+", "+tab[2]+", "+tab[3]+", "+tab[4]+", "+tab[5]+", "+tab[6]+", "+tab[7]+", "+tab[8]+", "+tab[9]+", ";
System.out.println(strTemp);
} catch (ProcessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//.getBacklinkTitles("Projet:Articles les plus demandés/1-1000");//getAllPageTitles("Projet:Articles les plus demandés/1-1000", "", true, true, ARTICLE_NAMESPACE);//.getCategoryMembers("Projet:Articles les plus demandés/1-1000", 102);
//getAllPageTitles
} catch (ActionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return strTemp;
}
}