Florianschmidtwelzow has uploaded a new change for review.
https://gerrit.wikimedia.org/r/280950
Change subject: WIP: Allow to create a page as a translateion from an existing
source language
......................................................................
WIP: Allow to create a page as a translateion from an existing source language
This in fact works currently, but definitely needs some more work.
Bug: T124036
Change-Id: I10d10ab2565c6678e5858822da600fa4f2174d13
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/SpecialAboutTopic.php
M modules/ext.articleplaceholder.createArticle.js
R
modules/ext.articleplaceholder.defaultDisplay/ext.articleplaceholder.defaultDisplay.css
R
modules/ext.articleplaceholder.defaultDisplay/ext.articleplaceholder.defaultDisplaySmall.css
A
modules/ext.articleplaceholder.handleArticle/ext.articleplaceholder.createArticle.js
A
modules/ext.articleplaceholder.handleArticle/ext.articleplaceholder.processDialog.js
A
modules/ext.articleplaceholder.translateArticle/ext.articleplaceholder.translateArticle.js
10 files changed, 305 insertions(+), 69 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ArticlePlaceholder
refs/changes/50/280950/1
diff --git a/extension.json b/extension.json
index d166bef..467f63e 100644
--- a/extension.json
+++ b/extension.json
@@ -29,7 +29,10 @@
"ResourceModules": {
"ext.articleplaceholder.createArticle": {
"position": "bottom",
- "scripts": "ext.articleplaceholder.createArticle.js",
+ "scripts": [
+
"ext.articleplaceholder.handleArticle/ext.articleplaceholder.processDialog.js",
+
"ext.articleplaceholder.handleArticle/ext.articleplaceholder.createArticle.js"
+ ],
"dependencies": [
"oojs-ui",
"mediawiki.api",
@@ -44,10 +47,18 @@
"cancel"
]
},
+ "ext.articleplaceholder.translateArticle": {
+ "position": "bottom",
+ "scripts":
"ext.articleplaceholder.translateArticle/ext.articleplaceholder.translateArticle.js",
+ "dependencies": [
+ "ext.articleplaceholder.createArticle",
+ "ext.cx.sitemapper"
+ ]
+ },
"ext.articleplaceholder.defaultDisplay": {
"styles": {
- "0":
"ext.articleplaceholder.defaultDisplay.css",
-
"ext.articleplaceholder.defaultDisplaySmall.css": {
+ "0":
"ext.articleplaceholder.defaultDisplay/ext.articleplaceholder.defaultDisplay.css",
+
"ext.articleplaceholder.defaultDisplay/ext.articleplaceholder.defaultDisplaySmall.css":
{
"media": "(max-width: 880px)"
}
},
diff --git a/i18n/en.json b/i18n/en.json
index 5c5135e..9f25626 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -12,6 +12,7 @@
"articleplaceholder-abouttopic-no-entity-error": "This is not a valid
entity id.",
"articleplaceholder-abouttopic-create-article": "Create a new article
with the title",
"articleplaceholder-abouttopic-create-article-label": "Article title",
+ "articleplaceholder-abouttopic-translate-article-label": "Source
language:",
"articleplaceholder-abouttopic-create-article-button": "Create an
article",
"articleplaceholder-abouttopic-create-article-submit-button": "Submit",
"articleplaceholder-abouttopic-article-exists-error": "An article with
this name already exists",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index fb4fd1a..60b924d 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -15,6 +15,7 @@
"articleplaceholder-abouttopic-create-article": "Text in the popup
encouraging the user to create an article with a selectable title",
"articleplaceholder-abouttopic-create-article-label": "Label of the
article page title input in the 'Create article' popup.",
"articleplaceholder-abouttopic-create-article-button": "Label on create
article button",
+ "articleplaceholder-abouttopic-translate-article-label": "Label of the
source language input in the 'Creta earticle' popup.",
"articleplaceholder-abouttopic-create-article-submit-button": "Label on
submit button\n{{Identical|Submit}}",
"articleplaceholder-abouttopic-article-exists-error": "Error to
indicate the given article title already exists",
"articleplaceholder-abouttopic-lua-entity": "Header of the entity
section\n{{Identical|Entity}}",
diff --git a/includes/SpecialAboutTopic.php b/includes/SpecialAboutTopic.php
index e92ad15..76e8139 100644
--- a/includes/SpecialAboutTopic.php
+++ b/includes/SpecialAboutTopic.php
@@ -3,6 +3,7 @@
namespace ArticlePlaceholder;
use Html;
+use Language;
use OOUI;
use SiteStore;
use SpecialPage;
@@ -261,7 +262,10 @@
$output->enableOOUI();
$output->addModuleStyles(
'ext.articleplaceholder.defaultDisplay' );
- $output->addModules( 'ext.articleplaceholder.createArticle' );
+ $output->addModules( array(
+ 'ext.articleplaceholder.createArticle',
+ 'ext.articleplaceholder.translateArticle',
+ ) );
$output->addJsConfigVars( 'apLabel', $label );
$button = new OOUI\ButtonWidget( array(
@@ -269,7 +273,13 @@
'infusable' => true,
'label' => $this->msg(
'articleplaceholder-abouttopic-create-article-button' )->text(),
'target' => 'blank'
- ) );
+ ) ) . new OOUI\ButtonWidget( array(
+ 'id' => 'translate-article-button',
+ 'infusable' => true,
+ 'label' => $this->msg(
'articleplaceholder-abouttopic-translate-article-button' )->text(),
+ 'target' => 'blank'
+ ) )
+ ;
$output->addHTML( $button );
}
@@ -295,6 +305,7 @@
*/
private function showTitle( $label ) {
if ( $label !== null ) {
+ $this->getContext()->setTitle( Title::newFromText(
$label ) );
$this->getOutput()->setPageTitle( htmlspecialchars(
$label ) );
}
}
@@ -305,18 +316,22 @@
* @todo set links to other projects in sidebar, too!
*/
private function showLanguageLinks( ItemId $entityId ) {
+ $out = $this->getOutput();
$siteLinks = $this->sitelinkLookup->getSiteLinksForItem(
$entityId );
$languageLinks = array();
+ $forJsVar = array();
foreach ( $siteLinks as $siteLink ) {
$languageCode = $this->siteStore->getSite(
$siteLink->getSiteId() )->getLanguageCode();
if ( $languageCode !== null ) {
$languageLinks[$languageCode] = $languageCode .
':' . $siteLink->getPageName();
+ $forJsVar[] = array( 'data' => $languageCode,
'label' => Language::fetchLanguageName( $languageCode ) );
}
}
+ $out->addJsConfigVars( 'wgArticlePlaceholderLanguages',
$forJsVar );
- $this->getOutput()->setLanguageLinks( $languageLinks );
+ $out->setLanguageLinks( $languageLinks );
}
/**
diff --git a/modules/ext.articleplaceholder.createArticle.js
b/modules/ext.articleplaceholder.createArticle.js
index 30ffd5e..e36e81b 100644
--- a/modules/ext.articleplaceholder.createArticle.js
+++ b/modules/ext.articleplaceholder.createArticle.js
@@ -8,31 +8,40 @@
var titleInput;
- function onSubmit() {
+ function onSubmit( deferred ) {
var titleRaw = titleInput.getValue(),
api = new mw.Api();
- api.get( { action: 'query', titles: titleRaw } ).done( function
( data ) {
- var query = data.query,
- pageKeys = Object.keys( query.pages ),
- title,
- link;
+ if ( titleRaw === '' ) {
+ deferred.reject( new OO.ui.Error(
+ mw.msg(
'articleplaceholder-abouttopic-create-article-mandatory' )
+ ) );
+ } else {
+ api.get( { action: 'query', titles: titleRaw } ).done(
function ( data ) {
+ var query = data.query,
+ pageKeys,
+ title,
+ link;
- if ( titleRaw !== titleInput.getValue() ) {
- return;
- }
+ if ( query && query.hasOwnProperty( 'pages' ) )
{
+ pageKeys = Object.keys( query.pages );
+ if ( titleRaw !== titleInput.getValue()
) {
+ return;
+ }
- if ( pageKeys[ 0 ] === '-1' ) {
- title = mw.Title.newFromUserInput( titleRaw, 0
);
- link = '?title=' + encodeURIComponent(
title.getNameText() ) + '&action=edit';
- link = mw.util.wikiScript() + link;
- document.location.href = link;
- } else {
- $( '#mw-article-placeholder-error' ).append(
- '<p>' + mw.message(
'articleplaceholder-abouttopic-article-exists-error' ).escaped() + '</p>'
- );
- }
- } );
+ if ( pageKeys[ 0 ] === '-1' ) {
+ title =
mw.Title.newFromUserInput( titleRaw, 0 );
+ link = '?title=' +
encodeURIComponent( title.getNameText() ) + '&action=edit';
+ link = mw.util.wikiScript() +
link;
+ document.location.href = link;
+ } else {
+ deferred.reject( new
OO.ui.Error(
+ mw.msg(
'articleplaceholder-abouttopic-article-exists-error' )
+ ) );
+ }
+ }
+ } );
+ }
return false;
}
@@ -48,6 +57,7 @@
value: mw.config.get( 'apLabel' ),
label: mw.msg(
'articleplaceholder-abouttopic-create-article-label' ),
multiline: false,
+ required: true,
autosize: true
} );
@@ -58,51 +68,15 @@
$( '#mw-article-placeholder-error' ).empty();
} );
- titleInput.on( 'enter', function () {
- submitButton.emit( 'click' );
- } );
-
- function CreateArticleDialog( config ) {
- CreateArticleDialog.super.call( this, config ); //
jshint:ignore
- }
- OO.inheritClass( CreateArticleDialog, OO.ui.ProcessDialog );
-
- CreateArticleDialog.static.title = mw.message(
'articleplaceholder-abouttopic-create-article' ).text();
- CreateArticleDialog.static.actions = [
- {
- action: 'save',
- label: mw.message(
'articleplaceholder-abouttopic-create-article-submit-button' ).text(),
- flags: [ 'primary', 'progressive' ]
- },
- { label: mw.message( 'cancel' ).text(), flags: 'safe' }
- ];
-
- // Customize the initialize() function: This is where to add
content to the dialog body and set up event handlers.
- CreateArticleDialog.prototype.initialize = function () {
- CreateArticleDialog.super.prototype.initialize.call(
this ); // jshint:ignore
- this.content = new OO.ui.PanelLayout( { $: this.$,
padded: true, expanded: false } );
- this.content.$element.append( dialogContent );
- this.$body.append( this.content.$element );
- };
-
- CreateArticleDialog.prototype.getBodyHeight = function () {
- return this.content.$element.outerHeight( true );
- };
-
- CreateArticleDialog.prototype.getActionProcess = function (
action ) {
- if ( action ) {
- return new OO.ui.Process( function () {
- var saveDeferred = $.Deferred();
- onSubmit();
- return saveDeferred.promise();
- }, this );
- }
- return
CreateArticleDialog.parent.prototype.getActionProcess.call( this, action );
- };
-
- dialog = new CreateArticleDialog( {
+ dialog = new mw.articleplaceholder.ProcessDialog( {
size: 'medium'
} );
+ dialog.setContent( dialogContent );
+ dialog.onSubmit = onSubmit;
+
+ titleInput.on( 'enter', function () {
+ dialog.executeAction( 'save' );
+ } );
windowManager = new OO.ui.WindowManager();
diff --git a/modules/ext.articleplaceholder.defaultDisplay.css
b/modules/ext.articleplaceholder.defaultDisplay/ext.articleplaceholder.defaultDisplay.css
similarity index 100%
rename from modules/ext.articleplaceholder.defaultDisplay.css
rename to
modules/ext.articleplaceholder.defaultDisplay/ext.articleplaceholder.defaultDisplay.css
diff --git a/modules/ext.articleplaceholder.defaultDisplaySmall.css
b/modules/ext.articleplaceholder.defaultDisplay/ext.articleplaceholder.defaultDisplaySmall.css
similarity index 100%
rename from modules/ext.articleplaceholder.defaultDisplaySmall.css
rename to
modules/ext.articleplaceholder.defaultDisplay/ext.articleplaceholder.defaultDisplaySmall.css
diff --git
a/modules/ext.articleplaceholder.handleArticle/ext.articleplaceholder.createArticle.js
b/modules/ext.articleplaceholder.handleArticle/ext.articleplaceholder.createArticle.js
new file mode 100644
index 0000000..e36e81b
--- /dev/null
+++
b/modules/ext.articleplaceholder.handleArticle/ext.articleplaceholder.createArticle.js
@@ -0,0 +1,95 @@
+/**
+ * @licence GNU GPL v2+
+ *
+ * @author Lucie-Aimée Kaffee
+ */
+
+( function ( $, mw, OO ) {
+
+ var titleInput;
+
+ function onSubmit( deferred ) {
+ var titleRaw = titleInput.getValue(),
+ api = new mw.Api();
+
+ if ( titleRaw === '' ) {
+ deferred.reject( new OO.ui.Error(
+ mw.msg(
'articleplaceholder-abouttopic-create-article-mandatory' )
+ ) );
+ } else {
+ api.get( { action: 'query', titles: titleRaw } ).done(
function ( data ) {
+ var query = data.query,
+ pageKeys,
+ title,
+ link;
+
+ if ( query && query.hasOwnProperty( 'pages' ) )
{
+ pageKeys = Object.keys( query.pages );
+ if ( titleRaw !== titleInput.getValue()
) {
+ return;
+ }
+
+ if ( pageKeys[ 0 ] === '-1' ) {
+ title =
mw.Title.newFromUserInput( titleRaw, 0 );
+ link = '?title=' +
encodeURIComponent( title.getNameText() ) + '&action=edit';
+ link = mw.util.wikiScript() +
link;
+ document.location.href = link;
+ } else {
+ deferred.reject( new
OO.ui.Error(
+ mw.msg(
'articleplaceholder-abouttopic-article-exists-error' )
+ ) );
+ }
+ }
+ } );
+ }
+
+ return false;
+ }
+
+ function onWikipageContent() {
+ var dialog,
+ windowManager,
+ button,
+ submitButton,
+ dialogContent;
+
+ titleInput = new OO.ui.TextInputWidget( {
+ value: mw.config.get( 'apLabel' ),
+ label: mw.msg(
'articleplaceholder-abouttopic-create-article-label' ),
+ multiline: false,
+ required: true,
+ autosize: true
+ } );
+
+ dialogContent = titleInput.$element;
+ dialogContent.append( '<div
id="mw-article-placeholder-error"></div>' );
+
+ titleInput.on( 'change', function () {
+ $( '#mw-article-placeholder-error' ).empty();
+ } );
+
+ dialog = new mw.articleplaceholder.ProcessDialog( {
+ size: 'medium'
+ } );
+ dialog.setContent( dialogContent );
+ dialog.onSubmit = onSubmit;
+
+ titleInput.on( 'enter', function () {
+ dialog.executeAction( 'save' );
+ } );
+
+ windowManager = new OO.ui.WindowManager();
+
+ $( 'body' ).append( windowManager.$element );
+ // Add the window to the window manager using the addWindows()
method.
+ windowManager.addWindows( [ dialog ] );
+
+ button = OO.ui.infuse( 'create-article-button' );
+ button.on( 'click', function () {
+ windowManager.openWindow( dialog );
+ } );
+ }
+
+ mw.hook( 'wikipage.content' ).add( onWikipageContent );
+
+} )( jQuery, mediaWiki, OO );
diff --git
a/modules/ext.articleplaceholder.handleArticle/ext.articleplaceholder.processDialog.js
b/modules/ext.articleplaceholder.handleArticle/ext.articleplaceholder.processDialog.js
new file mode 100644
index 0000000..c983637
--- /dev/null
+++
b/modules/ext.articleplaceholder.handleArticle/ext.articleplaceholder.processDialog.js
@@ -0,0 +1,61 @@
+/**
+ * @licence GNU GPL v2+
+ *
+ * @author Florian Schmidt
+ */
+
+( function ( $, mw, OO ) {
+ function CreateArticleDialog( config ) {
+ CreateArticleDialog.super.call( this, config ); // jshint:ignore
+ }
+ OO.inheritClass( CreateArticleDialog, OO.ui.ProcessDialog );
+
+ CreateArticleDialog.static.title = mw.message(
'articleplaceholder-abouttopic-create-article' ).text();
+ CreateArticleDialog.static.actions = [
+ {
+ action: 'save',
+ label: mw.message(
'articleplaceholder-abouttopic-create-article-submit-button' ).text(),
+ flags: [ 'primary', 'progressive' ]
+ },
+ { label: mw.message( 'cancel' ).text(), flags: 'safe' }
+ ];
+
+ // Customize the initialize() function: This is where to add content to
the dialog body and set up event handlers.
+ CreateArticleDialog.prototype.initialize = function () {
+ CreateArticleDialog.super.prototype.initialize.call( this ); //
jshint:ignore
+ this.content = new OO.ui.PanelLayout( { $: this.$, padded:
true, expanded: false } );
+ this.content.$element.append( this.dialogContent );
+ this.$body.append( this.content.$element );
+ };
+
+ CreateArticleDialog.prototype.setContent = function( dialogContent ) {
+ this.dialogContent = dialogContent;
+ };
+
+ CreateArticleDialog.prototype.getBodyHeight = function () {
+ return this.content.$element.outerHeight( true ) * 2;
+ };
+
+ CreateArticleDialog.prototype.getActionProcess = function ( action ) {
+ var self = this;
+
+ if ( action ) {
+ return new OO.ui.Process( function () {
+ var saveDeferred = $.Deferred();
+ self.onSubmit( saveDeferred );
+
+ return saveDeferred.promise();
+ }, this );
+ }
+ return
CreateArticleDialog.parent.prototype.getActionProcess.call( this, action );
+ };
+
+ CreateArticleDialog.prototype.onSubmit = function () {
+ return true;
+ };
+
+ // FIXME: Shouldn't life in this file
+ mw.articleplaceholder = {};
+ mw.articleplaceholder.ProcessDialog = CreateArticleDialog;
+
+} )( jQuery, mediaWiki, OO );
diff --git
a/modules/ext.articleplaceholder.translateArticle/ext.articleplaceholder.translateArticle.js
b/modules/ext.articleplaceholder.translateArticle/ext.articleplaceholder.translateArticle.js
new file mode 100644
index 0000000..b1e1e16
--- /dev/null
+++
b/modules/ext.articleplaceholder.translateArticle/ext.articleplaceholder.translateArticle.js
@@ -0,0 +1,78 @@
+/**
+ * @licence GNU GPL v2+
+ *
+ * @author Lucie-Aimée Kaffee
+ */
+
+( function ( $, mw, OO ) {
+
+ var titleInput;
+
+ function onSubmit( deferred ) {
+ var titleRaw = titleInput.getValue(),
+ api = new mw.Api();
+
+ if ( titleRaw === '' ) {
+ deferred.reject( new OO.ui.Error(
+ mw.msg(
'articleplaceholder-abouttopic-create-article-mandatory' )
+ ) );
+ return false;
+ }
+ document.location.href = mw.cx.SiteMapper.prototype.getCXUrl(
+ mw.config.get( 'wgPageName' ),
+ titleRaw,
+ dropdownInput.getValue(),
+ mw.config.get( 'wgContentLanguage' )
+ );
+
+ return false;
+ }
+
+ function onWikipageContent() {
+ var dialog,
+ windowManager,
+ button,
+ dialogContent;
+
+ titleInput = new OO.ui.TextInputWidget( {
+ value: mw.config.get( 'apLabel' ),
+ label: mw.msg(
'articleplaceholder-abouttopic-create-article-label' ),
+ multiline: false,
+ required: true,
+ autosize: true
+ } );
+
+ dropdownInput = new OO.ui.DropdownInputWidget( {
+ text: mw.msg(
'articleplaceholder-abouttopic-translate-article-label' ),
+ options: mw.config.get( 'wgArticlePlaceholderLanguages'
),
+ required: true
+ } );
+
+ dialogContent = titleInput.$element;
+ dialogContent.append( dropdownInput.$element );
+
+ dialog = new mw.articleplaceholder.ProcessDialog( {
+ size: 'medium'
+ } );
+ dialog.setContent( dialogContent );
+ dialog.onSubmit = onSubmit;
+
+ titleInput.on( 'enter', function () {
+ dialog.executeAction( 'save' );
+ } );
+
+ windowManager = new OO.ui.WindowManager();
+
+ $( 'body' ).append( windowManager.$element );
+ // Add the window to the window manager using the addWindows()
method.
+ windowManager.addWindows( [ dialog ] );
+
+ button = OO.ui.infuse( 'translate-article-button' );
+ button.on( 'click', function () {
+ windowManager.openWindow( dialog );
+ } );
+ }
+
+ mw.hook( 'wikipage.content' ).add( onWikipageContent );
+
+} )( jQuery, mediaWiki, OO );
--
To view, visit https://gerrit.wikimedia.org/r/280950
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I10d10ab2565c6678e5858822da600fa4f2174d13
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ArticlePlaceholder
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits