X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSpecialValidate.php;h=23bf6f62eab29ec3317d191feda4b1be61a0e8ed;hb=2a03980093b5168a834bbf65e820c5400e29b21b;hp=735de01659dab1ecbacc3a3fbc475735848149a8;hpb=797b07d809dcf8ea667b6050f4e1e24dbce0ac7f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SpecialValidate.php b/includes/SpecialValidate.php index 735de01659..23bf6f62ea 100644 --- a/includes/SpecialValidate.php +++ b/includes/SpecialValidate.php @@ -17,151 +17,160 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # http://www.gnu.org/copyleft/gpl.html -class Validation - { +/** + * + * @package MediaWiki + * @subpackage SpecialPage + */ + +/** + * + * @package MediaWiki + * @subpackage SpecialPage + */ +class Validation { - function find_this_version ( $article_title , &$article_time , &$id , &$tab ) - { - $id = "" ; - $tab = "" ; - $sql = "SELECT cur_id,cur_timestamp FROM cur WHERE cur_namespace=0 AND cur_title='" . wfStrencode( $article_title ) . "'" ; + function find_this_version( $article_title , &$article_time , &$id , &$tab ) { + $id = ""; + $tab = ""; + $sql = "SELECT cur_id,cur_timestamp FROM cur WHERE cur_namespace=0 AND cur_title='" . wfStrencode( $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( $s = wfFetchObject( $res ) ) { + if ( $article_time == "" ) { + # No timestamp = current version + $article_time = $s->cur_timestamp; + } elseif ( $article_time == $s->cur_timestamp ) { + # Means current version + $tab = "cur"; + $id = $s->cur_id; } + } - if ( $id == "" ) - { + if ( $id == "" ) { $sql = "SELECT old_id FROM old WHERE old_namespace=0 AND old_title='" . wfStrencode( $article_title ) . - "' AND old_timestamp='" . wfStrencode( $article_time ) . "'" ; + "' AND old_timestamp='" . wfStrencode( $article_time ) . "'"; $res = wfQuery( $sql, DB_READ ); - if( $s = wfFetchObject( $res ) ) - { - $tab = "old" ; - $id = $s->old_id ; - } + if( $s = wfFetchObject( $res ) ) { + $tab = "old"; + $id = $s->old_id; } } - - function get_prev_data ( $user_id , $article_title , $article_timestamp = "" ) - { - $ret = array () ; + } + + function get_prev_data( $user_id , $article_title , $article_timestamp = "" ) { + $ret = array (); $sql = "SELECT * FROM validate WHERE val_user='" . wfStrencode( $user_id ) . - "' AND val_title='" . wfStrencode( $article_title ) . "'" ; - if ( $article_timestamp != "" ) $sql .= " AND val_timestamp='" . wfStrencode( $article_timestamp ) . "'" ; + "' AND val_title='" . wfStrencode( $article_title ) . "'"; + if ( $article_timestamp != "" ) { + $sql .= " AND val_timestamp='" . wfStrencode( $article_timestamp ) . "'"; + } $res = wfQuery( $sql, DB_READ ); - while( $s = wfFetchObject( $res ) ) $ret[$s->val_timestamp][$s->val_type] = $s ; - return $ret ; + while( $s = wfFetchObject( $res ) ) { + $ret[$s->val_timestamp][$s->val_type] = $s; } - - function validate_form ( $article_title = "" ) - { - global $wgOut, $wgLang, $wgUser, $wgArticle ; + return $ret; + } + + function validate_form( $article_title = "" ) { + global $wgOut, $wgLang, $wgUser, $wgArticle, $wgRequest; - if ( $wgUser->getID() == 0 ) # Anon - { - $wgOut->addHTML ( wfMsg ( 'val_no_anon_validation' ) . $this->getPageStatistics ( $article_title ) ) ; - return ; - } + if ( $wgUser->getID() == 0 ) { + # Anon + $wgOut->addHTML( htmlspecialchars( wfMsg( 'val_no_anon_validation' ) ) . + $this->getPageStatistics ( $article_title ) ) ; + return; + } - $validationtypes = $wgLang->getValidationTypes() ; - if ( $article_title == "" ) - { - $article_title = $_GET['article_title'] ; - $heading = "

" . $article_title . "

\n" ; - } - else $heading = "" ; - $article_time = "" ; - if ( isset ( $_GET['timestamp'] ) ) $article_time = $_GET['timestamp'] ; - else $article_time = "" ; - $article = Title::newFromText ( $article_title ) ; + $validationtypes = $wgLang->getValidationTypes(); + if ( $article_title == "" ) { + $article_title = $wgRequest->getVal( 'article_title' ); + $heading = "

" . htmlspecialchars( $article_title ) . "

\n"; + } else { + $heading = ""; + } + $article_time = ""; + $article_time = $wgRequest->getVal( 'timestamp' ); + $article = Title::newFromText( $article_title ); + if( is_null( $article ) ) { + $wgOut->errorpage( "badtitle", "badtitletext" ); + return; + } # 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 ) ; + $val = $this->get_prev_data( $wgUser->getID() , $article_title ); # No votes for this version, initial data - if ( !isset ( $val[$article_time] ) ) - { - if ( $article_time == "" ) - { + if( !isset( $val[$article_time] ) ) { + if( $article_time == "" ) { $res = wfQuery( "select cur_timestamp FROM cur WHERE cur_title='" . wfStrencode( $article_title ) . "' AND cur_namespace=0", DB_READ ); - if ( $s = wfFetchObject( $res ) ) $article_time = $s->cur_timestamp ; + if( $s = wfFetchObject( $res ) ) { + $article_time = $s->cur_timestamp; } - $val[$article_time] = array () ; } + $val[$article_time] = array(); + } - krsort ( $val ) ; # Newest versions first + # Newest versions first + krsort( $val ); # User has clicked "Doit" before, so evaluate form - if ( isset ( $_POST['doit'] ) ) - { - $oldtime = $_POST['oldtime'] ; - if ( !isset ( $val["{$oldtime}"] ) ) $val["{$oldtime}"] = array () ; + if( $wgRequest->wasPosted() ) { + $oldtime = StrVal( $wgRequest->getVal( 'oldtime' ) ); + if( !isset ( $val[$oldtime] ) ) { + $val[$oldtime] = array(); + } # Reading postdata - $postrad = array () ; - $poscomment = array () ; - for ( $idx = 0 ; $idx < count ( $validationtypes) ; $idx++ ) - { - $postrad[$idx] = $_POST["rad{$idx}"] ; - $postcomment[$idx] = $_POST["comment{$idx}"] ; - } + $postrad = array(); + $poscomment = array(); + for( $idx = 0 ; $idx < count( $validationtypes) ; $idx++ ) { + $postrad[$idx] = $wgRequest->getVal( "rad{$idx}" ); + $postcomment[$idx] = $wgRequest->getText( "comment{$idx}" ); + } # Merge others into this one - if ( isset ( $_POST['merge_other'] ) && $_POST['merge_other'] == 1 ) - { - foreach ( $val AS $time => $stuff ) - { - if ( $time <> $article_time ) - { - for ( $idx = 0 ; $idx < count ( $validationtypes) ; $idx++ ) - { - $rad = $postrad[$idx] ; - if ( isset ( $stuff[$idx] ) AND $stuff[$idx]->val_value != -1 AND $rad == -1 ) - { - $postrad[$idx] = $stuff[$idx]->val_value ; - $postcomment[$idx] = $stuff[$idx]->val_comment ; - } + if( $wgRequest->getCheck( 'merge_other' ) ) { + foreach( $val as $time => $stuff ) { + if( $time != $article_time ) { + for( $idx = 0; $idx < count( $validationtypes ); $idx++ ) { + $rad = $postrad[$idx]; + if( isset ( $stuff[$idx] ) && $stuff[$idx]->val_value != -1 && $rad == -1 ) { + $postrad[$idx] = $stuff[$idx]->val_value; + $postcomment[$idx] = $stuff[$idx]->val_comment; } } } } - + } + # Clear all others - if ( isset ( $_POST['clear_other'] ) && $_POST['clear_other'] == 1 ) - { + if( $wgRequest->getCheck( 'clear_other' ) ) { $sql = "DELETE FROM validate WHERE val_title='" . wfStrencode( $article_title ) . - "' AND val_timestamp<>'" . wfStrencode( $oldtime ) . "' AND val_user='" ; - $sql .= wfStrencode( $wgUser->getID() ) . "'" ; + "' AND val_timestamp<>'" . wfStrencode( $oldtime ) . "' AND val_user='"; + $sql .= wfStrencode( $wgUser->getID() ) . "'"; wfQuery( $sql, DB_WRITE ); - $val2 = $val["{$oldtime}"] ; # Only version left - $val = array () ; # So clear others - $val["{$oldtime}"] = $val2 ; - } + $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='" . wfStrencode( $article_title ) . - "' AND val_timestamp='" . wfStrencode( $oldtime ) . "' AND val_user='" ; - $sql .= wfStrencode( $wgUser->getID() ) . "'" ; + "' AND val_timestamp='" . wfStrencode( $oldtime ) . "' AND val_user='"; + $sql .= wfStrencode( $wgUser->getID() ) . "'"; wfQuery( $sql, DB_WRITE ); - + # Incorporate changes - for ( $idx = 0 ; $idx < count ( $validationtypes) ; $idx++ ) # Changes - { + for( $idx = 0; $idx < count( $validationtypes ); $idx++ ) { $comment = $postcomment[$idx] ; $rad = $postrad[$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 ( !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 ( '" . wfStrencode( $wgUser->getID() ) . "','" . @@ -169,350 +178,375 @@ class Validation wfStrencode( $oldtime ) . "','" . wfStrencode( $idx ) . "','" . wfStrencode( $rad ) . "','" . - wfStrencode( $comment ) . "')" ; - if ( $rad != -1 ) wfQuery( $sql, DB_WRITE ); - } + wfStrencode( $comment ) . "')"; + wfQuery( $sql, DB_WRITE ); } - $wgArticle->showArticle( "Juhuu", wfMsg( 'val_validated' ) ); - return ; # Show article instead of validation page } - + $wgArticle->showArticle( "Juhuu", wfMsg( 'val_validated' ) ); + return; # Show article instead of validation page + } + # Generating HTML - $html = "" ; - - $skin = $wgUser->getSkin() ; - $staturl = $skin->makeSpecialURL ( "validate" , "mode=stat_page&article_title=" . urlencode( $article_title ) ) ; - $listurl = $skin->makeSpecialURL ( "validate" , "mode=list_page" ) ; - $html .= "" . wfMsg('val_stat_link_text') . " \n" ; - $html .= "" . wfMsg('val_article_lists') . "
\n" ; - $html .= "" . wfMsg('val_form_note') . "
\n" ; + $html = ""; + + $skin = $wgUser->getSkin(); + $staturl = $skin->makeSpecialURL( "validate" , "mode=stat_page&article_title=" . urlencode( $article_title ) ); + $listurl = $skin->makeSpecialURL( "validate" , "mode=list_page" ); + $html .= "" . wfMsg('val_stat_link_text') . " \n"; + $html .= "" . wfMsg('val_article_lists') . "
\n"; + $html .= "" . wfMsg('val_form_note') . "
\n"; # Generating data tables - $tabsep = "" ; - $topstyle = "style='border-top:2px solid black'" ; - foreach ( $val AS $time => $stuff ) - { - $tablestyle = "cellspacing='0' cellpadding='2'" ; - if ( $article_time == $time ) $tablestyle .=" style='border: 2px solid red'" ; - $html .= "

" . wfMsg( 'val_version_of', gmdate( "F d, Y H:i:s", wfTimestamp2Unix( $time ) ) ) ; - $this->find_this_version ( $article_title , $time , $table_id , $table_name ) ; - if ( $table_name == "cur" ) $html .= " (" . wfMsg ( 'val_this_is_current_version' ) . ")" ; + $tabsep = ""; + $topstyle = "style='border-top:2px solid black'"; + foreach( $val as $time => $stuff ) { + $tablestyle = "cellspacing='0' cellpadding='2'"; + if ( $article_time == $time ) { + $tablestyle .=" style='border: 2px solid red'"; + } + $html .= "

" . wfMsg( 'val_version_of', gmdate( "F d, Y H:i:s", wfTimestamp2Unix( $time ) ) ); + $this->find_this_version ( $article_title , $time , $table_id , $table_name ); + if( $table_name == "cur" ) { + $html .= " (" . wfMsg( 'val_this_is_current_version' ) . ")"; + } $html .= "

\n" ; $html .= "
\n" ; $html .= "" ; $html .= "\n" ; - $html .= wfMsg( 'val_table_header', $tabsep ) ; - for ( $idx = 0 ; $idx < count ( $validationtypes) ; $idx++ ) - { - $x = explode ( "|" , $validationtypes[$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 .= "{$tabsep}" ; - $html .= "\n" ; + $html .= wfMsg( 'val_table_header', $tabsep ); + for( $idx = 0; $idx < count( $validationtypes ); $idx++ ) { + $x = explode( "|" , $validationtypes[$idx] , 4 ); + if( isset ( $stuff[$idx] ) ) { + $choice = $stuff[$idx]->val_value; + } else { + $choice = -1; } - $html .= "{$tabsep}" + . ""; + $html .= "\n"; + } + $html .= "" ; - $html .= "
{$x[0]}{$x[1]}" ; - for ( $cnt = 0 ; $cnt < $x[3] ; $cnt++) - { - $html .= "{$tabsep}" ; - $html .= "
" ; - + if( isset( $stuff[$idx] ) ) { + $comment = $stuff[$idx]->val_comment; + } else { + $comment = ""; + } + $html .= "
{$x[0]}{$x[1]}" ; + for( $cnt = 0 ; $cnt < $x[3] ; $cnt++) { + $html .= "{$tabsep}"; + $html .= "
"; + # link to version - $title = Title::newFromDBkey ( $article_title ) ; - if ( $table_name == "cur" ) $link_version = $title->getLocalURL( "" ) ; - else $link_version = $title->getLocalURL( "oldid={$table_id}" ) ; - $link_version = "" . wfMsg ( 'val_view_version' ) . "" ; - $html .= $link_version ; - $html .= "" ; - $html .= "" ; - $html .= wfMsg ( 'val_merge_old' ); - $html .= "
" ; - $html .= wfMsg ( 'val_clear_old', $skin->makeKnownLinkObj( $article ) ); - $html .= "
\n" ; + $title = Title::newFromDBkey( $article_title ); + if ( $table_name == "cur" ) { + $link_version = $title->getLocalURL( "" ); + } else { + $link_version = $title->getLocalURL( "oldid={$table_id}" ); } - - $html .= "

" . wfMsg ( 'preview' ) . "

" ; - $wgOut->addHTML ( $html ) ; - $wgOut->addWikiText ( $wgArticle->getContent( true ) ) ; + $link_version = "" . wfMsg ( 'val_view_version' ) . ""; + $html .= $link_version; + $html .= ""; + $html .= ""; + $html .= wfMsg( 'val_merge_old' ); + $html .= "
"; + $html .= wfMsg( 'val_clear_old', $skin->makeKnownLinkObj( $article ) ); + $html .= ""; + $html .= "\n"; } - function getData ( $user = -1 , $title = "" , $type = -1 ) - { - $ret = array () ; - $sql = array () ; - if ( $user != -1 ) $sql[] = "val_user='" . wfStrencode( $user ) . "'" ; - if ( $type != -1 ) $sql[] = "val_type='" . wfStrencode( $type ) . "'" ; - if ( $title != "" ) $sql[] = "val_title='" . wfStrencode( $title ) . "'" ; - $sql = implode ( " AND " , $sql ) ; - if ( $sql != "" ) $sql = " WHERE " . $sql ; - $sql = "SELECT * FROM validate" . $sql ; + $html .= "

" . wfMsg( 'preview' ) . "

"; + $wgOut->addHTML( $html ); + $wgOut->addWikiText( $wgArticle->getContent( true ) ); + } + + function getData( $user = -1 , $title = "" , $type = -1 ) { + $ret = array(); + $sql = array(); + if( $user != -1 ) { + $sql[] = "val_user='" . wfStrencode( $user ) . "'"; + } + if( $type != -1 ) { + $sql[] = "val_type='" . wfStrencode( $type ) . "'"; + } + if( $title != "" ) { + $sql[] = "val_title='" . wfStrencode( $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 ; + while( $s = wfFetchObject( $res ) ) { + $ret["{$s->val_title}"]["{$s->val_timestamp}"]["{$s->val_type}"][] = $s; } - + return $ret; + } + # Show statistics for the different versions of a single article - function getPageStatistics ( $article_title = "" ) - { - global $wgLang, $wgUser , $wgOut ; - $validationtypes = $wgLang->getValidationTypes() ; - if ( $article_title == "" ) $article_title = $_GET['article_title'] ; - $d = $this->getData ( -1 , $article_title , -1 ) ; - if ( count ( $d ) ) $d = array_shift ( $d ) ; - else $d = array () ; - krsort ( $d ) ; + function getPageStatistics( $article_title = "" ) { + global $wgLang, $wgUser, $wgOut, $wgRequest; + $validationtypes = $wgLang->getValidationTypes(); + if( $article_title == "" ) { + $article_title = $wgRequest->getVal( 'article_title' ); + } + $d = $this->getData( -1 , $article_title , -1 ); + if( count ( $d ) ) { + $d = array_shift ( $d ) ; + } else { + $d = array(); + } + krsort( $d ); # Getting table data (cur_id, old_id etc.) for each version - $table_id = array() ; - $table_name = array() ; - foreach ( $d AS $version => $data ) - { - $this->find_this_version ( $article_title , $version , $table_id[$version] , $table_name[$version] ) ; - } - + $table_id = array(); + $table_name = array(); + foreach( $d as $version => $data ) { + $this->find_this_version( $article_title, $version, $table_id[$version], $table_name[$version] ); + } + # Generating HTML - $title = Title::newFromDBkey ( $article_title ) ; - $wgOut->setPageTitle ( wfMsg ( 'val_page_validation_statistics' , $title->getText() ) ) ; -# $html = "

" . wfMsg ( 'val_page_validation_statistics' , $title->getText() ) . "

\n" ; - $html = "" ; - $skin = $wgUser->getSkin() ; - $listurl = $skin->makeSpecialURL ( "validate" , "mode=list_page" ) ; - $html .= "" . wfMsg('val_article_lists') . "

\n" ; - - $html .= "\n" ; - $html .= "" ; - foreach ( $validationtypes AS $idx => $title ) - { - $title = explode ( "|" , $title ) ; - $html .= "" ; - } - $html .= "" ; - $html .= "\n" ; - foreach ( $d AS $version => $data ) - { + $title = Title::newFromDBkey( $article_title ); + $wgOut->setPageTitle( wfMsg( 'val_page_validation_statistics' , $title->getPrefixedText() ) ); + $html = ""; + $skin = $wgUser->getSkin(); + $listurl = $skin->makeSpecialURL( "validate" , "mode=list_page" ); + $html .= "" . wfMsg( 'val_article_lists' ) . "

\n"; + + $html .= "
" . wfMsg('val_version') . "{$title[0]}" . wfMsg('val_total') . "
\n"; + $html .= ""; + foreach( $validationtypes as $idx => $title ) { + $title = explode ( "|" , $title ); + $html .= ""; + } + $html .= ""; + $html .= "\n"; + foreach( $d as $version => $data ) { # Preamble for this version - $title = Title::newFromDBkey ( $article_title ) ; - $version_date = gmdate("F d, Y H:i:s",wfTimestamp2Unix($version)) ; - $version_validate_link = $title->getLocalURL( "action=validate×tamp={$version}" ) ; - $version_validate_link = "" . wfMsg('val_validate_version') . "" ; - if ( $table_name[$version] == 'cur' ) $version_view_link = $title->getLocalURL( "" ) ; - else $version_view_link = $title->getLocalURL( "oldid={$table_id[$version]}" ) ; - $version_view_link = "" . wfMsg('val_view_version') . "" ; - $html .= "" ; - $html .= "" ; + $title = Title::newFromDBkey( $article_title ); + $version_date = $wgLang->timeanddate( $version ); + $version_validate_link = $title->escapeLocalURL( "action=validate×tamp={$version}" ); + $version_validate_link = "" . wfMsg('val_validate_version') . ""; + if( $table_name[$version] == 'cur' ) { + $version_view_link = $title->escapeLocalURL( "" ); + } else { + $version_view_link = $title->escapeLocalURL( "oldid={$table_id[$version]}" ); + } + $version_view_link = "" . wfMsg('val_view_version') . ""; + $html .= ""; + $html .= ""; # Individual data - $vmax = array() ; - $vcur = array() ; - $users = array() ; - foreach ( $data AS $type => $x2 ) - { + $vmax = array(); + $vcur = array(); + $users = array(); + foreach( $data as $type => $x2 ) { if ( !isset ( $vcur[$type] ) ) $vcur[$type] = 0 ; if ( !isset ( $vmax[$type] ) ) $vmax[$type] = 0 ; if ( !isset ( $users[$type] ) ) $users[$type] = 0 ; - foreach ( $x2 AS $user => $x ) - { - $vcur[$type] += $x->val_value ; - $temp = explode ( "|" , $validationtypes[$type]) ; - $vmax[$type] += $temp[3] - 1 ; - $users[$type] += 1 ; - } + foreach( $x2 as $user => $x ) { + $vcur[$type] += $x->val_value; + $temp = explode( "|" , $validationtypes[$type] ); + $vmax[$type] += $temp[3] - 1; + $users[$type] += 1; } - - $total_count = 0 ; - $total_percent = 0 ; - foreach ( $validationtypes AS $idx => $title ) - { - if ( isset ( $vcur[$idx] ) ) - { + } + + $total_count = 0; + $total_percent = 0; + foreach( $validationtypes as $idx => $title ) { + if( isset ( $vcur[$idx] ) ) { $average = 100 * $vcur[$idx] / $vmax[$idx] ; - $total_count += 1 ; - $total_percent += $average ; - if ( $users[$idx] > 1 ) $msgid = "val_percent" ; - else $msgid = "val_percent_single" ; - $html .= "" ; - } - - if ( $total_count > 0 ) - { - $total = $total_percent / $total_count ; - $total = number_format ( $total , 2 ) . " %" ; + $html .= "" ; + $html .= ""; + } - $html .= "" ; + if( $total_count > 0 ) { + $total = $total_percent / $total_count; + $total = number_format( $total , 2 ) . " %"; + } else { + $total = ""; } - $html .= "
" . wfMsg('val_version') . "{$title[0]}" . wfMsg('val_total') . "
{$version_date}
{$version_view_link}
{$version_validate_link}
{$version_date}
{$version_view_link}
{$version_validate_link}
" . - wfMsg ( $msgid, number_format ( $average , 2 ) , - $vcur[$idx] , $vmax[$idx] , $users[$idx] ) ; - } - else - { - $html .= "" ; - $html .= "(" . wfMsg ( "val_noop" ) . ")" ; + $total_count += 1; + $total_percent += $average; + if( $users[$idx] > 1 ) { + $msgid = "val_percent"; + } else { + $msgid = "val_percent_single"; } - $html .= "" . + wfMsg( $msgid, number_format( $average, 2 ) , + $vcur[$idx] , $vmax[$idx] , $users[$idx] ); + } else { + $html .= ""; + $html .= "(" . wfMsg ( "val_noop" ) . ")"; } - else $total = "" ; - $html .= "{$total}
\n" ; - return $html ; + $html .= "{$total}"; + + $html .= ""; } + $html .= "\n"; + return $html ; + } - function countUserValidations ( $userid ) - { + function countUserValidations( $userid ) { $sql = "SELECT count(DISTINCT val_title) AS num FROM validate WHERE val_user=" . IntVal( $userid ); $res = wfQuery( $sql, DB_READ ); - if ( $s = wfFetchObject( $res ) ) $num = $s->num ; - else $num = 0 ; - return $num ; + if ( $s = wfFetchObject( $res ) ) { + $num = $s->num; + } else { + $num = 0; } - - function getArticleList () - { - global $wgLang , $wgOut ; - $validationtypes = $wgLang->getValidationTypes() ; - $wgOut->setPageTitle ( wfMsg ( 'val_article_lists' ) ) ; - $html = "" ; - + return $num; + } + + function getArticleList() { + global $wgLang, $wgOut; + $validationtypes = $wgLang->getValidationTypes(); + $wgOut->setPageTitle( wfMsg( 'val_article_lists' ) ); + $html = ""; + # Choices - $choice = array () ; - $maxw = 0 ; - foreach ( $validationtypes AS $idx => $data ) - { - $x = explode ( "|" , $data , 4 ) ; - if ( $x[3] > $maxw ) $maxw = $x[3] ; + $choice = array (); + $maxw = 0; + foreach( $validationtypes as $idx => $data ) { + $x = explode( "|" , $data , 4 ); + if( $x[3] > $maxw ) { + $maxw = $x[3]; } - foreach ( $validationtypes AS $idx => $data ) - { - $choice[$idx] = array () ; - for ( $a = 0 ; $a < $maxw ; $a++ ) - { - $var = "cb_{$idx}_{$a}" ; - if ( isset ( $_POST[$var] ) ) $choice[$idx][$a] = $_POST[$var] ; # Selected + } + foreach( $validationtypes as $idx => $data ) { + $choice[$idx] = array(); + for( $a = 0 ; $a < $maxw ; $a++ ) { + $var = "cb_{$idx}_{$a}"; + if( isset ( $_POST[$var] ) ) $choice[$idx][$a] = $_POST[$var] ; # Selected else if ( !isset ( $_POST["doit"] ) ) $choice[$idx][$a] = 1 ; # First time else $choice[$idx][$a] = 0 ; # De-selected - } } + } - # The form - $html .= "
\n" ; + $html .= "\n"; $html .= "" ; - foreach ( $validationtypes AS $idx => $data ) - { - $x = explode ( "|" , $data , 4 ) ; + foreach( $validationtypes as $idx => $data ) { + $x = explode ( "|" , $data , 4 ); - $html .= "" ; - $html .= "" ; - $html .= "" ; - - for ( $a = 0 ; $a < $maxw ; $a++ ) - { - if ( $a < $x[3] ) - { - $td = "\n" ; - $html .= "" ; - $html .= "
{$x[0]}{$x[1]}
\n" ; - $html .= "
\n" ; + + $html .= "{$x[2]}"; + $html .= "\n"; + } + $html .= "\n"; + $html .= ""; + $html .= "\n"; + $html .= "\n"; # The query - $articles = array() ; - $sql = "SELECT DISTINCT val_title,val_timestamp,val_type,avg(val_value) AS avg FROM validate GROUP BY val_title,val_timestamp,val_type" ; + $articles = array(); + $sql = "SELECT DISTINCT val_title,val_timestamp,val_type,avg(val_value) AS avg FROM validate GROUP BY val_title,val_timestamp,val_type"; $res = wfQuery( $sql, DB_READ ); - while( $s = wfFetchObject( $res ) ) $articles[$s->val_title][$s->val_timestamp][$s->val_type] = $s ; + while( $s = wfFetchObject( $res ) ) { + $articles[$s->val_title][$s->val_timestamp][$s->val_type] = $s; + } # The list - $html .= "\n"; + return $html; + } - function getVersionLink ( &$title , $timestamp ) - { - $dbkey = $title->getDBkey () ; - $this->find_this_version ( $dbkey , $timestamp , $table_id , $table_name ) ; - if ( $table_name == 'cur' ) $link = $title->getLocalURL( "" ) ; - else $link = $title->getLocalURL( "action=validate×tamp={$table_id}" ) ; - $linktitle = wfMsg( 'val_version_of', gmdate( "F d, Y H:i:s", wfTimestamp2Unix( $timestamp ) ) ) ; - $link = "" . $linktitle . "" ; - if ( $table_name == 'cur' ) $link .= " (" . wfMsg ( 'val_this_is_current_version' ) . ")" ; - - $vlink = wfMsg ( 'val_tab' ) ; - $vlink = "[escapeLocalURL( "action=validate×tamp={$timestamp}" ) . "\">{$vlink}] " . $link ; - return $vlink ; + function getVersionLink( &$title , $timestamp ) { + global $wgLang; + $dbkey = $title->getDBkey(); + $this->find_this_version( $dbkey, $timestamp, $table_id, $table_name ); + if( $table_name == 'cur' ) { + $link = $title->getLocalURL( "" ); + } else { + $link = $title->getLocalURL( "action=validate×tamp={$table_id}" ); + } + $linktitle = wfMsg( 'val_version_of', $wgLang->timeanddate( $timestamp ) ); + $link = "" . $linktitle . ""; + if( $table_name == 'cur' ) { + $link .= " (" . wfMsg ( 'val_this_is_current_version' ) . ")"; } + $vlink = wfMsg( 'val_tab' ); + $vlink = "[escapeLocalURL( "action=validate×tamp={$timestamp}" ) . "\">{$vlink}] " . $link; + return $vlink ; + } + +} + +/** + * constructor + */ +function wfSpecialValidate( $page = '' ) { + global $wgOut, $wgRequest, $wgUseValidation; + + if( !$wgUseValidation ) { + $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" ); + return; } -function wfSpecialValidate( $page = "" ) - { - global $wgOut ; - if ( isset ( $_GET['mode'] ) ) $mode = $_GET['mode'] ; - else $mode = "form" ; - $v = new Validation ; + $mode = $wgRequest->getVal( 'mode', 'form' ); + $v = new Validation; $html = "" ; -/* if ( $mode == "form" ) - { +/* if( $mode == "form" ) { $html = $v->validate_form () ; - } - else */ - if ( $mode == "stat_page" ) - { - $html = $v->getPageStatistics () ; - } - else if ( $mode == "list_page" ) - { - $html = $v->getArticleList () ; - } - - $wgOut->addHTML( $html ) ; + } else */ + if( $mode == "stat_page" ) { + $html = $v->getPageStatistics(); + } else if( $mode == "list_page" ) { + $html = $v->getArticleList(); } + + $wgOut->addHTML( $html ); +} ?>