Utilisateur:Cynddl/checkwiki.cgi

Une page de Wikiversité.
Aller à : Navigation, rechercher
#!/usr/bin/perl -w
# from toolserver.org/~sk/public_html/checkwiki
 
use strict;
use CGI qw(param);
use CGI::Carp qw(fatalsToBrowser);
use URI::Escape;
use Encode;
use LWP::UserAgent;
use DBI;
 
 
#load password
open(PWD, "</home/sk/.mytop");
my $password = '';
do {
        my $test = <PWD>;
        if ($test =~ /^pass=/ ) {
                $password = $test;
                $password =~ s/^pass=//g;
                $password =~ s/\n//g;
        }
}
while (eof(PWD) != 1);
close(PWD);
 
#Connect to database u_sk
my $dbh = DBI->connect( 'DBI:mysql:u_sk_yarrow:host=sql',
                        'sk',
                        $password,
                                                {
                          RaiseError => 1,
                          AutoCommit => 1
                        }
                      ) or die "Database connection not made: $DBI::errstr" . DBI->errstr;
print "Content-type: text/html\n\n";
$password = '';
 
 
##############
our $param_error = param('error');
our $param_id = param('id');
 
 
 
print <<HTML_HEAD;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
<head>
<style type="text/css">
body {  
 
        font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif;
        font-size:14px;
        font-style:normal;
 
        /* color:#9A91ff; */
 
        /* background-color:#00077A; */
        /* background-image:url(back.jpg); */
        /* background:url(back_new.jpg) no-repeat fixed top center; */
        /* background:url(../images/back_new.jpg) no-repeat fixed top center; */
        /* background:url(../images/back_schaf2.jpg) no-repeat fixed bottom left; */
        /* background:url(../images/back_schaf3.jpg) no-repeat fixed bottom left; */
 
        background-color:white;
        color:#555555;
        text-decoration:none; 
        line-height:normal; 
        font-weight:normal; 
        font-variant:normal; 
        text-transform:none; 
        margin-left:5%;
        margin-right:5%;
        }
 
h1      {
        /*color:red; */
        font-size:20px;
        }
 
h2      {
        /*color:red; */
        font-size:16px;
        }
 
a       {  
 
        /*nur blau */
        /* color:#80BFBF; */ 
        /* color:#4889c5; */ 
        /* color:#326a9e; */  
 
        color:#4889c5;
        font-weight:bold;
        /*nettes grün */
        /*color:#7CFC00;*/
 
        /* Nette Kombination */
        /*color:#00077A; */
        /*background-color:#eee8fd;*/
 
 
        /* Kein Unterstrich */
        text-decoration:none; 
 
        /*Außenabstand*/
        /*padding:2px;*/
        }
 
a:hover {  
        background-color:#ffdeff;
        color:red;
        }
 
.nocolor{  
        background-color:white;
        color:white;
        } 
 
a:hover.nocolor{  
        background-color:white;
        color:white;
        }
 
.table{
        font-size:12px; 
 
        vertical-align:top;
 
        border-width:thin;
        border-style:solid;
        border-color:blue;
        background-color:#EEEEEE;
 
        /*Innenabstand*/
        padding-top:2px;
        padding-bottom:2px;
        padding-left:5px;
        padding-right:5px;
 
        /* dünne Rahmen */
        border-collapse:collapse; 
 
        /*kein Zeilenumbruch
        white-space:nowrap;*/
 
        }
 
</style>
 
<title>Personendaten Verbesserungsvorschläge</title></head>
HTML_HEAD
 
 
print "<body><h1>PD Verbesserungsvorschläge</h1>\n";
print "<p>Version 0.1 Alpha</p>\n";
 
if (     $param_error eq ''
         and $param_id eq '') {
 
 
print <<EINFUEHRUNGSTEXT;
 
<h2>Startseite</h2>
<p>Auf dieser Seite werden Verbesserungsvorschläge für die Personendaten in der deutschsprachigen Wikipedia angezeigt.  Für weitere Informationen am besten mal hier reinschauen: <a href="http://de.wikipedia.org/wiki/Wikipedia:Personendaten/Wartung/Fehlerliste">Wikipedia:Personendaten/Wartung/Fehlerliste</a>.</p>
 
EINFUEHRUNGSTEXT
 
 
print 'Aktuell sind <b>'.get_number_all_errors().'</b> Verbesserungsvorschläge in <b>'.get_number_all_article().'</b> Artikeln bekannt. <br />'."\n";
 
 
print '<ul>';
print '<li>'.get_number_of_prio(1)." Verbesserungsvorschläge von <a href='http://toolserver.org/~sk/cgi-bin/pd/pd.cgi?error=high'>höchster Priorität</a></li>";
print '<li>'.get_number_of_prio(2)." Verbesserungsvorschläge von <a href='http://toolserver.org/~sk/cgi-bin/pd/pd.cgi?error=middle'>mittlerer Priorität</a></li>";
print '<li>'.get_number_of_prio(3)." Verbesserungsvorschläge von <a href='http://toolserver.org/~sk/cgi-bin/pd/pd.cgi?error=low'>niedriger Priorität</a></li>";
print '</ul>';
print '<ul>';
print "<li><a href='http://toolserver.org/~sk/cgi-bin/pd/pd.cgi?error=top25'>Top 25 Artikel</a></li>";
print '</ul>';
print '<p>Seit dem letzten Update wurden <b>'.get_number_of_ok().'</b> Verbesserungsvorschläge abgearbeitet. </p>'."\n";
print '<p>? Startseite</p>'."\n";       
}
 
if (   $param_error eq 'high'
        or $param_error eq 'middle'
        or $param_error eq 'low') {
 
 
        my $prio = 0;
        my $headline = '';
        if ($param_error eq 'high') {
                $prio = 1;
                $headline = 'Hohe Priorität';
        }
 
        if ($param_error eq 'middle') {
                $prio = 2;
                $headline = 'Mittlere Priorität';
        }
 
        if ($param_error eq 'low') {
                $prio = 3;
                $headline = 'Niedrige Priorität';
        }
 
 
        print '<h2>'.$headline.'</h2>'."\n";
        print '<ul>';
        print get_number_error_and_desc_by_prio($prio);
        print '</ul>';  
 
        print '<p>? <a href="http://toolserver.org/~sk/cgi-bin/pd/pd.cgi">Startseite</a> ? '.$headline.'</p>'."\n";     
 
 
 
}
 
if (   $param_error eq 'top25') {
        print '<h2>Top 25</h2>'."\n";
        print get_top25();      
        print '<p>? <a href="http://toolserver.org/~sk/cgi-bin/pd/pd.cgi">Startseite</a> ? Top25</p>'."\n";     
 
}       
 
 
if (    $param_id =~ /^[0-9]+$/
        and $param_error =~ /^[0-9]+$/ ) {
        # Artikel abgearbeitet
        my $sql_text = "update pd_error set ok=1 where id=".$param_id." and error=".$param_error.";";
        my $sth = $dbh->prepare( $sql_text )  ||  die "Kann Statement nicht vorbereiten: $DBI::errstr\n";
        $sth->execute or die $sth->errstr; # hier geschieht die Anfrage an die DB       
}
 
 
if (   $param_error =~ /^[0-9]+$/) {
        # Ein konkrete Fehlernummer auflisten
        my $headline = '';
        $headline = get_headline($param_error);
 
        print '<h2>'.$headline.'</h2>'."\n";
        print '<p>'.get_description($param_error).'</p>'."\n";
        print '<p>'.get_number_of_error($param_error).' mal gefunden (Nr. '.$param_error .')</p>'."\n";
 
        print get_article_of_error($param_error);
 
        my $prio = get_prio_of_error($param_error);
        $prio = '<a href="http://toolserver.org/~sk/cgi-bin/pd/pd.cgi?error=high">Höchster Priorität</a>' if ($prio eq '1');
        $prio = '<a href="http://toolserver.org/~sk/cgi-bin/pd/pd.cgi?error=middle">Mittlere Priorität</a>' if ($prio eq '2');
        $prio = '<a href="http://toolserver.org/~sk/cgi-bin/pd/pd.cgi?error=low">Niedrigste Priorität</a>' if ($prio eq '3');
        print '<p>? <a href="http://toolserver.org/~sk/cgi-bin/pd/pd.cgi">Startseite</a> ? '.$prio.' ? '.$headline.'</p>'."\n"; 
 
 
}
 
if (    $param_id =~ /^[0-9]+$/
        and $param_error eq '' ) {
        # Details zu einem Artikel anzeigen
        print '<h2>Detailansicht</h2>'."\n";
        my $sql_text = "select title from pd_error where id=".$param_id.";";
        my $sth = $dbh->prepare( $sql_text )  ||  die "Kann Statement nicht vorbereiten: $DBI::errstr\n";
        $sth->execute or die $sth->errstr;      
                while (my $arrayref = $sth->fetchrow_arrayref()) {      
                foreach(@$arrayref) {
                        print '<p>Artikel: <a href="http://de.wikipedia.org/wiki/'.$_.'">'.$_.'</a></p>';
                }
        }
 
        print get_all_error_of_article($param_id);
 
        print '<p>? <a href="http://toolserver.org/~sk/cgi-bin/pd/pd.cgi">Startseite</a> ? <a href="http://toolserver.org/~sk/cgi-bin/pd/pd.cgi?error=top25">Top25</a> ? Detailansicht</p>'."\n";       
 
 
 
 
}
 
 
 
print '</body>';
print '</html>';
 
# Datenbank beenden
$dbh->disconnect();
 
 
 
 
###########################################     
 
 
 
sub get_number_all_article{
        my $sql_text = "select count(a.title) from (select title from pd_error where ok=0 group by title) a;";
        my $result = 0;
        my $sth = $dbh->prepare( $sql_text )  ||  die "Kann Statement nicht vorbereiten: $DBI::errstr\n";
        #print '<p class="smalltext"/>'.$sql_text."</p>\n";                                       
        $sth->execute or die $sth->errstr; # hier geschieht die Anfrage an die DB
        while (my $arrayref = $sth->fetchrow_arrayref()) {      
                foreach(@$arrayref) {
                        $result = $_;
                }
        }
        return ($result);
}
 
sub get_number_of_ok{
        my $sql_text = "select count(*) from pd_error where ok=1;";
        my $result = 0;
        my $sth = $dbh->prepare( $sql_text )  ||  die "Kann Statement nicht vorbereiten: $DBI::errstr\n";
        #print '<p class="smalltext"/>'.$sql_text."</p>\n";                                       
        $sth->execute or die $sth->errstr; # hier geschieht die Anfrage an die DB
        while (my $arrayref = $sth->fetchrow_arrayref()) {      
                foreach(@$arrayref) {
                        $result = $_;
                }
        }
        return ($result);
}
 
 
sub get_number_all_errors{
        my $sql_text = "select count(*) from pd_error where ok=0 ;";
        my $result = 0;
        my $sth = $dbh->prepare( $sql_text )  ||  die "Kann Statement nicht vorbereiten: $DBI::errstr\n";
        #print '<p class="smalltext"/>'.$sql_text."</p>\n";                                       
        $sth->execute or die $sth->errstr; # hier geschieht die Anfrage an die DB
        while (my $arrayref = $sth->fetchrow_arrayref()) {      
                foreach(@$arrayref) {
                        $result = $_;
                }
        }
        return ($result);
}
 
sub get_number_of_error{
        # Anzahl gefundenen Vorkommen eines Fehlers
        my $error = $_[0];
        my $sql_text = "select count(*) from pd_error where ok=0 and error = ".$error.";";
        my $result = 0;
        my $sth = $dbh->prepare( $sql_text )  ||  die "Kann Statement nicht vorbereiten: $DBI::errstr\n";
        #print '<p class="smalltext"/>'.$sql_text."</p>\n";                                       
        $sth->execute or die $sth->errstr; # hier geschieht die Anfrage an die DB
        while (my $arrayref = $sth->fetchrow_arrayref()) {      
                foreach(@$arrayref) {
                        $result = $_;
                }
        }
        return ($result);
}
 
sub get_number_of_prio{
        my $prio = $_[0];
        my $sql_text = "select count(*) from pd_error a join pd_error_desc b on ( a.error = b.id) where b.prio = ".$prio." and ok=0;";
        my $result = 0;
        my $sth = $dbh->prepare( $sql_text )  ||  die "Kann Statement nicht vorbereiten: $DBI::errstr\n";
        #print '<p class="smalltext"/>'.$sql_text."</p>\n";                                       
        $sth->execute or die $sth->errstr; # hier geschieht die Anfrage an die DB
        while (my $arrayref = $sth->fetchrow_arrayref()) {      
                foreach(@$arrayref) {
                        $result = $_;
                }
        }
        return ($result);
}
 
sub get_number_error_and_desc_by_prio{
        my $prio = $_[0];
        my $sql_text = " select count(*), b.id,  b.name from pd_error a join pd_error_desc b on ( a.error = b.id) where b.prio = ".$prio." and a.ok=0 group by b.id order by b.name;";
        my $result = '';
        my $sth = $dbh->prepare( $sql_text )  ||  die "Kann Statement nicht vorbereiten: $DBI::errstr\n";
        #print '<p class="smalltext"/>'.$sql_text."</p>\n";                                       
        $sth->execute or die $sth->errstr; # hier geschieht die Anfrage an die DB
        $result .= '<table class="table">';
        $result .= '<tr><th class="table">Anzahl</th><th class="table">Beschreibung</th><th class="table">Nummer</th>'."\n";
        while (my $arrayref = $sth->fetchrow_arrayref()) {      
                my @output;
                my $i = 0;
                my $j = 0;
                foreach(@$arrayref) {
                        #print $_."\n";
                        $output[$i][$j] = $_;
                        $j = $j +1;
                        if ($j == 3) {
                                $j= 0;
                                $i ++;
                        }
                        #print $_."\n";
                }
                my $number_of_error = $i;
                for (my $i = 0; $i< $number_of_error; $i++) {           
                        $result .= '<tr><td class="table" align="right"  valign="middle">'.$output[$i][0].'</td><td class="table"><a href="http://toolserver.org/~sk/cgi-bin/pd/pd.cgi?error='.$output[$i][1].'">'.$output[$i][2].'</a></td><td class="table" align="right"  valign="middle">'.$output[$i][1]."</td></tr>\n";   
                }
        }
        $result .= '</table>';
        return ($result);
}
 
sub get_headline{
        my $error = $_[0];
        my $sql_text = " select name from pd_error_desc where id = ".$error.";";
        my $result = '';
        my $sth = $dbh->prepare( $sql_text )  ||  die "Kann Statement nicht vorbereiten: $DBI::errstr\n";
        #print '<p class="smalltext"/>'.$sql_text."</p>\n";                                       
        $sth->execute or die $sth->errstr; # hier geschieht die Anfrage an die DB
        while (my $arrayref = $sth->fetchrow_arrayref()) {      
                foreach(@$arrayref) {
                        $result = $_;
                }
        }
        return ($result);
}
 
 
sub get_description{
        my $error = $_[0];
        my $sql_text = " select text from pd_error_desc where id = ".$error.";";
        my $result = '';
        my $sth = $dbh->prepare( $sql_text )  ||  die "Kann Statement nicht vorbereiten: $DBI::errstr\n";
        #print '<p class="smalltext"/>'.$sql_text."</p>\n";                                       
        $sth->execute or die $sth->errstr; # hier geschieht die Anfrage an die DB
        while (my $arrayref = $sth->fetchrow_arrayref()) {      
                foreach(@$arrayref) {
                        $result = $_;
                }
        }
        return ($result);
}
 
sub get_prio_of_error{
        my $error = $_[0];
        my $sql_text = " select prio from pd_error_desc where id = ".$error.";";
        my $result = '';
        my $sth = $dbh->prepare( $sql_text )  ||  die "Kann Statement nicht vorbereiten: $DBI::errstr\n";
        #print '<p class="smalltext"/>'.$sql_text."</p>\n";                                       
        $sth->execute or die $sth->errstr; # hier geschieht die Anfrage an die DB
        while (my $arrayref = $sth->fetchrow_arrayref()) {      
                foreach(@$arrayref) {
                        $result = $_;
                }
        }
        return ($result);
}
 
sub get_article_of_error{
        my $error = $_[0];
        #my $sql_text = " select title, hinweis, id from pd_error where error = ".$error." and ok=0 order by title limit 25;";
        my $sql_text =   "select a.title, a.hinweis, a.id from (
                 select title, hinweis, id ,
                 replace(replace (REVERSE (title),')',''),'.','') Test
                 from pd_error
                where error = ".$error."
                 and ok = 0
                 order by Test
                 limit 25)a order by a.title;";
 
 
        my $result = '';
        my $sth = $dbh->prepare( $sql_text )  ||  die "Kann Statement nicht vorbereiten: $DBI::errstr\n";
        #print '<p class="smalltext"/>'.$sql_text."</p>\n";                                       
        $sth->execute or die $sth->errstr; # hier geschieht die Anfrage an die DB
        $result .= '<table class="table">';
        $result .= '<tr><th class="table">Artikel</th><th class="table">Hinweis</th><th class="table">Abarbeitung</th>'."\n";
        while (my $arrayref = $sth->fetchrow_arrayref()) {      
                my @output;
                my $i = 0;
                my $j = 0;
                foreach(@$arrayref) {
                        #print $_."\n";
                        $output[$i][$j] = $_;
                        $j = $j +1;
                        if ($j == 3) {
                                $j= 0;
                                $i ++;
                        }
                        #print $_."\n";
                }
                my $number_of_error = $i;
                for (my $i = 0; $i< $number_of_error; $i++) {           
                        $result .= '<tr><td class="table"><a href="http://de.wikipedia.org/wiki/'.$output[$i][0].'">'.$output[$i][0].'</a></td><td class="table">'.$output[$i][1].'</td><td class="table">';
 
                        $result .= "<a href='http://toolserver.org/~sk/cgi-bin/pd/pd.cgi?error=".$error."&id=".$output[$i][2]."'>Erledigt</a>";
                        $result .= "</td></tr>\n";      
                }
        }
        $result .= '</table>';
        return ($result);
}
 
 
sub get_top25{
        my $sql_text = "select title, count(*), id from pd_error group by title order by count(*) desc, title limit 25;";
        my $sth = $dbh->prepare( $sql_text )  ||  die "Kann Statement nicht vorbereiten: $DBI::errstr\n";
        #print '<p class="smalltext"/>'.$sql_text."</p>\n";                                       
        $sth->execute or die $sth->errstr; # hier geschieht die Anfrage an die DB
        my $result = '';
        $result .= '<table class="table">';
        $result .= '<tr><th class="table">Fehleranzahl</th><th class="table">Artikel</th></tr>'."\n";
 
        while (my $arrayref = $sth->fetchrow_arrayref()) {      
                my @output;
                my $i = 0;
                my $j = 0;
                foreach(@$arrayref) {
                        #print $_."\n";
                        $output[$i][$j] = $_;
                        $j = $j +1;
                        if ($j == 3) {
                                $j= 0;
                                $i ++;
                        }
                        #print $_."\n";
                }
                my $number_of_error = $i;
                for (my $i = 0; $i< $number_of_error; $i++) {           
                        $result .= '<tr><td class="table">'.$output[$i][1].'</td><td class="table"><a href="http://de.wikipedia.org/wiki/'.$output[$i][0].'">'.$output[$i][0].'</a></td>';
                        $result .= '<td class="table" align="middle"  valign="middle"><a href="http://toolserver.org/~sk/cgi-bin/pd/pd.cgi?id='.$output[$i][2].'">Details</a></td>';
                        $result .= '</tr>'."\n";        
                }
        }
        $result .= '</table>';
        return ($result);
}
 
 
sub get_all_error_of_article{
        my $id = $_[0];
        my $sql_text = "select a.error, b.name, a.hinweis, a.id from pd_error a join pd_error_desc b on ( a.error = b.id) where a.title = (select title from pd_error where id = ".$id.");";
        my $sth = $dbh->prepare( $sql_text )  ||  die "Kann Statement nicht vorbereiten: $DBI::errstr\n";
        #print '<p class="smalltext"/>'.$sql_text."</p>\n";                                       
        $sth->execute or die $sth->errstr; # hier geschieht die Anfrage an die DB
        my $result = '';
        $result .= '<table class="table">';
        $result .= '<tr><th class="table">Fehler</th><th class="table">Hinweis</th><th class="table">Abarbeitung</th></tr>'."\n";
 
        while (my $arrayref = $sth->fetchrow_arrayref()) {      
                my @output;
                my $i = 0;
                my $j = 0;
                foreach(@$arrayref) {
                        #print $_."\n";
                        $output[$i][$j] = $_;
                        $j = $j +1;
                        if ($j == 4) {
                                $j= 0;
                                $i ++;
                        }
                        #print $_."\n";
                }
                my $number_of_error = $i;
                for (my $i = 0; $i< $number_of_error; $i++) {           
                        $result .= '<tr><td class="table">'.$output[$i][1].'</td><td class="table">'.$output[$i][2].'</td>';
 
                        #$result .= "<td><a href='http://toolserver.org/~sk/cgi-bin/pd/pd.cgi?error=".$output[$i][0]."&id=".$output[$i][3]."'>Erledigt</a></td>";
                        $result .= "</tr>\n";           
                }
        }
        $result .= '</table>';
        return ($result);
}