From 96de8572080327a15f9bbda060b3c52b370274d7 Mon Sep 17 00:00:00 2001 From: Magnus Manske Date: Mon, 19 Jul 2004 19:16:42 +0000 Subject: [PATCH] Article validation code (statistics) --- includes/SpecialValidate.php | 308 ++++++++++++++++++++++------------- languages/Language.php | 5 + 2 files changed, 201 insertions(+), 112 deletions(-) diff --git a/includes/SpecialValidate.php b/includes/SpecialValidate.php index 3c3908a732..f5b432ee93 100644 --- a/includes/SpecialValidate.php +++ b/includes/SpecialValidate.php @@ -17,145 +17,229 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # http://www.gnu.org/copyleft/gpl.html -function find_this_version ( $article_title , &$article_time , &$id , &$tab ) +class Validation { - $id = "" ; - $sql = "SELECT cur_id,cur_timestamp FROM cur WHERE cur_namespace=0 AND cur_title='{$article_title}'" ; - $res = wfQuery( $sql, DB_READ ); - if( $s = wfFetchObject( $res ) ) + # Things that should be in the language files + var $types = array ( + "0" => "Style|Awful|Awesome|5", + "1" => "Legal|Illegal|Legal|5", + "2" => "Completeness|Stub|Extensive|5", + "3" => "Facts|Wild guesses|Concrete|5" + ) ; + + function find_this_version ( $article_title , &$article_time , &$id , &$tab ) { - if ( $article_time == "" ) $article_time = $s->cur_timestamp ; # No timestamp = current version - if ( $article_time == $s->cur_timestamp ) # Means current version + $id = "" ; + $sql = "SELECT cur_id,cur_timestamp FROM cur WHERE cur_namespace=0 AND cur_title='{$article_title}'" ; + $res = wfQuery( $sql, DB_READ ); + if( $s = wfFetchObject( $res ) ) + { + if ( $article_time == "" ) $article_time = $s->cur_timestamp ; # No timestamp = current version + if ( $article_time == $s->cur_timestamp ) # Means current version + { + $tab = "cur" ; + $id = $s->cur_id ; + } + } + + if ( $id == "" ) { - $tab = "cur" ; - $id = $s->cur_id ; + $sql = "SELECT old_id FROM old WHERE old_namespace=0 AND old_title='{$article_title}' AND old_timestamp='{$article_time}'" ; + $res = wfQuery( $sql, DB_READ ); + if( $s = wfFetchObject( $res ) ) + { + $tab = "old" ; + $id = $s->old_id ; + } } } - if ( $id == "" ) + function get_prev_data ( $user_id , $article_title , $article_timestamp = "" ) { - $sql = "SELECT old_id FROM old WHERE old_namespace=0 AND old_title='{$article_title}' AND old_timestamp='{$article_time}'" ; + $ret = array () ; + $sql = "SELECT * FROM validate WHERE val_user='{$user_id}' AND val_title='{$article_title}'" ; + if ( $article_timestamp != "" ) $sql .= " AND val_timestamp='{$article_timestamp}'" ; $res = wfQuery( $sql, DB_READ ); - if( $s = wfFetchObject( $res ) ) - { - $tab = "old" ; - $id = $s->old_id ; - } + while( $s = wfFetchObject( $res ) ) $ret[$s->val_timestamp][$s->val_type] = $s ; + return $ret ; } - } -function get_prev_data ( $user_id , $article_title , $article_timestamp = "" ) - { - $ret = array () ; - $sql = "SELECT * FROM validate WHERE val_user='{$user_id}' AND val_title='{$article_title}'" ; - if ( $article_timestamp != "" ) $sql .= " AND val_timestamp='{$article_timestamp}'" ; - $res = wfQuery( $sql, DB_READ ); - while( $s = wfFetchObject( $res ) ) $ret[$s->val_timestamp][$s->val_type] = $s ; - return $ret ; - } - -function wfSpecialValidate( $page = "" ) { - global $wgOut, $wgLang, $wgUser; - if ( $wgUser->getID() == 0 ) return ; # Anon - $article_title = $_GET['article'] ; - $article_time = "" ; - if ( isset ( $_GET['timestamp'] ) ) $article_time = $_GET['timestamp'] ; - find_this_version ( $article_title , $article_time , $id , $tab ) ; - $article = Title::newFromText ( $article_title ) ; - - # $tab now contains "cur" or "old" - # $id contains the id in that table - - # Things that should be in the language files - $clear_old = "Clear my other validation data for this article" ; - $noop = "No opinion" ; - $types = array ( - "0" => "Style|Awful|Awesome|5", - "1" => "Legal|Illegal|Legal|5", - "2" => "Completeness|Stub|Extensive|5", - "3" => "Facts|Wild guesses|Concrete|5" - ) ; - - # Now we get all the "votes" for the different versions of this article for this user - $val = get_prev_data ( $wgUser->getID() , $article_title ) ; -# if ( !isset ( $val[$article_time] ) ) $val["{$article_time}"] = array () ; - - # User has clicked "Doit" before, so evaluate form - if ( isset ( $_POST['doit'] ) ) + function validate_form ( $article_title = "" ) { - $oldtime = $_POST['oldtime'] ; - if ( !isset ( $val["{$oldtime}"] ) ) $val["{$oldtime}"] = array () ; - if ( isset ( $_POST['clear_other'] ) && $_POST['clear_other'] == 1 ) # Clear all others + global $wgOut, $wgLang, $wgUser; + if ( $wgUser->getID() == 0 ) return ; # Anon + if ( $article_title == "" ) $article_title = $_GET['article'] ; + $article_time = "" ; + if ( isset ( $_GET['timestamp'] ) ) $article_time = $_GET['timestamp'] ; + $article = Title::newFromText ( $article_title ) ; + + # Now we get all the "votes" for the different versions of this article for this user + $val = $this->get_prev_data ( $wgUser->getID() , $article_title ) ; + + # User has clicked "Doit" before, so evaluate form + if ( isset ( $_POST['doit'] ) ) { - $sql = "DELETE FROM validate WHERE val_title='{$article_title}' AND val_timestamp<>'{$oldtime}' AND val_user='" ; + $oldtime = $_POST['oldtime'] ; + if ( !isset ( $val["{$oldtime}"] ) ) $val["{$oldtime}"] = array () ; + if ( isset ( $_POST['clear_other'] ) && $_POST['clear_other'] == 1 ) # Clear all others + { + $sql = "DELETE FROM validate WHERE val_title='{$article_title}' AND val_timestamp<>'{$oldtime}' AND val_user='" ; + $sql .= $wgUser->getID() . "'" ; + wfQuery( $sql, DB_WRITE ); + $val2 = $val["{$oldtime}"] ; # Only version left + $val = array () ; # So clear others + $val["{$oldtime}"] = $val2 ; + } + + # Delete old "votes" for this version + $sql = "DELETE FROM validate WHERE val_title='{$article_title}' AND val_timestamp='{$oldtime}' AND val_user='" ; $sql .= $wgUser->getID() . "'" ; wfQuery( $sql, DB_WRITE ); - $val2 = $val["{$oldtime}"] ; # Only version left - $val = array () ; # So clear others - $val["{$oldtime}"] = $val2 ; + + for ( $idx = 0 ; $idx < count ( $this->types) ; $idx++ ) # Changes + { + $comment = $_POST["comment{$idx}"] ; + $comment_sql = str_replace ( "'" , "\'" , $comment ) ; + $rad = $_POST["rad{$idx}"] ; + if ( !isset ( $val["{$oldtime}"][$idx] ) ) $val["{$oldtime}"][$idx] = "" ; + $val["{$oldtime}"][$idx]->val_value = $rad ; + $val["{$oldtime}"][$idx]->val_comment = $comment ; + if ( $rad != -1 ) + { + # Store it in the database + $sql = "INSERT INTO validate (val_user,val_title,val_timestamp,val_type,val_value,val_comment) " . + "VALUES ( '" . $wgUser->getID() . "','{$article_title}','{$oldtime}','{$idx}','{$rad}','{$comment_sql}')" ; + if ( $rad != -1 ) wfQuery( $sql, DB_WRITE ); + } + } } - - # Delete old "votes" for this version - $sql = "DELETE FROM validate WHERE val_title='{$article_title}' AND val_timestamp='{$oldtime}' AND val_user='" ; - $sql .= $wgUser->getID() . "'" ; - wfQuery( $sql, DB_WRITE ); - - for ( $idx = 0 ; $idx < count ( $types) ; $idx++ ) # Changes + + # Generating HTML + $html = "

