From 1a788d69db2b2804c71d1d911669d31347e3a747 Mon Sep 17 00:00:00 2001 From: Magnus Manske Date: Sun, 18 Jul 2004 20:45:28 +0000 Subject: [PATCH] Article validation code (a start) --- includes/SpecialGeo.php | 2 +- includes/SpecialPage.php | 3 +- includes/SpecialValidate.php | 152 +++++++++++++++++++++++++++++++++++ languages/Language.php | 1 + maintenance/tables.sql | 11 +++ 5 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 includes/SpecialValidate.php diff --git a/includes/SpecialGeo.php b/includes/SpecialGeo.php index c20c40fd66..1eac8dbebc 100644 --- a/includes/SpecialGeo.php +++ b/includes/SpecialGeo.php @@ -1,5 +1,5 @@ +# Copyright (C) 2004 Magnus Manske # http://www.mediawiki.org/ # # This program is free software; you can redistribute it and/or modify diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 4dcb7e9b17..dd4d4c2137 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -37,7 +37,8 @@ $wgSpecialPages = array_merge($wgSpecialPages, array ( "Recentchangeslinked" => new UnlistedSpecialPage( "Recentchangeslinked" ), "Movepage" => new UnlistedSpecialPage( "Movepage" ), "Blockme" => new UnlistedSpecialPage( "Blockme" ), - "Geo" => new SpecialPage( "Geo" ), + "Geo" => new SpecialPage( "Geo" ), + "Validate" => new SpecialPage( "Validate" ), "Booksources" => new SpecialPage( "Booksources" ), "Categories" => new SpecialPage( "Categories" ), "Export" => new SpecialPage( "Export" ), diff --git a/includes/SpecialValidate.php b/includes/SpecialValidate.php new file mode 100644 index 0000000000..975902ab06 --- /dev/null +++ b/includes/SpecialValidate.php @@ -0,0 +1,152 @@ + +# http://www.mediawiki.org/ +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# http://www.gnu.org/copyleft/gpl.html + +function find_this_version ( $article_title , &$article_time , &$id , &$tab ) + { + $id = "" ; + $sql = "SELECT cur_id,cur_timestamp FROM cur WHERE cur_namespace=0 AND cur_title='{$article_title}'" ; + $res = wfQuery( $sql, DB_READ ); + if( $s = wfFetchObject( $res ) ) + { + if ( $article_time == "" ) $article_time = $s->cur_timestamp ; # No timestamp = current version + if ( $article_time == $s->cur_timestamp ) # Means current version + { + $tab = "cur" ; + $id = $s->cur_id ; + } + } + + if ( $id == "" ) + { + $sql = "SELECT old_id FROM old WHERE old_namespace=0 AND old_title='{$article_title}' AND old_timestamp='{$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={$user_id} AND val_title='{$article_title}'" ; + if ( $article_timestamp != "" ) $sql .= " AND val_timestamp='{$article_timestamp}'" ; + $res = wfQuery( $sql, DB_READ ); + while( $s = wfFetchObject( $res ) ) $ret[$s->val_timestamp][$s->val_type] = $s ; + return $ret ; + } + +function wfSpecialValidate( $page = "" ) { + global $wgOut, $wgLang, $wgUser; + if ( $wgUser->getID() == 0 ) return ; # Anon + $article_title = $_GET['article'] ; + $article_time = "" ; + if ( isset ( $_GET['timestamp'] ) ) $article_time = $_GET['timestamp'] ; + find_this_version ( $article_title , $article_time , $id , $tab ) ; + $article = Title::newFromText ( $article_title ) ; + + # $tab now contains "cur" or "old" + # $id contains the id in that table + + # Things that should be in the language files + $clear_old = "Clear my other validation data for this article" ; + $noop = "No opinion" ; + $types = array ( + "0" => "Style|Awful|Awesome|5", + "1" => "Legal|Illegal|Legal|5", + "2" => "Completeness|Stub|Extensive|5", + "3" => "Facts|Wild guesses|Concrete|5" + ) ; + + # Now we get all the "votes" for the different versions of this article for this user + $val = get_prev_data ( $wgUser->getID() , $article_title ) ; + if ( !isset ( $val[$article_time] ) ) $val["{$article_time}"] = array () ; + + # User has clicked "Doit" before, so evaluating form + if ( isset ( $_POST['doit'] ) ) + { + $oldtime = $_POST['oldtime'] ; + if ( !isset ( $val["{$oldtime}"] ) ) $val["{$oldtime}"] = array () ; + if ( isset ( $_POST['clear_other'] ) && $_POST['clear_other'] == 1 ) # Clear all others + { + $sql = "DELETE FROM validate WHERE val_title='{$article_title}' AND val_timestamp<>'{$oldtime}' AND val_user='" ; + $sql .= $wgUser->getID() . "'" ; + wfQuery( $sql, DB_WRITE ); + $val2 = $val["{$oldtime}"] ; # Only version left + $val = array () ; # So clear others + $val["{$oldtime}"] = $val2 ; + } + + # Delete old "votes" for this version + $sql = "DELETE FROM validate WHERE val_title='{$article_title}' AND val_timestamp='{$oldtime}' AND val_user='" ; + $sql .= $wgUser->getID() . "'" ; + wfQuery( $sql, DB_WRITE ); + + for ( $idx = 0 ; $idx < count ( $types) ; $idx++ ) # Changes + { + $rad = $_POST["rad{$idx}"] ; + if ( !isset ( $val["{$oldtime}"][$idx] ) ) $val["{$oldtime}"][$idx] = "" ; + $val["{$oldtime}"][$idx]->value = $rad ; + if ( $rad != -1 ) + { + # Store it in the database + $sql = "INSERT INTO validate VALUES ( '" . $wgUser->getID() . "','{$article_title}','{$oldtime}','{$idx}','{$rad}')" ; + if ( $rad != -1 ) wfQuery( $sql, DB_WRITE ); + } + } + } + + # Generating HTML + $html = "

