jenkins-bot has submitted this change and it was merged.
Change subject: Create new article
......................................................................
Create new article
Add a button to create a new article from a given title and test if the title
already exists.
Bug: T109452
Change-Id: Ida87ac4df5a144968b3021aa200f78b61207f238
---
M ArticlePlaceholder.php
M Specials/SpecialFancyUnicorn.php
M i18n/en.json
M i18n/qqq.json
A modules/ext.articleplaceholder.createArticle.js
5 files changed, 209 insertions(+), 37 deletions(-)
Approvals:
Hoo man: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ArticlePlaceholder.php b/ArticlePlaceholder.php
index 0ea24a8..a202960 100644
--- a/ArticlePlaceholder.php
+++ b/ArticlePlaceholder.php
@@ -1,4 +1,5 @@
<?php
+
/**
* AticlePlaceholder extension
*
@@ -10,16 +11,12 @@
* The license governing the extension code:
* @license GNU General Public Licence 2.0 or later
*/
-
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
-
'name' => 'ArticlePlaceholder',
-
'author' => array(
'Lucie-Aimée Kaffee',
),
-
'url' => 'https://www.mediawiki.org/wiki/Extension:ArticlePlaceholder',
'descriptionmsg' => 'articleplaceholder-desc',
);
@@ -33,10 +30,31 @@
$wgHooks['ScribuntoExternalLibraryPaths'][] =
'\ArticlePlaceholder\Hooks::registerScribuntoExternalLibraryPaths';
$wgHooks['SpecialSearchResultsAppend'][] =
'\ArticlePlaceholder\SearchHookHandler::onSpecialSearchResultsAppend';
-$wgMessagesDirs[ 'ArticlePlaceholder' ] = __DIR__ . '/i18n';
+$wgMessagesDirs['ArticlePlaceholder'] = __DIR__ . '/i18n';
$wgExtensionMessagesFiles['ArticlePlaceholderAliases'] = __DIR__ .
'/ArticlePlaceholder.alias.php';
-$wgSpecialPages[ 'FancyUnicorn' ] = array(
+$wgSpecialPages['FancyUnicorn'] = array(
'ArticlePlaceholder\Specials\SpecialFancyUnicorn',
'newFromGlobalState'
);
+
+preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) . '(?:vendor|extensions)'
+ . preg_quote( DIRECTORY_SEPARATOR ) . '.*+', __DIR__, $remoteExtPath );
+
+$wgResourceModules['ext.articleplaceholder.createArticle'] = array(
+ 'position' => 'bottom',
+ 'scripts' => 'ext.articleplaceholder.createArticle.js',
+ 'dependencies' => array(
+ 'oojs-ui',
+ 'mediawiki.api',
+ 'mediawiki.Title',
+ 'mediawiki.util'
+ ),
+ 'localBasePath' => __DIR__ . '/modules',
+ 'remoteExtPath' => '..' . $remoteExtPath[0],
+ 'messages' => array(
+ 'articleplaceholder-fancyunicorn-create-article',
+ 'articleplaceholder-fancyunicorn-article-exists-error',
+ 'articleplaceholder-fancyunicorn-create-article-submit-button'
+ )
+);
diff --git a/Specials/SpecialFancyUnicorn.php b/Specials/SpecialFancyUnicorn.php
index 62a1f41..e62358c 100644
--- a/Specials/SpecialFancyUnicorn.php
+++ b/Specials/SpecialFancyUnicorn.php
@@ -22,6 +22,7 @@
use Wikibase\Lib\Store\SiteLinkLookup;
use SiteStore;
use SpecialPage;
+use OOUI;
class SpecialFancyUnicorn extends SpecialPage {
@@ -45,7 +46,7 @@
/**
* @var LanguageFallbackLabelDescriptionLookupFactory
*/
- private $lfldlf;
+ private $termLookupFactory;
/**
* @var SitelinkLookup
@@ -72,14 +73,14 @@
*/
public function __construct(
EntityIdParser $idParser,
- LanguageFallbackLabelDescriptionLookupFactory $lfldlf,
+ LanguageFallbackLabelDescriptionLookupFactory
$termLookupFactory,
SiteLinkLookup $sitelinkLookup,
SiteStore $siteStore,
TitleFactory $titleFactory,
$siteGlobalID
) {
$this->idParser = $idParser;
- $this->lfldlf = $lfldlf;
+ $this->termLookupFactory = $termLookupFactory;
$this->sitelinkLookup = $sitelinkLookup;
$this->siteStore = $siteStore;
$this->titleFactory = $titleFactory;
@@ -127,7 +128,8 @@
// Form header
$this->getOutput()->addHTML(
Html::openElement(
- 'form', array(
+ 'form',
+ array(
'method' => 'get',
'action' =>
$this->getPageTitle()->getFullUrl(),
'name' => 'ap-fancyunicorn',
@@ -143,9 +145,10 @@
// Form body
$this->getOutput()->addHTML(
Html::input(
- 'submit', $this->msg(
'articleplaceholder-fancyunicorn-submit' )->text(), 'submit', array(
- 'id' => 'submit'
- )
+ 'submit',
+ $this->msg(
'articleplaceholder-fancyunicorn-submit' )->text(),
+ 'submit',
+ array( 'id' => 'submit' )
)
. Html::closeElement( 'fieldset' )
. Html::closeElement( 'form' )
@@ -160,23 +163,29 @@
*/
protected function getFormElements() {
return Html::rawElement(
- 'p', array(), $this->msg(
'articleplaceholder-fancyunicorn-intro' )->parse()
- )
- . Html::element( 'br' )
- . Html::element(
- 'label', array(
- 'for' => 'ap-fancyunicorn-entityid',
- 'class' => 'ap-label'
- ), $this->msg(
'articleplaceholder-fancyunicorn-entityid' )->text()
- )
- . Html::element( 'br' )
- . Html::input(
- 'entityid',
$this->getRequest()->getVal( 'entityid' ), 'text', array(
- 'class' => 'ap-input',
- 'id' => 'ap-fancyunicorn-entityid'
- )
- )
- . Html::element( 'br' );
+ 'p',
+ array(),
+ $this->msg( 'articleplaceholder-fancyunicorn-intro'
)->parse()
+ )
+ . Html::element( 'br' )
+ . Html::element(
+ 'label',
+ array(
+ 'for' => 'ap-fancyunicorn-entityid',
+ 'class' => 'ap-label'
+ ),
+ $this->msg( 'articleplaceholder-fancyunicorn-entityid'
)->text()
+ )
+ . Html::element( 'br' )
+ . Html::input(
+ 'entityid',
+ $this->getRequest()->getVal( 'entityid' ),
+ 'text', array(
+ 'class' => 'ap-input',
+ 'id' => 'ap-fancyunicorn-entityid'
+ )
+ )
+ . Html::element( 'br' );
}
private function getTextParam( $name, $fallback ) {
@@ -217,19 +226,50 @@
*/
private function showPlaceholder( ItemId $entityId ) {
$this->getOutput()->addWikiText( "{{fancyUnicorn|" .
$entityId->getSerialization() . "}}" );
- $this->showTitle( $entityId );
+ $label = $this->getLabel( $entityId );
+ $this->showTitle( $label );
+ $this->showCreateArticle( $label );
$this->showLanguageLinks( $entityId );
+ }
+
+ private function showCreateArticle( $label ) {
+ $output = $this->getOutput();
+
+ $output->enableOOUI();
+ $output->addModules( 'ext.articleplaceholder.createArticle' );
+ $output->addJsConfigVars( 'apLabel', $label );
+
+ $button = new OOUI\ButtonWidget( array(
+ 'id' => 'create-article-button',
+ 'infusable' => true,
+ 'label' => $this->msg(
'articleplaceholder-fancyunicorn-create-article-button' )->text(),
+ 'target' => 'blank'
+ ) );
+
+ $output->addHTML( $button );
+ }
+
+ /**
+ * @param EntityId $entityId
+ * @return string|null label
+ */
+ private function getLabel( ItemId $entityId ) {
+ $label = $this->termLookupFactory->newLabelDescriptionLookup(
$this->getLanguage(), array() )->getLabel( $entityId );
+
+ if ( $label !== null ) {
+ return $label->getText();
+ }
+
+ return null;
}
/**
* Show label as page title
- * @param EntityId $entityId
+ * @param string|null $label
*/
- private function showTitle( ItemId $entityId ) {
- $array[] = $entityId;
- $label = $this->lfldlf->newLabelDescriptionLookup(
$this->getLanguage(), $array )->getLabel( $entityId );
+ private function showTitle( $label ) {
if ( $label !== null ) {
- $this->getOutput()->setPageTitle( $label->getText() );
+ $this->getOutput()->setPageTitle( $label );
}
}
@@ -274,4 +314,4 @@
return null;
}
-}
\ No newline at end of file
+}
diff --git a/i18n/en.json b/i18n/en.json
index 3ba61a8..4acbf12 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -10,6 +10,10 @@
"articleplaceholder-fancyunicorn-intro": "This is the SpecialPage Fancy
Unicorn of the ArticlePlaceholder extension. Much fancy, very unicorn. (so
exciting)",
"articleplaceholder-fancyunicorn-entityid": "Enter a entity ID to get a
auto generated Article Placeholder.",
"articleplaceholder-fancyunicorn-submit": "craft",
+ "articleplaceholder-fancyunicorn-create-article": "Create a new article
with the title",
+ "articleplaceholder-fancyunicorn-create-article-button": "Create an
article",
+ "articleplaceholder-fancyunicorn-create-article-submit-button":
"Submit",
+ "articleplaceholder-fancyunicorn-article-exists-error": "An article
with this name already exists",
"articleplaceholder-fancyunicorn-lua-entity": "Entity",
"articleplaceholder-fancyunicorn-lua-description": "Description:",
"articleplaceholder-fancyunicorn-lua-reference": "Reference",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index de6a28a..8da4abf 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -10,6 +10,10 @@
"articleplaceholder-fancyunicorn-intro": "Intro paragraph shown on
SpecialFancyUnicorn.",
"articleplaceholder-fancyunicorn-entityid": "Text to encourage the user
to enter an entity id.",
"articleplaceholder-fancyunicorn-submit": "Label on the submit button.",
+ "articleplaceholder-fancyunicorn-create-article": "Text in the popup
encouraging the user to create an article with a selectable title",
+ "articleplaceholder-fancyunicorn-create-article-button": "Label on
create article button",
+ "articleplaceholder-fancyunicorn-create-article-submit-button":
"Label on submit button",
+ "articleplaceholder-fancyunicorn-article-exists-error": "Error to
indicate the given article title already exists",
"articleplaceholder-fancyunicorn-lua-entity": "Header of the entity
section",
"articleplaceholder-fancyunicorn-lua-description": "Word before the
description string",
"articleplaceholder-fancyunicorn-lua-reference": "Header of the
reference section",
diff --git a/modules/ext.articleplaceholder.createArticle.js
b/modules/ext.articleplaceholder.createArticle.js
new file mode 100644
index 0000000..b50bfdd
--- /dev/null
+++ b/modules/ext.articleplaceholder.createArticle.js
@@ -0,0 +1,106 @@
+/**
+ * @licence GNU GPL v2+
+ *
+ * @author Lucie-Aimée Kaffee
+ */
+
+( function ( $, mw, OO ) {
+
+ var titleInput;
+
+ function onSubmit() {
+ 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 !== 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-fancyunicorn-article-exists-error' ).escaped() + '</p>'
+ );
+ }
+ } );
+
+ return false;
+ }
+
+ function onWikipageContent() {
+ var dialog,
+ windowManager,
+ button,
+ submitButton,
+ dialogContent
+;
+ titleInput = new OO.ui.TextInputWidget( {
+ value: mw.config.get( 'apLabel' ),
+ multiline: false,
+ autosize: true
+ } );
+
+ submitButton = new OO.ui.ButtonWidget( {
+ label: mw.message(
'articleplaceholder-fancyunicorn-create-article-submit-button' ).text()
+ } );
+
+ dialogContent = $( '<p>' + mw.message(
'articleplaceholder-fancyunicorn-create-article' ).escaped() + '</p>' );
+ dialogContent.append( titleInput.$element );
+ dialogContent.append( submitButton.$element );
+ dialogContent.append( '<div
id="mw-article-placeholder-error"></div>' );
+
+ submitButton.on( 'click', onSubmit );
+
+ titleInput.on( 'change', function () {
+ $( '#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.Dialog );
+
+ // 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 );
+ };
+
+ dialog = new CreateArticleDialog( {
+ size: 'medium'
+ } );
+ windowManager = new OO.ui.WindowManager();
+ button = OO.ui.infuse( 'create-article-button' );
+
+ $( 'body' ).append( windowManager.$element );
+ // Add the window to the window manager using the addWindows()
method.
+ windowManager.addWindows( [ dialog ] );
+
+ button.on( 'click', function () {
+ windowManager.openWindow( dialog );
+ } );
+ }
+
+ mw.hook( 'wikipage.content' ).add( onWikipageContent );
+
+} )( jQuery, mediaWiki, OO );
--
To view, visit https://gerrit.wikimedia.org/r/242608
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ida87ac4df5a144968b3021aa200f78b61207f238
Gerrit-PatchSet: 32
Gerrit-Project: mediawiki/extensions/ArticlePlaceholder
Gerrit-Branch: master
Gerrit-Owner: Lucie Kaffee <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: JanZerebecki <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Lucie Kaffee <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits