jenkins-bot has submitted this change and it was merged.
Change subject: Remove post-edit state detection (in core now)
......................................................................
Remove post-edit state detection (in core now)
This change transfers the responsibility for detecting post-edit state and
transmitting it to client-side code from the extension to MediaWiki core, which
(thanks to Matt Flaschen's work in 375687eddb) now implements all the requisite
behavior.
It might make sense to merge the remainder of the extension into core, too, but
I think it makes sense to have the intermediate step (represented by this
patch) of leaving state handling to core but still doing the UI bits in the
extension.
Change-Id: Ifc61b4d3b4581b861cba443adc9d493515a2e395
---
D PostEdit.hooks.php
M PostEdit.php
M resources/ext.postEdit.js
3 files changed, 10 insertions(+), 122 deletions(-)
Approvals:
Mattflaschen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/PostEdit.hooks.php b/PostEdit.hooks.php
deleted file mode 100644
index 409c080..0000000
--- a/PostEdit.hooks.php
+++ /dev/null
@@ -1,84 +0,0 @@
-<?php
-/**
- * Hooks for PostEdit extension
- *
- * @file
- * @ingroup Extensions
- */
-
-class PostEditHooks {
-
- /**
- * @var null|int: If a page was saved, the PageContentSaveComplete
- * handler sets this to the ID of that page. If no
- * page was saved, this remains null.
- */
- public static $savedPageId = null;
-
- /**
- * MakeGlobalVariablesScript hook.
- * Add config vars to mw.config.
- *
- * @param $vars array
- * @param $out OutputPage output page
- * @return bool
- */
- public static function onMakeGlobalVariablesScript( &$vars, $out ) {
- global $wgCookiePath;
-
- if ( $out->getRequest()->getCookie( 'showPostEdit' ) ) {
- $vars[ 'wgCookiePath' ] = $wgCookiePath;
- }
-
- return true;
- }
-
- /**
- * BeforePageDisplay hook.
- *
- * Adds the modules to the page.
- *
- * @param $out OutputPage output page
- * @param $skin Skin current skin
- * @return bool
- */
- public static function onBeforePageDisplay( $out ) {
- if ( $out->getRequest()->getCookie( 'showPostEdit' ) ) {
- $out->addModules( 'ext.postEdit' );
- }
- return true;
- }
-
-
- /**
- * PageContentSaveComplete hook handler.
- * @return bool
- */
- public static function onPageContentSaveComplete( $article, $user,
$content, $summary,
- $isMinor, $isWatch, $section, $flags, $revision, $status,
$baseRevId ) {
- if ( isset( $revision ) ) {
- self::$savedPageId = $article->getId();
- }
- return true;
- }
-
- /**
- * BeforePageRedirect hook.
- * @return bool
- */
- public static function onBeforePageRedirect() {
- global $wgCookiePrefix, $wgCookiePath, $wgCookieDomain;
-
- if ( self::$savedPageId !== null ) {
- // The cookie we set here must be clearable by
JavaScript code, so
- // it must not be marked HttpOnly. Since
WebRequest::setcookie
- // has no way to guarantee this behavior, we have to
use PHP's
- // setcookie() directly.
- setcookie( $wgCookiePrefix . 'showPostEdit',
- self::$savedPageId, 0, $wgCookiePath,
$wgCookieDomain );
- }
-
- return true;
- }
-
-}
diff --git a/PostEdit.php b/PostEdit.php
index 6b43706..c42224a 100644
--- a/PostEdit.php
+++ b/PostEdit.php
@@ -12,7 +12,7 @@
$wgExtensionCredits[ 'other' ][] = array(
'path' => __FILE__,
'name' => 'PostEdit',
- 'version' => '0.3',
+ 'version' => '0.4',
'url' => 'https://www.mediawiki.org/wiki/Extension:PostEdit',
'author' => array(
'Munaf Assaf',
@@ -24,7 +24,6 @@
/* Setup */
// Register files
-$wgAutoloadClasses[ 'PostEditHooks' ] = __DIR__ . '/PostEdit.hooks.php';
$wgExtensionMessagesFiles[ 'PostEdit' ] = __DIR__ . '/PostEdit.i18n.php';
// Register modules
@@ -34,9 +33,7 @@
'skinStyles' => array(
'monobook' => 'resources/ext.postEdit.monobook.css',
),
- 'dependencies' => array(
- 'jquery.cookie',
- ),
+ 'dependencies' => 'mediawiki.action.view.postEdit',
'messages' => array(
'postedit-confirmation',
),
@@ -45,8 +42,9 @@
'remoteExtPath' => 'PostEdit',
);
-// Register hooks
-$wgHooks[ 'PageContentSaveComplete' ][] =
'PostEditHooks::onPageContentSaveComplete';
-$wgHooks[ 'BeforePageDisplay' ][] = 'PostEditHooks::onBeforePageDisplay';
-$wgHooks[ 'BeforePageRedirect' ][] = 'PostEditHooks::onBeforePageRedirect';
-$wgHooks[ 'MakeGlobalVariablesScript' ][] =
'PostEditHooks::onMakeGlobalVariablesScript';
+$wgHooks[ 'BeforePageDisplay' ][] = function ( $out ) {
+ if ( Action::getActionName( $out ) === 'view' ) {
+ $out->addModules( 'ext.postEdit' );
+ }
+ return true;
+};
diff --git a/resources/ext.postEdit.js b/resources/ext.postEdit.js
index 7932fd4..0eaccff 100644
--- a/resources/ext.postEdit.js
+++ b/resources/ext.postEdit.js
@@ -3,19 +3,7 @@
( function ( mw, $ ) {
'use strict';
- var div, key = mw.config.get( 'wgCookiePrefix' ) + 'showPostEdit';
-
- /**
- * Retrieve and clear a cookie.
- * @param string key: Name of cookie to pop (including prefix).
- */
- function popCookie( key ) {
- var val = $.cookie( key );
- if ( val !== null ) {
- $.cookie( key, null, { path: mw.config.get(
'wgCookiePath' ) } );
- }
- return val;
- }
+ var div;
/**
* @param {jQuery.Event|undefined} e
@@ -35,22 +23,8 @@
}
}
- // If the cookie exists, *and* its value is the same as wgArticleId, set
- // wgPostEdit. We have to compare the page ID declared on the cookie to
the
- // current page's ID because pages sometimes load out-of-order,
especially
- // when using MediaWiki from multiple tabs.
- //
- // *Note*: we clear the cookie regardless of value. This might mean we
- // drop another page's PostEdit, but at least we don't get into funky
- // states.
-
- if ( parseInt( popCookie( key ), 10 ) === mw.config.get( 'wgArticleId'
) ) {
- // Since the cookie will be gone now, we use mw.config to allow
other
- // scripts to activate certain behaviour for the post-edit page.
- mw.config.set( 'wgPostEdit', true );
-
+ if ( mw.config.get( 'wgPostEdit' ) ) {
div = document.createElement( 'div' );
-
div.className = 'postedit-container';
div.innerHTML =
'<div class="postedit">' +
--
To view, visit https://gerrit.wikimedia.org/r/54992
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifc61b4d3b4581b861cba443adc9d493515a2e395
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/PostEdit
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Spage <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits