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
29 var $rev_fields = "rev_id,rev_page,rev_timestamp,rev_user_text,rev_user,rev_comment" ;
31 function getRevisionFromId( $rev_id ) {
32 if( isset( $this->id2rev
[$rev_id] ) ) return $this->id2rev
[$rev_id];
34 $db =& wfGetDB( DB_SLAVE
);
35 $fname = 'SpecialValidate::getRevisionFromId';
36 $res = $db->select( 'revision', $this->rev_fields
, array( 'rev_id' => $rev_id ), $fname, array( 'LIMIT' => 1 ) );
37 $rev = $db->fetchObject($res);
38 $db->freeResult($res);
40 $this->id2rev
[$rev->rev_id
] = $rev;
41 $this->ts2rev
[$rev->rev_timestamp
] = $rev;
46 function getRevisionFromTimestamp( $timestamp ) {
47 if( isset( $this->ts2rev
[$timestamp] ) ) return $this->ts2rev
[$timestamp];
49 $db =& wfGetDB( DB_SLAVE
);
50 $fname = 'SpecialValidate::getRevisionFromTimestamp';
51 $res = $db->select( 'revision', $this->rev_fields
,
52 array( 'rev_page' => $this->page_id
, 'rev_timestamp' => $timestamp ),
53 $fname, array( 'LIMIT' => 1 )
55 $rev = $db->fetchObject($res);
56 $db->freeResult($res);
58 $this->id2rev
[$rev->rev_id
] = $rev;
59 $this->ts2rev
[$rev->rev_timestamp
] = $rev;
64 # Returns a HTML link to the specified article revision
65 function getRevisionLink( &$article, $revision, $text = "" ) {
67 $sk = $wgUser->getSkin();
68 $t = $article->getTitle();
69 if( $text == "" ) $text = wfMsg("val_view_version");
70 return $sk->makeKnownLinkObj( $t, $this->getParsedWiki($text), 'oldid='.urlencode($revision) );
73 # Returns an array containing all topics you can vote on
74 function getTopicList() {
75 $db =& wfGetDB( DB_SLAVE
);
79 # NOTE : This query returns only the topics to vote on
80 $res = $db->select( 'validate', '*', array( 'val_page' => 0 ), 'SpecialValidate::getTopicList' );
81 while( $topic = $db->fetchObject($res) ) {
82 $topics[$topic->val_type
] = $topic;
84 $db->freeResult($res);
90 # Merges one dataset into another
91 function mergeInto( &$source, &$dest ) {
93 foreach( $source as $x => $y ) {
95 if( !isset( $dest[$x] ) ) {
97 } elseif( $dest[$x]->value
== 0 ) {
111 # Merges all votes prior to the given revision into it
112 function mergeOldRevisions( &$article, $revision ) {
113 $tmp = $this->voteCache
;
116 $ts = $this->getRevisionTimestamp( $revision );
117 $data = $this->voteCache
[$ts];
118 foreach( $tmp as $x => $y ) {
120 if( $this->mergeInto( $y, $data ) ) {
126 $this->setRevision( $article, $revision, $data );
130 # Clears all votes prior to the given revision
131 function clearOldRevisions( &$article, $revision ) {
132 $tmp = $this->voteCache
;
133 $ts = $this->getRevisionTimestamp( $revision );
134 foreach( $tmp as $x => $y ) {
136 $this->deleteRevisionVote ( $article, $this->getRevisionId( $x ) );
141 # Updates the votes for the given revision from the FORM data
142 function updateRevision( &$article, $revision ) {
145 if( isset( $this->voteCache
[$this->getRevisionTimestamp( $revision )] ) ) {
146 $data = $this->voteCache
[$this->getRevisionTimestamp( $revision )];
150 $nv = $wgRequest->getArray( "re_v_{$revision}", array() );
151 $nc = $wgRequest->getArray( "re_c_{$revision}", array() );
153 foreach( $nv as $x => $y ) {
154 $data[$x]->value
= $y;
155 $data[$x]->comment
= $nc[$x];
159 $this->setRevision( $article, $revision, $data );
162 # Sets a specific revision to both cache and database
163 function setRevision( &$article, $revision, &$data ) {
165 $this->deleteRevisionVote( $article, $revision );
166 $this->voteCache
[ $this->getRevisionTimestamp($revision) ] = $data;
167 foreach( $data as $x => $y ) {
168 if( $y->value
> 0 ) {
169 $ip = $wgUser->isAnon() ?
$wgUser->getName() : '';
170 $dbw =& wfGetDB( DB_MASTER
);
171 $dbw->insert( 'validate',
173 'val_user' => $wgUser->getId(),
174 'val_page' => $article->getId(),
175 'val_revision' => $revision,
177 'val_value' => $y->value
,
178 'val_comment' => $y->comment
,
180 'SpecialValidate::setRevision'
186 # Returns a map identifying the current user
187 function identifyUser( $user = "" ) {
189 if( $user == "" ) $user = $wgUser->getID();
190 return User
::isIP($user)
191 ?
array( 'val_user' => 0, 'val_ip' => $user )
192 : array( 'val_user' => $user );
195 # Deletes a specific vote set in both cache and database
196 function deleteRevisionVote( &$article, $revision ) {
197 $ts = $this->getRevisionTimestamp( $revision );
198 if( !isset ( $this->voteCache
[$ts] ) ) return;
200 $db =& wfGetDB( DB_MASTER
);
204 $this->identifyUser(),
206 'val_page' => $article->getID(),
207 'val_revision' => $revision
210 'SpecialValidate::deleteRevisionVote'
213 unset( $this->voteCache
[$ts] );
216 # Reads the entire vote list for this user for the given article
217 function getVoteList( $id, $user = "" ) {
218 $db =& wfGetDB( DB_SLAVE
);
220 # NOTE : This query gets the votes for a single user on a single page.
221 # Assuming most people will use the "merge" feature,
222 # this will be only a single entry.
223 $res = $db->select( 'validate', '*', array_merge( array( 'val_page' => $id ), $this->identifyUser($user) ) );
225 $revisions = array();
226 while( $vote = $db->fetchObject($res) ) {
227 $ts = $this->getRevisionTimestamp( $vote->val_revision
);
228 if( ! isset( $revisions[$ts] ) ) {
229 $revisions[$ts] = array();
231 $revisions[$ts][$vote->val_type
]->value
= $vote->val_value
;
232 $revisions[$ts][$vote->val_type
]->comment
= $vote->val_comment
;
234 $db->freeResult($res);
239 # Reads a partial vote list for this user for all articles
240 function getAllVoteLists( $user , $offset , $limit ) {
241 $db =& wfGetDB( DB_SLAVE
);
242 $a = $this->identifyUser($user) ;
243 $b = array ( "ORDER BY" => "val_page,val_revision" , "OFFSET" => $offset , "LIMIT" => $limit ) ;
244 $res = $db->select( 'validate', '*', $a , 'getAllVotesList' , $b );
247 while( $vote = $db->fetchObject($res) ) {
248 $votes[$vote->val_page
][$vote->val_revision
][$vote->val_type
] = $vote;
250 $db->freeResult($res);
255 # This functions adds a topic to the database
256 function addTopic( $topic, $limit ) {
257 $db =& wfGetDB( DB_MASTER
);
260 while( isset( $this->topicList
[$next_idx] ) ) {
270 'val_type' => $next_idx,
271 'val_value' => $limit,
272 'val_comment' => $topic,
275 'SpecialValidate::addTopic'
278 $t->val_user
= $t->val_page
= $t->val_revision
= 0;
279 $t->val_type
= $next_idx;
280 $t->val_value
= $limit;
281 $t->val_comment
= $topic;
283 $this->topicList
[$next_idx] = $t;
285 ksort( $this->topicList
);
288 # This function deletes a topic and all votes for it. CAREFUL!
289 function deleteTopic( $id ) {
290 $db =& wfGetDB( DB_MASTER
);
291 $db->delete( 'validate', array( 'val_type' => $id ), 'SpecialValidate::deleteTopic' );
292 unset( $this->topicList
[$id] );
295 # This function returns a link text to the page validation statistics
296 function getStatisticsLink( &$article ) {
298 $sk = $wgUser->getSkin();
299 $nt = $article->getTitle();
300 return $sk->makeKnownLinkObj( $nt, wfMsg( 'val_rev_stats', $nt->getPrefixedText() ), 'action=validate&mode=list' );
303 # This function returns a link text to the page validation statistics of a single revision
304 function getRevisionStatsLink( &$article, $revision ) {
306 $sk = $wgUser->getSkin();
307 $nt = $article->getTitle();
308 $text = $this->getParsedWiki( wfMsg('val_revision_stats_link') );
309 $query = "action=validate&mode=details&revision={$revision}";
310 return '(' . $sk->makeKnownLinkObj( $nt, $text, $query ) . ')';
313 # This function returns a link text to the user rating statistics page
314 function getUserRatingsLink( $user, $text ) {
316 $sk = $wgUser->getSkin();
317 if( $user == 0 ) $user = $wgUser->getName();
318 $nt = Title
::newFromText( 'Special:Validate' );
319 return $sk->makeKnownLinkObj( $nt, $text, 'mode=userstats&user='.urlencode($user) );
322 # Returns the timestamp of a revision based on the revision number
323 function getRevisionTimestamp( $rev_id ) {
324 $rev = $this->getRevisionFromId( $rev_id );
325 return $rev->rev_timestamp
;
328 # Returns the revision number of a revision based on the timestamp
329 function getRevisionId( $ts ) {
330 $rev = $this->getRevisionFromTimestamp( $ts );
335 # HTML generation functions from this point on
337 # Returns the metadata string for a revision
338 function getMetadata( $rev_id, &$article ) {
340 $sk = $wgUser->getSkin();
343 $x = $this->getRevisionFromId($rev_id);
344 $metadata .= wfTimestamp( TS_DB
, $x->rev_timestamp
);
346 if( $x->rev_user
== 0 ) {
347 $metadata .= $x->rev_user_text
;
350 $u->setId( $x->rev_user
);
351 $u->setName( $x->rev_user_text
);
352 $nt = $u->getUserPage();
353 $metadata .= $sk->makeKnownLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
355 $metadata .= ': '. $sk->commentBlock( $x->rev_comment
, $article->getTitle() );
359 # Generates a link to the topic description
360 function getTopicLink($s) {
361 $t = Title
::newFromText ( wfMsg ( 'val_topic_desc_page' ) ) ;
362 # FIXME: Why doesn't this use standard linking code?
364 $r .= $t->escapeLocalURL () ;
365 $r .= "#" . urlencode ( $s ) ;
366 $r .= "\">{$s}</a>" ;
370 # Generates HTML from a wiki text, e.g., a wfMsg
371 function getParsedWiki ( $text ) {
372 global $wgOut, $wgTitle, $wgParser ;
373 $parserOutput = $wgParser->parse( $text , $wgTitle, $wgOut->mParserOptions
,false);
374 return $parserOutput->getText() ;
377 # Generates a form for a single revision
378 function getRevisionForm( &$article, $idx, &$data, $focus = false ) {
379 # Fill data with blank values
381 $revision = $this->getRevisionId( $ts );
382 foreach( $this->topicList
as $x => $y ) {
383 if( !isset( $data[$x] ) ) {
384 $data[$x]->value
= 0;
385 $data[$x]->comment
= "";
389 $token = htmlspecialchars( $wgUser->editToken() );
392 $table_class = $focus ?
'revisionform_focus' : 'revisionform_default';
393 $ret = "<form method='post'><table class='{$table_class}'>\n"
394 . '<input type="hidden" name="wpEditToken" value="' . $token .'" />';
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 $token = htmlspecialchars( $wgUser->editToken() );
531 # FIXME: Wikitext this
532 $r .= "<p>" . $this->getParsedWiki( wfMsg( 'val_warning' ) ) . "</p>\n";
533 $r .= "<form method='post'>\n";
534 $r .= '<input type="hidden" name="wpEditToken" value="' . $token .'" />';
536 $r .= "<tr>" . wfMsg( 'val_list_header' ) . "</tr>\n";
537 foreach( $this->topicList
as $x => $y ) {
539 $r .= "<th>{$y->val_type}</th>\n";
540 $r .= "<td>" . $this->getTopicLink ( $y->val_comment
) . "</td>\n";
541 $r .= "<td>1 .. <b>" . intval( $y->val_value
) . "</b></td>\n";
542 $r .= "<td><input type='submit' name='m_del[" . intval( $x ) . "]' value='" . htmlspecialchars( wfMsg( 'val_del' ) ) . "'/></td>\n";
546 # Add topic, or too-many-topics warning
547 if ( count ( $this->topicList
) >= $wgValidationMaxTopics ) {
548 $r .= "<tr><td colspan='4' align='center'>" ;
549 $r .= wfMsg ( 'val_max_topics' , $wgValidationMaxTopics ) ;
554 $r .= '<td><input type="text" name="m_topic" value=""/></td>' . "\n";
555 $r .= '<td>1 .. <input type="text" name="m_limit" value="" size="4"/></td>' . "\n";
557 $r .= '<input type="submit" name="m_add" value="' . htmlspecialchars( wfMsg( 'val_add' ) ) . '"/>' ;
558 $r .= '</td>' . "\n";
564 # This is fot the checkbox "I am sure" for actions, which was found to be unituitive
565 # $r .= '<p><input type="checkbox" name="iamsure" id="iamsure" value="1"/>';
566 # $r .= '<label for="iamsure">' . $this->getParsedWiki( wfMsg( 'val_iamsure' ) ) . "</label></p>\n";
572 # Generates an ID for both logged-in users and anons; $res is an object from an SQL query
573 function make_user_id( &$res ) {
574 return $res->val_user
== 0 ?
$res->val_ip
: $res->val_user
;
577 function showDetails( &$article, $revision ) {
578 global $wgOut, $wgUser;
579 $this->page_id
= $article->getID();
580 $this->topicList
= $this->getTopicList();
581 if ( $this->getNoTopicsWarning() ) return "" ;
583 $sk = $wgUser->getSkin();
584 $title = $article->getTitle();
585 $wgOut->setPageTitle( str_replace( '$1', $title->getPrefixedText(), wfMsg( 'val_validation_of' ) ) );
591 # Collecting statistic data
592 $db =& wfGetDB( DB_SLAVE
);
593 $res = $db->select( 'validate', '*', array( 'val_page' => $this->page_id
, 'val_revision' => $revision ), 'SpecialValidate::showDetails' );
594 while( $x = $db->fetchObject($res) ) {
595 $data[$this->make_user_id($x)][$x->val_type
] = $x;
596 $users[$this->make_user_id($x)] = true;
597 $topics[$x->val_type
] = true;
599 $db->freeResult($res);
601 # Sorting lists of topics and users
605 $ts = $this->getRevisionTimestamp( $revision );
606 $url = $this->getRevisionLink( $article, $revision, wfTimestamp( TS_DB
, $ts ) );
610 $ret .= "<p><b>" . str_replace( '$1', $url, wfMsg( 'val_revision_of' ) ) . "</b></p>\n";
612 $ret .= "<tr><th>" . $this->getParsedWiki ( wfMsg('val_details_th') ) . "</th>" ;
614 foreach( $topics as $t => $dummy ) {
615 $ret .= '<th>' . $sk->commentBlock( $this->topicList
[$t]->val_comment
, $article->getTitle() ) . '</th>';
620 foreach( $users as $u => $dummy ) { # Every row a user
623 if( !User
::IsIP( $u ) ) { # Logged-in user rating
624 $ret .= $this->getUserRatingsLink( $u, User
::whoIs( $u ) );
625 } else { # Anon rating
626 $ret .= $this->getUserRatingsLink( $u, $u );
629 foreach( $topics as $t => $dummy ) { # Every column a topic
630 if( !isset( $data[$u][$t] ) ) {
634 $ret .= $data[$u][$t]->val_value
;
635 if( $data[$u][$t]->val_comment
!= "" ) {
636 $ret .= ' ' . $sk->commentBlock( $data[$u][$t]->val_comment
, $article->getTitle() );
644 $ret .= "<p>" . $this->getStatisticsLink( $article ) . "</p>";
645 $ret .= "<p>" . $this->getUserRatingsLink( $wgUser->getID(), wfMsg( 'val_show_my_ratings' ) ) . "</p>";
650 function showList( &$article ) {
651 global $wgOut, $wgUser , $wgRequest;
652 $this->page_id
= $article->getID();
653 $this->topicList
= $this->getTopicList();
654 if ( $this->getNoTopicsWarning() ) return "" ;
656 $title = $article->getTitle();
657 $wgOut->setPageTitle( wfMsg( 'val_validation_of', $title->getPrefixedText() ) );
659 $offset = $wgRequest->getVal ( "offset" , 0 ) ;
660 $limit = $wgRequest->getVal ( "limit" , 25 ) ;
662 # Collecting statistic data
663 # Unfortunately, it has to read all the data, though it will only display a part
664 $db =& wfGetDB( DB_SLAVE
);
665 $res = $db->select( 'validate', 'val_revision,val_type,val_value', array( "val_page" => $this->page_id
), 'SpecialValidate::showList' );#, $b );
667 $statistics = array();
668 while( $vote = $db->fetchObject($res) ) {
669 $ts = $this->getRevisionTimestamp($vote->val_revision
);
670 if ( !isset ( $statistics[$ts] ) ) $statistics[$ts] = array () ;
671 if ( !isset ( $statistics[$ts][$vote->val_type
]->count
) ) $statistics[$ts][$vote->val_type
]->count
= 0 ;
672 if ( !isset ( $statistics[$ts][$vote->val_type
]->sum
) ) $statistics[$ts][$vote->val_type
]->sum
= 0 ;
673 $statistics[$ts][$vote->val_type
]->count++
;
674 $statistics[$ts][$vote->val_type
]->sum +
= $vote->val_value
;
676 $db->freeResult($res);
678 krsort( $statistics );
680 $ret = "<table><tr>\n";
681 $ret .= "<th>" . $this->getParsedWiki( wfMsg( "val_revision" ) ) . "</th>\n";
682 foreach( $this->topicList
as $topic ) {
683 $ret .= "<th>" . $this->getTopicLink($topic->val_comment
) . "</th>";
688 $statistics = array_slice ( $statistics , $offset , $limit ) ;
690 foreach( $statistics as $ts => $data ) {
691 $rev_id = $this->getRevisionId( $ts );
692 $revision_link = $this->getRevisionLink( $article, $rev_id, wfTimestamp( TS_DB
, $ts ) );
693 $details_link = $this->getRevisionStatsLink( $article, $rev_id );
694 $ret .= "<tr><td>{$revision_link} {$details_link}</td>";
695 foreach( $this->topicList
as $topicType => $topic ) {
696 if( isset( $data[$topicType] ) ) {
697 $stats = $data[$topicType];
698 $average = $stats->count
== 0 ?
0 : $stats->sum
/ $stats->count
;
699 $ret .= sprintf( "<td><b>%1.1f</b> (%d)</td>", $average, $stats->count
);
706 $ret .= "</table>\n";
709 $s = $this->navBar ( $offset , $limit , count ( $statistics ) , "list" ) ;
710 $ret = $s . $ret . $s . "<p/>" ;
712 $ret .= "<p>" . $this->getUserRatingsLink( $wgUser->getID(), wfMsg( 'val_show_my_ratings' ) ) . "</p>";
717 function getRatingText( $value, $max ) {
718 if( $max == 2 && $value == 1 ) {
719 $ret = wfMsg ( "val_no" ) . " ";
720 } elseif( $max == 2 && $value == 2 ) {
721 $ret = wfMsg( "val_yes" );
722 } elseif( $value != 0 ) {
723 $ret = wfMsg( "val_of", $value, $max ) . " ";
730 function navBar ( $offset , $limit , $lastcount , $mode = "userstats" ) {
731 global $wgRequest , $wgUser , $wgTitle ;
732 $sk = $wgUser->getSkin();
734 $user = $wgRequest->getVal( "user" );
736 if ( $mode == "userstats" ) {
737 $nt = Title
::newFromText( 'Special:Validate' );
742 $base = "action=validate&mode={$mode}&" ;
743 if ( $user != "" ) $base .= "user={$user}&" ;
744 $base .= "limit={$limit}&offset=" ;
747 $o = $offset - $limit ;
748 $t = $offset-$limit+
1 ;
749 $r[] = $sk->makeKnownLinkObj( $nt, "{$t} <<" , $base.$o );
753 $s2 = $s1 +
$lastcount - 1 ;
754 $r[] = $s1 . " - " . $s2 ;
756 if ( $lastcount == $limit ) {
757 $o = $offset +
$limit ;
758 $t = $offset+
$limit+
1 ;
759 $r[] = $sk->makeKnownLinkObj( $nt, ">> {$t}" , $base.$o );
762 $r = implode ( " | " , $r ) ;
766 function showUserStats( $user ) {
767 global $wgOut, $wgUser, $wgRequest;
768 $this->topicList
= $this->getTopicList();
769 if ( $this->getNoTopicsWarning() ) return "" ;
770 $sk = $wgUser->getSkin();
772 $offset = $wgRequest->getVal( "offset" , 0 );
773 $limit = $wgRequest->getVal( "limit" , 25 );
774 $data = $this->getAllVoteLists( $user , $offset , $limit ) ;
776 if( $user == $wgUser->getID() ) {
777 $wgOut->setPageTitle ( wfMsg ( 'val_my_stats_title' ) );
778 } elseif( !User
::IsIP( $user ) ) {
779 $wgOut->setPageTitle( wfMsg( 'val_user_stats_title', User
::whoIs( $user ) ) );
781 $wgOut->setPageTitle( wfMsg( 'val_user_stats_title', $user ) );
791 foreach ( $data AS $articleid => $revisions ) {
792 $title = Title
::newFromID( $articleid );
793 if ( $lastpage != $articleid ) {
794 $ret .= "<tr><th colspan='4'>";
795 $ret .= $sk->makeKnownLinkObj( $title, $title->getEscapedText() );
796 $ret .= "</th></tr>";
797 $lastpage = $articleid ;
800 krsort( $revisions );
801 foreach( $revisions as $revid => $revision ) {
802 $url = $title->getLocalURL( "oldid={$revid}" );
803 if ( $lastrevision != $revid ) {
805 $lastrevision = $revid ;
810 $ret .= $sk->makeKnownLinkObj( $title, wfMsg('val_revision_number', $revid ), "oldid={$revid}" );
815 foreach( $revision as $topic => $rating ) {
820 $ret .= "<td>" . $this->getTopicLink ( $this->topicList
[$topic]->val_comment
) . "</td>";
821 $ret .= "<td>" . $this->getRatingText( $rating->val_value
, $this->topicList
[$topic]->val_value
) . "</td>";
822 $ret .= "<td>" . $sk->commentBlock( $rating->val_comment
) . "</td>";
832 $s = $this->navBar ( $offset , $limit , $linecount ) ;
833 if ( $s != "" ) $ret = $s . "<br/>" . $ret . "<br/>" . $s ;
838 function getNoTopicsWarning () {
840 if ( !isset ( $this->topicList
) ) # Just making sure, shouldn't be necessary...
841 $this->topicList
= $this->getTopicList();
842 if ( count ( $this->topicList
) > 0 ) return false ; # Topics set, all right
843 $wgOut->errorpage( "val_no_topics_defined", "val_no_topics_defined_text" );
852 function wfSpecialValidate( $page = '' ) {
853 global $wgOut, $wgRequest, $wgUseValidation, $wgUser;
855 if( !$wgUseValidation ) {
856 $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
861 if( ! $wgUser->isBureaucrat() ) {#isAllowed('change_validation') ) {
862 $wgOut->sysopRequired();
866 $mode = $wgRequest->getVal( "mode" );
867 $skin = $wgUser->getSkin();
869 $token = $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
872 if( $mode == "manage" ) {
873 $v = new Validation();
874 $html = $v->manageTopics();
875 } elseif( $mode == "userstats" ) {
876 $v = new Validation();
877 $user = $wgRequest->getVal( "user" );
878 $html = $v->showUserStats( $user );
881 $html = htmlspecialchars( $mode );
884 $t = Title
::newFromText( "Special:Validate" );
885 $url = $t->escapeLocalURL( "mode=manage" );
886 $html .= "<li><a href=\"" . $url . "\">Manage</a></li>\n";
891 $wgOut->addHTML( $html );