validation improvements
authorMagnus Manske <magnusmanske@users.mediawiki.org>
Fri, 18 Mar 2005 21:59:13 +0000 (21:59 +0000)
committerMagnus Manske <magnusmanske@users.mediawiki.org>
Fri, 18 Mar 2005 21:59:13 +0000 (21:59 +0000)
includes/SpecialPage.php
includes/SpecialValidate.php
languages/Language.php

index 9b4e2da..a77fe96 100644 (file)
@@ -51,6 +51,10 @@ $wgSpecialPages = array(
        'Unusedimages'      => new SpecialPage( 'Unusedimages' )
 );
 
+global $wgUseValidation ;
+if ( $wgUseValidation )
+       $wgSpecialPages['Validate'] = new SpecialPage( 'Validate' );
+
 global $wgDisableCounters;
 if( !$wgDisableCounters ) {
        $wgSpecialPages['Popularpages'] = new SpecialPage( 'Popularpages' );
index 3441c30..d0a2101 100644 (file)
@@ -711,7 +711,7 @@ class Validation {
                $ret = "" ;
                $title = $article->getTitle();
                $title = $title->getPrefixedText() ;
-               $wgOut->setPageTitle ( "Revisions for " . $title ) ;
+               $wgOut->setPageTitle ( wfMsg ( 'val_rev_for' ) . $title ) ;
                foreach ( $this->voteCache AS $x => $y )
                        {
                        $ret .= $this->getRevisionForm ( $article , $x , $y , $x == $revision ) ;
@@ -719,6 +719,74 @@ class Validation {
                        }
                return $ret ;   
        }
+       
+       # 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 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 ;
+       }
 
 }
 
@@ -726,22 +794,31 @@ class Validation {
  * constructor
  */
 function wfSpecialValidate( $page = '' ) {
-       global $wgOut, $wgRequest, $wgUseValidation;
+       global $wgOut, $wgRequest, $wgUseValidation, $wgUser, $wgContLang;
        
        if( !$wgUseValidation ) {
                $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
                return;
        }
+
+       $mode = $wgRequest->getVal ( "mode" ) ;
+       $skin = $wgUser->getSkin() ;
+
        
-       $mode = $wgRequest->getVal( 'mode', 'form' );
-       $v = new Validation;
-       $html = "" ;
-       if( $mode == "stat_page" ) {
-               $html = $v->getPageStatistics();
-       } else if( $mode == "list_page" ) {
-               $html = $v->getArticleList();
+       if ( $mode == "manage" ) {
+               $v = new Validation ;
+               $html = $v->manageTopics () ;
+       } else {
+               $t = Title::newFromText ( "Special:Validate" ) ;
+               $url = $t->getLocalURL ( "mode=manage" ) ;
+               $html = "$mode" ;
+               $html .= "<ul>\n" ;
+               $html .= "<li><a href=\"" . $url . "\">Manage</a></li>\n" ;
+               $html .= "<li></li>\n" ;
+               $html .= "<li></li>\n" ;
+               $html .= "</ul>\n" ;
        }
-       
+
        $wgOut->addHTML( $html );
 }
 
index 06ab035..56650ec 100644 (file)
@@ -1460,6 +1460,12 @@ Type the name of the user in the box and press the button to make the user an ad
 # Validation
 'val_yes' => 'Yes',
 'val_no' => 'No',
+'val_list_header' => '<th>#</th><th>Topic</th><th>Range</th><th>Action</th>',
+'val_add' => 'Add',
+'val_del' => 'Delete',
+'val_warning' => '<b>Never, <i>ever</i>, change something here without <i>explicit</i> community consensus!</b>',
+'val_ref_for' => 'Revisions for ',
+'val_iamsure' => 'Check this box if you really mean it!',
 'val_clear_old' => 'Clear my older validation data',
 'val_merge_old' => 'Use my previous assessment where selected \'No opinion\'',
 'val_form_note' => '<b>Hint:</b> Merging your data means that for the article