- $res = $dbw->query( $sql, $fname );
- $row = $dbw->fetchObject( $res );
- $now = wfTimestampNow();
-
- if( $row->count == 0) {
- # Have to create new article...
- $sql = "SELECT ar_text,ar_comment,ar_user,ar_user_text,ar_timestamp,ar_minor_edit,ar_flags FROM $archive WHERE ar_namespace={$namespace} AND ar_title='{$t}' ";
- if( !$restoreAll ) {
- $max = $dbw->addQuotes( $dbw->timestamp( array_shift( $timestamps ) ) );
- $sql .= "AND ar_timestamp={$max} ";
- }
- $sql .= "ORDER BY ar_timestamp DESC LIMIT 1 FOR UPDATE";
- $res = $dbw->query( $sql, $fname );
- $s = $dbw->fetchObject( $res );
- if( $restoreAll ) {
- $max = $s->ar_timestamp;
- }
- $text = Revision::getRevisionText( $s, "ar_" );
-
- $redirect = MagicWord::get( MAG_REDIRECT );
- $redir = $redirect->matchStart( $text ) ? 1 : 0;
-
- $rand = wfRandom();
- $dbw->insert( 'cur', array(
- 'cur_id' => $dbw->nextSequenceValue( 'cur_cur_id_seq' ),
- 'cur_namespace' => $namespace,
- 'cur_title' => $ttl,
- 'cur_text' => $text,
- 'cur_comment' => $s->ar_comment,
- 'cur_user' => $s->ar_user,
- 'cur_timestamp' => $s->ar_timestamp,
- 'cur_minor_edit' => $s->ar_minor_edit,
- 'cur_user_text' => $s->ar_user_text,
- 'cur_is_redirect' => $redir,
- 'cur_random' => $rand,
- 'cur_touched' => $dbw->timestamp( $now ),
- ), $fname );
-
- $newid = $dbw->insertId();
- if( $restoreAll ) {
- $oldones = "AND ar_timestamp<" . $dbw->addQuotes( $dbw->timestamp( $max ) );
- }