New global config setting $wgMaxTocLevel: Maximum indent level of toc.
[lhc/web/wiklou.git] / includes / SpecialValidate.php
1 <?php
2 # Copyright (C) 2004 Magnus Manske <magnus.manske@web.de>
3 # http://www.mediawiki.org/
4 #
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.
9 #
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.
14 #
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
19
20 function find_this_version ( $article_title , &$article_time , &$id , &$tab )
21 {
22 $id = "" ;
23 $sql = "SELECT cur_id,cur_timestamp FROM cur WHERE cur_namespace=0 AND cur_title='{$article_title}'" ;
24 $res = wfQuery( $sql, DB_READ );
25 if( $s = wfFetchObject( $res ) )
26 {
27 if ( $article_time == "" ) $article_time = $s->cur_timestamp ; # No timestamp = current version
28 if ( $article_time == $s->cur_timestamp ) # Means current version
29 {
30 $tab = "cur" ;
31 $id = $s->cur_id ;
32 }
33 }
34
35 if ( $id == "" )
36 {
37 $sql = "SELECT old_id FROM old WHERE old_namespace=0 AND old_title='{$article_title}' AND old_timestamp='{$article_time}'" ;
38 $res = wfQuery( $sql, DB_READ );
39 if( $s = wfFetchObject( $res ) )
40 {
41 $tab = "old" ;
42 $id = $s->old_id ;
43 }
44 }
45 }
46
47 function get_prev_data ( $user_id , $article_title , $article_timestamp = "" )
48 {
49 $ret = array () ;
50 $sql = "SELECT * FROM validate WHERE val_user={$user_id} AND val_title='{$article_title}'" ;
51 if ( $article_timestamp != "" ) $sql .= " AND val_timestamp='{$article_timestamp}'" ;
52 $res = wfQuery( $sql, DB_READ );
53 while( $s = wfFetchObject( $res ) ) $ret[$s->val_timestamp][$s->val_type] = $s ;
54 return $ret ;
55 }
56
57 function wfSpecialValidate( $page = "" ) {
58 global $wgOut, $wgLang, $wgUser;
59 if ( $wgUser->getID() == 0 ) return ; # Anon
60 $article_title = $_GET['article'] ;
61 $article_time = "" ;
62 if ( isset ( $_GET['timestamp'] ) ) $article_time = $_GET['timestamp'] ;
63 find_this_version ( $article_title , $article_time , $id , $tab ) ;
64 $article = Title::newFromText ( $article_title ) ;
65
66 # $tab now contains "cur" or "old"
67 # $id contains the id in that table
68
69 # Things that should be in the language files
70 $clear_old = "Clear my other validation data for <a href=\"$1\">this article</a>" ;
71 $noop = "No opinion" ;
72 $types = array (
73 "0" => "Style|Awful|Awesome|5",
74 "1" => "Legal|Illegal|Legal|5",
75 "2" => "Completeness|Stub|Extensive|5",
76 "3" => "Facts|Wild guesses|Concrete|5"
77 ) ;
78
79 # Now we get all the "votes" for the different versions of this article for this user
80 $val = get_prev_data ( $wgUser->getID() , $article_title ) ;
81 if ( !isset ( $val[$article_time] ) ) $val["{$article_time}"] = array () ;
82
83 # User has clicked "Doit" before, so evaluating form
84 if ( isset ( $_POST['doit'] ) )
85 {
86 $oldtime = $_POST['oldtime'] ;
87 if ( !isset ( $val["{$oldtime}"] ) ) $val["{$oldtime}"] = array () ;
88 if ( isset ( $_POST['clear_other'] ) && $_POST['clear_other'] == 1 ) # Clear all others
89 {
90 $sql = "DELETE FROM validate WHERE val_title='{$article_title}' AND val_timestamp<>'{$oldtime}' AND val_user='" ;
91 $sql .= $wgUser->getID() . "'" ;
92 wfQuery( $sql, DB_WRITE );
93 $val2 = $val["{$oldtime}"] ; # Only version left
94 $val = array () ; # So clear others
95 $val["{$oldtime}"] = $val2 ;
96 }
97
98 # Delete old "votes" for this version
99 $sql = "DELETE FROM validate WHERE val_title='{$article_title}' AND val_timestamp='{$oldtime}' AND val_user='" ;
100 $sql .= $wgUser->getID() . "'" ;
101 wfQuery( $sql, DB_WRITE );
102
103 for ( $idx = 0 ; $idx < count ( $types) ; $idx++ ) # Changes
104 {
105 $rad = $_POST["rad{$idx}"] ;
106 if ( !isset ( $val["{$oldtime}"][$idx] ) ) $val["{$oldtime}"][$idx] = "" ;
107 $val["{$oldtime}"][$idx]->value = $rad ;
108 if ( $rad != -1 )
109 {
110 # Store it in the database
111 $sql = "INSERT INTO validate VALUES ( '" . $wgUser->getID() . "','{$article_title}','{$oldtime}','{$idx}','{$rad}')" ;
112 if ( $rad != -1 ) wfQuery( $sql, DB_WRITE );
113 }
114 }
115 }
116
117 # Generating HTML
118 $html = "<h1>" . $article->getPrefixedText() . "</h1>\n" ;
119 foreach ( $val AS $time => $stuff )
120 {
121 if ( $time == $article_time ) $html .= "<h2>This version</h2>\n" ;
122 else $html .= "<h2>Version of {$time}</h2>\n" ;
123 $html .= "<form method=post>\n" ;
124 $html .= "<input type=hidden name=oldtime value='{$time}'>" ;
125 $html .= "<table>\n" ;
126 for ( $idx = 0 ; $idx < count ( $types) ; $idx++ )
127 {
128 $x = explode ( "|" , $types[$idx] , 4 ) ;
129 if ( isset ( $stuff[$idx] ) ) $choice = $stuff[$idx]->value ;
130 else $choice = -1 ;
131 $html .= "<tr><th align=left>{$x[0]}</th><td align=right>{$x[1]}</td><td>" ;
132 for ( $cnt = 0 ; $cnt < $x[3] ; $cnt++)
133 {
134 $html .= "<input type=radio name='rad{$idx}' value='{$cnt}'" ;
135 if ( $choice == $cnt ) $html .= " checked" ;
136 $html .= "> " ;
137 }
138 $html .= "</td><td>{$x[2]}</td>" ;
139 $html .= "<td><input type=radio name='rad{$idx}' value='-1'" ;
140 if ( $choice == -1 ) $html .= " checked" ;
141 $html .= "> {$noop}</td></tr>\n" ;
142 }
143 $html .= "<tr><td></td><td colspan=3><input type=checkbox name=clear_other value=1 checked>" ;
144 $html .= str_replace ( "$1" , $article->getFullURL() , $clear_old ) ;
145 $html .= "</td><td align=right><input type=submit name=doit value='Do it'></td>" ;
146 $html .= "</tr></table></form>\n" ;
147 }
148
149 $wgOut->addHTML( $html ) ;
150 }
151
152 ?>