r7788 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r7787‎ | r7788 | r7789 >
Date:19:08, 20 March 2005
Author:magnus_manske
Status:old
Tags:
Comment:
Removed old code
Modified paths:
  • /trunk/phase3/includes/SpecialValidate.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialValidate.php
@@ -29,478 +29,7 @@
3030 * @subpackage SpecialPage
3131 */
3232 class Validation {
33 -
34 - function find_this_version( $article_title , &$article_time , &$id , &$tab ) {
35 -/* $id = "";
36 - $tab = "";
37 - $sql = "SELECT cur_id,cur_timestamp FROM cur WHERE cur_namespace=".NS_MAIN." AND cur_title='" . wfStrencode( $article_title ) . "'";
38 - $res = wfQuery( $sql, DB_READ );
39 - if( $s = wfFetchObject( $res ) ) {
40 - if ( $article_time == "" ) {
41 - # No timestamp = current version
42 - $article_time = $s->cur_timestamp;
43 - } elseif ( $article_time == $s->cur_timestamp ) {
44 - # Means current version
45 - $tab = "cur";
46 - $id = $s->cur_id;
47 - }
48 - }
49 -
50 - if ( $id == "" ) {
51 - $sql = "SELECT old_id FROM old WHERE old_namespace=".NS_MAIN." AND old_title='" . wfStrencode( $article_title ) .
52 - "' AND old_timestamp='" . wfStrencode( $article_time ) . "'";
53 - $res = wfQuery( $sql, DB_READ );
54 - if( $s = wfFetchObject( $res ) ) {
55 - $tab = "old";
56 - $id = $s->old_id;
57 - }
58 - }*/
59 - }
6033
61 - function get_prev_data( $user_id , $article_title , $article_timestamp = "" ) {
62 - $ret = array ();
63 -/* $sql = "SELECT * FROM validate WHERE val_user='" . wfStrencode( $user_id ) .
64 - "' AND val_title='" . wfStrencode( $article_title ) . "'";
65 - if ( $article_timestamp != "" ) {
66 - $sql .= " AND val_timestamp='" . wfStrencode( $article_timestamp ) . "'";
67 - }
68 - $res = wfQuery( $sql, DB_READ );
69 - while( $s = wfFetchObject( $res ) ) {
70 - $ret[$s->val_timestamp][$s->val_type] = $s;
71 - }*/
72 - return $ret;
73 - }
74 -
75 - function validate_form( $article_title = "" ) {
76 -/* global $wgOut, $wgLang, $wgUser, $wgArticle, $wgRequest;
77 -
78 - if ( $wgUser->getID() == 0 ) {
79 - # Anon
80 - $wgOut->addHTML( htmlspecialchars( wfMsg( 'val_no_anon_validation' ) ) .
81 - $this->getPageStatistics ( $article_title ) ) ;
82 - return;
83 - }
84 -
85 - $validationtypes = $wgLang->getValidationTypes();
86 - if ( $article_title == "" ) {
87 - $article_title = $wgRequest->getVal( 'article_title' );
88 - $heading = "<h1>" . htmlspecialchars( $article_title ) . "</h1>\n";
89 - } else {
90 - $heading = "";
91 - }
92 - $article_time = "";
93 - $article_time = $wgRequest->getVal( 'timestamp' );
94 - $article = Title::newFromText( $article_title );
95 - if( is_null( $article ) ) {
96 - $wgOut->errorpage( "badtitle", "badtitletext" );
97 - return;
98 - }
99 -
100 - # Now we get all the "votes" for the different versions of this article for this user
101 - $val = $this->get_prev_data( $wgUser->getID() , $article_title );
102 -
103 - # No votes for this version, initial data
104 - if( !isset( $val[$article_time] ) ) {
105 - if( $article_time == "" ) {
106 - $res = wfQuery( "select cur_timestamp FROM cur WHERE cur_title='" .
107 - wfStrencode( $article_title ) . "' AND cur_namespace=".NS_MAIN, DB_READ );
108 - if( $s = wfFetchObject( $res ) ) {
109 - $article_time = $s->cur_timestamp;
110 - }
111 - }
112 - $val[$article_time] = array();
113 - }
114 -
115 - # Newest versions first
116 - krsort( $val );
117 -
118 - # User has clicked "Doit" before, so evaluate form
119 - if( $wgRequest->wasPosted() ) {
120 - $oldtime = StrVal( $wgRequest->getVal( 'oldtime' ) );
121 - if( !isset ( $val[$oldtime] ) ) {
122 - $val[$oldtime] = array();
123 - }
124 -
125 - # Reading postdata
126 - $postrad = array();
127 - $poscomment = array();
128 - for( $idx = 0 ; $idx < count( $validationtypes) ; $idx++ ) {
129 - $postrad[$idx] = $wgRequest->getVal( "rad{$idx}" );
130 - $postcomment[$idx] = $wgRequest->getText( "comment{$idx}" );
131 - }
132 -
133 - # Merge others into this one
134 - if( $wgRequest->getCheck( 'merge_other' ) ) {
135 - foreach( $val as $time => $stuff ) {
136 - if( $time != $article_time ) {
137 - for( $idx = 0; $idx < count( $validationtypes ); $idx++ ) {
138 - $rad = $postrad[$idx];
139 - if( isset ( $stuff[$idx] ) && $stuff[$idx]->val_value != -1 && $rad == -1 ) {
140 - $postrad[$idx] = $stuff[$idx]->val_value;
141 - $postcomment[$idx] = $stuff[$idx]->val_comment;
142 - }
143 - }
144 - }
145 - }
146 - }
147 -
148 - # Clear all others
149 - if( $wgRequest->getCheck( 'clear_other' ) ) {
150 - $sql = "DELETE FROM validate WHERE val_title='" . wfStrencode( $article_title ) .
151 - "' AND val_timestamp<>'" . wfStrencode( $oldtime ) . "' AND val_user='";
152 - $sql .= wfStrencode( $wgUser->getID() ) . "'";
153 - wfQuery( $sql, DB_WRITE );
154 - $val2 = $val[$oldtime]; # Only version left
155 - $val = array(); # So clear others
156 - $val[$oldtime] = $val2;
157 - }
158 -
159 - # Delete old "votes" for this version
160 - $sql = "DELETE FROM validate WHERE val_title='" . wfStrencode( $article_title ) .
161 - "' AND val_timestamp='" . wfStrencode( $oldtime ) . "' AND val_user='";
162 - $sql .= wfStrencode( $wgUser->getID() ) . "'";
163 - wfQuery( $sql, DB_WRITE );
164 -
165 - # Incorporate changes
166 - for( $idx = 0; $idx < count( $validationtypes ); $idx++ ) {
167 - $comment = $postcomment[$idx] ;
168 - $rad = $postrad[$idx] ;
169 - if ( !isset( $val[$oldtime][$idx] ) ) {
170 - $val[$oldtime][$idx] = "";
171 - }
172 - $val[$oldtime][$idx]->val_value = $rad;
173 - $val[$oldtime][$idx]->val_comment = $comment;
174 - if( $rad != -1 ) {
175 - # Store it in the database
176 - $sql = "INSERT INTO validate (val_user,val_title,val_timestamp,val_type,val_value,val_comment) " .
177 - "VALUES ( '" . wfStrencode( $wgUser->getID() ) . "','" .
178 - wfStrencode( $article_title ) . "','" .
179 - wfStrencode( $oldtime ) . "','" .
180 - wfStrencode( $idx ) . "','" .
181 - wfStrencode( $rad ) . "','" .
182 - wfStrencode( $comment ) . "')";
183 - wfQuery( $sql, DB_WRITE );
184 - }
185 - }
186 - $wgArticle->showArticle( "Juhuu", wfMsg( 'val_validated' ) );
187 - return; # Show article instead of validation page
188 - }
189 -
190 - # Generating HTML
191 - $html = "";
192 -
193 - $skin = $wgUser->getSkin();
194 - $staturl = $skin->makeSpecialURL( "validate" , "mode=stat_page&article_title=" . urlencode( $article_title ) );
195 - $listurl = $skin->makeSpecialURL( "validate" , "mode=list_page" );
196 - $html .= "<a href=\"" . htmlspecialchars( $staturl ) . "\">" . wfMsg('val_stat_link_text') . "</a> \n";
197 - $html .= "<a href=\"" . htmlspecialchars( $listurl ) . "\">" . wfMsg('val_article_lists') . "</a><br />\n";
198 - $html .= "<small>" . wfMsg('val_form_note') . "</small><br />\n";
199 -
200 - # Generating data tables
201 - $tabsep = "<td width='0' style='border-left:2px solid black;'></td>";
202 - $topstyle = "style='border-top:2px solid black'";
203 - foreach( $val as $time => $stuff ) {
204 - $tablestyle = "cellspacing='0' cellpadding='2'";
205 - if ( $article_time == $time ) {
206 - $tablestyle .=" style='border: 2px solid red'";
207 - }
208 - $html .= "<h2>" . wfMsg( 'val_version_of', gmdate( "F d, Y H:i:s", wfTimestamp( TW_UNIX, $time ) ) );
209 - $this->find_this_version ( $article_title , $time , $table_id , $table_name );
210 - if( $table_name == "cur" ) {
211 - $html .= " (" . wfMsg( 'val_this_is_current_version' ) . ")";
212 - }
213 - $html .= "</h2>\n" ;
214 - $html .= "<form method='post'>\n" ;
215 - $html .= "<input type='hidden' name='oldtime' value=\"" . htmlspecialchars( $time ) . "\" />" ;
216 - $html .= "<table {$tablestyle}>\n" ;
217 - $html .= wfMsg( 'val_table_header', $tabsep );
218 - for( $idx = 0; $idx < count( $validationtypes ); $idx++ ) {
219 - $x = explode( "|" , $validationtypes[$idx] , 4 );
220 - if( isset ( $stuff[$idx] ) ) {
221 - $choice = $stuff[$idx]->val_value;
222 - } else {
223 - $choice = -1;
224 - }
225 - if( isset( $stuff[$idx] ) ) {
226 - $comment = $stuff[$idx]->val_comment;
227 - } else {
228 - $comment = "";
229 - }
230 - $html .= "<tr><th align='left'>{$x[0]}</th>{$tabsep}<td align='right'>{$x[1]}</td>"
231 - . "<td align='center'><span style='white-space: nowrap;'>" ;
232 - for( $cnt = 0 ; $cnt < $x[3] ; $cnt++) {
233 - $html .= "<input type='radio' name='rad{$idx}' value='{$cnt}'";
234 - if ( $choice == $cnt ) $html .= " checked='checked'";
235 - $html .= " /> ";
236 - }
237 - $html .= "</span></td><td>{$x[2]}</td>";
238 - $html .= "<td><input type='radio' name='rad{$idx}' value='-1'";
239 - if( $choice == -1 ) {
240 - $html .= " checked='checked'";
241 - }
242 - $html .= " /> " . wfMsg ( "val_noop" ) . "</td>{$tabsep}";
243 - $html .= "<td><input type='text' name='comment{$idx}' value=\"" . htmlspecialchars( $comment ) . "\" /></td>";
244 - $html .= "</tr>\n";
245 - }
246 - $html .= "<tr><td {$topstyle} colspan='2'>";
247 -
248 - # link to version
249 - $title = Title::newFromDBkey( $article_title );
250 - if ( $table_name == "cur" ) {
251 - $link_version = $title->getLocalURL( "" );
252 - } else {
253 - $link_version = $title->getLocalURL( "oldid={$table_id}" );
254 - }
255 - $link_version = "<a href=\"" . htmlspecialchars( $link_version ) . "\">" . wfMsg ( 'val_view_version' ) . "</a>";
256 - $html .= $link_version;
257 - $html .= "</td><td {$topstyle} colspan='5'>";
258 - $html .= "<input type='checkbox' name='merge_other' value='1' checked='checked' />";
259 - $html .= wfMsg( 'val_merge_old' );
260 - $html .= "<br /><input type='checkbox' name='clear_other' value='1' checked='checked' />";
261 - $html .= wfMsg( 'val_clear_old', $skin->makeKnownLinkObj( $article ) );
262 - $html .= "</td><td {$topstyle} align='right' valign='center'><input type='submit' name='doit' value=\"" . htmlspecialchars( wfMsg("ok") ) . "\" /></td>";
263 - $html .= "</tr></table></form>\n";
264 - }
265 -
266 - $html .= "<h2>" . wfMsg( 'preview' ) . "</h2>";
267 - $wgOut->addHTML( $html );
268 - $wgOut->addWikiText( $wgArticle->getContent( true ) );*/
269 - }
270 -
271 - function getData( $user = -1 , $title = "" , $type = -1 ) {
272 -/* $ret = array();
273 - $sql = array();
274 - if( $user != -1 ) {
275 - $sql[] = "val_user='" . wfStrencode( $user ) . "'";
276 - }
277 - if( $type != -1 ) {
278 - $sql[] = "val_type='" . wfStrencode( $type ) . "'";
279 - }
280 - if( $title != "" ) {
281 - $sql[] = "val_title='" . wfStrencode( $title ) . "'";
282 - }
283 - $sql = implode( " AND " , $sql );
284 - if( $sql != "" ) {
285 - $sql = " WHERE " . $sql;
286 - }
287 - $sql = "SELECT * FROM validate" . $sql;
288 - $res = wfQuery( $sql, DB_READ );
289 - while( $s = wfFetchObject( $res ) ) {
290 - $ret["{$s->val_title}"]["{$s->val_timestamp}"]["{$s->val_type}"][] = $s;
291 - }
292 - return $ret;*/
293 - }
294 -
295 - # Show statistics for the different versions of a single article
296 - function getPageStatistics( $article_title = "" ) {
297 -/* global $wgLang, $wgUser, $wgOut, $wgRequest;
298 - $validationtypes = $wgLang->getValidationTypes();
299 - if( $article_title == "" ) {
300 - $article_title = $wgRequest->getVal( 'article_title' );
301 - }
302 - $d = $this->getData( -1 , $article_title , -1 );
303 - if( count ( $d ) ) {
304 - $d = array_shift ( $d ) ;
305 - } else {
306 - $d = array();
307 - }
308 - krsort( $d );
309 -
310 - # Getting table data (cur_id, old_id etc.) for each version
311 - $table_id = array();
312 - $table_name = array();
313 - foreach( $d as $version => $data ) {
314 - $this->find_this_version( $article_title, $version, $table_id[$version], $table_name[$version] );
315 - }
316 -
317 - # Generating HTML
318 - $title = Title::newFromDBkey( $article_title );
319 - $wgOut->setPageTitle( wfMsg( 'val_page_validation_statistics' , $title->getPrefixedText() ) );
320 - $html = "";
321 - $skin = $wgUser->getSkin();
322 - $listurl = $skin->makeSpecialURL( "validate" , "mode=list_page" );
323 - $html .= "<a href=\"" . htmlspecialchars( $listurl ) . "\">" . wfMsg( 'val_article_lists' ) . "</a><br /><br />\n";
324 -
325 - $html .= "<table border='1' cellpadding='2' style='font-size:8pt;'>\n";
326 - $html .= "<tr><th>" . wfMsg('val_version') . "</th>";
327 - foreach( $validationtypes as $idx => $title ) {
328 - $title = explode ( "|" , $title );
329 - $html .= "<th>{$title[0]}</th>";
330 - }
331 - $html .= "<th>" . wfMsg('val_total') . "</th>";
332 - $html .= "</tr>\n";
333 - foreach( $d as $version => $data ) {
334 - # Preamble for this version
335 - $title = Title::newFromDBkey( $article_title );
336 - $version_date = $wgLang->timeanddate( $version );
337 - $version_validate_link = $title->escapeLocalURL( "action=validate&timestamp={$version}" );
338 - $version_validate_link = "<a href=\"{$version_validate_link}\">" . wfMsg('val_validate_version') . "</a>";
339 - if( $table_name[$version] == 'cur' ) {
340 - $version_view_link = $title->escapeLocalURL( "" );
341 - } else {
342 - $version_view_link = $title->escapeLocalURL( "oldid={$table_id[$version]}" );
343 - }
344 - $version_view_link = "<a href=\"{$version_view_link}\">" . wfMsg('val_view_version') . "</a>";
345 - $html .= "<tr>";
346 - $html .= "<td align='center' valign='top' nowrap='nowrap'><b>{$version_date}</b><br />{$version_view_link}<br />{$version_validate_link}</td>";
347 -
348 - # Individual data
349 - $vmax = array();
350 - $vcur = array();
351 - $users = array();
352 - foreach( $data as $type => $x2 ) {
353 - if ( !isset ( $vcur[$type] ) ) $vcur[$type] = 0 ;
354 - if ( !isset ( $vmax[$type] ) ) $vmax[$type] = 0 ;
355 - if ( !isset ( $users[$type] ) ) $users[$type] = 0 ;
356 - foreach( $x2 as $user => $x ) {
357 - $vcur[$type] += $x->val_value;
358 - $temp = explode( "|" , $validationtypes[$type] );
359 - $vmax[$type] += $temp[3] - 1;
360 - $users[$type] += 1;
361 - }
362 - }
363 -
364 - $total_count = 0;
365 - $total_percent = 0;
366 - foreach( $validationtypes as $idx => $title ) {
367 - if( isset ( $vcur[$idx] ) ) {
368 - $average = 100 * $vcur[$idx] / $vmax[$idx] ;
369 - $total_count += 1;
370 - $total_percent += $average;
371 - if( $users[$idx] > 1 ) {
372 - $msgid = "val_percent";
373 - } else {
374 - $msgid = "val_percent_single";
375 - }
376 - $html .= "<td align='center' valign='top'>" .
377 - wfMsg( $msgid, number_format( $average, 2 ) ,
378 - $vcur[$idx] , $vmax[$idx] , $users[$idx] );
379 - } else {
380 - $html .= "<td align='center' valign='center'>";
381 - $html .= "(" . wfMsg ( "val_noop" ) . ")";
382 - }
383 - $html .= "</td>";
384 - }
385 -
386 - if( $total_count > 0 ) {
387 - $total = $total_percent / $total_count;
388 - $total = number_format( $total , 2 ) . " %";
389 - } else {
390 - $total = "";
391 - }
392 - $html .= "<td align='center' valign='top' nowrap='nowrap'><b>{$total}</b></td>";
393 -
394 - $html .= "</tr>";
395 - }
396 - $html .= "</table>\n";
397 - return $html ;*/
398 - }
399 -
400 - function countUserValidations( $userid ) {
401 -/* $sql = "SELECT count(DISTINCT val_title) AS num FROM validate WHERE val_user=" . IntVal( $userid );
402 - $res = wfQuery( $sql, DB_READ );
403 - if ( $s = wfFetchObject( $res ) ) {
404 - $num = $s->num;
405 - } else {
406 - $num = 0;
407 - }
408 - return $num;*/
409 - }
410 -
411 - function getArticleList() {
412 -/* global $wgLang, $wgOut;
413 - $validationtypes = $wgLang->getValidationTypes();
414 - $wgOut->setPageTitle( wfMsg( 'val_article_lists' ) );
415 - $html = "";
416 -
417 - # Choices
418 - $choice = array ();
419 - $maxw = 0;
420 - foreach( $validationtypes as $idx => $data ) {
421 - $x = explode( "|" , $data , 4 );
422 - if( $x[3] > $maxw ) {
423 - $maxw = $x[3];
424 - }
425 - }
426 - foreach( $validationtypes as $idx => $data ) {
427 - $choice[$idx] = array();
428 - for( $a = 0 ; $a < $maxw ; $a++ ) {
429 - $var = "cb_{$idx}_{$a}";
430 - if( isset ( $_POST[$var] ) ) $choice[$idx][$a] = $_POST[$var] ; # Selected
431 - else if ( !isset ( $_POST["doit"] ) ) $choice[$idx][$a] = 1 ; # First time
432 - else $choice[$idx][$a] = 0 ; # De-selected
433 - }
434 - }
435 -
436 - # The form
437 - $html .= "<form method='post'>\n";
438 - $html .= "<table border='1' cellspacing='0' cellpadding='2'>" ;
439 - foreach( $validationtypes as $idx => $data ) {
440 - $x = explode ( "|" , $data , 4 );
441 -
442 - $html .= "<tr>";
443 - $html .= "<th nowrap='nowrap'>{$x[0]}</th>";
444 - $html .= "<td align='right' nowrap='nowrap'>{$x[1]}</td>";
445 -
446 - for( $a = 0; $a < $maxw; $a++ ) {
447 - if( $a < $x[3] ) {
448 - $td = "<input type='checkbox' name='cb_{$idx}_{$a}' value='1'";
449 - if( $choice[$idx][$a] == 1 ) {
450 - $td .= " checked='checked'" ;
451 - }
452 - $td .= " />";
453 - } else {
454 - $td = '';
455 - }
456 - $html .= "<td>{$td}</td>";
457 - }
458 -
459 - $html .= "<td nowrap='nowrap'>{$x[2]}</td>";
460 - $html .= "</tr>\n";
461 - }
462 - $html .= "<tr><td colspan='" . ( $maxw + 2 ) . "'></td>\n";
463 - $html .= "<td align='right' valign='center'><input type='submit' name='doit' value=\"" . htmlspecialchars( wfMsg ( 'ok' ) ) . "\" /></td></tr>";
464 - $html .= "</table>\n";
465 - $html .= "</form>\n";
466 -
467 - # The query
468 - $articles = array();
469 - $sql = "SELECT DISTINCT val_title,val_timestamp,val_type,avg(val_value) AS avg FROM validate GROUP BY val_title,val_timestamp,val_type";
470 - $res = wfQuery( $sql, DB_READ );
471 - while( $s = wfFetchObject( $res ) ) {
472 - $articles[$s->val_title][$s->val_timestamp][$s->val_type] = $s;
473 - }
474 -
475 - # The list
476 - $html .= "<ul>\n";
477 - foreach( $articles as $dbkey => $timedata ) {
478 - $title = Title::newFromDBkey( $dbkey );
479 - $out = array();
480 - krsort( $timedata );
481 -
482 - foreach( $timedata as $timestamp => $typedata ) {
483 - $showit = true;
484 - foreach( $typedata as $type => $data ) {
485 - $avg = intval ( $data->avg + 0.5 );
486 - if ( $choice[$type][$avg] == 0 ) $showit = false;
487 - }
488 - if( $showit ) {
489 - $out[] = "<li>" . $this->getVersionLink ( $title , $timestamp ) . "</li>\n";
490 - }
491 - }
492 -
493 - if( count( $out ) > 0 ) {
494 - $html .= "<li>\n";
495 - $html .= htmlspecialchars( $title->getText() ) . "\n";
496 - $html .= "<ul>\n";
497 - $html .= implode( "\n" , $out );
498 - $html .= "</ul>\n</li>\n";
499 - }
500 - }
501 - $html .= "</ul>\n";
502 - return $html;*/
503 - }
504 -
50534 # Returns a HTML link to the specified article revision
50635 function getVersionLink( &$article , $revision , $text = "" ) {
50736 $t = $article->getTitle() ;

Status & tagging log