Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tags #527

Closed
wants to merge 17 commits into from
14 changes: 14 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@
"oojs-ui-widgets"
]
},
"ext.createwiki.oouiform.wikiTags": {
"scripts": "ext.createwiki.oouiform.wikiTags.js",
"targets": [ "desktop", "mobile" ],
"messages": [
"createwiki-label-wiki-tags"
],
"dependencies": [
"oojs-ui-widgets"
]
},
"ext.createwiki.oouiform.styles": {
"styles": "ext.createwiki.oouiform.ooui.less"
}
Expand All @@ -276,6 +286,10 @@
"description": "Array. Regexes in request descriptions to never auto approve if matched.",
"value": []
},
"CreateWikiAvailableTags": {
"description": "Array. List of available wiki tags. If set to an empty array, tags are disabled.",
"value": []
},
"CreateWikiCacheDirectory": {
"description": "String. The path to store CreateWiki cache files at.",
"value": ""
Expand Down
1 change: 1 addition & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"createwiki-label-requester": "Requester:",
"createwiki-label-sitename": "Sitename:",
"createwiki-label-statuschangecomment": "Reason for this action:",
"createwiki-label-wiki-tags": "Wiki tags",
"createwiki-no-changes": "No changes made.",
"createwiki-request-locked": "This request has been locked. It cannot be edited, and no comments can be added to it.",
"createwiki-request-updated": "Updated request.",
Expand Down
1 change: 1 addition & 0 deletions i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"createwiki-label-requester": "Used as a label for 'requester'.\n{{Identical|Requester}}",
"createwiki-label-sitename": "Used as a label for 'sitename'.\n{{Identical|Sitename}}",
"createwiki-label-statuschangecomment": "Label for the comment field when changing the status of a wiki request.",
"createwiki-label-wiki-tags": "Used as a label for 'wiki tags'.",
"createwiki-no-changes": "Error message displayed when no changes have been made to the wiki request.",
"createwiki-request-locked": "Message indicating that the wiki request is locked and cannot be edited or commented on.",
"createwiki-request-updated": "Comment sent to the wiki request when it has been updated.",
Expand Down
14 changes: 14 additions & 0 deletions includes/RequestWiki/SpecialRequestWiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public function execute( $par ): void {

$this->checkPermissions();

$this->getOutput()->addModules( [ 'ext.createwiki.oouiform.wikiTags' ] );
$this->getOutput()->addJsConfigVars( [
'wgCreateWikiAvailableTags' => $this->getConfig()->get( ConfigNames::AvailableTags ),
] );

$form = $this->getForm();
if ( $form->show() ) {
$this->onSuccess();
Expand Down Expand Up @@ -100,6 +105,15 @@ protected function getFormFields(): array {
];
}

if ( $this->getConfig()->get( ConfigNames::AvailableTags ) {
$formDescriptor['wikitags'] = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when someone requests more than five tags?

'type' => 'text',
'label-message' => 'createwiki-label-wiki-tags',
'cssclass' => 'createwiki-wikitags',
'disabled' => true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be readonly => true, no? Or else it won't be sent with the form?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may be right. This still has a lot of work like also passing to cw_requests also

];
}

if ( $this->getConfig()->get( ConfigNames::UsePrivateWikis ) ) {
$formDescriptor['private'] = [
'type' => 'check',
Expand Down
38 changes: 38 additions & 0 deletions modules/ext.createwiki.oouiform.wikiTags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
( function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need two IIFEs?

$( function () {
var $fallbackLayout = $( '.createwiki-wikitags.oo-ui-layout' );
var $fallbackInput = $( '#mw-input-wpwikitags' );

var infusedFallbackLayout = OO.ui.infuse( $fallbackLayout );
var infusedFallbackInput = OO.ui.infuse( $fallbackInput );

infusedFallbackLayout.$element.css( 'display', 'none' );

var tags = [];
for ( var key in mw.config.get( 'wgCreateWikiAvailableTags' ) ) {
tags.push( {
data: key,
label: mw.config.get( 'wgCreateWikiAvailableTags' )[ key ]
} );
}

var multiTagSelect = new OO.ui.MenuTagMultiselectWidget( {
options: tags,
tagLimit: 5
} );

var multiTagSelectLayout = new OO.ui.FieldLayout( multiTagSelect, {
label: mw.msg( 'createwiki-label-wiki-tags' ),
align: 'top'
} );

multiTagSelect.on( 'change', function ( items ) {
// Map selection changes back to the fallback input so that it is included in form submit
infusedFallbackInput.setValue( items.map( function ( val ) {
return val.data;
} ).join( ',' ) );
} );

infusedFallbackLayout.$element.before( multiTagSelectLayout.$element );
} );
}() );
1 change: 1 addition & 0 deletions sql/cw_wikis.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CREATE TABLE /*_*/cw_wikis (
wiki_settings LONGTEXT NULL,
wiki_dbcluster VARCHAR(5) DEFAULT 'c1',
wiki_category VARCHAR(64) NOT NULL,
wiki_tags VARCHAR(128) NOT NULL DEFAULT '',
wiki_extensions MEDIUMTEXT NULL,
wiki_experimental TINYINT NOT NULL DEFAULT '0'
) /*$wgDBTableOptions*/;
Expand Down
2 changes: 2 additions & 0 deletions sql/patches/patch-cw_wikis-add-wiki_tags.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE /*$wgDBprefix*/cw_wikis
ADD COLUMN wiki_tags VARCHAR(128) NOT NULL DEFAULT '' AFTER wiki_category;
Loading