Squid branch merge. Calls to purge functions in Article.php and special pages.
[lhc/web/wiklou.git] / includes / SpecialUndelete.php
index 116ec67..83003b8 100644 (file)
@@ -19,7 +19,7 @@ function wfSpecialUndelete( $par )
     }
     
     # List undeletable articles    
-    $sql = "SELECT ar_namespace,ar_title, COUNT(*) AS count FROM archive GROUP BY ar_namespace,ar_title ORDER BY ar_title";
+    $sql = "SELECT ar_namespace,ar_title, COUNT(*) AS count FROM archive GROUP BY ar_namespace,ar_title ORDER BY ar_namespace,ar_title";
     $res = wfQuery( $sql, DB_READ );
     
        $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
@@ -36,7 +36,7 @@ function wfSpecialUndelete( $par )
        $wgOut->addHTML( "<li>" .
          $sk->makeKnownLink( $wgLang->specialPage( "Undelete" ),
           $n, "target=" . urlencode($n) ) . " " .
-         str_replace( '$1', $row->count, wfMsg( "undeleterevisions" )) );
+                 wfMsg( "undeleterevisions", $row->count ) );
     }
     $wgOut->addHTML( "</ul>\n" );
     
@@ -48,15 +48,14 @@ function wfSpecialUndelete( $par )
     
     if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
     
-    $sql = "SELECT ar_text FROM archive WHERE ar_namespace={$namespace} AND ar_title=\"{$title}\" AND ar_timestamp={$timestamp}";
+    $sql = "SELECT ar_text,ar_flags FROM archive WHERE ar_namespace={$namespace} AND ar_title=\"{$title}\" AND ar_timestamp={$timestamp}";
     $ret = wfQuery( $sql, DB_READ );
     $row = wfFetchObject( $ret );
     
     $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
-    $wgOut->addWikiText( "(" . str_replace("$1",
-      $wgLang->date($timestamp, true), wfMsg( "undeleterevision" ))
-      . ")\n<hr>\n" . $row->ar_text );
-    
+    $wgOut->addWikiText( "(" . wfMsg( "undeleterevision", $wgLang->date($timestamp, true) )
+      . ")\n<hr>\n" . Article::getRevisionText( $row, "ar_" ) );
+
        return 0;
 }
 
@@ -65,6 +64,17 @@ function wfSpecialUndelete( $par )
     
     $sk = $wgUser->getSkin();
     $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
+
+    $sql = "SELECT ar_minor_edit,ar_timestamp,ar_user,ar_user_text,ar_comment
+      FROM archive WHERE ar_namespace={$namespace} AND ar_title=\"{$title}\"
+      ORDER BY ar_timestamp DESC";
+    $ret = wfQuery( $sql, DB_READ );
+
+       if( wfNumRows( $ret ) == 0 ) {
+               $wgOut->addWikiText( wfMsg( "nohistory" ) );
+               return 0;
+       }
+       
     $wgOut->addWikiText( wfMsg( "undeletehistory" ) . "\n<hr>\n" . $row->ar_text );
 
        $action = wfLocalUrlE( $wgLang->specialPage( "Undelete" ), "action=submit" );
@@ -81,11 +91,6 @@ function wfSpecialUndelete( $par )
        $wgOut->addWikiText( $m[1] );
     }
     
-    $sql = "SELECT ar_minor_edit,ar_timestamp,ar_user,ar_user_text,ar_comment
-      FROM archive WHERE ar_namespace={$namespace} AND ar_title=\"{$title}\"
-      ORDER BY ar_timestamp DESC";
-    $ret = wfQuery( $sql, DB_READ );
-    
     $special = $wgLang->getNsText( Namespace::getSpecial() );
     $wgOut->addHTML("<ul>");
     while( $row = wfFetchObject( $ret ) ) {
@@ -105,6 +110,7 @@ function wfSpecialUndelete( $par )
 /* private */ function doUndeleteArticle( $namespace, $title )
        {
                global $wgUser, $wgOut, $wgLang, $target, $wgDeferredUpdateList;
+               global  $wgUseSquid, $wgInternalServer;
 
                $fname = "doUndeleteArticle";
 
@@ -118,14 +124,21 @@ function wfSpecialUndelete( $par )
                $sql = "SELECT COUNT(*) AS count FROM cur WHERE cur_namespace={$namespace} AND cur_title='{$t}'";
                $res = wfQuery( $sql, DB_READ );
                $row = wfFetchObject( $res );
+               $now = wfTimestampNow();
+
                if( $row->count == 0) {
                        # Have to create new article...
-                       $now = wfTimestampNow();
-                       $max = wfGetSQL( "archive", "MAX(ar_timestamp)", "ar_namespace={$namespace} AND ar_title='{$t}'" );
-               $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
-                         "cur_comment,cur_user,cur_user_text,cur_timestamp,inverse_timestamp,cur_minor_edit,cur_random,cur_touched)" .
+                       $sql = "SELECT ar_text,ar_timestamp,ar_flags FROM archive WHERE ar_namespace={$namespace} AND ar_title='{$t}' ORDER BY ar_timestamp DESC LIMIT 1";
+                       $res = wfQuery( $sql, DB_READ, $fname );
+                       $s = wfFetchObject( $res );
+                       $max = $s->ar_timestamp;
+                       $redirect = MagicWord::get( MAG_REDIRECT );
+                       $redir = $redirect->matchStart( $s->ar_text ) ? 1 : 0;
+                       
+                       $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
+                         "cur_comment,cur_user,cur_user_text,cur_timestamp,inverse_timestamp,cur_minor_edit,cur_is_redirect,cur_random,cur_touched)" .
                          "SELECT ar_namespace,ar_title,ar_text,ar_comment," .
-                         "ar_user,ar_user_text,ar_timestamp,99999999999999-ar_timestamp,ar_minor_edit,RAND(),'{$now}' FROM archive " .
+                         "ar_user,ar_user_text,ar_timestamp,99999999999999-ar_timestamp,ar_minor_edit,{$redir},RAND(),'{$now}' FROM archive " .
                          "WHERE ar_namespace={$namespace} AND ar_title='{$t}' AND ar_timestamp={$max}";
                        wfQuery( $sql, DB_WRITE, $fname );
                $newid = wfInsertId();
@@ -134,6 +147,13 @@ function wfSpecialUndelete( $par )
                        # If already exists, put history entirely into old table
                        $oldones = "";
                        $newid = 0;
+                       
+                       # But to make the history list show up right, we need to touch it.
+                       $sql = "UPDATE cur SET cur_touched='{$now}' WHERE cur_namespace={$namespace} AND cur_title='{$t}'";
+                       wfQuery( $sql, DB_WRITE, $fname );
+                       
+                       # FIXME: Sometimes restored entries will be _newer_ than the current version.
+                       # We should merge.
                }
                
                $sql = "INSERT INTO old (old_namespace,old_title,old_text," .
@@ -159,6 +179,15 @@ function wfSpecialUndelete( $par )
 
                        $u = new LinksUpdate( $newid, $to->getPrefixedDBkey() );
                        array_push( $wgDeferredUpdateList, $u );
+                               
+                       Article::onArticleCreate( $to );
+
+                       # Squid purging
+                       if ( $wgUseSquid ) {
+                               /* this needs to be done after LinksUpdate */
+                               $u = new SquidUpdate($to);
+                               array_push( $wgDeferredUpdateList, $u );
+                       }
 
                        #TODO: SearchUpdate, etc.
                }
@@ -169,9 +198,11 @@ function wfSpecialUndelete( $par )
                wfQuery( $sql, DB_WRITE, $fname );
 
                
-        # Touch the log?
-        
-        $wgOut->addWikiText(str_replace("$1", $target, wfMsg("undeletedtext")));
+               # Touch the log?
+               $log = new LogPage( wfMsg( "dellogpage" ), wfMsg( "dellogpagetext" ) );
+               $log->addEntry( wfMsg( "undeletedarticle", $target ), "" );
+
+               $wgOut->addWikiText( wfMsg( "undeletedtext", $target ) );
                return 0;
        }
 ?>