" . $article->getPrefixedText() . "

\n" ; + foreach ( $val AS $time => $stuff ) + { + if ( $time == $article_time ) $html .= "

This version

\n" ; + else $html .= "

Version of {$time}

\n" ; + $html .= "
\n" ; + $html .= "" ; + $html .= "\n" ; + for ( $idx = 0 ; $idx < count ( $types) ; $idx++ ) + { + $x = explode ( "|" , $types[$idx] , 4 ) ; + if ( isset ( $stuff[$idx] ) ) $choice = $stuff[$idx]->value ; + else $choice = -1 ; + $html .= "" ; + $html .= "
{$x[0]}{$x[1]}" ; + for ( $cnt = 0 ; $cnt < $x[3] ; $cnt++) + { + $html .= "getFullURL() , $clear_old ) ; + $html .= "
\n" ; + } + + $wgOut->addHTML( $html ) ; +} + +?> diff --git a/languages/Language.php b/languages/Language.php index 0a61d6246d..e10a74a82b 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -924,6 +924,7 @@ That comes to '''$5''' average edits per page, and '''$6''' views per edit.", # 'orphans' => 'Orphaned pages', 'geo' => 'GEO coordinates', +'validate' => 'Validate page', 'lonelypages' => 'Orphaned pages', 'unusedimages' => 'Unused images', 'popularpages' => 'Popular pages', diff --git a/maintenance/tables.sql b/maintenance/tables.sql index 6d1e4d482e..161d4d7fd2 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -251,3 +251,14 @@ CREATE TABLE blobs ( blob_data longblob NOT NULL default '', UNIQUE key blob_index (blob_index) ); + +-- For article validation + +CREATE TABLE `validate` ( + `val_user` int(11) NOT NULL default '0', + `val_title` varchar(255) binary NOT NULL default '', + `val_timestamp` varchar(14) binary NOT NULL default '', + `val_type` int(10) unsigned NOT NULL default '0', + `val_value` int(11) default '0', + KEY `val_user` (`val_user`,`val_title`,`val_timestamp`) +) TYPE=MyISAM; -- 2.20.1