Content deleted Content added
merging a ton of code, upping version to 3.0 |
→Code: upgrade to 3.10 |
||
(One intermediate revision by the same user not shown) | |||
Line 9: | Line 9: | ||
*'''''[http://en.wikipedia.org/w/index.php?title=User:Titoxd/Flcelloguy%27s_Tool&diff=30655953&oldid=30570248 v2.10]''''': Minor edits implemented, some code for edit summaries created (not operational yet). |
*'''''[http://en.wikipedia.org/w/index.php?title=User:Titoxd/Flcelloguy%27s_Tool&diff=30655953&oldid=30570248 v2.10]''''': Minor edits implemented, some code for edit summaries created (not operational yet). |
||
*'''''[http://en.wikipedia.org/w/index.php?title=User%3ATitoxd%2FFlcelloguy%27s_Tool&diff=30668709&oldid=30656082 v2.15]''''': <tt>Contrib</tt> class parses namespaces. |
*'''''[http://en.wikipedia.org/w/index.php?title=User%3ATitoxd%2FFlcelloguy%27s_Tool&diff=30668709&oldid=30656082 v2.15]''''': <tt>Contrib</tt> class parses namespaces. |
||
*'''''[http://en.wikipedia.org/w/index.php?title=User%3ATitoxd%2FFlcelloguy%27s_Tool&diff=30676652&oldid=30668988 v3.00]''''': Merged my code with Flcelloguy's code. |
|||
== Code == |
== Code == |
||
=== Stats.java (same file as [[User:Flcelloguy/Tool|Flcelloguy's tool]], only updated) === |
=== Stats.java (same file as [[User:Flcelloguy/Tool|Flcelloguy's tool]], only updated) === |
||
<pre> |
<pre> |
||
<nowiki>/* |
<nowiki>/** |
||
* @author Flcelloguy et al. |
|||
* |
* @program Flcelloguy's Tool (Stats.java) |
||
* |
* @version 3.10; released December 13 2005 |
||
* @see [[User:Flcelloguy/Tool]] |
|||
*Capabilities: Count edits, break down by namespace, count minor edits and calculate percentage |
|||
* @docRoot code from http://en.wikipedia.org/wiki/User:Flcelloguy/Tool |
|||
*Please leave this block in. |
|||
* @copyright Permission is granted to distribute freely, provided attribution is granted. |
|||
*Code from http://en.wikipedia.org/wiki/User:Flcelloguy/Tool |
|||
* Capabilities: Count edits, break down by namespace, count minor edits and calculate percentage |
|||
* [[User:Flcelloguy/Tool]] |
|||
* Please leave this block in. |
|||
* Permission is granted to distribute freely, provided attribution is granted. |
|||
* Note: This new version does not require cut-and-pasting. Just go to http://en.wikipedia.org/w/index.php?title=Special:Contributions&target={{USERNAME}}&offset=0&limit=5000, where {{USERNAME}} is the name of the user you want to run a check on. Also, this tool is temporarily restricted to only 5,000 edits at a time (will be fixed later). Thanks! |
* Note: This new version does not require cut-and-pasting. Just go to http://en.wikipedia.org/w/index.php?title=Special:Contributions&target={{USERNAME}}&offset=0&limit=5000, where {{USERNAME}} is the name of the user you want to run a check on. Also, this tool is temporarily restricted to only 5,000 edits at a time (will be fixed later). Thanks! |
||
*/ |
*/ |
||
Line 27: | Line 29: | ||
import java.io.BufferedReader; |
import java.io.BufferedReader; |
||
import java.io.BufferedWriter; |
import java.io.BufferedWriter; |
||
import java.io.FileNotFoundException; |
|||
import java.io.FileReader; |
import java.io.FileReader; |
||
import java.io.FileWriter; |
import java.io.FileWriter; |
||
import java.io.IOException; |
import java.io.IOException; |
||
import java.util.StringTokenizer; |
|||
import java.io.*; |
|||
import java.util.*; |
|||
//import java.util.FileReader; |
//import java.util.FileReader; |
||
public class Stats |
public class Stats |
||
{ |
{ |
||
private static int numEdits = 0; |
private static int numEdits = 0; |
||
private static int minorEdits = 0; |
private static int minorEdits = 0; |
||
Line 62: | Line 59: | ||
private static int Media = 0; //so I'm adding support for them, but I'm not sure they are used. |
private static int Media = 0; //so I'm adding support for them, but I'm not sure they are used. |
||
public static void main |
public static void main(String args[]) throws IOException |
||
{ |
|||
{ |
|||
/** |
|||
JOptionPane.showMessageDialog(null, |
|||
* the GUI is too complex to screw |
|||
"Flcelloguy's Tool \n Designed by Flcelloguy \n Statistics for editcounters", "Welcome!", |
|||
* up clean, crisp code like this, |
|||
JOptionPane.INFORMATION_MESSAGE); |
|||
* so I'm moving it to a separate class. |
|||
* --Titoxd |
|||
*/ |
|||
GUI.main(null); |
|||
} |
|||
public static void mainSingle (String inFile$) throws IOException |
|||
{ |
|||
if (inFile$==null) inFile$ = JOptionPane.showInputDialog("Input file:", inFile$); |
|||
JOptionPane.showMessageDialog(null, |
JOptionPane.showMessageDialog(null, |
||
"Current status: \n " + |
"Current status: \n " + |
||
Line 73: | Line 80: | ||
"Breakdown by namespace \n Minor edits usage \n User friendly version \n Edit summary usage \n First edit date", "Information", |
"Breakdown by namespace \n Minor edits usage \n User friendly version \n Edit summary usage \n First edit date", "Information", |
||
JOptionPane.INFORMATION_MESSAGE); |
JOptionPane.INFORMATION_MESSAGE); |
||
JOptionPane.showMessageDialog(null, |
JOptionPane.showMessageDialog(null, |
||
"Number of edits: " + editcount(), "Results", |
"Number of edits: " + editcount(inFile$), "Results", |
||
JOptionPane.INFORMATION_MESSAGE); |
JOptionPane.INFORMATION_MESSAGE); |
||
} |
} |
||
public static int editcount() throws IOException |
public static int editcount(String inFile$) throws IOException |
||
{ |
{ |
||
String inFile$= ""; |
|||
String outFile$=""; |
|||
inFile$ = JOptionPane.showInputDialog("Input file:", inFile$); |
|||
//inFile$ = "C:\\Tito\\TitoSuite 1.40\\dat\\wikiedit\\Titoxd_1.txt"; |
|||
//outFile$= "C:\\Tito\\TitoSuite 1.40\\dat\\wikiedit\\Titoxd_o.txt"; |
|||
System.out.println("Computing..."); |
System.out.println("Computing..."); |
||
Line 189: | Line 192: | ||
numEdits++; |
numEdits++; |
||
} |
|||
public static void mainMulti(String[] args) throws IOException |
|||
{ |
|||
String outFile$=null; |
|||
String inFile$=null; |
|||
outFile$ = JOptionPane.showInputDialog(null, |
|||
"Enter the filename of the output file:", |
|||
outFile$, JOptionPane.QUESTION_MESSAGE); |
|||
FileWriter writer = new FileWriter(outFile$); |
|||
BufferedWriter out = new BufferedWriter(writer); |
|||
out.write("<ul>",0,"<ul>".length()); |
|||
out.newLine(); |
|||
inFile$ = JOptionPane.showInputDialog(null, |
|||
"Enter the filename of the next contributions file:", |
|||
inFile$, JOptionPane.QUESTION_MESSAGE); |
|||
while (inFile$!=null) |
|||
{ |
|||
FileReader reader = new FileReader(inFile$); |
|||
BufferedReader in = new BufferedReader(reader); |
|||
String inString =""; |
|||
boolean endContribs = false; //marks whether all the contributions have been parsed |
|||
inString = in.readLine(); //read from file and discard |
|||
do |
|||
{ |
|||
if ((inString.trim().compareTo("<ul>")==0) && (endContribs == false)) //until the <ul> tag is reached, |
|||
{ |
|||
do |
|||
{ |
|||
inString = in.readLine(); //then start reading and recording |
|||
if ((inString.trim().compareTo("</ul>")!=0)) |
|||
{ |
|||
out.write(inString.trim(),0,inString.length()); |
|||
out.newLine(); |
|||
//System.out.println(inString.trim()); |
|||
} |
|||
else |
|||
{ |
|||
endContribs = true; |
|||
} |
|||
} while (endContribs != true); |
|||
} |
|||
inString = in.readLine(); //read from file and discard |
|||
} while (inString != null); |
|||
in.close(); |
|||
inFile$ = JOptionPane.showInputDialog(null, |
|||
"Enter the filename of the next contributions file:", |
|||
inFile$, JOptionPane.QUESTION_MESSAGE); |
|||
} |
|||
out.write("</ul>",0,"</ul>".length()); |
|||
out.newLine(); |
|||
out.close(); |
|||
mainSingle(outFile$); |
|||
} |
} |
||
}</nowiki></pre> |
}</nowiki></pre> |
||
Line 195: | Line 262: | ||
<pre> |
<pre> |
||
<nowiki>/** |
<nowiki>/** |
||
* HTML -> ContribFile converter for Flcelloguy's Tool |
|||
* @see [[User:Flcelloguy/Tool]] |
|||
* @author Titoxd |
* @author Titoxd |
||
* @program HTML -> ContribFile converter for Flcelloguy's Tool |
|||
* @version 3.00 |
|||
* @version 3.10; released December 13 2005 |
|||
* @docRoot: http://en.wikipedia.org/wiki/User:Titoxd/Flcelloguy's_Tool |
|||
* @see [[User:Flcelloguy/Tool]] |
|||
* @copyright: Permission is granted to distribute freely, provided attribution is granted. |
|||
* @docRoot http://en.wikipedia.org/wiki/User:Titoxd/Flcelloguy's_Tool |
|||
* @copyright Permission is granted to distribute freely, provided attribution is granted. |
|||
*/ |
*/ |
||
import java.io.BufferedReader; |
|||
import java.io.BufferedWriter; |
|||
import java.io.FileReader; |
|||
import java.io.FileWriter; |
|||
import java.io.IOException; |
import java.io.IOException; |
||
import java.util.StringTokenizer; |
import java.util.StringTokenizer; |
||
import javax.swing.JOptionPane; |
|||
public class PurgeContribs |
public class PurgeContribs |
||
{ |
{ |
||
Line 328: | Line 389: | ||
return contrib; |
return contrib; |
||
} |
} |
||
}</nowiki></pre> |
}</nowiki></pre> |
||
Line 333: | Line 396: | ||
<pre> |
<pre> |
||
<nowiki>/** |
<nowiki>/** |
||
* Contribution class for Flcelloguy's Tool |
|||
* @see [[User:Flcelloguy/Tool]] |
|||
* @author Titoxd |
* @author Titoxd |
||
* @program Contribution class for Flcelloguy's Tool |
|||
* @version 3.00 |
|||
* @version 3.10; released December 13 2005 |
|||
* @docRoot: http://en.wikipedia.org/wiki/User:Titoxd/Flcelloguy's_Tool |
|||
* @see [[User:Flcelloguy/Tool]] |
|||
* @copyright: Permission is granted to distribute freely, provided attribution is granted. |
|||
* @docRoot http://en.wikipedia.org/wiki/User:Titoxd/Flcelloguy's_Tool |
|||
* @copyright Permission is granted to distribute freely, provided attribution is granted. |
|||
*/ |
*/ |
||
public class Contrib |
public class Contrib |
||
{ |
{ |
||
public Contrib(String inStamp, String inName, boolean inMin, String inSummary, boolean inTop) |
public Contrib(String inStamp, String inName, boolean inMin, String inSummary, boolean inTop) |
||
{ |
{ |
||
Line 406: | Line 470: | ||
return returnString; |
return returnString; |
||
} |
} |
||
}</nowiki></pre> |
|||
=== GUI.java === |
|||
<pre><nowiki>/** |
|||
* @author Titoxd |
|||
* @program Graphical User Interface for Flcelloguy's Tool |
|||
* @version 3.10; released December 13 2005 |
|||
* @see [[User:Flcelloguy/Tool]] |
|||
* @docRoot http://en.wikipedia.org/wiki/User:Titoxd/Flcelloguy's_Tool |
|||
* @copyright Permission is granted to distribute freely, provided attribution is granted. |
|||
*/ |
|||
import java.awt.BorderLayout; |
|||
import java.awt.Container; |
|||
import java.awt.GridLayout; |
|||
import java.awt.event.ActionEvent; |
|||
import java.awt.event.ActionListener; |
|||
import java.io.IOException; |
|||
import javax.swing.BorderFactory; |
|||
import javax.swing.BoxLayout; |
|||
import javax.swing.ButtonGroup; |
|||
import javax.swing.JButton; |
|||
import javax.swing.JDialog; |
|||
import javax.swing.JFrame; |
|||
import javax.swing.JLabel; |
|||
import javax.swing.JPanel; |
|||
import javax.swing.JRadioButton; |
|||
import javax.swing.UIManager; |
|||
import javax.swing.UnsupportedLookAndFeelException; |
|||
public class GUI extends JPanel |
|||
{ |
|||
private static final long serialVersionUID = -6193690254966297431L; |
|||
static JLabel label; |
|||
JFrame frame; |
|||
String simpleDialogDesc = "Contribution file types:"; |
|||
public static void main(String[] args) { |
|||
//Schedule a job for the event-dispatching thread: |
|||
//creating and showing this application's GUI. |
|||
javax.swing.SwingUtilities.invokeLater(new Runnable() { |
|||
public void run() { |
|||
createAndShowGUI(); |
|||
} |
|||
}); |
|||
} |
|||
private static void createAndShowGUI() |
|||
{ |
|||
//Having the GUI look like the native system it is running in. |
|||
try |
|||
{ |
|||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
|||
} |
|||
catch (ClassNotFoundException e) |
|||
{ |
|||
// TODO Auto-generated catch block |
|||
e.printStackTrace(); |
|||
} |
|||
catch (InstantiationException e) |
|||
{ |
|||
// TODO Auto-generated catch block |
|||
e.printStackTrace(); |
|||
} |
|||
catch (IllegalAccessException e) |
|||
{ |
|||
// TODO Auto-generated catch block |
|||
e.printStackTrace(); |
|||
} |
|||
catch (UnsupportedLookAndFeelException e) |
|||
{ |
|||
// TODO Auto-generated catch block |
|||
e.printStackTrace(); |
|||
} |
|||
JFrame.setDefaultLookAndFeelDecorated(true); |
|||
JDialog.setDefaultLookAndFeelDecorated(true); |
|||
//Create and set up the window. |
|||
JFrame frame = new JFrame("Flcelloguy's Tool"); |
|||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|||
//Set up the content pane. |
|||
Container contentPane = frame.getContentPane(); |
|||
contentPane.setLayout(new GridLayout(1,1)); |
|||
contentPane.add(new GUI(frame)); |
|||
//Display the window. |
|||
frame.pack(); |
|||
frame.setVisible(true); |
|||
} |
|||
public GUI(JFrame frame) |
|||
{ |
|||
super(new BorderLayout()); |
|||
this.frame = frame; |
|||
JLabel title; |
|||
//Create the components. |
|||
JPanel choicePanel = createSimpleDialogBox(); |
|||
System.out.println("passed createSimpleDialogBox"); |
|||
title = new JLabel("Please select one of the following options.", |
|||
JLabel.CENTER); |
|||
label = new JLabel("Flcelloguy's Tool: Statistics for editcounters", JLabel.CENTER); |
|||
label.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); |
|||
choicePanel.setBorder(BorderFactory.createEmptyBorder(20,20,5,20)); |
|||
//Lay out the main panel. |
|||
add(title, BorderLayout.NORTH); |
|||
add(label, BorderLayout.SOUTH); |
|||
add(choicePanel, BorderLayout.CENTER); |
|||
} |
|||
private JPanel createSimpleDialogBox() |
|||
{ |
|||
final int numButtons = 2; |
|||
JRadioButton[] radioButtons = new JRadioButton[numButtons]; |
|||
final ButtonGroup group = new ButtonGroup(); |
|||
JButton continueButton = null; |
|||
final String singleContribs= "SingleParse"; |
|||
final String multiContribs= "MultiParse"; |
|||
radioButtons[0] = new JRadioButton( |
|||
"Single contributions file"); |
|||
radioButtons[0].setActionCommand(singleContribs); |
|||
radioButtons[1] = new JRadioButton( |
|||
"Multiple contribution files"); |
|||
radioButtons[1].setActionCommand(multiContribs); |
|||
for (int i = 0; i < numButtons; i++) |
|||
{ |
|||
group.add(radioButtons[i]); |
|||
} |
|||
//Select the first button by default. |
|||
radioButtons[0].setSelected(true); |
|||
continueButton = new JButton("Continue"); |
|||
continueButton.addActionListener(new ActionListener() |
|||
{ |
|||
public void actionPerformed(ActionEvent e) |
|||
{ |
|||
String command = group.getSelection().getActionCommand(); |
|||
if (command == singleContribs) |
|||
{ |
|||
try |
|||
{ |
|||
Stats.mainSingle(null); |
|||
} |
|||
catch (IOException e1) |
|||
{ |
|||
// TODO Auto-generated catch block |
|||
e1.printStackTrace(); |
|||
} |
|||
} |
|||
else if (command == multiContribs) |
|||
{ |
|||
try |
|||
{ |
|||
Stats.mainMulti(null); |
|||
} |
|||
catch (IOException e1) |
|||
{ |
|||
// TODO Auto-generated catch block |
|||
e1.printStackTrace(); |
|||
} |
|||
} |
|||
return; |
|||
} |
|||
}); |
|||
System.out.println("calling createPane"); |
|||
return createPane(simpleDialogDesc + ":", |
|||
radioButtons, |
|||
continueButton); |
|||
} |
|||
private JPanel createPane(String description, |
|||
JRadioButton[] radioButtons, |
|||
JButton showButton) |
|||
{ |
|||
int numChoices = radioButtons.length; |
|||
JPanel box = new JPanel(); |
|||
JLabel label = new JLabel(description); |
|||
box.setLayout(new BoxLayout(box, BoxLayout.PAGE_AXIS)); |
|||
box.add(label); |
|||
for (int i = 0; i < numChoices; i++) |
|||
{ |
|||
box.add(radioButtons[i]); |
|||
} |
|||
JPanel pane = new JPanel(new BorderLayout()); |
|||
pane.add(box, BorderLayout.NORTH); |
|||
pane.add(showButton, BorderLayout.SOUTH); |
|||
System.out.println("returning pane"); |
|||
return pane; |
|||
} |
|||
}</nowiki></pre> |
}</nowiki></pre> |
Revision as of 19:31, 13 December 2005
This is an extension of Flcelloguy's Tool, which processes the HTML from a contribs file and parses it into a file readable by the tool. It is not finished, but the core is done, so I'm publishing it as v1.00.
It won't run, since the functions written by Flcelloguy (which actually count the contributions) are in a separate file (available at User:Flcelloguy/Tool). All it does is parse the contributions. Titoxd(?!? - did you read this?) 04:21, 8 December 2005 (UTC)
Revisions
- v1.00: Original version, parses contribs to HTML file
- v1.01: Revision, split into a separate class, removed print command to system buffer (slowing down tool, only used for debugging)
- v2.00: begun processing the raw HTML file, parsed date/time stamp and page name into a special "Contrib" class. Minor edits, edit summaries and most recent edits still to be implemented.
- v2.10: Minor edits implemented, some code for edit summaries created (not operational yet).
- v2.15: Contrib class parses namespaces.
- v3.00: Merged my code with Flcelloguy's code.
Code
Stats.java (same file as Flcelloguy's tool, only updated)
/** * @author Flcelloguy et al. * @program Flcelloguy's Tool (Stats.java) * @version 3.10; released December 13 2005 * @see [[User:Flcelloguy/Tool]] * @docRoot code from http://en.wikipedia.org/wiki/User:Flcelloguy/Tool * @copyright Permission is granted to distribute freely, provided attribution is granted. * Capabilities: Count edits, break down by namespace, count minor edits and calculate percentage * Please leave this block in. * Note: This new version does not require cut-and-pasting. Just go to http://en.wikipedia.org/w/index.php?title=Special:Contributions&target={{USERNAME}}&offset=0&limit=5000, where {{USERNAME}} is the name of the user you want to run a check on. Also, this tool is temporarily restricted to only 5,000 edits at a time (will be fixed later). Thanks! */ import javax.swing.JOptionPane; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; //import java.util.FileReader; public class Stats { private static int numEdits = 0; private static int minorEdits = 0; private static int Mainspace = 0; private static int Talk = 0; private static int User = 0; private static int User_talk = 0; private static int Wikipedia = 0; private static int Wikipedia_talk = 0; private static int Image = 0; private static int Image_talk= 0; private static int MediaWiki = 0; private static int MediaWiki_talk = 0; private static int Template = 0; private static int Template_talk = 0; private static int Help = 0; private static int Help_talk = 0; private static int Category = 0; private static int Category_talk = 0; private static int Portal = 0; private static int Portal_talk = 0; private static int Special = 0; //these two are listed at [[Wikipedia:Namespace]], private static int Media = 0; //so I'm adding support for them, but I'm not sure they are used. public static void main(String args[]) throws IOException { /** * the GUI is too complex to screw * up clean, crisp code like this, * so I'm moving it to a separate class. * --Titoxd */ GUI.main(null); } public static void mainSingle (String inFile$) throws IOException { if (inFile$==null) inFile$ = JOptionPane.showInputDialog("Input file:", inFile$); JOptionPane.showMessageDialog(null, "Current status: \n " + "Editcount only \n " + "Coming soon: \n " + "Breakdown by namespace \n Minor edits usage \n User friendly version \n Edit summary usage \n First edit date", "Information", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, "Number of edits: " + editcount(inFile$), "Results", JOptionPane.INFORMATION_MESSAGE); } public static int editcount(String inFile$) throws IOException { System.out.println("Computing..."); FileReader reader = new FileReader(inFile$); BufferedReader in = new BufferedReader(reader); //FileWriter writer = new FileWriter(outFile$); //for debugging //BufferedWriter out = new BufferedWriter(writer); //for debugging String inString =""; Contrib outContrib; boolean endContribs = false; //marks whether all the contributions have been parsed inString = in.readLine(); //read from file and discard do { if ((inString.trim().compareTo("<ul>")==0) && (endContribs == false)) //until the <ul> tag is reached, { do { inString = in.readLine(); //then start reading and recording if ((inString.trim().compareTo("</ul>")!=0)) { //System.out.println(inString.trim()); outContrib = PurgeContribs.Parse(inString.trim()); //System.out.println(outString.trim()); AnalyzeContrib(outContrib); //out.newLine(); } else { endContribs = true; } } while (endContribs != true); } inString = in.readLine(); //read from file and discard } while (inString != null); in.close(); //out.close(); //Prints out statistics System.out.println("-------------------"); System.out.println("Breakdown by namespace:"); if (Mainspace != 0)System.out.println("Main (articles): " + Mainspace); if (Talk != 0)System.out.println("Article talk: " + Talk); if (User != 0)System.out.println("User: " + User); if (User_talk != 0)System.out.println("User talk: " + User_talk); if (Wikipedia != 0)System.out.println("Project: " + Wikipedia); if (Wikipedia_talk != 0)System.out.println("Project talk: " + Wikipedia_talk); if (Image != 0)System.out.println("Image: " + Image); if (Image_talk != 0)System.out.println("Image talk: " + Image_talk); if (MediaWiki != 0)System.out.println("MediaWiki: " + MediaWiki); if (MediaWiki_talk != 0)System.out.println("MediaWiki talk: " + MediaWiki_talk); if (Template != 0)System.out.println("Template: " + Template); if (Template_talk != 0)System.out.println("Template talk: " + Template_talk); if (Help != 0)System.out.println("Help: " + Help); if (Help_talk != 0)System.out.println("Help talk: " + Help_talk); if (Category != 0)System.out.println("Category: " + Category); if (Category_talk != 0)System.out.println("Category talk: " + Category_talk); if (Portal != 0)System.out.println("Portal: " + Portal); if (Portal_talk != 0)System.out.println("Portal talk: " + Portal_talk); if (Special != 0) System.out.println("Special: " + Special); if (Media != 0) System.out.println("Media: " + Media); System.out.println("-------------------"); System.out.println("Overall statistics: "); System.out.println("Total edits: " + numEdits); System.out.println("Minor edits: " + minorEdits); System.out.println("Percentage of minor edits: " + (int)(((double)minorEdits)/numEdits * 100.0) + "% *"); System.out.println("* - percentage is always rounded down to nearest whole number percentage."); System.out.println("Percent edit summary: Not available yet."); System.out.println("-------------------"); return numEdits; } private static void AnalyzeContrib(Contrib contrib) { if (contrib.minorEdit==true) { minorEdits++; } if (contrib.namespace.equals("Main")) Mainspace++; if (contrib.namespace.equals("Talk")) Talk++; if (contrib.namespace.equals("User")) User++; if (contrib.namespace.equals("User_talk")) User_talk++; if (contrib.namespace.equals("Wikipedia")) Wikipedia++; if (contrib.namespace.equals("Wikipedia_talk")) Wikipedia_talk++; if (contrib.namespace.equals("Image")) Image++; if (contrib.namespace.equals("Image_talk")) Image_talk++; if (contrib.namespace.equals("MediaWiki")) MediaWiki++; if (contrib.namespace.equals("MediaWiki_talk")) MediaWiki_talk++; if (contrib.namespace.equals("Template")) Template++; if (contrib.namespace.equals("Template_talk")) Template_talk++; if (contrib.namespace.equals("Help")) Help++; if (contrib.namespace.equals("Help_talk")) Help_talk++; if (contrib.namespace.equals("Category")) Category++; if (contrib.namespace.equals("Category_talk")) Category_talk++; if (contrib.namespace.equals("Portal")) Portal++; if (contrib.namespace.equals("Portal_talk")) Portal_talk++; if (contrib.namespace.equals("Special")) Special++; if (contrib.namespace.equals("Media")) Media++; numEdits++; } public static void mainMulti(String[] args) throws IOException { String outFile$=null; String inFile$=null; outFile$ = JOptionPane.showInputDialog(null, "Enter the filename of the output file:", outFile$, JOptionPane.QUESTION_MESSAGE); FileWriter writer = new FileWriter(outFile$); BufferedWriter out = new BufferedWriter(writer); out.write("<ul>",0,"<ul>".length()); out.newLine(); inFile$ = JOptionPane.showInputDialog(null, "Enter the filename of the next contributions file:", inFile$, JOptionPane.QUESTION_MESSAGE); while (inFile$!=null) { FileReader reader = new FileReader(inFile$); BufferedReader in = new BufferedReader(reader); String inString =""; boolean endContribs = false; //marks whether all the contributions have been parsed inString = in.readLine(); //read from file and discard do { if ((inString.trim().compareTo("<ul>")==0) && (endContribs == false)) //until the <ul> tag is reached, { do { inString = in.readLine(); //then start reading and recording if ((inString.trim().compareTo("</ul>")!=0)) { out.write(inString.trim(),0,inString.length()); out.newLine(); //System.out.println(inString.trim()); } else { endContribs = true; } } while (endContribs != true); } inString = in.readLine(); //read from file and discard } while (inString != null); in.close(); inFile$ = JOptionPane.showInputDialog(null, "Enter the filename of the next contributions file:", inFile$, JOptionPane.QUESTION_MESSAGE); } out.write("</ul>",0,"</ul>".length()); out.newLine(); out.close(); mainSingle(outFile$); } }
PurgeContribs.java
/** * @author Titoxd * @program HTML -> ContribFile converter for Flcelloguy's Tool * @version 3.10; released December 13 2005 * @see [[User:Flcelloguy/Tool]] * @docRoot http://en.wikipedia.org/wiki/User:Titoxd/Flcelloguy's_Tool * @copyright Permission is granted to distribute freely, provided attribution is granted. */ import java.io.IOException; import java.util.StringTokenizer; public class PurgeContribs { /** * @param purgedLine (input line in raw HTML, leading and trailing whitespace removed) * @return Contrib class object: for analysis * @throws IOException */ public static Contrib Parse(String purgedLine) throws IOException { /**** Take out the <li> tags ****/ String midString1; String timeStamp; String editSummary = null; boolean minorEdit = false; boolean endLoop = false; boolean newestEdit = false; midString1 = purgedLine.substring(4,purgedLine.length()-5); /**** Process the time stamp ****/ StringTokenizer token; token = new StringTokenizer(midString1.trim()); { String time = token.nextToken(); String day = token.nextToken(); String month = token.nextToken(); String year = token.nextToken(); timeStamp = time + " " + day + " " + month + " " + year; } /**** Process the page name ****/ String dummy = token.nextToken(); //get rid of (<a String URL = token.nextToken(); String pageName = URL.substring(25,URL.length()-20); /**** Get rid of a few extra tokens ****/ do { endLoop = false; dummy = token.nextToken(); if (dummy.lastIndexOf('<') != -1) { if (dummy.substring(dummy.lastIndexOf('<'),dummy.lastIndexOf('<')+3).compareTo("</a>") != 0) endLoop = true; } } while (endLoop==false); /**** Do the same with the diff link ****/ dummy = token.nextToken(); //get rid of (<a String dummyURL = token.nextToken(); //this URL is not needed, so it is dummied out String dummyPageName = URL.substring(25,dummyURL.length()-20); //ditto do { endLoop = false; dummy = token.nextToken(); if (dummy.lastIndexOf('<') != -1) { if (dummy.substring(dummy.lastIndexOf('<'),dummy.lastIndexOf('<')+3).compareTo("</a>") != 0) endLoop = true; } } while (endLoop==false); /**** Determine if edit is minor or not ****/ dummy = token.nextToken(); //get rid of (<span dummy = token.nextToken(); //read the next token; it should be class="minor">m</span> if a minor edit if (dummy.compareTo("class=\"minor\">m</span>") == 0) { minorEdit = true; dummyPageName = null; } else { minorEdit = false; dummyPageName = dummy; } if (dummyPageName == null) //if it was a minor edit, advance token cursor to match non-minor edits { dummy = token.nextToken(); //get rid of <a dummyPageName = token.nextToken(); } do { endLoop = false; dummy = token.nextToken(); if (dummy.lastIndexOf('<') != -1) { if (dummy.substring(dummy.lastIndexOf('<'),dummy.lastIndexOf('<')+3).compareTo("</a>") != 0) endLoop = true; } } while (endLoop==false); /*if (token.hasMoreTokens() == true) { dummy = token.nextToken(); //read whether it is <span or <strong> if (dummy.compareTo("<span") == 0) //<span: there is an edit summary { String dummySummary = token.nextToken(); } //class='comment'>(added link to magnesium hydroxide page)</span> //(top)</strong> } else //no edit summaries, edit is not the most recent edit to page { editSummary = null; newestEdit = false; } */ Contrib contrib = new Contrib(timeStamp, pageName, minorEdit, null, false); return contrib; } }
Contrib.java
/** * @author Titoxd * @program Contribution class for Flcelloguy's Tool * @version 3.10; released December 13 2005 * @see [[User:Flcelloguy/Tool]] * @docRoot http://en.wikipedia.org/wiki/User:Titoxd/Flcelloguy's_Tool * @copyright Permission is granted to distribute freely, provided attribution is granted. */ public class Contrib { public Contrib(String inStamp, String inName, boolean inMin, String inSummary, boolean inTop) { timeStamp = inStamp; pageName = inName; namespace = FindNameSpace(pageName); shortName = FindShortName(pageName); minorEdit = inMin; editSummary= inSummary; topEdit = inTop; } private String FindNameSpace(String inName) { String[] nameArray=inName.split(":",2); if (nameArray[0].compareTo(inName)==0) { nameArray[0] = namespaceArray[0]; } return nameArray[0]; } private String FindShortName(String inName) { String name=null; if (inName.contains(":")) { String[] nameArray=inName.split(":",2); name = nameArray[1]; } else { name = inName; } return name; } public String timeStamp; public String pageName; public String namespace; public String shortName; public boolean minorEdit; public String editSummary; public boolean topEdit; private static String[] namespaceArray = //list of namespaces from [[Wikipedia:Namespace]] { "Main", "Talk", "User", "User_talk", "Wikipedia", "Wikipedia_talk", "Image", "Image_talk", "MediaWiki", "MediaWiki_talk", "Template", "Template_talk", "Help", "Help_talk", "Category", "Category_talk", "Portal", "Portal_talk", "Media", "Special", }; public String toString() { String returnString = "Time: " + timeStamp + "\r" + "Page: " + pageName + " (Namespace: " + namespace + "; Article: " + shortName + ")\r" + "Minor edit: " + minorEdit + "\r" + "Edit Summary: " + editSummary + "\r" + "Most recent edit: " + topEdit; return returnString; } }
GUI.java
/** * @author Titoxd * @program Graphical User Interface for Flcelloguy's Tool * @version 3.10; released December 13 2005 * @see [[User:Flcelloguy/Tool]] * @docRoot http://en.wikipedia.org/wiki/User:Titoxd/Flcelloguy's_Tool * @copyright Permission is granted to distribute freely, provided attribution is granted. */ import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class GUI extends JPanel { private static final long serialVersionUID = -6193690254966297431L; static JLabel label; JFrame frame; String simpleDialogDesc = "Contribution file types:"; public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } private static void createAndShowGUI() { //Having the GUI look like the native system it is running in. try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedLookAndFeelException e) { // TODO Auto-generated catch block e.printStackTrace(); } JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); //Create and set up the window. JFrame frame = new JFrame("Flcelloguy's Tool"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(1,1)); contentPane.add(new GUI(frame)); //Display the window. frame.pack(); frame.setVisible(true); } public GUI(JFrame frame) { super(new BorderLayout()); this.frame = frame; JLabel title; //Create the components. JPanel choicePanel = createSimpleDialogBox(); System.out.println("passed createSimpleDialogBox"); title = new JLabel("Please select one of the following options.", JLabel.CENTER); label = new JLabel("Flcelloguy's Tool: Statistics for editcounters", JLabel.CENTER); label.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); choicePanel.setBorder(BorderFactory.createEmptyBorder(20,20,5,20)); //Lay out the main panel. add(title, BorderLayout.NORTH); add(label, BorderLayout.SOUTH); add(choicePanel, BorderLayout.CENTER); } private JPanel createSimpleDialogBox() { final int numButtons = 2; JRadioButton[] radioButtons = new JRadioButton[numButtons]; final ButtonGroup group = new ButtonGroup(); JButton continueButton = null; final String singleContribs= "SingleParse"; final String multiContribs= "MultiParse"; radioButtons[0] = new JRadioButton( "Single contributions file"); radioButtons[0].setActionCommand(singleContribs); radioButtons[1] = new JRadioButton( "Multiple contribution files"); radioButtons[1].setActionCommand(multiContribs); for (int i = 0; i < numButtons; i++) { group.add(radioButtons[i]); } //Select the first button by default. radioButtons[0].setSelected(true); continueButton = new JButton("Continue"); continueButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String command = group.getSelection().getActionCommand(); if (command == singleContribs) { try { Stats.mainSingle(null); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else if (command == multiContribs) { try { Stats.mainMulti(null); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } return; } }); System.out.println("calling createPane"); return createPane(simpleDialogDesc + ":", radioButtons, continueButton); } private JPanel createPane(String description, JRadioButton[] radioButtons, JButton showButton) { int numChoices = radioButtons.length; JPanel box = new JPanel(); JLabel label = new JLabel(description); box.setLayout(new BoxLayout(box, BoxLayout.PAGE_AXIS)); box.add(label); for (int i = 0; i < numChoices; i++) { box.add(radioButtons[i]); } JPanel pane = new JPanel(new BorderLayout()); pane.add(box, BorderLayout.NORTH); pane.add(showButton, BorderLayout.SOUTH); System.out.println("returning pane"); return pane; } }