From: Brion Vibber Date: Wed, 1 Jun 2005 05:59:43 +0000 (+0000) Subject: Get this more or less in line with code formatting standard. X-Git-Tag: 1.5.0alpha2~14 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=5e202cd3239e7ede9ec1e2b1ccc1876e00ef6e51;p=lhc%2Fweb%2Fwiklou.git Get this more or less in line with code formatting standard. Fix some HTML/JS injection bugs. Some aggressive escaping; some message bits should be wikified. Some database bits fixed up for current db system; others need to be done still. --- diff --git a/includes/SpecialValidate.php b/includes/SpecialValidate.php index dd8fa13b7d..8e9f2978bb 100644 --- a/includes/SpecialValidate.php +++ b/includes/SpecialValidate.php @@ -29,588 +29,663 @@ * @subpackage SpecialPage */ class Validation { - var $topicList ; - var $voteCache ; - var $rev2date ; - var $date2ref ; + var $topicList; + var $voteCache; + var $rev2date; + var $date2ref; # Reads all revision information of the specified article - function prepareRevisions ( $id ) { - global $wgDBprefix ; - $this->rev2date = array () ; - $this->date2rev = array () ; - $sql = "SELECT * FROM {$wgDBprefix}revision WHERE rev_page='{$id}'" ; + function prepareRevisions( $id ) { + global $wgDBprefix; + $this->rev2date = array(); + $this->date2rev = array(); + $sql = "SELECT * FROM {$wgDBprefix}revision WHERE rev_page='{$id}'"; $res = wfQuery( $sql, DB_READ ); while( $x = wfFetchObject( $res ) ) { - $this->rev2date[$x->rev_id] = $x ; - $this->date2rev[$x->rev_timestamp] = $x ; - } + $this->rev2date[$x->rev_id] = $x; + $this->date2rev[$x->rev_timestamp] = $x; } + } # Returns a HTML link to the specified article revision - function getVersionLink( &$article , $revision , $text = "" ) { - $t = $article->getTitle() ; - if ( $text == "" ) $text = wfMsg("val_view_version"); - $ret = "getLocalURL ( "oldid={$revision}" ) . "\">" . $text . "" ; - return $ret ; + function getVersionLink( &$article, $revision, $text = "" ) { + $t = $article->getTitle(); + if( $text == "" ) $text = wfMsg("val_view_version"); + $ret = "getLocalURL( "oldid={$revision}" ) . "\">" . $text . ""; + return $ret; } # Returns an array containing all topics you can vote on - function getTopicList () { - global $wgDBprefix ; - $ret = array () ; - $sql = "SELECT * FROM {$wgDBprefix}validate WHERE val_page=0" ; + function getTopicList() { + global $wgDBprefix; + $ret = array(); + $sql = "SELECT * FROM {$wgDBprefix}validate WHERE val_page=0"; $res = wfQuery( $sql, DB_READ ); while( $x = wfFetchObject( $res ) ) { - $ret[$x->val_type] = $x ; + $ret[$x->val_type] = $x; } - ksort ( $ret ) ; - return $ret ; + ksort( $ret ); + return $ret; } # Merges one dataset into another - function mergeInto ( &$source , &$dest ) { - $ret = false ; - foreach ( $source AS $x => $y ) { - $doit = false ; - if ( !isset ( $dest[$x] ) ) $doit = true ; - else if ( $dest[$x]->value == 0 ) $doit = true ; - if ( $doit ) { - $dest[$x] = $y ; - $ret = true ; + function mergeInto( &$source, &$dest ) { + $ret = false; + foreach( $source as $x => $y ) { + $doit = false; + if( !isset( $dest[$x] ) ) { + $doit = true; + } elseif( $dest[$x]->value == 0 ) { + $doit = true; } + if( $doit ) { + $dest[$x] = $y; + $ret = true; + } + } + if( $ret ) { + ksort ( $dest ); } - if ( $ret ) ksort ( $dest ) ; - return $ret ; + return $ret; } # Merges all votes prior to the given revision into it - function mergeOldRevisions ( &$article , $revision ) { - $tmp = $this->voteCache ; - krsort ( $tmp ) ; - $update = false ; - $ts = $this->getTimestamp($revision) ; - $data = $this->voteCache[$ts] ; - foreach ( $tmp AS $x => $y ) { - if ( $x < $ts ) { - if ( $this->mergeInto ( $y , $data ) ) $update = true ; + function mergeOldRevisions( &$article, $revision ) { + $tmp = $this->voteCache; + krsort( $tmp ); + $update = false; + $ts = $this->getTimestamp( $revision ); + $data = $this->voteCache[$ts]; + foreach( $tmp as $x => $y ) { + if( $x < $ts ) { + if( $this->mergeInto( $y, $data ) ) { + $update = true; + } } } - if ( $update ) $this->setRevision ( $article , $revision , $data ) ; + if( $update ) { + $this->setRevision( $article, $revision, $data ); + } } # Clears all votes prior to the given revision - function clearOldRevisions ( &$article , $revision ) { - $tmp = $this->voteCache ; - $ts = $this->getTimestamp($revision); - foreach ( $tmp AS $x => $y ) { - if ( $x < $ts ) $this->deleteRevision ( $article , $this->getRevisionNumber($x) ) ; + function clearOldRevisions( &$article, $revision ) { + $tmp = $this->voteCache; + $ts = $this->getTimestamp( $revision ); + foreach( $tmp as $x => $y ) { + if( $x < $ts ) { + $this->deleteRevision ( $article, $this->getRevisionNumber( $x ) ); + } } } # Updates the votes for the given revision from the FORM data - function updateRevision ( &$article , $revision ) { - global $wgUser, $wgRequest ; + function updateRevision( &$article, $revision ) { + global $wgUser, $wgRequest; - if ( isset ( $this->voteCache[$this->getTimestamp($revision)] ) ) $data = $this->voteCache[$this->getTimestamp($revision)] ; - else $data = array () ; - $nv = $wgRequest->getArray ( "re_v_{$revision}" , array() ) ; - $nc = $wgRequest->getArray ( "re_c_{$revision}" , array() ) ; + if( isset( $this->voteCache[$this->getTimestamp( $revision )] ) ) { + $data = $this->voteCache[$this->getTimestamp( $revision )]; + } else { + $data = array(); + } + $nv = $wgRequest->getArray( "re_v_{$revision}", array() ); + $nc = $wgRequest->getArray( "re_c_{$revision}", array() ); - foreach ( $nv AS $x => $y ) { - $data[$x]->value = $y ; - $data[$x]->comment = $nc[$x] ; + foreach( $nv as $x => $y ) { + $data[$x]->value = $y; + $data[$x]->comment = $nc[$x]; } - krsort ( $data ) ; + krsort( $data ); - $this->setRevision ( $article , $revision , $data ) ; + $this->setRevision( $article, $revision, $data ); } # Sets a specific revision to both cache and database - function setRevision ( &$article , $revision , &$data ) { - global $wgUser , $wgDBprefix ; - $this->deleteRevision ( $article , $revision ) ; - $this->voteCache[$this->getTimestamp($revision)] = $data ; - foreach ( $data AS $x => $y ) { - if ( $y->value > 0 ) { - $sql = "INSERT INTO {$wgDBprefix}validate (val_user,val_page,val_revision,val_type,val_value,val_comment,val_ip) VALUES ('" ; - $sql .= $wgUser->getID() . "','" ; - $sql .= $article->getID() . "','" ; - $sql .= $revision . "','" ; - $sql .= $x . "','" ; - $sql .= $y->value . "','" ; - $sql .= Database::strencode ( $y->comment ) . "','" ; - if ( $wgUser->isAnon() ) $sql .= $wgUser->getName() ; - $sql .= "')" ; - $res = wfQuery( $sql, DB_WRITE ); + function setRevision( &$article, $revision, &$data ) { + global $wgUser; + $this->deleteRevision( $article, $revision ); + $this->voteCache[$this->getTimestamp( $revision )] = $data; + foreach( $data as $x => $y ) { + if( $y->value > 0 ) { + $ip = $wgUser->isAnon() ? $wgUser->getName() : ''; + $dbw =& wfGetDB( DB_MASTER ); + $dbw->insert( 'validate', + array( + 'val_user' => $wgUser->getId(), + 'val_page' => $article->getId(), + 'val_revision' => $revision, + 'val_type' => $x, + 'val_value' => $y->value, + 'val_comment' => $y->comment, + 'val_ip' => $ip ), + 'Validation::setRevision' ); } } } # This function returns a MySQL statement to identify the current user - function identifyMe ( $user = "" ) { - global $wgUser ; - if ( $user == "" ) $user = $wgUser->GetID() ; - if ( User::isIP ( $user ) ) { - return "(val_user='0' AND val_ip='{$user}')" ; + function identifyMe( $user = "" ) { + global $wgUser; + if( $user == "" ) $user = $wgUser->GetID(); + if( User::isIP( $user ) ) { + return "(val_user='0' AND val_ip='{$user}')"; } else { - return "(val_user='{$user}')" ; - } + return "(val_user='{$user}')"; } + } # Deletes a specific vote set in both cache and database - function deleteRevision ( &$article , $revision ) { - global $wgUser , $wgDBprefix ; - $ts = $this->getTimestamp ( $revision ) ; - if ( !isset ( $this->voteCache[$ts] ) ) return ; # Nothing to do - $sql = "DELETE FROM {$wgDBprefix}validate WHERE" . $this->identifyMe() . " AND " ; - $sql .= " val_page='" . $article->getID() . "' AND val_revision='{$revision}'" ; + function deleteRevision( &$article, $revision ) { + global $wgUser, $wgDBprefix; + $ts = $this->getTimestamp( $revision ); + if( !isset ( $this->voteCache[$ts] ) ) { + return; # Nothing to do + } + $sql = "DELETE FROM {$wgDBprefix}validate WHERE" . $this->identifyMe() . " AND "; + $sql .= " val_page='" . $article->getID() . "' AND val_revision='{$revision}'"; $res = wfQuery( $sql, DB_WRITE ); - unset ( $this->voteCache[$ts] ) ; + unset( $this->voteCache[$ts] ); } # Reads the entire vote list for this user for the given article - function getVoteList ( $id , $user = "" ) { - global $wgUser , $wgDBprefix ; - if ( $user == "" ) $user = $wgUser->GetID() ; - $r = array () ; # Revisions - $sql = "SELECT * FROM {$wgDBprefix}validate WHERE val_page=" . $id . " AND " . $this->identifyMe($user) ; + function getVoteList( $id, $user = "" ) { + global $wgUser, $wgDBprefix; + if( $user == "" ) { + $user = $wgUser->GetID(); + } + $r = array() ; # Revisions + $sql = "SELECT * FROM {$wgDBprefix}validate WHERE val_page=" . $id . " AND " . $this->identifyMe( $user ); $res = wfQuery( $sql, DB_READ ); while( $x = wfFetchObject( $res ) ) { - #$y = $x->val_revision ; - $y = $this->rev2date[$x->val_revision] ; - $y = $y->rev_timestamp ; - if ( !isset($r[$y]) ) $r[$y] = array () ; - $r[$y][$x->val_type]->value = $x->val_value ; - $r[$y][$x->val_type]->comment = $x->val_comment ; + #$y = $x->val_revision; + $y = $this->rev2date[$x->val_revision]; + $y = $y->rev_timestamp; + if( !isset( $r[$y] ) ) { + $r[$y] = array(); + } + $r[$y][$x->val_type]->value = $x->val_value; + $r[$y][$x->val_type]->comment = $x->val_comment; } - return $r ; + return $r; } # Reads the entire vote list for this user for all articles - function getAllVoteLists ( $user ) { - global $wgDBprefix ; - $r = array () ; # Revisions - $sql = "SELECT * FROM {$wgDBprefix}validate WHERE " . $this->identifyMe ( $user ) ; + function getAllVoteLists( $user ) { + global $wgDBprefix; + $r = array() ; # Revisions + $sql = "SELECT * FROM {$wgDBprefix}validate WHERE " . $this->identifyMe( $user ); $res = wfQuery( $sql, DB_READ ); while( $x = wfFetchObject( $res ) ) { - $a = $x->val_page ; - $y = $x->val_revision ; - if ( !isset ( $r[$a] ) ) $r[$a] = array () ; - if ( !isset($r[$a][$y]) ) $r[$a][$y] = array () ; - $r[$a][$y][$x->val_type] = $x ; + $a = $x->val_page; + $y = $x->val_revision; + if( !isset( $r[$a] ) ) { + $r[$a] = array(); + } + if( !isset( $r[$a][$y] ) ) { + $r[$a][$y] = array(); + } + $r[$a][$y][$x->val_type] = $x; } - return $r ; + return $r; } # This functions adds a topic to the database - function addTopic ( $topic , $limit ) { - global $wgDBprefix ; - $a = 1 ; - while ( isset ( $this->topicList[$a] ) ) $a++ ; - $sql = "INSERT INTO {$wgDBprefix}validate (val_user,val_page,val_revision,val_type,val_value,val_comment,val_ip) VALUES (" ; - $sql .= "'0','0','0','{$a}','{$limit}','" ; - $sql .= Database::strencode ( $topic ) . "','')" ; + function addTopic( $topic, $limit ) { + global $wgDBprefix; + $a = 1; + while( isset( $this->topicList[$a] ) ) { + $a++; + } + $sql = "INSERT INTO {$wgDBprefix}validate (val_user,val_page,val_revision,val_type,val_value,val_comment,val_ip) VALUES ("; + $sql .= "'0','0','0','{$a}','{$limit}','"; + $sql .= Database::strencode( $topic ) . "','')"; $res = wfQuery( $sql, DB_WRITE ); - $x->val_user = $x->val_page = $x->val_revision = 0 ; - $x->val_type = $a ; - $x->val_value = $limit ; - $x->val_comment = $topic ; - $x->val_ip = "" ; - $this->topicList[$a] = $x ; - ksort ( $this->topicList ) ; + $x->val_user = $x->val_page = $x->val_revision = 0; + $x->val_type = $a; + $x->val_value = $limit; + $x->val_comment = $topic; + $x->val_ip = ""; + $this->topicList[$a] = $x; + ksort( $this->topicList ); } # This functions adds a topic to the database - function deleteTopic ( $id ) { - global $wgDBprefix ; - $sql = "DELETE FROM {$wgDBprefix}validate WHERE val_type='{$id}'" ; - $res = wfQuery( $sql, DB_WRITE ); - unset ( $this->topicList[$id] ) ; + function deleteTopic( $id ) { + global $wgDBprefix; + $dbw =& wfGetDB( DB_MASTER ); + $dbw->delete( 'validate', + array( 'val_type' => $id ), + 'Validation::deleteTopic' ); + unset( $this->topicList[$id] ); } # This function returns a link text to the page validation statistics - function link2statistics ( &$article ) { + function link2statistics( &$article ) { $nt = $article->getTitle(); - $url = htmlspecialchars( $nt->getLocalURL( "action=validate&mode=list" ) ); - return wfMsg ( 'val_rev_stats_link', $nt->getPrefixedText(), $url ); + $url = $nt->escapeLocalURL( "action=validate&mode=list" ); + return wfMsg( 'val_rev_stats_link', $nt->getPrefixedText(), $url ); } # This function returns a link text to the page validation statistics of a single revision - function link2revisionstatistics ( &$article , $revision ) { + function link2revisionstatistics( &$article, $revision ) { $nt = $article->getTitle(); - $url = htmlspecialchars( $nt->getLocalURL( "action=validate&mode=details&revision={$revision}" ) ); - return wfMsg ( 'val_revision_stats_link', $url ); + $url = $nt->escapeLocalURL( "action=validate&mode=details&revision={$revision}" ); + return wfMsg( 'val_revision_stats_link', $url ); } # This function returns a link text to the user rating statistics page - function link2userratings ( $user , $text ) { - global $wgUser ; - if ( $user == 0 ) $user = $wgUser->GetName() ; - $nt = Title::newFromText ( "Special:Validate" ) ; + function link2userratings( $user, $text ) { + global $wgUser; + if( $user == 0 ) { + $user = $wgUser->GetName(); + } + $nt = Title::newFromText( "Special:Validate" ); $url = htmlspecialchars( $nt->getLocalURL( "mode=userstats&user={$user}" ) ); - return "{$text}" ; + return "{$text}"; } # Returns the timestamp of a revision based on the revision number - function getTimestamp ( $revision ) { - $ts = $this->rev2date[$revision] ; - $ts = $ts->rev_timestamp ; - return $ts ; + function getTimestamp( $revision ) { + $ts = $this->rev2date[$revision]; + $ts = $ts->rev_timestamp; + return $ts; } # Returns the revision number of a revision based on the timestamp - function getRevisionNumber ( $ts ) { - $revision = $this->date2rev[$ts] ; - $revision = $revision->rev_id ; - return $revision ; + function getRevisionNumber( $ts ) { + $revision = $this->date2rev[$ts]; + $revision = $revision->rev_id; + return $revision; } # HTML generation functions from this point on # Returns the metadata string for a revision - function getMetadata ( $idx ) { - $metadata = "" ; - $x = $this->rev2date[$idx] ; - $metadata .= wfTimestamp ( TS_DB , $x->rev_timestamp ) ; - $metadata .= " by " ; - if ( $x->rev_user == 0 ) { - $metadata .= $x->rev_user_text ; + function getMetadata( $idx ) { + $metadata = ""; + $x = $this->rev2date[$idx]; + $metadata .= wfTimestamp( TS_DB, $x->rev_timestamp ); + $metadata .= " by "; + if( $x->rev_user == 0 ) { + $metadata .= $x->rev_user_text; } else { - $u = new User ; - $u->setId ( $x->rev_user ) ; - $u->setName ( $x->rev_user_text ) ; - $nt = $u->getUserPage() ; - $url = "" . $nt->getText() . "" ; - $metadata .= $url ; - } - $metadata .= " : \"" . htmlspecialchars ( $x->rev_comment ) . "\"" ; - return $metadata ; + $u = new User; + $u->setId( $x->rev_user ); + $u->setName( $x->rev_user_text ); + $nt = $u->getUserPage(); + $url = "" . $nt->getText() . ""; + $metadata .= $url; + } + $metadata .= " : \"" . htmlspecialchars( $x->rev_comment ) . "\""; + return $metadata; } # Generates a form for a single revision - function getRevisionForm ( &$article , $idx , &$data , $focus = false ) { + function getRevisionForm( &$article, $idx, &$data, $focus = false ) { # Fill data with blank values - $ts = $idx ; - $revision = $this->getRevisionNumber ( $ts ) ; - foreach ( $this->topicList AS $x => $y ) { - if ( !isset ( $data[$x] ) ) { - $data[$x]->value = 0 ; - $data[$x]->comment = "" ; + $ts = $idx; + $revision = $this->getRevisionNumber( $ts ); + foreach( $this->topicList as $x => $y ) { + if( !isset( $data[$x] ) ) { + $data[$x]->value = 0; + $data[$x]->comment = ""; } } - ksort ( $data ) ; + ksort( $data ) ; # Generate form - $ret = "
" ; - $ret .= "getVersionLink ( $article , $revision ) ; - $metadata = $this->getMetadata ( $revision ) ; - $ret .= "\n" ; - $line = 0 ; - foreach ( $data AS $x => $y ) { - $line = 1 - $line ; - $col = $line == 1 ? "#DDDDDD" : "#EEEEEE" ; - $idx = "_{$revision}[{$x}]" ; - $ret .= "\n" ; - $ret .= "\n" ; + $ret = ""; + $ret .= "
" . $head . " ({$link}) {$metadata}
" ; - $ret .= $this->topicList[$x]->val_comment ; - $ret .= "
getVersionLink( $article, $revision ); + $metadata = $this->getMetadata( $revision ); + $ret .= "\n"; + $line = 0; + foreach( $data as $x => $y ) { + $line = 1 - $line; + $col = $line == 1 ? "#DDDDDD" : "#EEEEEE"; + $idx = "_{$revision}[{$x}]"; + $ret .= "\n"; + $ret .= "\n"; - $tlx = $this->topicList[$x] ; - $vote = "" ; - $max = $tlx->val_value ; - for ( $a = 0 ; $a <= $max ; $a++ ) { - if ( $a == 0 ) $vote .= wfMsg ( "val_noop" ) ; - $vote .= "value ) $vote .= " checked" ; - $vote .= "/>" ; - if ( $max == 2 && $a == 1 ) $vote .= wfMsg ( "val_no" ) . " " ; - else if ( $max == 2 && $a == 2 ) $vote .= wfMsg ( "val_yes" ) ; - else if ( $a != 0 ) $vote .= $a . " " ; - if ( $a == 0 ) $vote .= "   " ; + $tlx = $this->topicList[$x]; + $vote = ""; + $max = $tlx->val_value; + for( $a = 0 ; $a <= $max ; $a++ ) { + if( $a == 0 ) { + $vote .= wfMsg ( "val_noop" ); + } + $vote .= "value ) { + $vote .= " checked"; + } + $vote .= "/>"; + if( $max == 2 && $a == 1 ) { + $vote .= wfMsg( "val_no" ) . " "; + } elseif( $max == 2 && $a == 2 ) { + $vote .= wfMsg( "val_yes" ); + } elseif( $a != 0 ) { + $vote .= $a . " "; + } + if ( $a == 0 ) { + $vote .= "   "; + } } - $ret .= "\n" ; + $ret .= "\n"; - $ret .= "\n" ; - } - $checked = $focus ? " checked" : "" ; - $ret .= "\n" ; - $ret .= "
" . $head . " ({$link}) {$metadata}
"; + $ret .= $this->topicList[$x]->val_comment; + $ret .= "{$vote}{$vote}" ; - $ret .= "
\n" ; - $ret .= "" . wfMsg( 'val_merge_old' ) . " \n" ; - $ret .= "" . wfMsg( 'val_clear_old' ) . " \n" ; - $ret .= "\n" ; - if ( $focus ) $ret .= "
\n" . wfMsg ( "val_form_note" ) . "" ; - $ret .= "
\n
\n\n" ; - return $ret ; + $ret .= ""; + $ret .= "\n"; + } + $checked = $focus ? " checked='checked'" : ""; + $ret .= "\n"; + $ret .= "" . htmlspecialchars( wfMsg( 'val_merge_old' ) ) . " \n"; + $ret .= "" . htmlspecialchars( wfMsg( 'val_clear_old' ) ) . " \n"; + $ret .= "\n"; + if( $focus ) { + $ret .= "
\n" . htmlspecialchars( wfMsg( "val_form_note" ) ) . ""; + } + $ret .= "\n"; + $ret .= "\n\n\n"; + return $ret; } # Generates the page from the validation tab - function validatePageForm ( &$article , $revision ) { - global $wgOut, $wgRequest, $wgUser ; + function validatePageForm( &$article, $revision ) { + global $wgOut, $wgRequest, $wgUser; - $ret = "" ; - $this->prepareRevisions ( $article->getID() ) ; - $this->topicList = $this->getTopicList() ; - $this->voteCache = $this->getVoteList ( $article->getID() ) ; + $ret = ""; + $this->prepareRevisions( $article->getID() ); + $this->topicList = $this->getTopicList(); + $this->voteCache = $this->getVoteList( $article->getID() ); # Check for POST data $re = $wgRequest->getArray( 're_submit' ); - if ( isset ( $re ) ) - { - $id = array_keys ( $re ) ; + if( isset( $re ) ) { + $id = array_keys( $re ); $id = $id[0] ; # $id is now the revision number the user clicked "OK" for - $clearOldRev = $wgRequest->getVal( "re_clear_{$id}" , 0 ); - $mergeOldRev = $wgRequest->getVal( "re_merge_{$id}" , 0 ); - $this->updateRevision ( $article , $id ) ; - if ( $mergeOldRev ) $this->mergeOldRevisions ( $article , $id ) ; - if ( $clearOldRev ) $this->clearOldRevisions ( $article , $id ) ; - $ret .= "

" . wfMsg ( 'val_revision_changes_ok' ) . "

" ; + $clearOldRev = $wgRequest->getVal( "re_clear_{$id}", 0 ); + $mergeOldRev = $wgRequest->getVal( "re_merge_{$id}", 0 ); + $this->updateRevision( $article, $id ); + if( $mergeOldRev ) { + $this->mergeOldRevisions( $article, $id ); } + if( $clearOldRev ) { + $this->clearOldRevisions( $article, $id ); + } + $ret .= "

" . htmlspecialchars( wfMsg( 'val_revision_changes_ok' ) ) . "

"; + } # Make sure the requested revision exists - $ts = $this->rev2date[$revision]->rev_timestamp ; - if ( !isset ( $this->voteCache[$ts] ) ) $this->voteCache[$ts] = array () ; + $ts = $this->rev2date[$revision]->rev_timestamp; + if( !isset( $this->voteCache[$ts] ) ) { + $this->voteCache[$ts] = array(); + } # Sort revisions list, newest first - krsort ( $this->voteCache ) ; + krsort( $this->voteCache ); # Output $title = $article->getTitle(); - $title = $title->getPrefixedText() ; - $wgOut->setPageTitle ( wfMsg ( 'val_rev_for' ) . $title ) ; - foreach ( $this->voteCache AS $x => $y ) - { - $ret .= $this->getRevisionForm ( $article , $x , $y , $x == $ts ) ; - $ret .= "
\n" ; - } - $ret .= $this->link2statistics ( $article ) ; - $ret .= "

" . $this->link2userratings ( $wgUser->GetID() , wfMsg('val_show_my_ratings') ) . "

" ; + $title = $title->getPrefixedText(); + $wgOut->setPageTitle( wfMsg( 'val_rev_for' ) . $title ); + foreach( $this->voteCache as $x => $y ) { + $ret .= $this->getRevisionForm( $article, $x, $y, $x == $ts ); + $ret .= "
\n"; + } + $ret .= $this->link2statistics( $article ); + $ret .= "

" . $this->link2userratings( $wgUser->getID(), wfMsg( 'val_show_my_ratings' ) ) . "

"; return $ret ; } # This function performs the "management" mode on Special:Validate - function manageTopics () { - global $wgRequest ; - $this->topicList = $this->getTopicList() ; + function manageTopics() { + global $wgRequest; + $this->topicList = $this->getTopicList(); - $iamsure = $wgRequest->getVal ( "iamsure" , "0" ) == 1 ; + $iamsure = $wgRequest->getVal( "iamsure", "0" ) == 1; - if ( $iamsure && $wgRequest->getVal ( "m_add" , "--" ) != "--" ) { - $new_topic = $wgRequest->getVal ( "m_topic" ) ; - $new_limit = $wgRequest->getVal ( "m_limit" ) ; - if ( $new_topic != "" && $new_limit > 1 ) - $this->addTopic ( $new_topic , $new_limit ) ; + if( $iamsure && $wgRequest->getVal( "m_add", "--" ) != "--" ) { + $new_topic = $wgRequest->getVal( "m_topic" ); + $new_limit = $wgRequest->getVal( "m_limit" ); + if( $new_topic != "" && $new_limit > 1 ) { + $this->addTopic( $new_topic, $new_limit ); + } } - $da = $wgRequest->getArray ( "m_del" ) ; - if ( $iamsure && isset ( $da ) && count ( $da ) > 0 ) { - $id = array_keys ( $da ) ; - $id = array_shift ( $id ) ; - $this->deleteTopic ( $id ) ; + $da = $wgRequest->getArray( "m_del" ); + if( $iamsure && isset( $da ) && count( $da ) > 0 ) { + $id = array_keys( $da ); + $id = array_shift( $id ); + $this->deleteTopic( $id ); } - $r = "

" . wfMsg ( 'val_warning' ) . "

\n" ; - $r .= "
\n" ; - $r .= "\n" ; - $r .= "" . wfMsg ( 'val_list_header' ) . "\n" ; - foreach ( $this->topicList AS $x => $y ) { - $r .= "\n" ; - $r .= "\n" ; - $r .= "\n" ; - $r .= "\n" ; - $r .= "\n" ; - $r .= "\n" ; - } - $r .= "\n" ; - $r .= "\n" ; - $r .= "\n" ; - $r .= "\n" ; - $r .= "\n" ; - $r .= "
" . $y->val_type . "{$y->val_comment}1 .. {$y->val_value}
\n" ; - $r .= "
\n" ; - $r .= "" . wfMsg ( 'val_iamsure' ) . "\n" ; - $r .= "
\n" ; - return $r ; + # FIXME: Wikitext this + $r = "

" . htmlspecialchars( wfMsg( 'val_warning' ) ) . "

\n"; + + $r .= "
\n"; + $r .= "\n"; + $r .= "" . wfMsg( 'val_list_header' ) . "\n"; + foreach( $this->topicList as $x => $y ) { + $r .= "\n"; + $r .= "\n"; + $r .= "\n"; + $r .= "\n"; + $r .= "\n"; + $r .= "\n"; + } + $r .= "\n"; + $r .= "\n"; + $r .= "\n"; + $r .= "\n"; + $r .= "\n"; + $r .= "
" . htmlspecialchars( $y->val_type ) . "" . htmlspecialchars( $y->val_comment ) . "1 .. " . intval( $y->val_value ) . "
\n"; + $r .= "
\n"; + $r .= "" . htmlspecialchars( wfMsg( 'val_iamsure' ) ) . "\n"; + $r .= "
\n"; + return $r; } # Generates a user ID for both logged-in users and anons; $x is an object from an SQL query - function make_user_id ( &$x ) { - if ( $x->val_user == 0 ) return $x->val_ip ; - else return $x->val_user ; + function make_user_id( &$x ) { + if( $x->val_user == 0 ) { + return $x->val_ip; + } else { + return $x->val_user; } + } - function showDetails ( &$article , $revision ) { - global $wgDBprefix , $wgOut, $wgUser ; - $this->prepareRevisions ( $article->getID() ) ; - $this->topicList = $this->getTopicList() ; + function showDetails( &$article, $revision ) { + global $wgDBprefix, $wgOut, $wgUser; + $this->prepareRevisions( $article->getID() ); + $this->topicList = $this->getTopicList(); - $title = $article->getTitle() ; - $wgOut->setPageTitle ( str_replace ( '$1' , $title->getPrefixedText() , wfMsg ( 'val_validation_of' ) ) ) ; + $title = $article->getTitle(); + $wgOut->setPageTitle( str_replace( '$1', $title->getPrefixedText(), wfMsg( 'val_validation_of' ) ) ); # Collecting statistic data - $id = $article->getID() ; - $sql = "SELECT * FROM {$wgDBprefix}validate WHERE val_page='{$id}' AND val_revision='{$revision}'" ; + $id = $article->getID(); + $sql = "SELECT * FROM {$wgDBprefix}validate WHERE val_page='{$id}' AND val_revision='{$revision}'"; $res = wfQuery( $sql, DB_READ ); - $data = array () ; - $users = array () ; - $topics = array () ; + $data = array(); + $users = array(); + $topics = array(); while( $x = wfFetchObject( $res ) ) { - $data[$this->make_user_id($x)][$x->val_type] = $x ; - $users[$this->make_user_id($x)] = true ; - $topics[$x->val_type] = true ; + $data[$this->make_user_id($x)][$x->val_type] = $x; + $users[$this->make_user_id($x)] = true; + $topics[$x->val_type] = true; } # Sorting lists of topics and users - ksort ( $users ) ; - ksort ( $topics ) ; + ksort( $users ); + ksort( $topics ); - $ts = $this->getTimestamp ( $revision ) ; - $url = $this->getVersionLink ( $article , $revision , wfTimestamp ( TS_DB , $ts ) ) ; + $ts = $this->getTimestamp( $revision ); + $url = $this->getVersionLink( $article, $revision, wfTimestamp( TS_DB, $ts ) ); # Table headers $ret = "" ; - $ret .= "

" . str_replace ( '$1' , $url , wfMsg ( 'val_revision_of' ) ) . "

\n" ; - $ret .= "\n" ; - $ret .= ""; } + $ret .= "
" ; + $ret .= "

" . str_replace( '$1', $url, wfMsg( 'val_revision_of' ) ) . "

\n"; + $ret .= "\n"; + $ret .= "" ; - } - $ret .= "\n" ; + foreach( $topics as $t => $dummy ) { + $ret .= ""; + } + $ret .= "\n"; # Table data - foreach ( $users AS $u => $dummy ) { # Every row a user - $ret .= "" ; - $ret .= ""; + $ret .= "" ; - foreach ( $topics AS $t => $dummy ) { # Every column a topic - if ( !isset ( $data[$u][$t] ) ) $ret .= "" ; + $ret .= ""; + foreach( $topics as $t => $dummy ) { # Every column a topic + if( !isset( $data[$u][$t] ) ) { + $ret .= ""; } } - $ret .= "" ; - } - $ret .= "
"; - foreach ( $topics AS $t => $dummy ) { - $ret .= "" . $this->topicList[$t]->val_comment . "
" . htmlspecialchars( $this->topicList[$t]->val_comment ) . "
" ; - if ( !User::IsIP ( $u ) ) { # Logged-in user rating - $ret .= $this->link2userratings ( $u , User::whoIs ( $u ) ) ; + foreach( $users as $u => $dummy ) { # Every row a user + $ret .= "
"; + if( !User::IsIP( $u ) ) { # Logged-in user rating + $ret .= $this->link2userratings( $u, User::whoIs( $u ) ); } else { # Anon rating - $ret .= $this->link2userratings ( $u , $u ) ; + $ret .= $this->link2userratings( $u, $u ); } - $ret .= "" ; - else { - $ret .= "" ; - $ret .= $data[$u][$t]->val_value ; - if ( $data[$u][$t]->val_comment != "" ) - $ret .= " (" . $data[$u][$t]->val_comment . ")" ; - $ret .= ""; + } else { + $ret .= ""; + $ret .= $data[$u][$t]->val_value; + if( $data[$u][$t]->val_comment != "" ) { + $ret .= " (" . htmlspecialchars( $data[$u][$t]->val_comment ) . ")"; + } + $ret .= "
" ; - $ret .= "

" . $this->link2statistics ( $article ) . "

" ; - $ret .= "

" . $this->link2userratings ( $wgUser->GetID() , wfMsg('val_show_my_ratings') ) . "

" ; - - return $ret ; + $ret .= "
"; + $ret .= "

" . $this->link2statistics( $article ) . "

"; + $ret .= "

" . $this->link2userratings( $wgUser->GetID(), wfMsg( 'val_show_my_ratings' ) ) . "

"; + + return $ret; + } - function showList ( &$article ) { - global $wgDBprefix , $wgOut, $wgUser; - $this->prepareRevisions ( $article->getID() ) ; - $this->topicList = $this->getTopicList() ; + function showList( &$article ) { + global $wgDBprefix, $wgOut, $wgUser; + $this->prepareRevisions( $article->getID() ); + $this->topicList = $this->getTopicList(); - $title = $article->getTitle() ; - $wgOut->setPageTitle ( str_replace ( '$1' , $title->getPrefixedText() , wfMsg ( 'val_validation_of' ) ) ) ; + $title = $article->getTitle(); + $wgOut->setPageTitle( str_replace( '$1', $title->getPrefixedText(), wfMsg( 'val_validation_of' ) ) ); # Collecting statistic data - $id = $article->getID() ; - $sql = "SELECT * FROM {$wgDBprefix}validate WHERE val_page='{$id}'" ; + $id = $article->getID(); + $sql = "SELECT * FROM {$wgDBprefix}validate WHERE val_page='{$id}'"; $res = wfQuery( $sql, DB_READ ); - $data = array () ; + $data = array(); while( $x = wfFetchObject( $res ) ) { - $idx = $this->getTimestamp ( $x->val_revision ) ; - if ( !isset ( $data[$idx] ) ) - $data[$idx] = array () ; - if ( !isset ( $data[$idx][$x->val_type] ) ) { - $data[$idx][$x->val_type]->count = 0 ; - $data[$idx][$x->val_type]->sum = 0 ; + $idx = $this->getTimestamp( $x->val_revision ); + if( !isset( $data[$idx] ) ) { + $data[$idx] = array(); } - $data[$idx][$x->val_type]->count++ ; - $data[$idx][$x->val_type]->sum += $x->val_value ; + if( !isset( $data[$idx][$x->val_type] ) ) { + $data[$idx][$x->val_type]->count = 0; + $data[$idx][$x->val_type]->sum = 0; + } + $data[$idx][$x->val_type]->count++; + $data[$idx][$x->val_type]->sum += $x->val_value; } - krsort ( $data ) ; + krsort( $data ); - $ret = "" ; - $ret .= "\n" ; - $ret .= "" ; - foreach ( $this->topicList AS $x => $y ) - $ret .= "" ; - $ret .= "\n" ; - foreach ( $data AS $ts => $y ) { - $revision = $this->getRevisionNumber ( $ts ) ; - $url = $this->getVersionLink ( $article , $revision , wfTimestamp ( TS_DB , $ts ) ) ; - $detailsurl = $this->link2revisionstatistics ( $article , $revision ) ; - $ret .= "" ; - foreach ( $this->topicList AS $topicID => $dummy ) { - if ( isset ( $y[$topicID] ) ) { - $z = $y[$topicID] ; - if ( $z->count == 0 ) $a = 0 ; - else $a = $z->sum / $z->count ; - $ret .= sprintf ( "" , $a , $z->count ) ; - } else $ret .= "
" . wfMsg("val_revision") . "{$y->val_comment}
{$url} {$detailsurl}%1.1f (%d)" ; + $ret = ""; + $ret .= "\n"; + $ret .= ""; + foreach( $this->topicList as $x => $y ) { + $ret .= ""; + } + $ret .= "\n"; + foreach( $data as $ts => $y ) { + $revision = $this->getRevisionNumber( $ts ); + $url = $this->getVersionLink( $article, $revision, wfTimestamp( TS_DB, $ts ) ); + $detailsurl = $this->link2revisionstatistics( $article, $revision ); + $ret .= ""; + foreach( $this->topicList as $topicID => $dummy ) { + if( isset( $y[$topicID] ) ) { + $z = $y[$topicID]; + if( $z->count == 0 ) { + $a = 0; + } else { + $a = $z->sum / $z->count; + } + $ret .= sprintf( "", $a, $z->count ); + } else { + $ret .= ""; } - $ret .= "\n" ; + } + $ret .= "\n"; } - $ret .= "
" . htmlspecialchars( wfMsg( "val_revision" ) ) . "" . htmlspecialchars( $y->val_comment ) . "
{$url} {$detailsurl}%1.1f (%d)
\n" ; - $ret .= "

" . $this->link2userratings ( $wgUser->GetID() , wfMsg('val_show_my_ratings') ) . "

" ; - return $ret ; + $ret .= "
\n"; + $ret .= "

" . $this->link2userratings( $wgUser->getID(), wfMsg( 'val_show_my_ratings' ) ) . "

"; + return $ret; } - function getRatingText ( $value , $max ) { - if ( $max == 2 && $value == 1 ) $ret = wfMsg ( "val_no" ) . " " ; - else if ( $max == 2 && $value == 2 ) $ret = wfMsg ( "val_yes" ) ; - else if ( $value != 0 ) $ret = wfMsg ( "val_of" , $value , $max ) . " " ; - else $ret = "" ; - return $ret ; + function getRatingText( $value, $max ) { + if( $max == 2 && $value == 1 ) { + $ret = wfMsg ( "val_no" ) . " "; + } elseif( $max == 2 && $value == 2 ) { + $ret = wfMsg( "val_yes" ); + } elseif( $value != 0 ) { + $ret = wfMsg( "val_of", $value, $max ) . " "; + } else { + $ret = ""; + } + return $ret; } - function showUserStats ( $user ) { - global $wgDBprefix , $wgOut, $wgUser ; - $this->topicList = $this->getTopicList() ; - $data = $this->getAllVoteLists ( $user ) ; + function showUserStats( $user ) { + global $wgDBprefix, $wgOut, $wgUser; + $this->topicList = $this->getTopicList(); + $data = $this->getAllVoteLists( $user ); - if ( $user == $wgUser->getID() ) $wgOut->setPageTitle ( wfMsg ( 'val_my_stats_title' ) ) ; - elseif ( ! User::IsIP ( $user ) ) $wgOut->setPageTitle ( wfMsg ( 'val_user_stats_title' , User::whoIs ( $user ) ) ) ; - else $wgOut->setPageTitle ( wfMsg ( 'val_user_stats_title' , $user ) ) ; + if( $user == $wgUser->getID() ) { + $wgOut->setPageTitle ( wfMsg ( 'val_my_stats_title' ) ); + } elseif( !User::IsIP( $user ) ) { + $wgOut->setPageTitle( wfMsg( 'val_user_stats_title', User::whoIs( $user ) ) ); + } else { + $wgOut->setPageTitle( wfMsg( 'val_user_stats_title', $user ) ); + } - $ret = "" ; - $ret .= "\n" ; + $ret = "
\n"; - foreach ( $data AS $articleid => $revisions ) { - $title = Title::newFromID ( $articleid ) ; - $ret .= "" ; - krsort ( $revisions ) ; - foreach ( $revisions AS $revid => $revision ) { - $url = $title->getLocalURL ( "oldid={$revid}" ) ; - $ret .= "" ; - ksort ( $revision ) ; - $initial = true ; - foreach ( $revision AS $topic => $rating ) { - if ( !$initial ) $ret .= "" ; - $ret .= "" ; - $ret .= "" ; - $ret .= "" ; + foreach( $data as $articleid => $revisions ) { + $title = Title::newFromID( $articleid ); + $ret .= ""; + krsort( $revisions ); + foreach( $revisions as $revid => $revision ) { + $url = $title->getLocalURL( "oldid={$revid}" ); + $ret .= ""; + ksort( $revision ); + $initial = true; + foreach( $revision as $topic => $rating ) { + if( !$initial ) { + $ret .= ""; + $ret .= ""; + $ret .= ""; + $ret .= ""; } } - $ret .= "" ; + $ret .= ""; } - $ret .= "
getLocalURL() . "\">" . $title->getPrefixedText() . "
" . wfMsg ( 'val_revision_number' , $revid ) . "
" ; - $initial = false ; - $ret .= "" . $this->topicList[$topic]->val_comment . "" . $this->getRatingText ( $rating->val_value , $this->topicList[$topic]->val_value ) . "" . htmlentities ( $rating->val_comment ) . "
escapeLocalURL() . "\">" . $title->getEscapedText() . "
" . wfMsg( 'val_revision_number', $revid ) . "
"; + } + $initial = false; + $ret .= "" . htmlspecialchars( $this->topicList[$topic]->val_comment ) . "" . $this->getRatingText( $rating->val_value, $this->topicList[$topic]->val_value ) . "" . htmlspecialchars( $rating->val_comment ) . "
" ; + $ret .= ""; - return $ret ; - } + return $ret; + } } @@ -627,32 +702,32 @@ function wfSpecialValidate( $page = '' ) { /* # Can do? - if ( ! $wgUser->isAllowed('change_validation') ) { + if( ! $wgUser->isAllowed('change_validation') ) { $wgOut->sysopRequired(); return; } */ - $mode = $wgRequest->getVal ( "mode" ) ; - $skin = $wgUser->getSkin() ; + $mode = $wgRequest->getVal( "mode" ); + $skin = $wgUser->getSkin(); - if ( $mode == "manage" ) { - $v = new Validation ; - $html = $v->manageTopics () ; - } else if ( $mode == "userstats" ) { - $v = new Validation ; - $user = $wgRequest->getVal ( "user" ) ; - $html = $v->showUserStats ( $user ) ; + if( $mode == "manage" ) { + $v = new Validation(); + $html = $v->manageTopics(); + } elseif( $mode == "userstats" ) { + $v = new Validation(); + $user = $wgRequest->getVal( "user" ); + $html = $v->showUserStats( $user ); } else { - $html = "$mode" ; - $html .= "\n"; } $wgOut->addHTML( $html );