2 # Copyright (C) 2004 Magnus Manske <magnus.manske@web.de>
3 # http://www.mediawiki.org/
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # http://www.gnu.org/copyleft/gpl.html
23 * @subpackage SpecialPage
31 var $rev_fields = "rev_id,rev_page,rev_timestamp,rev_user_text,rev_user,rev_comment" ;
33 function getRevisionFromId( $rev_id ) {
34 if( isset( $this->id2rev
[$rev_id] ) ) return $this->id2rev
[$rev_id];
36 $db =& wfGetDB( DB_SLAVE
);
37 $fname = 'SpecialValidate::getRevisionFromId';
38 $res = $db->select( 'revision', $this->rev_fields
, array( 'rev_id' => $rev_id ), $fname, array( 'LIMIT' => 1 ) );
39 $rev = $db->fetchObject($res);
40 $db->freeResult($res);
42 $this->id2rev
[$rev->rev_id
] = $rev;
43 $this->ts2rev
[$rev->rev_timestamp
] = $rev;
48 function getRevisionFromTimestamp( $timestamp ) {
49 if( isset( $this->ts2rev
[$timestamp] ) ) return $this->ts2rev
[$timestamp];
51 $db =& wfGetDB( DB_SLAVE
);
52 $fname = 'SpecialValidate::getRevisionFromTimestamp';
53 $res = $db->select( 'revision', $this->rev_fields
,
54 array( 'rev_page' => $this->page_id
, 'rev_timestamp' => $timestamp ),
55 $fname, array( 'LIMIT' => 1 )
57 $rev = $db->fetchObject($res);
58 $db->freeResult($res);
60 $this->id2rev
[$rev->rev_id
] = $rev;
61 $this->ts2rev
[$rev->rev_timestamp
] = $rev;
66 # Returns a HTML link to the specified article revision
67 function getRevisionLink( &$article, $revision, $text = "" ) {
69 $sk = $wgUser->getSkin();
70 $t = $article->getTitle();
71 if( $text == "" ) $text = wfMsg("val_view_version");
72 return $sk->makeKnownLinkObj( $t, $this->getParsedWiki($text), 'oldid='.urlencode($revision) );
75 # Returns an array containing all topics you can vote on
76 function getTopicList() {
77 $db =& wfGetDB( DB_SLAVE
);
81 # NOTE : This query returns only the topics to vote on
82 $res = $db->select( 'validate', '*', array( 'val_page' => 0 ), 'SpecialValidate::getTopicList' );
83 while( $topic = $db->fetchObject($res) ) {
84 $topics[$topic->val_type
] = $topic;
86 $db->freeResult($res);
92 # Merges one dataset into another
93 function mergeInto( &$source, &$dest ) {
95 foreach( $source as $x => $y ) {
97 if( !isset( $dest[$x] ) ) {
99 } elseif( $dest[$x]->value
== 0 ) {
113 # Merges all votes prior to the given revision into it
114 function mergeOldRevisions( &$article, $revision ) {
115 $tmp = $this->voteCache
;
118 $ts = $this->getRevisionTimestamp( $revision );
119 $data = $this->voteCache
[$ts];
120 foreach( $tmp as $x => $y ) {
122 if( $this->mergeInto( $y, $data ) ) {
128 $this->setRevision( $article, $revision, $data );
132 # Clears all votes prior to the given revision
133 function clearOldRevisions( &$article, $revision ) {
134 $tmp = $this->voteCache
;
135 $ts = $this->getRevisionTimestamp( $revision );
136 foreach( $tmp as $x => $y ) {
138 $this->deleteRevisionVote ( $article, $this->getRevisionId( $x ) );
143 # Updates the votes for the given revision from the FORM data
144 function updateRevision( &$article, $revision ) {
147 if( isset( $this->voteCache
[$this->getRevisionTimestamp( $revision )] ) ) {
148 $data = $this->voteCache
[$this->getRevisionTimestamp( $revision )];
152 $nv = $wgRequest->getArray( "re_v_{$revision}", array() );
153 $nc = $wgRequest->getArray( "re_c_{$revision}", array() );
155 foreach( $nv as $x => $y ) {
156 $data[$x]->value
= $y;
157 $data[$x]->comment
= $nc[$x];
161 $this->setRevision( $article, $revision, $data );
164 # Sets a specific revision to both cache and database
165 function setRevision( &$article, $revision, &$data ) {
167 $this->deleteRevisionVote( $article, $revision );
168 $this->voteCache
[ $this->getRevisionTimestamp($revision) ] = $data;
169 foreach( $data as $x => $y ) {
170 if( $y->value
> 0 ) {
171 $ip = $wgUser->isAnon() ?
$wgUser->getName() : '';
172 $dbw =& wfGetDB( DB_MASTER
);
173 $dbw->insert( 'validate',
175 'val_user' => $wgUser->getId(),
176 'val_page' => $article->getId(),
177 'val_revision' => $revision,
179 'val_value' => $y->value
,
180 'val_comment' => $y->comment
,
182 'SpecialValidate::setRevision'
188 # Returns a map identifying the current user
189 function identifyUser( $user = "" ) {
191 if( $user == "" ) $user = $wgUser->getID();
192 return User
::isIP($user)
193 ?
array( 'val_user' => 0, 'val_ip' => $user )
194 : array( 'val_user' => $user );
197 # Deletes a specific vote set in both cache and database
198 function deleteRevisionVote( &$article, $revision ) {
199 $ts = $this->getRevisionTimestamp( $revision );
200 if( !isset ( $this->voteCache
[$ts] ) ) return;
202 $db =& wfGetDB( DB_MASTER
);
206 $this->identifyUser(),
208 'val_page' => $article->getID(),
209 'val_revision' => $revision
212 'SpecialValidate::deleteRevisionVote'
215 unset( $this->voteCache
[$ts] );
218 # Reads the entire vote list for this user for the given article
219 function getVoteList( $id, $user = "" ) {
220 $db =& wfGetDB( DB_SLAVE
);
222 # NOTE : This query gets the votes for a single user on a single page.
223 # Assuming most people will use the "merge" feature,
224 # this will be only a single entry.
225 $res = $db->select( 'validate', '*', array_merge( array( 'val_page' => $id ), $this->identifyUser($user) ) );
227 $revisions = array();
228 while( $vote = $db->fetchObject($res) ) {
229 $ts = $this->getRevisionTimestamp( $vote->val_revision
);
230 if( ! isset( $revisions[$ts] ) ) {
231 $revisions[$ts] = array();
233 $revisions[$ts][$vote->val_type
]->value
= $vote->val_value
;
234 $revisions[$ts][$vote->val_type
]->comment
= $vote->val_comment
;
236 $db->freeResult($res);
241 # Reads a partial vote list for this user for all articles
242 function getAllVoteLists( $user , $offset , $limit ) {
243 $db =& wfGetDB( DB_SLAVE
);
244 $a = $this->identifyUser($user) ;
245 $b = array ( "ORDER BY" => "val_page,val_revision" , "OFFSET" => $offset , "LIMIT" => $limit ) ;
246 $res = $db->select( 'validate', '*', $a , 'getAllVotesList' , $b );
249 while( $vote = $db->fetchObject($res) ) {
250 $votes[$vote->val_page
][$vote->val_revision
][$vote->val_type
] = $vote;
252 $db->freeResult($res);
257 # This functions adds a topic to the database
258 function addTopic( $topic, $limit ) {
259 $db =& wfGetDB( DB_MASTER
);
262 while( isset( $this->topicList
[$next_idx] ) ) {
272 'val_type' => $next_idx,
273 'val_value' => $limit,
274 'val_comment' => $topic,
277 'SpecialValidate::addTopic'
280 $t->val_user
= $t->val_page
= $t->val_revision
= 0;
281 $t->val_type
= $next_idx;
282 $t->val_value
= $limit;
283 $t->val_comment
= $topic;
285 $this->topicList
[$next_idx] = $t;
287 ksort( $this->topicList
);
290 # This function deletes a topic and all votes for it. CAREFUL!
291 function deleteTopic( $id ) {
292 $db =& wfGetDB( DB_MASTER
);
293 $db->delete( 'validate', array( 'val_type' => $id ), 'SpecialValidate::deleteTopic' );
294 unset( $this->topicList
[$id] );
297 # This function returns a link text to the page validation statistics
298 function getStatisticsLink( &$article ) {
300 $sk = $wgUser->getSkin();
301 $nt = $article->getTitle();
302 return $sk->makeKnownLinkObj( $nt, wfMsg( 'val_rev_stats', $nt->getPrefixedText() ), 'action=validate&mode=list' );
305 # This function returns a link text to the page validation statistics of a single revision
306 function getRevisionStatsLink( &$article, $revision ) {
308 $sk = $wgUser->getSkin();
309 $nt = $article->getTitle();
310 $text = $this->getParsedWiki( wfMsg('val_revision_stats_link') );
311 $query = "action=validate&mode=details&revision={$revision}";
312 return '(' . $sk->makeKnownLinkObj( $nt, $text, $query ) . ')';
315 # This function returns a link text to the user rating statistics page
316 function getUserRatingsLink( $user, $text ) {
318 $sk = $wgUser->getSkin();
319 if( $user == 0 ) $user = $wgUser->getName();
320 $nt = Title
::newFromText( 'Special:Validate' );
321 return $sk->makeKnownLinkObj( $nt, $text, 'mode=userstats&user='.urlencode($user) );
324 # Returns the timestamp of a revision based on the revision number
325 function getRevisionTimestamp( $rev_id ) {
326 $rev = $this->getRevisionFromId( $rev_id );
327 return $rev->rev_timestamp
;
330 # Returns the revision number of a revision based on the timestamp
331 function getRevisionId( $ts ) {
332 $rev = $this->getRevisionFromTimestamp( $ts );
337 # HTML generation functions from this point on
339 # Returns the metadata string for a revision
340 function getMetadata( $rev_id, &$article ) {
342 $sk = $wgUser->getSkin();
345 $x = $this->getRevisionFromId($rev_id);
346 $metadata .= wfTimestamp( TS_DB
, $x->rev_timestamp
);
348 if( $x->rev_user
== 0 ) {
349 $metadata .= $x->rev_user_text
;
352 $u->setId( $x->rev_user
);
353 $u->setName( $x->rev_user_text
);
354 $nt = $u->getUserPage();
355 $metadata .= $sk->makeKnownLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
357 $metadata .= ': '. $sk->commentBlock( $x->rev_comment
, $article->getTitle() );
361 # Generates a link to the topic description
362 function getTopicLink($s) {
363 $t = Title
::newFromText ( wfMsg ( 'val_topic_desc_page' ) ) ;
364 # FIXME: Why doesn't this use standard linking code?
366 $r .= $t->escapeLocalURL () ;
367 $r .= "#" . urlencode ( $s ) ;
368 $r .= "\">{$s}</a>" ;
372 # Generates HTML from a wiki text, e.g., a wfMsg
373 function getParsedWiki ( $text ) {
374 global $wgOut, $wgTitle, $wgParser ;
375 $parserOutput = $wgParser->parse( $text , $wgTitle, $wgOut->mParserOptions
,false);
376 return $parserOutput->getText() ;
379 # Generates a form for a single revision
380 function getRevisionForm( &$article, $idx, &$data, $focus = false ) {
381 # Fill data with blank values
383 $revision = $this->getRevisionId( $ts );
384 foreach( $this->topicList
as $x => $y ) {
385 if( !isset( $data[$x] ) ) {
386 $data[$x]->value
= 0;
387 $data[$x]->comment
= "";
393 $table_class = $focus ?
'revisionform_focus' : 'revisionform_default';
394 $ret = "<form method='post'><table class='{$table_class}'>\n";
395 $head = "Revision #" . $revision;
396 $link = $this->getRevisionLink( $article, $revision );
397 $metadata = $this->getMetadata( $revision, $article );
398 $ret .= "<tr><th colspan='3'>" . $head . " ({$link}) {$metadata}</th></tr>\n";
400 foreach( $data as $x => $y ) {
402 $trclass = $line == 1 ?
"revision_tr_first" : "revision_tr_default";
403 $idx = "_{$revision}[{$x}]";
404 $ret .= "<tr class='{$trclass}'>\n";
406 $ret .= $this->getTopicLink ( $this->topicList
[$x]->val_comment
) ;
409 $tlx = $this->topicList
[$x];
411 $max = $tlx->val_value
;
412 for( $a = 0 ; $a <= $max ; $a++
) {
414 $vote .= wfMsg ( "val_noop" );
416 $vote .= "<input type='radio' name='re_v{$idx}' value='{$a}'";
417 if( $a == $y->value
) {
418 $vote .= " checked='checked'";
421 if( $max == 2 && $a == 1 ) {
422 $vote .= wfMsg( "val_no" ) . " ";
423 } elseif( $max == 2 && $a == 2 ) {
424 $vote .= wfMsg( "val_yes" );
425 } elseif( $a != 0 ) {
432 $ret .= "<td nowrap>{$vote}</td>\n";
434 $ret .= "<td width='100%'><input size='50' style='width:98%' maxlength='250' type='text' name='re_c{$idx}' value='{$y->comment}'/>";
435 $ret .= "</td></tr>\n";
437 $checked = $focus ?
" checked='checked'" : "";
438 $ret .= "<tr><td colspan='3'>\n";
439 $ret .= "<input type='checkbox' name='re_merge_{$revision}' value='1'{$checked} />" . $this->getParsedWiki( wfMsg( 'val_merge_old' ) ) . " \n";
440 $ret .= "<input type='checkbox' name='re_clear_{$revision}' value='1'{$checked} />" . $this->getParsedWiki( wfMsg( 'val_clear_old' ) ) . " \n";
441 $ret .= "<input type='submit' name='re_submit[{$revision}]' value=\"" . wfMsgHtml( "ok" ) . "\" />\n";
443 if( $focus ) $ret .= "<br/>\n<small>" . $this->getParsedWiki ( wfMsg( "val_form_note" ) ) . "</small>";
444 $ret .= "</td></tr>\n";
445 $ret .= "</table></form>\n\n";
450 # Generates the page from the validation tab
451 function validatePageForm( &$article, $revision ) {
452 global $wgOut, $wgRequest, $wgUser;
455 $this->page_id
= $article->getID();
456 $this->topicList
= $this->getTopicList();
457 if ( $this->getNoTopicsWarning() ) return "" ;
458 $this->voteCache
= $this->getVoteList( $article->getID() );
460 # Check for POST data
461 $re = $wgRequest->getArray( 're_submit' );
462 if ( isset( $re ) ) {
463 $id = array_keys( $re );
464 $id = $id[0] ; # $id is now the revision number the user clicked "OK" for
465 $clearOldRev = $wgRequest->getVal( "re_clear_{$id}", 0 );
466 $mergeOldRev = $wgRequest->getVal( "re_merge_{$id}", 0 );
467 $this->updateRevision( $article, $id );
469 $this->mergeOldRevisions( $article, $id );
472 $this->clearOldRevisions( $article, $id );
474 $ret .= '<p class="revision_saved">' . $this->getParsedWiki( wfMsg( 'val_revision_changes_ok' ) ) . "</p>";
476 $ret .= $this->getParsedWiki( wfMsg ('val_votepage_intro') );
479 # Make sure the requested revision exists
480 $rev = $this->getRevisionFromId($revision);
481 $ts = $rev->rev_timestamp
;
482 if( !isset( $this->voteCache
[$ts] ) ) {
483 $this->voteCache
[$ts] = array();
486 # Sort revisions list, newest first
487 krsort( $this->voteCache
);
490 $title = $article->getTitle();
491 $title = $title->getPrefixedText();
492 $wgOut->setPageTitle( wfMsg( 'val_rev_for', $title ) );
493 foreach( $this->voteCache
as $x => $y ) {
494 $ret .= $this->getRevisionForm( $article, $x, $y, $x == $ts );
497 $ret .= $this->getStatisticsLink( $article );
498 $ret .= "<p>" . $this->getUserRatingsLink( $wgUser->getID(), wfMsg( 'val_show_my_ratings' ) ) . "</p>";
502 # This function performs the "management" mode on Special:Validate
503 function manageTopics() {
504 global $wgRequest, $wgValidationMaxTopics;
505 $this->topicList
= $this->getTopicList();
507 $r = "" ; # Return value
508 $iamsure = true ; # Sure by default, see checkbox below # $wgRequest->getVal( "iamsure", "0" ) == 1;
510 if( $iamsure && $wgRequest->getVal( "m_add", "--" ) != "--" ) {
511 if ( count ( $this->topicList
) >= $wgValidationMaxTopics ) { # Catching this in case someone tries a manually edited URL...
512 $ret .= "<p><b>" . wfMsg ( 'val_max_topics' , $wgValidationMaxTopics ) . "</b></p>" ;
514 $new_topic = $wgRequest->getVal( "m_topic" );
515 $new_limit = $wgRequest->getVal( "m_limit" );
516 if( $new_topic != "" && $new_limit > 1 ) {
517 $this->addTopic( $new_topic, $new_limit );
522 $da = $wgRequest->getArray( "m_del" );
523 if( $iamsure && isset( $da ) && count( $da ) > 0 ) {
524 $id = array_keys( $da );
525 $id = array_shift( $id );
526 $this->deleteTopic( $id );
529 # FIXME: Wikitext this
530 $r .= "<p>" . $this->getParsedWiki( wfMsg( 'val_warning' ) ) . "</p>\n";
531 $r .= "<form method='post'>\n";
533 $r .= "<tr>" . wfMsg( 'val_list_header' ) . "</tr>\n";
534 foreach( $this->topicList
as $x => $y ) {
536 $r .= "<th>{$y->val_type}</th>\n";
537 $r .= "<td>" . $this->getTopicLink ( $y->val_comment
) . "</td>\n";
538 $r .= "<td>1 .. <b>" . intval( $y->val_value
) . "</b></td>\n";
539 $r .= "<td><input type='submit' name='m_del[" . intval( $x ) . "]' value='" . htmlspecialchars( wfMsg( 'val_del' ) ) . "'/></td>\n";
543 # Add topic, or too-many-topics warning
544 if ( count ( $this->topicList
) >= $wgValidationMaxTopics ) {
545 $r .= "<tr><td colspan='4' align='center'>" ;
546 $r .= wfMsg ( 'val_max_topics' , $wgValidationMaxTopics ) ;
551 $r .= '<td><input type="text" name="m_topic" value=""/></td>' . "\n";
552 $r .= '<td>1 .. <input type="text" name="m_limit" value="" size="4"/></td>' . "\n";
554 $r .= '<input type="submit" name="m_add" value="' . htmlspecialchars( wfMsg( 'val_add' ) ) . '"/>' ;
555 $r .= '</td>' . "\n";
561 # This is fot the checkbox "I am sure" for actions, which was found to be unituitive
562 # $r .= '<p><input type="checkbox" name="iamsure" id="iamsure" value="1"/>';
563 # $r .= '<label for="iamsure">' . $this->getParsedWiki( wfMsg( 'val_iamsure' ) ) . "</label></p>\n";
569 # Generates an ID for both logged-in users and anons; $res is an object from an SQL query
570 function make_user_id( &$res ) {
571 return $res->val_user
== 0 ?
$res->val_ip
: $res->val_user
;
574 function showDetails( &$article, $revision ) {
575 global $wgOut, $wgUser;
576 $this->page_id
= $article->getID();
577 $this->topicList
= $this->getTopicList();
578 if ( $this->getNoTopicsWarning() ) return "" ;
580 $sk = $wgUser->getSkin();
581 $title = $article->getTitle();
582 $wgOut->setPageTitle( str_replace( '$1', $title->getPrefixedText(), wfMsg( 'val_validation_of' ) ) );
588 # Collecting statistic data
589 $db =& wfGetDB( DB_SLAVE
);
590 $res = $db->select( 'validate', '*', array( 'val_page' => $this->page_id
, 'val_revision' => $revision ), 'SpecialValidate::showDetails' );
591 while( $x = $db->fetchObject($res) ) {
592 $data[$this->make_user_id($x)][$x->val_type
] = $x;
593 $users[$this->make_user_id($x)] = true;
594 $topics[$x->val_type
] = true;
596 $db->freeResult($res);
598 # Sorting lists of topics and users
602 $ts = $this->getRevisionTimestamp( $revision );
603 $url = $this->getRevisionLink( $article, $revision, wfTimestamp( TS_DB
, $ts ) );
607 $ret .= "<p><b>" . str_replace( '$1', $url, wfMsg( 'val_revision_of' ) ) . "</b></p>\n";
609 $ret .= "<tr><th>" . $this->getParsedWiki ( wfMsg('val_details_th') ) . "</th>" ;
611 foreach( $topics as $t => $dummy ) {
612 $ret .= '<th>' . $sk->commentBlock( $this->topicList
[$t]->val_comment
, $article->getTitle() ) . '</th>';
617 foreach( $users as $u => $dummy ) { # Every row a user
620 if( !User
::IsIP( $u ) ) { # Logged-in user rating
621 $ret .= $this->getUserRatingsLink( $u, User
::whoIs( $u ) );
622 } else { # Anon rating
623 $ret .= $this->getUserRatingsLink( $u, $u );
626 foreach( $topics as $t => $dummy ) { # Every column a topic
627 if( !isset( $data[$u][$t] ) ) {
631 $ret .= $data[$u][$t]->val_value
;
632 if( $data[$u][$t]->val_comment
!= "" ) {
633 $ret .= ' ' . $sk->commentBlock( $data[$u][$t]->val_comment
, $article->getTitle() );
641 $ret .= "<p>" . $this->getStatisticsLink( $article ) . "</p>";
642 $ret .= "<p>" . $this->getUserRatingsLink( $wgUser->getID(), wfMsg( 'val_show_my_ratings' ) ) . "</p>";
647 function showList( &$article ) {
648 global $wgOut, $wgUser , $wgRequest;
649 $this->page_id
= $article->getID();
650 $this->topicList
= $this->getTopicList();
651 if ( $this->getNoTopicsWarning() ) return "" ;
653 $title = $article->getTitle();
654 $wgOut->setPageTitle( wfMsg( 'val_validation_of', $title->getPrefixedText() ) );
656 $offset = $wgRequest->getVal ( "offset" , 0 ) ;
657 $limit = $wgRequest->getVal ( "limit" , 25 ) ;
659 # Collecting statistic data
660 # Unfortunately, it has to read all the data, though it will only display a part
661 $db =& wfGetDB( DB_SLAVE
);
662 $res = $db->select( 'validate', 'val_revision,val_type,val_value', array( "val_page" => $this->page_id
), 'SpecialValidate::showList' );#, $b );
664 $statistics = array();
665 while( $vote = $db->fetchObject($res) ) {
666 $ts = $this->getRevisionTimestamp($vote->val_revision
);
667 if ( !isset ( $statistics[$ts] ) ) $statistics[$ts] = array () ;
668 if ( !isset ( $statistics[$ts][$vote->val_type
]->count
) ) $statistics[$ts][$vote->val_type
]->count
= 0 ;
669 if ( !isset ( $statistics[$ts][$vote->val_type
]->sum
) ) $statistics[$ts][$vote->val_type
]->sum
= 0 ;
670 $statistics[$ts][$vote->val_type
]->count++
;
671 $statistics[$ts][$vote->val_type
]->sum +
= $vote->val_value
;
673 $db->freeResult($res);
675 krsort( $statistics );
677 $ret = "<table><tr>\n";
678 $ret .= "<th>" . $this->getParsedWiki( wfMsg( "val_revision" ) ) . "</th>\n";
679 foreach( $this->topicList
as $topic ) {
680 $ret .= "<th>" . $this->getTopicLink($topic->val_comment
) . "</th>";
685 $statistics = array_slice ( $statistics , $offset , $limit ) ;
687 foreach( $statistics as $ts => $data ) {
688 $rev_id = $this->getRevisionId( $ts );
689 $revision_link = $this->getRevisionLink( $article, $rev_id, wfTimestamp( TS_DB
, $ts ) );
690 $details_link = $this->getRevisionStatsLink( $article, $rev_id );
691 $ret .= "<tr><td>{$revision_link} {$details_link}</td>";
692 foreach( $this->topicList
as $topicType => $topic ) {
693 if( isset( $data[$topicType] ) ) {
694 $stats = $data[$topicType];
695 $average = $stats->count
== 0 ?
0 : $stats->sum
/ $stats->count
;
696 $ret .= sprintf( "<td><b>%1.1f</b> (%d)</td>", $average, $stats->count
);
703 $ret .= "</table>\n";
706 $s = $this->navBar ( $offset , $limit , count ( $statistics ) , "list" ) ;
707 $ret = $s . $ret . $s . "<p/>" ;
709 $ret .= "<p>" . $this->getUserRatingsLink( $wgUser->getID(), wfMsg( 'val_show_my_ratings' ) ) . "</p>";
714 function getRatingText( $value, $max ) {
715 if( $max == 2 && $value == 1 ) {
716 $ret = wfMsg ( "val_no" ) . " ";
717 } elseif( $max == 2 && $value == 2 ) {
718 $ret = wfMsg( "val_yes" );
719 } elseif( $value != 0 ) {
720 $ret = wfMsg( "val_of", $value, $max ) . " ";
727 function navBar ( $offset , $limit , $lastcount , $mode = "userstats" ) {
728 global $wgRequest , $wgUser , $wgTitle ;
729 $sk = $wgUser->getSkin();
731 $user = $wgRequest->getVal( "user" );
733 if ( $mode == "userstats" ) {
734 $nt = Title
::newFromText( 'Special:Validate' );
739 $base = "action=validate&mode={$mode}&" ;
740 if ( $user != "" ) $base .= "user={$user}&" ;
741 $base .= "limit={$limit}&offset=" ;
744 $o = $offset - $limit ;
745 $t = $offset-$limit+
1 ;
746 $r[] = $sk->makeKnownLinkObj( $nt, "{$t} <<" , $base.$o );
750 $s2 = $s1 +
$lastcount - 1 ;
751 $r[] = $s1 . " - " . $s2 ;
753 if ( $lastcount == $limit ) {
754 $o = $offset +
$limit ;
755 $t = $offset+
$limit+
1 ;
756 $r[] = $sk->makeKnownLinkObj( $nt, ">> {$t}" , $base.$o );
759 $r = implode ( " | " , $r ) ;
763 function showUserStats( $user ) {
764 global $wgOut, $wgUser, $wgRequest;
765 $this->topicList
= $this->getTopicList();
766 if ( $this->getNoTopicsWarning() ) return "" ;
767 $sk = $wgUser->getSkin();
769 $offset = $wgRequest->getVal( "offset" , 0 );
770 $limit = $wgRequest->getVal( "limit" , 25 );
771 $data = $this->getAllVoteLists( $user , $offset , $limit ) ;
773 if( $user == $wgUser->getID() ) {
774 $wgOut->setPageTitle ( wfMsg ( 'val_my_stats_title' ) );
775 } elseif( !User
::IsIP( $user ) ) {
776 $wgOut->setPageTitle( wfMsg( 'val_user_stats_title', User
::whoIs( $user ) ) );
778 $wgOut->setPageTitle( wfMsg( 'val_user_stats_title', $user ) );
788 foreach ( $data AS $articleid => $revisions ) {
789 $title = Title
::newFromID( $articleid );
790 if ( $lastpage != $articleid ) {
791 $ret .= "<tr><th colspan='4'>";
792 $ret .= $sk->makeKnownLinkObj( $title, $title->getEscapedText() );
793 $ret .= "</th></tr>";
794 $lastpage = $articleid ;
797 krsort( $revisions );
798 foreach( $revisions as $revid => $revision ) {
799 $url = $title->getLocalURL( "oldid={$revid}" );
800 if ( $lastrevision != $revid ) {
802 $lastrevision = $revid ;
807 $ret .= $sk->makeKnownLinkObj( $title, wfMsg('val_revision_number', $revid ), "oldid={$revid}" );
812 foreach( $revision as $topic => $rating ) {
817 $ret .= "<td>" . $this->getTopicLink ( $this->topicList
[$topic]->val_comment
) . "</td>";
818 $ret .= "<td>" . $this->getRatingText( $rating->val_value
, $this->topicList
[$topic]->val_value
) . "</td>";
819 $ret .= "<td>" . $sk->commentBlock( $rating->val_comment
) . "</td>";
829 $s = $this->navBar ( $offset , $limit , $linecount ) ;
830 if ( $s != "" ) $ret = $s . "<br/>" . $ret . "<br/>" . $s ;
835 function getNoTopicsWarning () {
837 if ( !isset ( $this->topicList
) ) # Just making sure, shouldn't be necessary...
838 $this->topicList
= $this->getTopicList();
839 if ( count ( $this->topicList
) > 0 ) return false ; # Topics set, all right
840 $wgOut->errorpage( "val_no_topics_defined", "val_no_topics_defined_text" );
849 function wfSpecialValidate( $page = '' ) {
850 global $wgOut, $wgRequest, $wgUseValidation, $wgUser;
852 if( !$wgUseValidation ) {
853 $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
858 if( ! $wgUser->isBureaucrat() ) {#isAllowed('change_validation') ) {
859 $wgOut->sysopRequired();
863 $mode = $wgRequest->getVal( "mode" );
864 $skin = $wgUser->getSkin();
866 if( $mode == "manage" ) {
867 $v = new Validation();
868 $html = $v->manageTopics();
869 } elseif( $mode == "userstats" ) {
870 $v = new Validation();
871 $user = $wgRequest->getVal( "user" );
872 $html = $v->showUserStats( $user );
877 $t = Title
::newFromText( "Special:Validate" );
878 $url = $t->escapeLocalURL( "mode=manage" );
879 $html .= "<li><a href=\"" . $url . "\">Manage</a></li>\n";
884 $wgOut->addHTML( $html );