3 function wfSpecialUndelete( $par )
5 global $wgLang, $wgUser, $wgOut, $action, $target, $timestamp, $restore;
6 $restore = $_REQUEST["restore"];
7 $timestamp = $_REQUEST["timestamp"];
9 if( $par != "" ) $target = $par;
10 if( isset($target ) ) {
11 $t = Title
::newFromURL( $target );
12 $title = $t->mDbkeyform
;
13 $namespace = $t->mNamespace
;
14 if( isset( $timestamp ) ) {
15 return doUndeleteShowRevision( $namespace, $title, $timestamp );
17 if( isset( $action ) and isset( $restore) and $action == "submit" ) {
18 return doUndeleteArticle( $namespace, $title );
20 return doUndeleteShowHistory( $namespace, $title );
23 # List undeletable articles
24 $sql = "SELECT ar_namespace,ar_title, COUNT(*) AS count FROM archive GROUP BY ar_namespace,ar_title ORDER BY ar_namespace,ar_title";
25 $res = wfQuery( $sql, DB_READ
);
27 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
28 $wgOut->addWikiText( wfMsg( "undeletepagetext" ) );
30 $special = $wgLang->getNsText( Namespace::getSpecial() );
31 $sk = $wgUser->getSkin();
32 $wgOut->addHTML( "<ul>\n" );
33 while ($row = wfFetchObject( $res )) {
34 $n = ($row->ar_namespace ?
35 ($wgLang->getNsText( $row->ar_namespace
) . ":") : "").
38 $wgOut->addHTML( "<li>" .
39 $sk->makeKnownLink( $wgLang->specialPage( "Undelete" ),
40 $n, "target=" . urlencode($n) ) . " " .
41 wfMsg( "undeleterevisions", $row->count
) );
43 $wgOut->addHTML( "</ul>\n" );
48 /* private */ function doUndeleteShowRevision( $namespace, $title, $timestamp ) {
49 global $wgLang, $wgUser, $wgOut, $action, $target, $timestamp, $restore;
51 if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
53 $sql = "SELECT ar_text FROM archive WHERE ar_namespace={$namespace} AND ar_title=\"{$title}\" AND ar_timestamp={$timestamp}";
54 $ret = wfQuery( $sql, DB_READ
);
55 $row = wfFetchObject( $ret );
57 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
58 $wgOut->addWikiText( "(" . wfMsg( "undeleterevision", $wgLang->date($timestamp, true) )
59 . ")\n<hr>\n" . $row->ar_text
);
64 /* private */ function doUndeleteShowHistory( $namespace, $title ) {
65 global $wgLang, $wgUser, $wgOut, $action, $target, $timestamp, $restore;
67 $sk = $wgUser->getSkin();
68 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
69 $wgOut->addWikiText( wfMsg( "undeletehistory" ) . "\n<hr>\n" . $row->ar_text
);
71 $action = wfLocalUrlE( $wgLang->specialPage( "Undelete" ), "action=submit" );
73 <form id=\"undelete\" method=\"post\" action=\"{$action}\">
74 <input type=hidden name=\"target\" value=\"{$target}\">
75 <input type=submit name=\"restore\" value=\"".wfMsg("undeletebtn")."\">
78 $log = wfGetSQL("cur", "cur_text", "cur_namespace=4 AND cur_title=\"".wfMsg("dellogpage")."\"" );
79 if(preg_match("/^(.*".
80 preg_quote( ($namespace ?
($wgLang->getNsText($namespace) . ":") : "")
81 . str_replace("_", " ", $title), "/" ).".*)$/m", $log, $m)) {
82 $wgOut->addWikiText( $m[1] );
85 $sql = "SELECT ar_minor_edit,ar_timestamp,ar_user,ar_user_text,ar_comment
86 FROM archive WHERE ar_namespace={$namespace} AND ar_title=\"{$title}\"
87 ORDER BY ar_timestamp DESC";
88 $ret = wfQuery( $sql, DB_READ
);
90 $special = $wgLang->getNsText( Namespace::getSpecial() );
91 $wgOut->addHTML("<ul>");
92 while( $row = wfFetchObject( $ret ) ) {
93 $wgOut->addHTML( "<li>" .
94 $sk->makeKnownLink( $wgLang->specialPage( "Undelete" ),
95 $wgLang->timeanddate( $row->ar_timestamp
, true ),
96 "target=" . urlencode($target) . "×tamp={$row->ar_timestamp}" ) . " " .
97 ". . {$row->ar_user_text}" .
98 " <i>(" . htmlspecialchars($row->ar_comment
) . "</i>)\n");
101 $wgOut->addHTML("</ul>");
106 /* private */ function doUndeleteArticle( $namespace, $title )
108 global $wgUser, $wgOut, $wgLang, $target, $wgDeferredUpdateList;
110 $fname = "doUndeleteArticle";
112 if ( "" == $title ) {
113 $wgOut->fatalError( wfMsg( "cannotundelete" ) );
116 $t = addslashes($title);
118 # Move article and history from the "archive" table
119 $sql = "SELECT COUNT(*) AS count FROM cur WHERE cur_namespace={$namespace} AND cur_title='{$t}'";
120 $res = wfQuery( $sql, DB_READ
);
121 $row = wfFetchObject( $res );
122 if( $row->count
== 0) {
123 # Have to create new article...
124 $now = wfTimestampNow();
125 $max = wfGetSQL( "archive", "MAX(ar_timestamp)", "ar_namespace={$namespace} AND ar_title='{$t}'" );
126 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
127 "cur_comment,cur_user,cur_user_text,cur_timestamp,inverse_timestamp,cur_minor_edit,cur_random,cur_touched)" .
128 "SELECT ar_namespace,ar_title,ar_text,ar_comment," .
129 "ar_user,ar_user_text,ar_timestamp,99999999999999-ar_timestamp,ar_minor_edit,RAND(),'{$now}' FROM archive " .
130 "WHERE ar_namespace={$namespace} AND ar_title='{$t}' AND ar_timestamp={$max}";
131 wfQuery( $sql, DB_WRITE
, $fname );
132 $newid = wfInsertId();
133 $oldones = "AND ar_timestamp<{$max}";
135 # If already exists, put history entirely into old table
140 $sql = "INSERT INTO old (old_namespace,old_title,old_text," .
141 "old_comment,old_user,old_user_text,old_timestamp,inverse_timestamp,old_minor_edit," .
142 "old_flags) SELECT ar_namespace,ar_title,ar_text,ar_comment," .
143 "ar_user,ar_user_text,ar_timestamp,99999999999999-ar_timestamp,ar_minor_edit,ar_flags " .
144 "FROM archive WHERE ar_namespace={$namespace} AND ar_title='{$t}' {$oldones}";
145 wfQuery( $sql, DB_WRITE
, $fname );
147 # Finally, clean up the link tables
149 # Create a dummy OutputPage to update the outgoing links
150 # This works at the moment due to good luck. It may stop working in the
151 # future. Damn globals.
152 $dummyOut = new OutputPage();
153 $to = Title
::newFromDBKey( $target );
154 $res = wfQuery( "SELECT cur_text FROM cur WHERE cur_id={$newid} " .
155 "AND cur_namespace={$namespace}", DB_READ
, $fname );
156 $row = wfFetchObject( $res );
157 $text = $row->cur_text
;
158 $dummyOut->addWikiText( $text );
159 wfFreeResult( $res );
161 $u = new LinksUpdate( $newid, $to->getPrefixedDBkey() );
162 array_push( $wgDeferredUpdateList, $u );
164 #TODO: SearchUpdate, etc.
167 # Now that it's safely stored, take it out of the archive
168 $sql = "DELETE FROM archive WHERE ar_namespace={$namespace} AND " .
170 wfQuery( $sql, DB_WRITE
, $fname );
174 $log = new LogPage( wfMsg( "dellogpage" ), wfMsg( "dellogpagetext" ) );
175 $log->addEntry( wfMsg( "undeletedarticle", $target ), "" );
177 $wgOut->addWikiText( wfMsg( "undeletedtext", $target ) );