VitaliyFilippov has uploaded a new change for review.
https://gerrit.wikimedia.org/r/71617
Change subject: Replace step-by-step publishing with publish-staying-in-editmode
......................................................................
Replace step-by-step publishing with publish-staying-in-editmode
Change-Id: I1c716b60369a248a54646d9866408f16c3fb78e7
---
M WikiEditor.i18n.php
M WikiEditor.php
M modules/jquery.wikiEditor.publish.js
3 files changed, 119 insertions(+), 171 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikiEditor
refs/changes/17/71617/1
diff --git a/WikiEditor.i18n.php b/WikiEditor.i18n.php
index e2f9390..fc26238 100644
--- a/WikiEditor.i18n.php
+++ b/WikiEditor.i18n.php
@@ -27,15 +27,9 @@
'wikieditor-previewDialog-tab' => 'Preview',
'wikieditor-previewDialog-loading' => 'Loading...',
/* Publish */
- 'wikieditor-publish-preference' => 'Enable step-by-step publishing',
+ 'wikieditor-publish-preference' => 'Enable publishing while staying in
edit mode',
'wikieditor-publish-button-publish' => 'Publish',
- 'wikieditor-publish-button-cancel' => 'Cancel',
- 'wikieditor-publish-dialog-title' => 'Publish to {{SITENAME}}',
- 'wikieditor-publish-dialog-summary' => 'Edit summary (briefly describe
the changes you have made):',
- 'wikieditor-publish-dialog-minor' => 'Minor edit',
- 'wikieditor-publish-dialog-watch' => 'Watch this page',
- 'wikieditor-publish-dialog-publish' => 'Publish',
- 'wikieditor-publish-dialog-goback' => 'Go back',
+ 'wikieditor-publish-error' => 'Error publishing: $1',
/* Template Editor */
'wikieditor-template-editor-preference' => 'Enable form-based editing
of wiki templates',
'wikieditor-template-editor-dialog-title' => 'Edit template',
@@ -316,23 +310,9 @@
'wikieditor-previewDialog-loading' => 'Alt text for spinner displayed
while preview is being loaded
{{Identical|Loading}}',
'wikieditor-publish-preference' => "Option in [[Special:Preferences]],
tab ''{{int:prefs-editing}}''",
- 'wikieditor-publish-button-publish' => 'Button to the right of the
Edit/Preview tabs that opens a dialog window that lets the user save their edit
+ 'wikieditor-publish-button-publish' => 'Button to the right of the
Edit/Preview tabs that publishes the article without leaving edit mode
{{Identical|Publish}}',
- 'wikieditor-publish-button-cancel' => 'Button to the right of the
Edit/Preview tabs that has the same effect as the {{msg-mw|Cancel}} link below
the edit box.
-
-{{Identical|Cancel}}',
- 'wikieditor-publish-dialog-title' => 'Title of the dialog that opens
when the user clicks the Publish button',
- 'wikieditor-publish-dialog-summary' => 'Label for the edit summary
textbox in the dialog that opens when the user clicks the Publish button. See
also {{msg-mw|Summary}}.',
- 'wikieditor-publish-dialog-minor' => 'Label for the minor edit checkbox
in the dialog that opens when the user clicks the Publish button. See also
{{msg-mw|Minoredit}}',
- 'wikieditor-publish-dialog-watch' => 'Label for the watch checkbox in
the dialog that opens when the user clicks the Publish button
-
-{{Identical|Watch this page}}',
- 'wikieditor-publish-dialog-publish' => "Button that saves the user's
edit in the dialog that opens when the user clicks the Publish button
-
-{{Identical|Publish}}",
- 'wikieditor-publish-dialog-goback' => 'Button that closes the dialog
that opens when the user clicks the Publish button.
-{{Identical|Go back}}',
'wikieditor-template-editor-dialog-submit' => '{{Identical|Update}}',
'wikieditor-template-editor-dialog-cancel' => '{{Identical|Cancel}}',
'wikieditor-toc-preference' => "Option at [[Special:Preferences]], tab
''{{int:prefs-editing}}''",
@@ -23417,15 +23397,9 @@
'wikieditor-previewDialog-preference' => 'Включить диалог
предпросмотра',
'wikieditor-previewDialog-tab' => 'Предпросмотр',
'wikieditor-previewDialog-loading' => 'Загрузка…',
- 'wikieditor-publish-preference' => 'Включить пошаговую публикацию',
+ 'wikieditor-publish-preference' => 'Включить публикацию без выхода из
редактирования',
'wikieditor-publish-button-publish' => 'Опубликовать',
- 'wikieditor-publish-button-cancel' => 'Отмена',
- 'wikieditor-publish-dialog-title' => 'Опубликование в проекте
{{SITENAME}}',
- 'wikieditor-publish-dialog-summary' => 'Описание изменений (кратко
укажите какие изменения были произведены):',
- 'wikieditor-publish-dialog-minor' => 'Малое изменение',
- 'wikieditor-publish-dialog-watch' => 'Наблюдать за этой страницей',
- 'wikieditor-publish-dialog-publish' => 'Опубликовать',
- 'wikieditor-publish-dialog-goback' => 'Назад',
+ 'wikieditor-publish-error' => 'Ошибка сохранения: $1',
'wikieditor-template-editor-preference' => 'Включить редактирование
шаблонов с помощью форм',
'wikieditor-template-editor-dialog-title' => 'Изменение шаблона',
'wikieditor-template-editor-dialog-submit' => 'Обновить',
diff --git a/WikiEditor.php b/WikiEditor.php
index dc6df0a..a367425 100644
--- a/WikiEditor.php
+++ b/WikiEditor.php
@@ -468,13 +468,7 @@
),
'messages' => array(
'wikieditor-publish-button-publish',
- 'wikieditor-publish-button-cancel',
- 'wikieditor-publish-dialog-title',
- 'wikieditor-publish-dialog-summary',
- 'wikieditor-publish-dialog-minor',
- 'wikieditor-publish-dialog-watch',
- 'wikieditor-publish-dialog-publish',
- 'wikieditor-publish-dialog-goback',
+ 'wikieditor-publish-error',
),
),
'ext.wikiEditor.templateEditor' => $wikiEditorTpl + array(
diff --git a/modules/jquery.wikiEditor.publish.js
b/modules/jquery.wikiEditor.publish.js
index b61140d..16090b3 100644
--- a/modules/jquery.wikiEditor.publish.js
+++ b/modules/jquery.wikiEditor.publish.js
@@ -4,152 +4,132 @@
$.wikiEditor.modules.publish = {
/**
- * Compatability map
- */
-browsers: {
- // Left-to-right languages
- ltr: {
- msie: [['>=', 7]],
- firefox: [['>=', 3]],
- opera: [['>=', 9.6]],
- safari: [['>=', 4]]
- },
- // Right-to-left languages
- rtl: {
- msie: [['>=', 8]],
- firefox: [['>=', 3]],
- opera: [['>=', 9.6]],
- safari: [['>=', 4]]
- }
-},
-/**
* Internally used functions
*/
fn: {
/**
- * Creates a publish module within a wikiEditor
+ * Creates a publish-staying-in-edit-mode button within a wikiEditor
* @param context Context object of editor to create module in
* @param config Configuration object to create module from
*/
create: function ( context, config ) {
- // Build the dialog behind the Publish button
- var dialogID = 'wikiEditor-' + context.instance + '-dialog';
- $.wikiEditor.modules.dialogs.fn.create(
- context,
- {
- previewsave: {
- id: dialogID,
- titleMsg:
'wikieditor-publish-dialog-title',
- html: '\
- <div
class="wikiEditor-publish-dialog-copywarn"></div>\
- <div
class="wikiEditor-publish-dialog-editoptions">\
- <form id="wikieditor-'
+ context.instance + '-publish-dialog-form">\
- <div
class="wikiEditor-publish-dialog-summary">\
- <label
for="wikiEditor-' + context.instance + '-dialog-summary"\
-
rel="wikieditor-publish-dialog-summary"></label>\
- <br />\
- <input
type="text" id="wikiEditor-' + context.instance + '-dialog-summary"\
-
style="width: 100%;" />\
- </div>\
- <div
class="wikiEditor-publish-dialog-options">\
- <input
type="checkbox"\
-
id="wikiEditor-' + context.instance + '-dialog-minor" />\
- <label
for="wikiEditor-' + context.instance + '-dialog-minor"\
-
rel="wikieditor-publish-dialog-minor"></label>\
- <input
type="checkbox"\
-
id="wikiEditor-' + context.instance + '-dialog-watch" />\
- <label
for="wikiEditor-' + context.instance + '-dialog-watch"\
-
rel="wikieditor-publish-dialog-watch"></label>\
- </div>\
- </form>\
- </div>',
- init: function () {
- var i;
-
- $(this).find( '[rel]' ).each(
function () {
- $(this).text(
mediaWiki.msg( $(this).attr( 'rel' ) ) );
- });
-
- /* REALLY DIRTY HACK! */
- // Reformat the copyright
warning stuff
- var copyWarnHTML = $(
'#editpage-copywarn p' ).html();
- // TODO: internationalize by
splitting on other characters that end statements
- var copyWarnStatements =
copyWarnHTML.split( '. ' );
- var newCopyWarnHTML = '<ul>';
- for ( i = 0; i <
copyWarnStatements.length; i++ ) {
- if (
copyWarnStatements[i] !== '' ) {
- var
copyWarnStatement = $.trim( copyWarnStatements[i] ).replace( /\.*$/, '' );
- newCopyWarnHTML
+= '<li>' + copyWarnStatement + '.</li>';
- }
+ if ( !document.editform ) {
+ return;
+ }
+ var saving = false;
+ context.$controls.show();
+ context.$buttons.show();
+ // Do not use context.fn.addButton as it prevents Enter click
on other form fields to correctly submit the form
+ var btn = $( '<input type="button" disabled="disabled"
id="wikieditor-publish-button" />' )
+ .val( $.wikiEditor.autoMsg( { captionMsg:
'wikieditor-publish-button-publish' }, 'caption' ) )
+ .appendTo( context.$buttons );
+ var doSave = function( newsection ) {
+ var sect = ( document.editform.wpSection || {} ).value;
+ var d = {
+ action: 'edit',
+ format: 'json',
+ title: mw.config.get( 'wgTitle' ),
+ summary: document.editform.wpSummary.value,
+ text: context.$textarea.val(),
+ basetimestamp:
document.editform.wpEdittime.value,
+ token: document.editform.wpEditToken.value,
+ minor: ( document.editform.wpMinoredit || {}
).checked ? 1 : undefined,
+ watch: ( document.editform.wpWatchthis || {}
).checked ? 1 : undefined
+ };
+ if ( sect ) {
+ d.section = sect;
+ }
+ $.ajax( {
+ url: mw.util.wikiScript( 'api' ),
+ type: 'POST',
+ dataType: 'json',
+ data: d,
+ success: function ( data ) {
+ if ( data.error ) {
+ console.log( data.error );
+ alert( mw.msg(
'wikieditor-publish-error', data.error.info ) );
+ } else {
+ if ( data.edit.newtimestamp ) {
+
document.editform.wpEdittime.value = data.edit.newtimestamp.replace( /\D+/g, ''
);
}
- newCopyWarnHTML += '</ul>';
- // No list if there's only one
element
- $(this).find(
'.wikiEditor-publish-dialog-copywarn' ).html(
-
copyWarnStatements.length > 1 ? newCopyWarnHTML : copyWarnHTML
- );
- /* END OF REALLY DIRTY HACK */
-
- if ( $( '#wpMinoredit' ).length
=== 0 )
- $( '#wikiEditor-' +
context.instance + '-dialog-minor' ).hide();
- else if ( $( '#wpMinoredit'
).is( ':checked' ) )
- $( '#wikiEditor-' +
context.instance + '-dialog-minor' )
- .prop(
'checked', true );
- if ( $( '#wpWatchthis' ).length
=== 0 )
- $( '#wikiEditor-' +
context.instance + '-dialog-watch' ).hide();
- else if ( $( '#wpWatchthis'
).is( ':checked' ) )
- $( '#wikiEditor-' +
context.instance + '-dialog-watch' )
- .prop(
'checked', true );
-
- $(this).find( 'form' ).submit(
function ( e ) {
- $(this).closest(
'.ui-dialog' ).find( 'button:first' ).click();
- e.preventDefault();
- });
- },
- immediateCreate: true,
- dialog: {
- buttons: {
-
'wikieditor-publish-dialog-publish': function () {
- var
minorChecked = $( '#wikiEditor-' + context.instance +
-
'-dialog-minor' ).is( ':checked' ) ?
-
'checked' : '';
- var
watchChecked = $( '#wikiEditor-' + context.instance +
-
'-dialog-watch' ).is( ':checked' ) ?
-
'checked' : '';
- $(
'#wpMinoredit' ).prop( 'checked', minorChecked );
- $(
'#wpWatchthis' ).prop( 'checked', watchChecked );
- $( '#wpSummary'
).val( $( '#wikiEditor-' + context.instance +
-
'-dialog-summary' ).val() );
- $( '#editform'
).submit();
- },
-
'wikieditor-publish-dialog-goback': function () {
- $(this).dialog(
'close' );
- }
- },
- open: function () {
- $( '#wikiEditor-' +
context.instance + '-dialog-summary' ).focus();
- },
- width: 500
- },
- resizeme: false
+ btn.prop( 'disabled', true );
+ if ( newsection ) {
+
document.editform.wpSection.value = sect = newsection;
+ }
+ if ( sect ) {
+ $.ajax( {
+ url:
mw.util.wikiScript( 'api' ),
+ type: 'POST',
+ dataType:
'json',
+ data: {
+ action:
'parse',
+ format:
'json',
+ page:
mw.config.get( 'wgTitle' ),
+ prop:
'wikitext',
+
section: sect
+ },
+ success:
function ( data ) {
+ if (
data.parse && data.parse.wikitext && data.parse.wikitext['*'] !== undefined ) {
+
context.$textarea.val( data.parse.wikitext['*'] );
+ }
+ }
+ } );
+ }
+ }
+ },
+ complete: function() {
+ document.getElementById( 'wpSave'
).disabled = false;
+ saving = false;
}
+ });
+ }
+ btn.click( function () {
+ if ( saving ) {
+ return;
}
- );
-
- context.fn.addButton( {
- 'captionMsg': 'wikieditor-publish-button-publish',
- 'action': function () {
- $( '#' + dialogID ).dialog( 'open' );
- return false;
+ saving = true;
+ document.getElementById( 'wpSave' ).disabled = true;
+ var sect = ( document.editform.wpSection || {} ).value;
+ if ( sect == 'new' ) {
+ // Query for the last section number before
saving
+ // X+1 will be the new section number
+ $.ajax( {
+ url: mw.util.wikiScript( 'api' ),
+ type: 'POST',
+ dataType: 'json',
+ data: {
+ action: 'parse',
+ format: 'json',
+ page: mw.config.get( 'wgTitle'
),
+ prop: 'sections'
+ },
+ success: function( data ) {
+ if ( data.parse &&
data.parse.sections ) {
+ doSave( parseInt(
data.parse.sections[data.parse.sections.length-1].index ) + 1 );
+ } else {
+ if ( data.error ) {
+ console.log(
data.error );
+ alert( mw.msg(
'wikieditor-publish-error', data.error.info ) );
+ }
+
document.getElementById( 'wpSave' ).disabled = false;
+ saving = false;
+ }
+ },
+ error: function() {
+ document.getElementById(
'wpSave' ).disabled = false;
+ saving = false;
+ }
+ } );
+ } else {
+ doSave();
}
+ return false;
} );
-
- context.fn.addButton( {
- 'captionMsg': 'wikieditor-publish-button-cancel',
- 'action': function () {
- window.location.href = $( '#mw-editform-cancel'
).attr( 'href' );
- return false;
- }
- } );
+ var chg = function() {
+ btn.prop( 'disabled', false );
+ return true;
+ };
+ context.$textarea.bind( 'cut paste keypress change', chg );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/71617
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1c716b60369a248a54646d9866408f16c3fb78e7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikiEditor
Gerrit-Branch: master
Gerrit-Owner: VitaliyFilippov <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits