Sophivorus has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/366855 )
Change subject: Improve sort key handling
......................................................................
Improve sort key handling
Now the extension leaves the sort key empty rather than defaulting
to the current title, which avoids having to update the keys when
renaming a page.
Also add extension registration
Change-Id: Icd2e0e5f6c28543b9cbe37466b7a83b463c82d3c
---
M MsCatSelect.body.php
M MsCatSelect.js
M MsCatSelect.php
A extension.json
4 files changed, 119 insertions(+), 61 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MsCatSelect
refs/changes/55/366855/1
diff --git a/MsCatSelect.body.php b/MsCatSelect.body.php
index 940cf4b..ded8a97 100755
--- a/MsCatSelect.body.php
+++ b/MsCatSelect.body.php
@@ -9,12 +9,12 @@
$wgOut->addModules( 'ext.MsCatSelect' );
// Make the configuration variables available to JavaScript
- $mscsVars = array(
+ $mscsVars = [
'MainCategories' => $wgMSCS_MainCategories,
'UseNiceDropdown' => $wgMSCS_UseNiceDropdown,
'WarnNoCategories' => $wgMSCS_WarnNoCategories,
'WarnNoCategoriesException' => str_replace( ' ', '_',
$wgMSCS_WarnNoCategoriesException ),
- );
+ ];
$mscsVars = json_encode( $mscsVars, true );
$wgOut->addScript( "<script>var mscsVars = $mscsVars;</script>"
);
return true;
@@ -33,17 +33,11 @@
// Get localised namespace string
$categoryNamespace = $wgContLang->getNsText( NS_CATEGORY );
- // Default sort key is page name with stripped namespace name,
otherwise sorting is ugly
- if ( $editPage->getContextTitle()->getNamespace() == NS_MAIN ) {
- $default_sortkey = "";
- } else {
- $default_sortkey = "|{{PAGENAME}}";
- }
-
// Iterate through all selected category entries:
$text = "\n";
if ( array_key_exists( 'SelectCategoryList', $_POST ) ) {
foreach ( $_POST['SelectCategoryList'] as $category ) {
+ $category = rtrim( $category, '|' ); // If the
sort key is empty, remove it
$text .= "\n[[" . $categoryNamespace . ":" .
$category . "]]";
}
}
diff --git a/MsCatSelect.js b/MsCatSelect.js
index 7230404..4a525de 100755
--- a/MsCatSelect.js
+++ b/MsCatSelect.js
@@ -15,7 +15,7 @@
if ( data && data.query && data.query.querypage ) {
// Success!
jQuery.each( data.query.querypage.results, function(
index, val ) {
- jQuery( '<option/>', { value: index + 1, text:
val.value.replace( /_/g, ' ' ) } ).appendTo( dd );
+ jQuery( '<option>', { value: index + 1, text:
val.value.replace( /_/g, ' ' ) } ).appendTo( dd );
});
if ( chosenDropDown ) {
dd.chosen( { disableSearchThreshold: 6 } );
@@ -42,20 +42,20 @@
if ( data && data.query && data.query.categorymembers ) {
// Success!
if ( data.query.categorymembers.length > 0 ) {
- jQuery( '<div/>' ).attr( 'class', 'node'
).prependTo( container );
+ jQuery( '<div>' ).attr( 'class', 'node'
).prependTo( container );
var dd = mscsCreateDropDown( selectedCat, ebene
+ 1 ).appendTo( container );
- jQuery( '<div/>' ).attr( 'id', 'mscs_subcat_' +
( ebene + 1 ) ).attr( 'class', 'subcat' ).appendTo( container );
+ jQuery( '<div>' ).attr( 'id', 'mscs_subcat_' +
( ebene + 1 ) ).attr( 'class', 'subcat' ).appendTo( container );
jQuery.each( data.query.categorymembers,
function( index, val ) {
var listElement = val.title.split( ':',
2 );
- jQuery( '<option/>', { value: index +
1, text: listElement[1] } ).appendTo( dd );
+ jQuery( '<option>', { value: index + 1,
text: listElement[1] } ).appendTo( dd );
});
if ( chosenDropDown ) {
dd.chosen({ disableSearchThreshold: 6
});
jQuery( '#mscs_dd_' + ( ebene + 1 ) +
'_chzn' ).width( dd.width() + 20 );
}
} else { //no subcats
- jQuery( '<div/>' ).attr( 'class', 'no-node'
).prependTo( jQuery( '#mscs_subcat_' + ebene ) );
+ jQuery( '<div>' ).attr( 'class', 'no-node'
).prependTo( jQuery( '#mscs_subcat_' + ebene ) );
}
} else if ( data && data.error ) {
mediaWiki.log( 'Error: API returned error code "' +
data.error.code + '": ' + data.error.info );
@@ -66,7 +66,7 @@
}
function mscsCreateDropDown( maincat, ebene ) {
- var dd = jQuery( '<select/>' ).attr( 'id', 'mscs_dd_' + ebene ).change(
function () {
+ var dd = jQuery( '<select>' ).attr( 'id', 'mscs_dd_' + ebene ).change(
function () {
var container = jQuery( '#mscs_subcat_' + ebene ).empty();
if ( jQuery( this ).val() !== '0' ) { //not ---
@@ -79,49 +79,44 @@
}
});
- jQuery( '<option/>', { value: '0', text: '---' } ).appendTo( dd );
+ jQuery( '<option>', { value: '0', text: '---' } ).appendTo( dd );
if ( ebene === 0 && maincat === '' ) { //first dd
if ( mscsVars.MainCategories === null ) {
mscsGetUncategorizedCats( dd );
} else {
jQuery.each( mscsVars.MainCategories, function(
ddIndex, ddValue ) {
- jQuery( '<option/>', { value: ddIndex + 1,
text: ddValue } ).appendTo( dd );
+ jQuery( '<option>', { value: ddIndex + 1, text:
ddValue } ).appendTo( dd );
});
}
}
return dd;
}
-function mscsAddCat( newCat, newSortkey ) {
- if ( newCat !== '---' && jQuery( '#mscs-added .mscs_entry[category="' +
newCat + '"]' ).length === 0 ) {
+function mscsAddCat( category, sortkey ) {
+ if ( category !== '---' && jQuery( '#mscs-added .mscs_entry[category="'
+ category + '"]' ).length === 0 ) {
- if ( newSortkey === '' ) {
- newSortkey = wgTitle; // Standard sortkey is the page
title
- }
-
- var entry = jQuery( '<div/>' ).attr({
+ var entry = jQuery( '<div>' ).attr({
'class': 'mscs_entry',
- 'category': newCat,
- 'sortkey': newSortkey
- }).text( newCat ).appendTo( jQuery( '#mscs-added' ) );
+ 'category': category,
+ 'sortkey': sortkey
+ }).text( category ).appendTo( jQuery( '#mscs-added' ) );
- jQuery( '<input/>' ).attr({
+ var input = jQuery( '<input>' ).attr({
'class': 'mscs_checkbox',
'type': 'checkbox',
'name': 'SelectCategoryList[]',
- 'value': newCat + '|' + newSortkey,
+ 'value': category + '|' + sortkey,
'checked': true
- }).prependTo( entry );
+ }).prependTo( entry );
- jQuery( '<span/>' ).attr( 'class', 'img-sortkey' ).attr(
'title', newSortkey ).click( function() {
- var userInput = prompt( unescape( mediaWiki.msg(
'mscs-sortkey' ) ), jQuery( this ).attr( 'title' ) );
- if ( userInput !== '' && userInput !== null &&
userInput !== newSortkey ) {
- var sortkey = userInput;
- mediaWiki.log( sortkey );
- entry.attr( 'sortkey', sortkey );
- entry.children( '.mscs_checkbox' ).attr(
'value', newCat + '|' + sortkey );
- jQuery( this ).attr( 'title', sortkey );
+ jQuery( '<span>' ).attr( 'class', 'img-sortkey' ).attr(
'title', sortkey ).click( function () {
+ var oldSortkey = entry.attr( 'sortkey' );
+ var newSortkey = prompt( unescape( mediaWiki.msg(
'mscs-sortkey' ) ), oldSortkey );
+ if ( newSortkey !== null ) {
+ entry.attr( 'sortkey', newSortkey );
+ input.attr( 'value', category + '|' +
newSortkey );
+ jQuery( this ).attr( 'title', newSortkey );
}
}).appendTo( entry );
}
@@ -186,7 +181,7 @@
//mediaWiki.log( latestDropDown );
var ddNext = jQuery( '#mscs_dd_' + ( latestDropDown + 1
) );
- jQuery( '<option/>', { value: 99, text: createdCat[1] }
).appendTo( ddNext );
+ jQuery( '<option>', { value: 99, text: createdCat[1] }
).appendTo( ddNext );
jQuery( '#mscs_subcat_' + latestDropDown + ' .node'
).removeClass( 'no-node' );
if ( chosenDropDown ) {
ddNext.chosen(); //wenn dropdown noch nicht
existiert
@@ -207,13 +202,13 @@
function mscsCreateArea() {
- var mscsDiv = jQuery( '<div/>' ).attr( 'id', 'MsCatSelect'
).insertBefore( '.editButtons' );
+ var mscsDiv = jQuery( '<div>' ).attr( 'id', 'MsCatSelect'
).insertBefore( '.editButtons' );
- var row1 = jQuery( '<div/>' ).attr( 'class', 'row row1' ).appendTo(
mscsDiv );
- var row2 = jQuery( '<div/>' ).attr( 'class', 'row row2' ).appendTo(
mscsDiv );
- var row3 = jQuery( '<div/>' ).attr( 'class', 'row row3' ).appendTo(
mscsDiv );
+ var row1 = jQuery( '<div>' ).attr( 'class', 'row row1' ).appendTo(
mscsDiv );
+ var row2 = jQuery( '<div>' ).attr( 'class', 'row row2' ).appendTo(
mscsDiv );
+ var row3 = jQuery( '<div>' ).attr( 'class', 'row row3' ).appendTo(
mscsDiv );
- jQuery( '<span/>' ).attr( 'class','label maincat' ).text(
mediaWiki.msg( 'mscs-title' ) ).appendTo( row1 );
+ jQuery( '<span>' ).attr( 'class','label maincat' ).text( mediaWiki.msg(
'mscs-title' ) ).appendTo( row1 );
mscsCreateDropDown( '', 0 ).appendTo( row1 );
@@ -223,23 +218,23 @@
//jQuery( '.chzn-drop' ).css( 'width', '+=10' );
}
- jQuery( '<div/>' ).attr( 'id', 'mscs_subcat_0' ).attr( 'class',
'subcat' ).appendTo( row1 );
+ jQuery( '<div>' ).attr( 'id', 'mscs_subcat_0' ).attr( 'class', 'subcat'
).appendTo( row1 );
- jQuery( '<div/>' ).attr( 'id', 'mscs_add' ).attr( 'class', 'addcat'
).click( function() {
+ jQuery( '<div>' ).attr( 'id', 'mscs_add' ).attr( 'class', 'addcat'
).click( function() {
mscsAddCat( selectedCat, '' );
}).text( mediaWiki.msg( 'mscs-add' ) ).appendTo( row1 );
- jQuery( '<span/>' ).attr( 'class', 'label' ).text( mediaWiki.msg(
'mscs-untercat' ) ).appendTo( row2 );
- var newCatInput = jQuery( '<input/>' ).attr( 'class', 'input' ).attr(
'type', 'text' ).attr( 'id', 'newCatInput' ).attr( 'size', '30' ).appendTo(
row2 );
- jQuery( '<div/>' ).attr( 'id', 'mscs_add_untercat' ).attr( 'class',
'addcat' ).click( function() {
+ jQuery( '<span>' ).attr( 'class', 'label' ).text( mediaWiki.msg(
'mscs-untercat' ) ).appendTo( row2 );
+ var newCatInput = jQuery( '<input>' ).attr( 'class', 'input' ).attr(
'type', 'text' ).attr( 'id', 'newCatInput' ).attr( 'size', '30' ).appendTo(
row2 );
+ jQuery( '<div>' ).attr( 'id', 'mscs_add_untercat' ).attr( 'class',
'addcat' ).click( function() {
mscsCreateNewCat( newCatInput.val(), selectedCat );
}).text( mediaWiki.msg( 'mscs-go' ) ).appendTo( row2 );
- jQuery( '<span/>' ).attr( 'class', 'untercat-hinw' ).text( '(' +
mediaWiki.msg( 'mscs-untercat-hinw' ) + ')' ).appendTo( row2 );
- jQuery( '<span/>' ).attr( 'class', 'label' ).text( mediaWiki.msg(
'mscs-cats' ) ).appendTo( row3 );
- jQuery( '<div/>' ).attr( 'id', 'mscs-added' ).appendTo( row3 );
+ jQuery( '<span>' ).attr( 'class', 'untercat-hinw' ).text( '(' +
mediaWiki.msg( 'mscs-untercat-hinw' ) + ')' ).appendTo( row2 );
+ jQuery( '<span>' ).attr( 'class', 'label' ).text( mediaWiki.msg(
'mscs-cats' ) ).appendTo( row3 );
+ jQuery( '<div>' ).attr( 'id', 'mscs-added' ).appendTo( row3 );
mscsGetPageCats( mediaWiki.config.get( 'wgArticleId' ) );
}
diff --git a/MsCatSelect.php b/MsCatSelect.php
index d0e898e..06a1fb1 100755
--- a/MsCatSelect.php
+++ b/MsCatSelect.php
@@ -1,18 +1,22 @@
<?php
-$wgExtensionCredits['parserhook'][] = array(
+$wgExtensionCredits['parserhook'][] = [
'name' => 'MsCatSelect',
'url' => 'https://www.mediawiki.org/wiki/Extension:MsCatSelect',
- 'version' => '6.1',
+ 'version' => '6.2',
'descriptionmsg' => 'mscs-desc',
'license-name' => 'GPL-2.0+',
- 'author' => array( '[mailto:[email protected] Martin Schwindl]',
'[mailto:[email protected] Martin Keyler]',
'[https://www.mediawiki.org/wiki/User:Luis_Felipe_Schenone Luis Felipe
Schenone]' ),
-);
+ 'author' => [
+ '[mailto:[email protected] Martin Schwindl]',
+ '[mailto:[email protected] Martin Keyler]',
+ '[https://www.mediawiki.org/wiki/User:Sophivorus Felipe
Schenone]'
+ ],
+];
-$wgResourceModules['ext.MsCatSelect'] = array(
+$wgResourceModules['ext.MsCatSelect'] = [
'scripts' => 'MsCatSelect.js',
'styles' => 'MsCatSelect.css',
- 'messages' => array(
+ 'messages' => [
'mscs-title',
'mscs-untercat',
'mscs-untercat-hinw',
@@ -22,11 +26,11 @@
'mscs-go',
'mscs-created',
'mscs-sortkey'
- ),
+ ],
'dependencies' => 'jquery.chosen',
'localBasePath' => __DIR__,
'remoteExtPath' => 'MsCatSelect'
-);
+];
$wgExtensionMessagesFiles['MsCatSelect'] = __DIR__ . '/MsCatSelect.i18n.php';
$wgMessagesDirs['MsCatSelect'] = __DIR__ . '/i18n';
@@ -41,4 +45,4 @@
$wgMSCS_MainCategories = null;
$wgMSCS_UseNiceDropdown = true;
$wgMSCS_WarnNoCategories = true;
-$wgMSCS_WarnNoCategoriesException = array();
\ No newline at end of file
+$wgMSCS_WarnNoCategoriesException = [];
\ No newline at end of file
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..22ab12a
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,65 @@
+{
+ "name": "MsCatSelect",
+ "version": "6.2",
+ "author": [
+ "[mailto:[email protected] Martin Schwindl]",
+ "[mailto:[email protected] Martin Keyler]",
+ "[https://www.mediawiki.org/wiki/User:Sophivorus Felipe
Schenone]"
+ ],
+ "url": "https://www.mediawiki.org/wiki/Extension:MsCatSelect",
+ "descriptionmsg": "mscs-desc",
+ "license-name": "GPL-2.0+",
+ "type": "parserhook",
+ "MessagesDirs": {
+ "MsCatSelect": [
+ "i18n"
+ ]
+ },
+ "AutoloadClasses": {
+ "MsCatSelect": "MsCatSelect.body.php"
+ },
+ "ResourceModules": {
+ "ext.MsCatSelect": {
+ "scripts": "MsCatSelect.js",
+ "styles": "MsCatSelect.css",
+ "messages": [
+ "mscs-title",
+ "mscs-untercat",
+ "mscs-untercat-hinw",
+ "mscs-warnnocat",
+ "mscs-cats",
+ "mscs-add",
+ "mscs-go",
+ "mscs-created",
+ "mscs-sortkey"
+ ],
+ "dependencies": "jquery.chosen"
+ }
+ },
+ "ResourceFileModulePaths": {
+ "localBasePath": "",
+ "remoteExtPath": "MsCatSelect"
+ },
+ "Hooks": {
+ "EditPage::showEditForm:initial": [
+ "MsCatSelect::start",
+ "MsCatSelect::showHook"
+ ],
+ "EditPage::attemptSave": "MsCatSelect::saveHook"
+ },
+ "config": {
+ "MSCS_MainCategories": {
+ "value": null
+ },
+ "MSCS_UseNiceDropdown": {
+ "value": true
+ },
+ "MSCS_WarnNoCategories": {
+ "value": true
+ },
+ "MSCS_WarnNoCategoriesException": {
+ "value": []
+ }
+ },
+ "manifest_version": 2
+}
--
To view, visit https://gerrit.wikimedia.org/r/366855
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icd2e0e5f6c28543b9cbe37466b7a83b463c82d3c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MsCatSelect
Gerrit-Branch: master
Gerrit-Owner: Sophivorus <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits