Use Revision for individual message loads; not using it for bulk load just now; need...
[lhc/web/wiklou.git] / includes / SpecialValidate.php
index 944c18b..3030f28 100644 (file)
 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 # http://www.gnu.org/copyleft/gpl.html
 
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
 class Validation {
        
        function find_this_version( $article_title , &$article_time , &$id , &$tab ) {
-               $id = "";
+/*             $id = "";
                $tab = "";
-               $sql = "SELECT cur_id,cur_timestamp FROM cur WHERE cur_namespace=0 AND cur_title='" . wfStrencode( $article_title ) . "'";
+               $sql = "SELECT cur_id,cur_timestamp FROM cur WHERE cur_namespace=".NS_MAIN." AND cur_title='" . wfStrencode( $article_title ) . "'";
                $res = wfQuery( $sql, DB_READ );
                if( $s = wfFetchObject( $res ) ) {
                        if ( $article_time == "" ) {
@@ -36,19 +47,19 @@ class Validation {
                }
                        
                if ( $id == "" ) {
-                       $sql = "SELECT old_id FROM old WHERE old_namespace=0 AND old_title='" . wfStrencode( $article_title ) .
+                       $sql = "SELECT old_id FROM old WHERE old_namespace=".NS_MAIN." AND old_title='" . wfStrencode( $article_title ) .
                                "' AND old_timestamp='" . wfStrencode( $article_time ) . "'";
                        $res = wfQuery( $sql, DB_READ );
                        if( $s = wfFetchObject( $res ) ) {
                                $tab = "old";
                                $id = $s->old_id;
                        }
-               }
+               }*/
        }
 
        function get_prev_data( $user_id , $article_title , $article_timestamp = "" ) {
                $ret = array ();
-               $sql = "SELECT * FROM validate WHERE val_user='" . wfStrencode( $user_id ) .
+/*             $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 ) . "'";
@@ -56,12 +67,12 @@ class Validation {
                $res = wfQuery( $sql, DB_READ );
                while( $s = wfFetchObject( $res ) ) {
                        $ret[$s->val_timestamp][$s->val_type] = $s;
-               }
+               }*/
                return $ret;
        }
 
        function validate_form( $article_title = "" ) {
-               global $wgOut, $wgLang, $wgUser, $wgArticle, $wgRequest;
+/*             global $wgOut, $wgLang, $wgUser, $wgArticle, $wgRequest;
                
                if ( $wgUser->getID() == 0 ) {
                        # Anon
@@ -92,7 +103,7 @@ class Validation {
                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 );
+                                       wfStrencode( $article_title ) . "' AND cur_namespace=".NS_MAIN, DB_READ );
                                if( $s = wfFetchObject( $res ) ) {
                                        $article_time = $s->cur_timestamp;
                                }
@@ -193,7 +204,7 @@ class Validation {
                        if ( $article_time == $time ) {
                                $tablestyle .=" style='border: 2px solid red'";
                        }
-                       $html .= "<h2>" . wfMsg( 'val_version_of', gmdate( "F d, Y H:i:s", wfTimestamp2Unix( $time ) ) );
+                       $html .= "<h2>" . wfMsg( 'val_version_of', gmdate( "F d, Y H:i:s", wfTimestamp( TW_UNIX, $time ) ) );
                        $this->find_this_version ( $article_title , $time , $table_id , $table_name );
                        if( $table_name == "cur" ) {
                                $html .= " (" . wfMsg( 'val_this_is_current_version' ) . ")";
@@ -253,11 +264,11 @@ class Validation {
                
                $html .= "<h2>" . wfMsg( 'preview' ) . "</h2>";
                $wgOut->addHTML( $html );
-               $wgOut->addWikiText( $wgArticle->getContent( true ) );
+               $wgOut->addWikiText( $wgArticle->getContent( true ) );*/
        }
 
        function getData( $user = -1 , $title = "" , $type = -1 ) {
-               $ret = array();
+/*             $ret = array();
                $sql = array();
                if( $user != -1 ) {
                        $sql[] = "val_user='" . wfStrencode( $user ) . "'";
@@ -277,12 +288,12 @@ class Validation {
                while( $s = wfFetchObject( $res ) ) {
                        $ret["{$s->val_title}"]["{$s->val_timestamp}"]["{$s->val_type}"][] = $s;
                }
-               return $ret;
+               return $ret;*/
        }
 
        # Show statistics for the different versions of a single article
        function getPageStatistics( $article_title = "" ) {
-               global $wgLang, $wgUser, $wgOut, $wgRequest;
+/*             global $wgLang, $wgUser, $wgOut, $wgRequest;
                $validationtypes = $wgLang->getValidationTypes();
                if( $article_title == "" ) {
                        $article_title = $wgRequest->getVal( 'article_title' );
@@ -382,22 +393,22 @@ class Validation {
                        $html .= "</tr>";
                }
                $html .= "</table>\n";
-               return $html ;
+               return $html ;*/
        }
 
        function countUserValidations( $userid ) {
-               $sql = "SELECT count(DISTINCT val_title) AS num FROM validate WHERE val_user=" . IntVal( $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;
+               return $num;*/
        }
 
        function getArticleList() {
-               global $wgLang, $wgOut;
+/*             global $wgLang, $wgOut;
                $validationtypes = $wgLang->getValidationTypes();
                $wgOut->setPageTitle( wfMsg( 'val_article_lists' ) );
                $html = "";
@@ -487,50 +498,400 @@ class Validation {
                        }
                }
                $html .= "</ul>\n";
-               return $html;
+               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&timestamp={$table_id}" );
+       # 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 = "<a href=\"" . $t->getLocalURL ( "oldid={$revision}" ) . "\">" . $text . "</a>" ;
+               return $ret ;
+       }
+
+       # Returns an array containing all topics you can vote on
+       function getTopicList () {
+               $ret = array () ;
+               $sql = "SELECT * FROM validate WHERE val_user=0" ;
+               $res = wfQuery( $sql, DB_READ );
+               while( $x = wfFetchObject( $res ) ) {
+                       $ret[$x->val_type] = $x ;
                }
-               $linktitle = wfMsg( 'val_version_of', $wgLang->timeanddate( $timestamp ) );
-               $link = "<a href=\"" . htmlspecialchars( $link ) . "\">" . $linktitle . "</a>";
-               if( $table_name == 'cur' ) {
-                       $link .= " (" . wfMsg ( 'val_this_is_current_version' ) . ")";
+               ksort ( $ret ) ;
+               return $ret ;
+       }
+       
+       # Generates a form for a single revision
+       function getRevisionForm ( &$article , $revision , &$data , $focus = false ) {
+               # Fill data with blank values
+               foreach ( $this->topicList AS $x => $y ) {
+                       if ( !isset ( $data[$x] ) ) {
+                               $data[$x]->value = 0 ;
+                               $data[$x]->comment = "" ;
+                       }
                }
+               ksort ( $data ) ;
+       
+               # Generate form
+               $ret = "<form method='post'>" ;
+               $ret .= "<table border='1' cellspacing='0' cellpadding='2'" ;
+               if ( $focus ) $ret .= " style='background-color:#00BBFF'" ;
+               $ret .= ">\n" ;
+               $head = "Revision #" . $revision ;
+#              if ( $focus ) $head = "<font color='red'>{$head}</font>" ;
+               $link = " " . $this->getVersionLink ( $article , $revision ) ;
+               $ret .= "<tr><th align='left' colspan='3'>" . $head . " ({$link})</th></tr>\n" ;
+               $line = 0 ;
+               foreach ( $data AS $x => $y ) {
+                       $line = 1 - $line ;
+                       $col = $line == 1 ? "#DDDDDD" : "#EEEEEE" ;
+                       $idx = "_{$revision}[{$x}]" ;
+                       $ret .= "<tr bgcolor='{$col}'>\n" ;
+                       $ret .= "<th nowrap>" ;
+                       $ret .= $this->topicList[$x]->val_comment ;
+                       $ret .= "</th>\n" ;
+                       
+                       $tlx = $this->topicList[$x] ;
+                       $vote = "" ;
+                       $max = $tlx->val_value ;
+                       for ( $a = 0 ; $a <= $max ; $a++ ) {
+                               if ( $a == 0 ) $vote .= wfMsg ( "val_noop" ) ;
+                               $vote .= "<input type='radio' name='re_v{$idx}' value='{$a}'" ;
+                               if ( $a == $y->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 .= " &nbsp; " ;
+                       }                       
+                       $ret .= "<td nowrap valign='center'>{$vote}</td>\n" ;
+                       
+                       $ret .= "<td width='100%' align='center'><input size='50' style='width:98%' maxlength='250' type='text' name='re_c{$idx}' value='{$y->comment}'/>" ;
+                       $ret .= "</td></tr>\n" ;
+               }
+               $checked = $focus ? " checked" : "" ;
+               $ret .= "<tr><td colspan='3' valign='center'>\n" ;
+               $ret .= "<input type='checkbox' name='re_merge_{$revision}' value='1'{$checked}/>" . wfMsg( 'val_merge_old' ) . " \n" ;
+               $ret .= "<input type='checkbox' name='re_clear_{$revision}' value='1'{$checked}/>" . wfMsg( 'val_clear_old' ) . " \n" ;
+               $ret .= "<input type='submit' name='re_submit[{$revision}]' value='" . htmlspecialchars( wfMsg("ok") ) . "'/>\n" ;
+               if ( $focus ) $ret .= "<br/>\n<small>" . wfMsg ( "val_form_note" ) . "</small>" ;
+               $ret .= "</td></tr>\n" ;
+               $ret .= "</table>\n</form>\n\n" ;
+               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 ;
+                       }
+               }
+               if ( $ret ) ksort ( $dest ) ;
+               return $ret ;
+       }
 
-               $vlink = wfMsg( 'val_tab' );
-               $vlink = "[<a href=\"" . $title->escapeLocalURL( "action=validate&timestamp={$timestamp}" ) . "\">{$vlink}</a>] " . $link;
-               return $vlink ;
+       # Merges all votes prior to the given revision into it
+       function mergeOldRevisions ( &$article , $revision ) {
+               $tmp = $this->voteCache ;
+               krsort ( $tmp ) ;
+               $update = false ;
+               $data = $this->voteCache[$revision] ;
+               foreach ( $tmp AS $x => $y ) {
+                       if ( $x < $revision ) {
+                               if ( $this->mergeInto ( $y , $data ) ) $update = true ;
+                       }
+               }
+               if ( $update ) $this->setRevision ( $article , $revision , $data ) ;
+       }
+       
+       # Clears all votes prior to the given revision
+       function clearOldRevisions ( &$article , $revision ) {
+               $tmp = $this->voteCache ;
+               foreach ( $tmp AS $x => $y ) {
+                       if ( $x < $revision ) $this->deleteRevision ( $article , $x ) ;
+               }
+       }
+       
+       # Updates the votes for the given revision from the FORM data
+       function updateRevision ( &$article , $revision ) {
+               global $wgUser, $wgRequest ;
+               
+               if ( isset ( $this->voteCache[$revision] ) ) $data = $this->voteCache[$revision] ;
+               else $data = array () ;
+               $nv = $wgRequest->getArray ( "re_v_{$revision}" , array() ) ;
+               $nc = $wgRequest->getArray ( "re_c_{$revision}" , array() ) ;
+               
+               foreach ( $nv AS $x => $y ) {
+#                      if ( $y > 0 ) {
+                               $data[$x]->value = $y ;
+                               $data[$x]->comment = $nc[$x] ;
+#                      }
+               }
+               krsort ( $data ) ;
+               
+               $this->setRevision ( $article , $revision , $data ) ;
+       }
+       
+       # Sets a specific revision to both cache and database
+       function setRevision ( &$article , $revision , &$data ) {
+               global $wgUser ;
+               $this->deleteRevision ( $article , $revision ) ;
+               $this->voteCache[$revision] = $data ;
+               foreach ( $data AS $x => $y ) {
+                       if ( $y->value > 0 ) {
+                               $sql = "INSERT INTO validate (val_user,val_page,val_revision,val_type,val_value,val_comment) VALUES ('" ;
+                               $sql .= $wgUser->getID() . "','" ;
+                               $sql .= $article->getID() . "','" ;
+                               $sql .= $revision . "','" ;
+                               $sql .= $x . "','" ;
+                               $sql .= $y->value . "','" ;
+                               $sql .= Database::strencode ( $y->comment ) . "')" ;
+                               $res = wfQuery( $sql, DB_WRITE );
+                       }
+               }
+       }
+       
+       # Deletes a specific vote set in both cache and database
+       function deleteRevision ( &$article , $revision ) {
+               global $wgUser ;
+               if ( !isset ( $this->voteCache[$revision] ) ) return ; # Nothing to do
+               $sql = "DELETE FROM validate WHERE val_user='" . $wgUser->GetID() . "' AND " ;
+               $sql .= " val_page='" . $article->getID() . "' AND val_revision='{$revision}'" ;
+               $res = wfQuery( $sql, DB_WRITE );
+               unset ( $this->voteCache[$revision] ) ;
+       }
+       
+       # Reads the entire vote list for this user for the given article
+       function getVoteList ( $id ) {
+               global $wgUser ;
+               $r = array () ; # Revisions
+               $sql = "SELECT * FROM validate WHERE val_page=" . $id . " AND val_user=" . $wgUser->getID() ;
+               $res = wfQuery( $sql, DB_READ );
+               while( $x = wfFetchObject( $res ) ) {
+                       if ( !isset($r[$x->val_revision]) ) $r[$x->val_revision] = array () ;
+                       $r[$x->val_revision][$x->val_type]->value = $x->val_value ;
+                       $r[$x->val_revision][$x->val_type]->comment = $x->val_comment ;
+               }               
+               return $r ;
+       }
+       
+       # This functions adds a topic to the database
+       function addTopic ( $topic , $limit ) {
+               $a = 1 ;
+               while ( isset ( $this->topicList[$a] ) ) $a++ ;
+               $sql = "INSERT INTO validate (val_user,val_page,val_revision,val_type,val_value,val_comment) 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 ;
+               $this->topicList[$a] = $x ;
+               ksort ( $this->topicList ) ;
        }
 
-}
+       # This functions adds a topic to the database
+       function deleteTopic ( $id ) {
+               $sql = "DELETE FROM validate WHERE val_type='{$id}'" ;
+               $res = wfQuery( $sql, DB_WRITE );
+               unset ( $this->topicList[$id] ) ;
+       }
+       
+       # This function returns a link text to the page validation statistics
+       function link2statistics ( &$article ) {
+               $ret = wfMsg ( 'val_rev_stats_link' ) ;
+               $nt = $article->getTitle() ;
+               $ret = str_replace ( "$1" , $nt->getPrefixedText() , $ret ) ;
+
+#              $t = Title::newFromText ( "Special:Validate" ) ;
+#              $url = $t->getLocalURL ( "mode=list&id=" . $article->getID() ) ;
+               $url = $nt->getLocalURL ( "action=validate&mode=list" ) ;
+               $ret = str_replace ( "$2" , $url , $ret ) ;
+
+               return $ret ;
+       }
+       
+
+
+       # HTML generation functions from this point on
 
-function wfSpecialValidate( $page = "" ) {
-       global $wgOut, $wgRequest, $wgUseValidation;
 
+       # Generates the page from the validation tab
+       function validatePageForm ( &$article , $revision ) {
+               global $wgOut, $wgRequest ;
+               
+               $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 ) ;
+                       $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 ) ;
+                       }
+               
+               # Make sure the requested revision exists
+               if ( !isset ( $this->voteCache[$revision] ) ) $this->voteCache[$revision] = array () ;
+               
+               # Sort revisions list, newest first
+               krsort ( $this->voteCache ) ;
+               
+               # Output
+               $ret = "" ;
+               $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 == $revision ) ;
+                       $ret .= "<br/>\n" ;
+                       }
+               $ret .= $this->link2statistics ( $article ) ;
+               return $ret ;   
+       }
+       
+       # This function performs the "management" mode on Special:Validate
+       function manageTopics () {
+               global $wgRequest ;
+               $this->topicList = $this->getTopicList() ;
+               
+               $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 ) ;
+               }
+
+               $da = $wgRequest->getArray ( "m_del" ) ;
+               if ( $iamsure && isset ( $da ) && count ( $da ) > 0 ) {
+                       $id = array_keys ( $da ) ;
+                       $id = array_shift ( $id ) ;
+                       $this->deleteTopic ( $id ) ;
+               }
+               
+               $r = "<p>" . wfMsg ( 'val_warning' ) . "</p>\n" ;
+               $r .= "<form method='post'>\n" ;
+               $r .= "<table border='1' cellspacing='0' cellpadding='2'>\n" ;
+               $r .= "<tr>" . wfMsg ( 'val_list_header' ) . "</tr>\n" ;
+               foreach ( $this->topicList AS $x => $y ) {
+                       $r .= "<tr>\n" ;
+                       $r .= "<th>" . $y->val_type . "</th>\n" ;
+                       $r .= "<td>{$y->val_comment}</td>\n" ;
+                       $r .= "<td>1 .. <b>{$y->val_value}</b></td>\n" ;
+                       $r .= "<td><input type='submit' name='m_del[{$x}]' value='" . wfMsg ( 'val_del' ) . "'/></td>\n" ;
+                       $r .= "</tr>\n" ;
+               }
+               $r .= "<tr>\n" ;
+               $r .= "<td/>\n" ;
+               $r .= "<td><input type='text' name='m_topic' value=''/></td>\n" ;
+               $r .= "<td><input type='text' name='m_limit' value=''/></td>\n" ;
+               $r .= "<td><input type='submit' name='m_add' value='" . wfMsg ( 'val_add' ) . "'/></td>\n" ;
+               $r .= "</tr>\n" ;
+               $r .= "</table>\n" ;
+               $r .= "<input type='checkbox' name='iamsure' value='1'/>" . wfMsg ( 'val_iamsure' ) . "\n" ;
+               $r .= "</form>\n" ;
+               return $r ;
+       }
+       
+       function showList ( &$article ) {
+               $this->topicList = $this->getTopicList() ;
+               
+               # Collecting statistic data
+               $id = $article->getID() ;
+               $sql = "SELECT * FROM validate WHERE val_page='{$id}'" ;
+               $res = wfQuery( $sql, DB_READ );
+               $data = array () ;
+               while( $x = wfFetchObject( $res ) ) {
+                       if ( !isset ( $data[$x->val_revision] ) )
+                               $data[$x->val_revision] = array () ;
+                       if ( !isset ( $data[$x->val_revision][$x->val_type] ) ) {
+                               $data[$x->val_revision][$x->val_type]->count = 0 ;
+                               $data[$x->val_revision][$x->val_type]->sum = 0 ;
+                       }
+                       $data[$x->val_revision][$x->val_type]->count++ ;
+                       $data[$x->val_revision][$x->val_type]->sum += $x->val_value ;
+               }
+               
+               $ret = "" ;
+               $ret .= "<table border='1' cellspacing='0' cellpadding='2'>\n" ;
+               $ret .= "<tr><th>Revision</th>" ;
+               foreach ( $this->topicList AS $x => $y )
+                       $ret .= "<th>{$y->val_comment}</th>" ;
+               $ret .= "</tr>\n" ;
+               foreach ( $data AS $revision => $y ) {
+                       $url = $this->getVersionLink ( $article , $revision , $revision ) ;
+                       $ret .= "<tr><th>{$url}</th>" ;
+                       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 ( "<td><b>%1.1f</b> (%d)</td>" , $a , $z->count ) ;
+                               } else $ret .= "<td/>" ;
+                               }
+                       $ret .= "</tr>\n" ;
+               }
+               $ret .= "</table>\n" ;
+               return $ret ;
+       }
+
+}
+
+/**
+ * constructor
+ */
+function wfSpecialValidate( $page = '' ) {
+       global $wgOut, $wgRequest, $wgUseValidation, $wgUser, $wgContLang;
+       
        if( !$wgUseValidation ) {
                $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
                return;
        }
 
-       $mode = $wgRequest->getVal( 'mode', 'form' );
-       $v = new Validation;
-       $html = "" ;
-/*     if( $mode == "form" ) {
-               $html = $v->validate_form () ;
-       } else */
-       if( $mode == "stat_page" ) {
-               $html = $v->getPageStatistics();
-       } else if( $mode == "list_page" ) {
-               $html = $v->getArticleList();
+/*
+       # Can do?
+       if ( ! $wgUser->isAllowed('change_validation') ) {
+               $wgOut->sysopRequired();
+               return;
        }
+*/     
+
+       $mode = $wgRequest->getVal ( "mode" ) ;
+       $skin = $wgUser->getSkin() ;
+
        
+       if ( $mode == "manage" ) {
+               $v = new Validation ;
+               $html = $v->manageTopics () ;
+#      } else if ( $mode == "list" ) {
+#              $v = new Validation ;
+#              $html = $v->showList ( $wgRequest->getVal ( "id" ) ) ;
+       } else {
+               $html = "$mode" ;
+               $html .= "<ul>\n" ;
+
+               $t = Title::newFromText ( "Special:Validate" ) ;
+               $url = $t->getLocalURL ( "mode=manage" ) ;
+               $html .= "<li><a href=\"" . $url . "\">Manage</a></li>\n" ;
+
+               $html .= "</ul>\n" ;
+       }
+
        $wgOut->addHTML( $html );
 }