From d2aaa5f07797448eeda564cb1deb4cdec4265726 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Tue, 2 Aug 2005 20:17:23 +0000 Subject: [PATCH] Add experimental code which causes edit conflict if someone deletes page someone else is currently editing --- includes/EditPage.php | 99 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 4 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index b259aad44b..1125b94065 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -20,9 +20,9 @@ class EditPage { # Form values var $save = false, $preview = false, $diff = false; - var $minoredit = false, $watchthis = false; + var $minoredit = false, $watchthis = false, $recreate = false; var $textbox1 = '', $textbox2 = '', $summary = ''; - var $edittime = '', $section = ''; + var $edittime = '', $section = '', $starttime = ''; var $oldid = 0; /** @@ -217,6 +217,7 @@ class EditPage { $this->summary = $request->getText( 'wpSummary' ); $this->edittime = $request->getVal( 'wpEdittime' ); + $this->starttime = $request->getVal( 'wpStarttime' ); if( is_null( $this->edittime ) ) { # If the form is incomplete, force to preview. $this->preview = true; @@ -239,6 +240,12 @@ class EditPage { $this->edittime = null; } + if( !preg_match( '/^\d{14}$/', $this->starttime )) { + $this->starttime = null; + } + + $this->recreate = $request->getCheck( 'wpRecreate' ); + $this->minoredit = $request->getCheck( 'wpMinoredit' ); $this->watchthis = $request->getCheck( 'wpWatchthis' ); } else { @@ -248,11 +255,13 @@ class EditPage { $this->mMetaData = ''; $this->summary = ''; $this->edittime = ''; + $this->starttime = wfTimestampNow(); $this->preview = false; $this->save = false; $this->diff = false; $this->minoredit = false; $this->watchthis = false; + $this->recreate = false; } $this->oldid = $request->getInt( 'oldid' ); @@ -306,7 +315,32 @@ class EditPage { // css / js subpages of user pages get a special treatment $isCssJsSubpage = $wgTitle->isCssJsSubpage(); - if(!$this->mTitle->getArticleID()) { # new article + + /* Notice that we can't use isDeleted, because it returns true if article is ever deleted + * no matter it's current state + */ + $deletetime = 0; + $confirmdelete = false; + if ( $this->edittime != '' ) { + /* Note that we rely on logging table, which hasn't been always there, + * but that doesn't matter, because this only applies to brand new + * deletes. This is done on every preview and save request. Move it further down + * to only perform it on saves + */ + if ( $this->mTitle->isDeleted() ) { + $query = $this->getLastDelete(); + if ( !is_null($query) ) { + $deletetime = $query->log_timestamp; + if ( ($deletetime - $this->starttime) > 0 ) { + $confirmdelete = true; + } + } + } + } + + + + if(!$this->mTitle->getArticleID() && ('initial' == $formtype || $firsttime )) { # new article $editintro = $wgRequest->getText( 'editintro' ); $addstandardintro=true; if($editintro) { @@ -373,6 +407,11 @@ class EditPage { return; } + # If the article has been deleted while editing, don't save it without + # confirmation + if ( !$confirmdelete || $this->recreate ) { + + # If article is new, insert it. $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE ); if ( 0 == $aid ) { @@ -485,6 +524,7 @@ wfdebug("CONFLICT: edittime=".$this->edittime." article timestamp=".$this->mArti } } } + } # First time through: get contents, set time for conflict # checking, etc. @@ -703,6 +743,23 @@ wfdebug("CONFLICT: edittime=".$this->edittime." article timestamp=".$this->mArti } else $metadata = "" ; + $hidden = ''; + $recreate = ''; + if ($confirmdelete) { + if ( 'save' != $formtype ) { + $wgOut->addWikiText( wfMsg('bw_deletedwhileediting')); + } else { + // Hide the toolbar and edit area, use can click preview to get it back + // Add an confirmation checkbox and explanation. + $toolbar = ''; + $hidden = 'type="hidden" style="display:none;"'; + $recreate = $wgOut->parse( wfMsg( 'bw_confirmrecreate', $query->user_name , $query->log_comment )); + $recreate .= + "
". + ""; + } + } + $safemodehtml = $this->checkUnicodeCompliantBrowser() ? "" : "\n"; @@ -711,9 +768,10 @@ wfdebug("CONFLICT: edittime=".$this->edittime." article timestamp=".$this->mArti {$toolbar}
+$recreate {$commentsubject}