Page MenuHomePhabricator

Add "Create new item" link to property value drop-down menu (particularly when no item matches) in Wikidata
Open, LowPublic

Description

It would be really great in wikidata for there to be a "create new item" link in the dropdown menu for when you want to add an item to a property, but the item does not exist. The current workflow is to try to add an item, see it doesn't exist yet, navigate away from the page, and then create a new item, navigate back to the original page, and then add it.

(Even better would be if it were possible to create an item without leaving the page, i.e. create an item by name and then directly add it from the page, maybe in a pop-up. Then, presumably the user could go on to expand the newly created item.

The tool could even be extended to add citoid support for references by allowing users to add items as references this way, and attempt to use citoid to fill in some of the parameters. (T131661).

This project could start life as an on wiki Gadget and then later be added to the WikibaseRepository extension. )

Event Timeline

Mvolz created this task.Aug 2 2015, 11:09 AM
Mvolz updated the task description. (Show Details)
Mvolz raised the priority of this task from to Needs Triage.
Mvolz added a project: Wikidata.
Mvolz moved this task to incoming on the Wikidata board.
Mvolz added a subscriber: Mvolz.
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptAug 2 2015, 11:09 AM

It is duplicate of T51068, but that task was closed as declined a year ago.

Mvolz added a comment.Aug 3 2015, 7:27 AM

I thought it seemed obvious but couldn't find that, thanks. Looks like it
was closed as it should start life as a gadget, but no one ever made one?
Alas.
matej_suchanek added a subscriber: matej_suchanek.
matej_suchanek added a comment.

It is duplicate of https://phabricator.wikimedia.org/T51068, but that task
was closed as declined a year ago.

TASK DETAIL

https://phabricator.wikimedia.org/T107693

EMAIL PREFERENCES

https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: matej_suchanek
Cc: matej_suchanek, Aklapper, Mvolz, Wikidata-bugs, aude, Malyacko, P.Copp

daniel triaged this task as Low priority.Sep 10 2015, 3:45 PM
daniel added a subscriber: daniel.

Setting this to low. I'd personally love to have this feature, but there seems to be surprisingly little demand. And it could easily be implemented as a gadget.

Now that there is a text showing up during no results, it should be much easier to create a gadget. A link to a pre-filled Special:NewItem would do.

Restricted Application added a subscriber: PokestarFan. · View Herald TranscriptJul 25 2017, 8:14 AM
Aklapper added a subscriber: Ladsgroup.

@Ladsgroup: If you plan to mentor this in GCi2017, could you edit the task description and explain which exact odebase(s) this task is about? Thanks!

Mvolz updated the task description. (Show Details)Nov 25 2017, 11:06 PM
Mvolz renamed this task from Add "Create new item" link to property value drop-down menu (particularly when no item matches) to Add "Create new item" link to property value drop-down menu (particularly when no item matches) in Wikidata.
Mvolz updated the task description. (Show Details)Nov 25 2017, 11:12 PM
Mvolz updated the task description. (Show Details)

@Ladsgroup: If you plan to mentor this in GCi2017, could you edit the task description and explain which exact odebase(s) this task is about? Thanks!

Whoops, I misread that as GSoC and just expanded it to be more GSoC-y. It could *potentially* be a fairly involved project.

But just adding the link would be a great first step - but the discussion seems to be talking about making a gadget. If it's just the link, that seems like something simple that could be added directly to wikibase?

Mvolz updated the task description. (Show Details)Nov 25 2017, 11:16 PM

I am not convinced this is a beneficial change which is why I want this to be trialed as a gadget first.

@Ladsgroup: If you plan to mentor this in GCi2017, could you edit the task description and explain which exact odebase(s) this task is about? Thanks!

The codebase about this would be a user script (User:Foo/common.js) and they way to test it, would be to copy paste it in console. Is this enough?

I guess that this gadget will have to override _initMenu function in jquery.wikibase.entityselector.js and replace the null with the open new URL function?

customItems.unshift( new $.ui.ooMenu.CustomItem(
    this.options.messages.notfound,
    function () {
      return self._cache.suggestions && !self._cache.suggestions.length
        && self.element.val().trim() !== '';
    },
    null,
    'ui-entityselector-notfound'
  ) );

But I can't find how to do this with user script. Or is there any other easier method?

Mvolz added a comment.Dec 9 2017, 2:33 PM

You should be able to traverse the DOM with JS to insert it directly into
the menu. Try inspecting the element using your browser's debugger to see
where that would be.

I guess the hard part is when the script should be triggered; maybe on
typing in the box? And check every time to see if the list has no results
and then replace it?

(If nothing I'm typing is making sense please ask for clarification :))

eflyjason added a comment.EditedDec 9 2017, 2:58 PM

https://www.wikidata.org/wiki/User:Eflyjason/Gadget-CreateNewItem.js

var currentFieldText = "";
$(document).on('input propertychange paste', ".ui-suggester-input", function() {
	currentFieldText = $(this).val();
	//console.log("Entering: "+currentFieldText);
});
$(document).on('DOMSubtreeModified', ".ui-entityselector-list",function(){
	var firstLi = $(this).find("li").first();
	var isNotFound = firstLi.hasClass('ui-entityselector-notfound');
	console.log('Current Text Field content: '+currentFieldText+". Not found: "+isNotFound);
	if(isNotFound){
		var innerA = firstLi.find("a").first();
		innerA.attr("href", "https://www.wikidata.org/wiki/Special:NewItem?label="+currentFieldText).attr("target", "_blank");
	}
});

The basic feature should be working right now :D (though I'm not sure if it's the best approach?)

I will optimize it and make it into a popup later :D

Great so far! Is it possible to use OOjs UI for the popup though? We are slowly transforming our current gadgets to it. The form will automatically look correct as well then.

Mvolz added a comment.Dec 9 2017, 6:40 PM

Nice!

But I'm getting an error when trying to create an item from the pop-up

"[Wiws9wpAME0AABYAle0AAABL] 2017-12-09 18:35:51: Fatal exception of type "Wikimedia\Rdbms\DBQueryError"

Also it would be nice if there was some indication that you can click on the no results found link - like making a "create new item" link and have it be underlined, so people know it's clickable.

I don't want feature creep on this, honestly having the pop-up at all is great (even if it isn't OOUI) - it *is* supposed to be a small task!

eflyjason added a comment.EditedDec 10 2017, 3:31 AM

https://www.wikidata.org/w/index.php?title=User:Eflyjason/Gadget-CreateNewItem.js&oldid=606566480


Great so far! Is it possible to use OOjs UI for the popup though? We are slowly transforming our current gadgets to it. The form will automatically look correct as well then.

Updated with OOjs UI :D


Also it would be nice if there was some indication that you can click on the no results found link - like making a "create new item" link and have it be underlined, so people know it's clickable.

Added :)


But I'm getting an error when trying to create an item from the pop-up

"[Wiws9wpAME0AABYAle0AAABL] 2017-12-09 18:35:51: Fatal exception of type "Wikimedia\Rdbms\DBQueryError"

That's weird. I tested again and created entity successfully.


There are some problems related performance I think caused by DOMSubtreeModified. It would be nice if there are .on for detecting the list change directly.

"[Wiws9wpAME0AABYAle0AAABL] 2017-12-09 18:35:51: Fatal exception of type "Wikimedia\Rdbms\DBQueryError"

Looks like a temp. problem T182505.

I saw that the script also affects the property input field, I don't think that should be happening.

I saw that the script also affects the property input field, I don't think that should be happening.

Fixed :D

https://www.wikidata.org/w/index.php?title=User:Eflyjason/Gadget-CreateNewItem.js&oldid=606686398

Mvolz added a comment.Dec 10 2017, 6:18 PM

I saw that the script also affects the property input field, I don't think that should be happening.

Fixed :D

https://www.wikidata.org/w/index.php?title=User:Eflyjason/Gadget-CreateNewItem.js&oldid=606686398

Would you like to submit this work for review on the google code-in website? We can't approve it unless that is done :).

Would you like to submit this work for review on the google code-in website? We can't approve it unless that is done :).

Thank you! I've added it to https://www.wikidata.org/wiki/Wikidata:Tools/User_scripts#AddNewItem and also localized the script in Chinese. :D

srishakatux added a subscriber: srishakatux.

Removing the Possible-Tech-Projects tag as we are planning to kill it soon! This project does not seem to fit in the Outreach-Programs-Projects category in its current state, so I am not adding that tag right now!

It would be great if the script allowed to create a new item even if there are (irrelevant) results.