From fdbdd7707ba98066456ea20892572b34d2ead649 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Mon, 31 Oct 2005 22:36:35 +0000 Subject: [PATCH] More informative error message for loss of session data on save --- includes/EditPage.php | 42 ++++++++++++++++++++++++++---------------- languages/Language.php | 2 ++ 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index b4bb6facb1..d1d0e20bb4 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -23,6 +23,7 @@ class EditPage { var $formtype; var $firsttime; var $lastDelete; + var $mTokenOk = true; # Form values var $save = false, $preview = false, $diff = false; @@ -327,19 +328,22 @@ class EditPage { wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" ); $this->preview = true; } else { - if( $this->tokenOk( $request ) ) { - # Some browsers will not report any submit button - # if the user hits enter in the comment box. - # The unmarked state will be assumed to be a save, - # if the form seems otherwise complete. - wfDebug( "$fname: Passed token check.\n" ); - $this->preview = $request->getCheck( 'wpPreview' ); - $this->diff = $request->getCheck( 'wpDiff' ); - } else { - # Page might be a hack attempt posted from - # an external site. Preview instead of saving. - wfDebug( "$fname: Failed token check; forcing preview\n" ); - $this->preview = true; + $this->preview = $request->getCheck( 'wpPreview' ); + $this->diff = $request->getCheck( 'wpDiff' ); + + if( !$this->preview ) { + if ( $this->tokenOk( $request ) ) { + # Some browsers will not report any submit button + # if the user hits enter in the comment box. + # The unmarked state will be assumed to be a save, + # if the form seems otherwise complete. + wfDebug( "$fname: Passed token check.\n" ); + } else { + # Page might be a hack attempt posted from + # an external site. Preview instead of saving. + wfDebug( "$fname: Failed token check; forcing preview\n" ); + $this->preview = true; + } } } $this->save = ! ( $this->preview OR $this->diff ); @@ -395,10 +399,11 @@ class EditPage { if( $wgUser->isAnon() ) { # Anonymous users may not have a session # open. Don't tokenize. - return true; + $this->mTokenOk = true; } else { - return $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) ); + $this->mTokenOk = $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) ); } + return $this->mTokenOk; } function showIntro() { @@ -1006,8 +1011,13 @@ END $fname = 'EditPage::getPreviewText'; wfProfileIn( $fname ); + if ( $this->mTokenOk ) { + $msg = 'previewnote'; + } else { + $msg = 'session_fail_preview'; + } $previewhead = '

' . htmlspecialchars( wfMsg( 'preview' ) ) . "

\n" . - "
" . $wgOut->parse( wfMsg( 'previewnote' ) ) . "
\n"; + "
" . $wgOut->parse( wfMsg( $msg ) ) . "
\n"; if ( $this->isConflict ) { $previewhead.='

' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "

\n"; } diff --git a/languages/Language.php b/languages/Language.php index 74e24b5415..95ccc27eeb 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -730,6 +730,8 @@ If you are here by mistake, just click your browser's '''back''' button.", 'updated' => '(Updated)', 'note' => 'Note: ', 'previewnote' => 'This is only a preview; changes have not yet been saved!', +'session_fail_preview' => 'Sorry! We could not process your edit due to a loss of session data. +Please try again. If it still doesn\'t work, try logging out and logging back in.', 'previewconflict' => 'This preview reflects the text in the upper text editing area as it will appear if you choose to save.', 'editing' => "Editing $1", -- 2.20.1