" . $article->getPrefixedText() . "

\n" ; + foreach ( $val AS $time => $stuff ) { - $comment = $_POST["comment{$idx}"] ; - $comment_sql = str_replace ( "'" , "\'" , $comment ) ; - $rad = $_POST["rad{$idx}"] ; - if ( !isset ( $val["{$oldtime}"][$idx] ) ) $val["{$oldtime}"][$idx] = "" ; - $val["{$oldtime}"][$idx]->val_value = $rad ; - $val["{$oldtime}"][$idx]->val_comment = $comment ; - if ( $rad != -1 ) + if ( $time == $article_time ) $html .= "

This version

\n" ; + else $html .= "

Version of {$time}

\n" ; + $html .= "
\n" ; + $html .= "" ; + $html .= "\n" ; + $html .= "\n" ; + for ( $idx = 0 ; $idx < count ( $this->types) ; $idx++ ) { - # Store it in the database - $sql = "INSERT INTO validate (val_user,val_title,val_timestamp,val_type,val_value,val_comment) " . - "VALUES ( '" . $wgUser->getID() . "','{$article_title}','{$oldtime}','{$idx}','{$rad}','{$comment_sql}')" ; - if ( $rad != -1 ) wfQuery( $sql, DB_WRITE ); + $x = explode ( "|" , $this->types[$idx] , 4 ) ; + if ( isset ( $stuff[$idx] ) ) $choice = $stuff[$idx]->val_value ; + else $choice = -1 ; + if ( isset ( $stuff[$idx] ) ) $comment = $stuff[$idx]->val_comment ; + else $comment = "" ; + $html .= "" ; + $html .= "\n" ; } + $html .= "" ; + $html .= "
ClassOpinionComment
{$x[0]}{$x[1]}" ; + for ( $cnt = 0 ; $cnt < $x[3] ; $cnt++) + { + $html .= "" ; + $html .= "
" ; + $html .= str_replace ( "$1" , $article->getPrefixedURL() , wfMsg("clear_old") ) ; + $html .= "
\n" ; } + return $html ; } - - # Generating HTML - $html = "

" . $article->getPrefixedText() . "

\n" ; - foreach ( $val AS $time => $stuff ) + + function getData ( $user = -1 , $title = "" , $type = -1 ) { - if ( $time == $article_time ) $html .= "

This version

\n" ; - else $html .= "

Version of {$time}

\n" ; - $html .= "
\n" ; - $html .= "" ; - $html .= "\n" ; - $html .= "\n" ; - for ( $idx = 0 ; $idx < count ( $types) ; $idx++ ) + $ret = array () ; + $sql = array () ; + if ( $user != -1 ) $sql[] = "val_user='{$user}'" ; + if ( $type != -1 ) $sql[] = "val_type='{$type}'" ; + if ( $title != "" ) $sql[] = "val_title='{$title}'" ; + $sql = implode ( " AND " , $sql ) ; + if ( $sql != "" ) $sql = " WHERE " . $sql ; + $sql = "SELECT * FROM validate" . $sql ; + $res = wfQuery( $sql, DB_READ ); + while( $s = wfFetchObject( $res ) ) $ret["{$s->val_title}"]["{$s->val_timestamp}"]["{$s->val_type}"] = $s ; + return $ret ; + } + + function getPageStatistics ( $article_title = "" ) + { + $article_title = $_GET['article'] ; + $html = "

Page validation statistics

\n" ; + $d = $this->getData ( -1 , $article_title , -1 ) ; + if ( count ( $d ) ) $d = array_shift ( $d ) ; + else $d = array () ; + $html .= "
ClassOpinionComment
\n" ; + $html .= "" ; + foreach ( $this->types AS $idx => $title ) { - $x = explode ( "|" , $types[$idx] , 4 ) ; - if ( isset ( $stuff[$idx] ) ) $choice = $stuff[$idx]->val_value ; - else $choice = -1 ; - if ( isset ( $stuff[$idx] ) ) $comment = $stuff[$idx]->val_comment ; - else $comment = "" ; - $html .= "" ; + } + $html .= "\n" ; + foreach ( $d AS $version => $data ) + { + $html .= "" ; + $html .= "" ; + + $vmax = array() ; + $vcur = array() ; + foreach ( $data AS $type => $x ) { - $html .= "val_value ; + $vmax[$type] += $title[3] ; } - $html .= "" ; - $html .= "" ; + } + + $html .= "" ; } - $html .= "" ; - $html .= "
Version
{$x[0]}{$x[1]}" ; - for ( $cnt = 0 ; $cnt < $x[3] ; $cnt++) + $title = explode ( "|" , $title ) ; + $html .= "{$title[0]}
{$version}{$x[2]}types AS $idx => $title ) + { + $html .= "" ; + if ( isset ( $vcur[$idx] ) ) + { + $average = 100 * $vcur[$idx] / $vmax[$idx] ; + $h = wfMsg ( "val_percent" ) ; + $h = str_replace ( "$1" , $average , $h ) ; + $h = str_replace ( "$2" , $vcur[$idx] , $h ) ; + $h = str_replace ( "$3" , $vmax[$idx] , $h ) ; + $html .= $h ; + } + else $html .= "(" . wfMsg ( "val_noop" ) . ")" ; + $html .= "
" ; - $html .= str_replace ( "$1" , $article->getFullURL() , $clear_old ) ; - $html .= "
\n" ; + $html .= "\n" ; + return $html ; } + + } +function wfSpecialValidate( $page = "" ) + { + global $wgOut ; + if ( isset ( $_GET['mode'] ) ) $mode = $_GET['mode'] ; + else $mode = "form" ; + $v = new Validation ; + $html = "" ; + if ( $mode == "form" ) + { + $html = $v->validate_form () ; + } + else if ( $mode == "stat_page" ) + { + $html = $v->getPageStatistics () ; + } + $wgOut->addHTML( $html ) ; -} + } ?> diff --git a/languages/Language.php b/languages/Language.php index e10a74a82b..47cc8b7361 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -1228,6 +1228,11 @@ Type the name of the user in the box and press the button to make the user an ad 'set_rights_fail' => "User rights for \"$1\" could not be set. (Did you enter the name correctly?)", 'makesysop' => 'Make a user into a sysop', +# Validation +'val_clear_old' => 'Clear my other validation data for the article', +'val_noop' => 'No opinion', +'val_percent' => '$1% ($2 of $3 points)', + # Move page # 'movepage' => 'Move page', -- 2.20.1