Fomafix has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/351092 )
Change subject: Clear postEdit cookie on server-side
......................................................................
Clear postEdit cookie on server-side
This change redefines the global JavaScript variable wgPostEdit from true
to a string and set it on server-side.
Change-Id: I22f105b0a2f1b9179de834da19dbb813f52ed079
---
M includes/EditPage.php
M includes/page/Article.php
M resources/Resources.php
M resources/src/mediawiki.action/mediawiki.action.view.postEdit.js
4 files changed, 12 insertions(+), 20 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/92/351092/1
diff --git a/includes/EditPage.php b/includes/EditPage.php
index e98dd52..6f6368a 100644
--- a/includes/EditPage.php
+++ b/includes/EditPage.php
@@ -1452,10 +1452,8 @@
* This uses a temporary cookie for each revision ID so separate saves
will never
* interfere with each other.
*
- * The cookie is deleted in the mediawiki.action.view.postEdit JS
module after
- * the redirect. It must be clearable by JavaScript code, so it must
not be
- * marked HttpOnly. The JavaScript code converts the cookie to a
wgPostEdit config
- * variable.
+ * Article::view deletes the cookie on server-side after the redirect
and
+ * converts the value to the global JavaScript variable wgPostEdit.
*
* If the variable were set on the server, it would be cached, which is
unwanted
* since the post-edit state should only apply to the load right after
the save.
@@ -1474,9 +1472,7 @@
}
$response = RequestContext::getMain()->getRequest()->response();
- $response->setCookie( $postEditKey, $val, time() +
self::POST_EDIT_COOKIE_DURATION, [
- 'httpOnly' => false,
- ] );
+ $response->setCookie( $postEditKey, $val, time() +
self::POST_EDIT_COOKIE_DURATION );
}
/**
diff --git a/includes/page/Article.php b/includes/page/Article.php
index 41b45b8..9009712 100644
--- a/includes/page/Article.php
+++ b/includes/page/Article.php
@@ -656,8 +656,11 @@
# Load the postEdit module when this revision was just saved.
$request = $this->getContext()->getRequest();
$cookieKey = EditPage::POST_EDIT_COOKIE_KEY_PREFIX .
$this->getRevIdFetched();
- if ( $request->getCookie( $cookieKey ) ) {
+ $postEdit = $request->getCookie( $cookieKey );
+ if ( $postEdit ) {
+ $outputPage->addJsConfigVars( 'wgPostEdit', $postEdit );
$outputPage->addModules(
'mediawiki.action.view.postEdit' );
+ $request->response()->clearCookie( $cookieKey );
}
}
diff --git a/resources/Resources.php b/resources/Resources.php
index d0a3447..27e50a5 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -1494,7 +1494,6 @@
'scripts' =>
'resources/src/mediawiki.action/mediawiki.action.view.postEdit.js',
'styles' =>
'resources/src/mediawiki.action/mediawiki.action.view.postEdit.less',
'dependencies' => [
- 'mediawiki.cookie',
'mediawiki.jqueryMsg',
'mediawiki.notification'
],
diff --git a/resources/src/mediawiki.action/mediawiki.action.view.postEdit.js
b/resources/src/mediawiki.action/mediawiki.action.view.postEdit.js
index 87572ec..8759759 100644
--- a/resources/src/mediawiki.action/mediawiki.action.view.postEdit.js
+++ b/resources/src/mediawiki.action/mediawiki.action.view.postEdit.js
@@ -22,10 +22,8 @@
* @member mw.hook
*/
- var cookieVal,
- config = mw.config.get( [ 'wgAction', 'wgCurRevisionId' ] ),
- // This should match EditPage::POST_EDIT_COOKIE_KEY_PREFIX:
- cookieKey = 'PostEditRevision' + config.wgCurRevisionId;
+ var postEdit,
+ config = mw.config.get( [ 'wgAction', 'wgCurRevisionId' ] );
function showConfirmation( data ) {
var $container, $popup, $content, timeoutId;
@@ -71,22 +69,18 @@
// Only when viewing wiki pages, that exist
// (E.g. not on special pages or non-view actions)
if ( config.wgCurRevisionId && config.wgAction === 'view' ) {
- cookieVal = mw.cookie.get( cookieKey );
- if ( cookieVal ) {
- mw.config.set( 'wgPostEdit', true );
-
+ postEdit = mw.config.get( 'wgPostEdit' );
+ if ( postEdit ) {
mw.hook( 'postEdit' ).fire( {
// The following messages can be used here:
// postedit-confirmation-saved
// postedit-confirmation-created
// postedit-confirmation-restored
message: mw.msg(
- 'postedit-confirmation-' + cookieVal,
+ 'postedit-confirmation-' + postEdit,
mw.user
)
} );
-
- mw.cookie.set( cookieKey, null );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/351092
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I22f105b0a2f1b9179de834da19dbb813f52ed079
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Fomafix <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits