Page MenuHomePhabricator

'file' HTMLForm inputs don't process required=>true correctly
Closed, ResolvedPublicBUG REPORT

Description

This is pretty minor since files are very rarely used. Presumably it gets confused because the normal value of the file doesn't really exist.

Steps to replicate the issue (include links if applicable):

  • Create an HTMLForm where one of the fields have [ type=>'file', 'required' => true]
  • Submit the form including the file

What happens?:
Error about file not being present even though it is.

What should have happened instead?:

  • It should think the required requirement is satisified

Software version (skip for WMF-hosted wikis like Wikipedia):

current master (1.40)

What needs to be done
Probably override HTMLFileField::validate method to check required differently (e.g. get the Upload value from WebRequest, and check it is really there instead of doing what the parent is).

Alternatively, maybe the data for the field should not be null.

Event Timeline

hello @Bawolff I want to work on this issue as I am new to open source can you guide me in the right direction on how to get started and set up locally

Hi @Aklapper thanks for mentioning the resource I have successfully setup everything git Gerrit but I wanted to know how can I started working on this issue

Hi. How familiar are you with PHP currently?

The first step I would suggest, is for you to find a way to reproduce the bug (You can't be sure you fixed it if you can't test it). You could modify one of MW core's special pages to add a file upload form field marked required => true, just for testing purposes. You could do it by modifying one of Core's FormSpecialPage (E.g. Special:RandomInCategory - includes/specials/SpecialRandomInCategory ) to add an entry to the value returned from getFormFields for the file control. e.g. you would add a form field descriptor to thereturned array like:

'myfield' => [
    'type'=> 'file',
    'label' => 'File upload',
    'required' => true
]

You could verify that going to the special page, it now has a field where you can upload a file. And then verify the bug is present. e.g. Try to submit the form even with uploading a file, note that you still get an error.

Once you've verified that you can reproduce the bug, you should try to fix it.

The file you have to modify is includes/htmlform/fields/HTMLFileField.php . Currently it uses its parent class to do validation - the validate() method of HTMLFormField ( includes/htmlform/HTMLFormField.php ). You have to override that method to do the same thing as the parent class does, but tweaked to make sure the "required" processing works correctly.

CBID2 subscribed.
This comment was removed by CBID2.

Hi CBID2. Looks like Hashraf743 is already working on this one, but there are lots of others to choose from.

ask.png (873×2 px, 315 KB)

hi @Bawolff @Aklapper I am facing difficulty in this step I have successfully installed and setup the apache but in my directory there is no uploaded folder can you please steps down some simpler steps to do .
OS : Macos Ventura

OR can I directly installed MAMP?

Hi, you can use MAMP if you want to.

I'm not super familiar with MAMP, but i believe it works by creatings "sites", which you can configure a document root for. Often the document root is somewhere in a Sites directory.

Anyways, if you are using MAMP, you have to figure out what directory the document root is. You have to go to that directory and clone mediawiki into it. You can follow the directions at https://www.mediawiki.org/wiki/Download_from_Git#Download_for_development but to reiterate:

  • Setup a developer account at wikitech along with setting up your ssh key.
  • Open terminal.app
  • Change directory to the document root setup with MAMP
  • Run git clone ssh://<USERNAME>@gerrit.wikimedia.org:29418/mediawiki/core.git mediawiki replacing <USERNAME> with the shell name setup with your developer account. I am assuming you already have git installed. If not you may have to install it.
  • change into the mediawiki directory that was just created
  • Install composer
  • run composer install
  • In your web browser, go to http://localhost/mediawiki if everything worked right, you should be prompted with a welcome screen
  • follow installation steps on the screen.

@Hashraf743 Hi, please see https://www.mediawiki.org/wiki/New_Developers where to bring up general development questions unrelated to the task itself. Thanks!

main.png (1×2 px, 1 MB)

hello @Bawolff @Aklapper I have made all the changes suggested by you now I am encountering this error so can you further assist me in solving the particular error I am trying hard to learn PHP and related work

That looks like an error from the special page you are using as the base of your test and not the part you are testing/experimenting with.

See also https://www.mediawiki.org/wiki/Help:RandomInCategory and https://www.mediawiki.org/wiki/Help:Categories

hi @Bawolff can you explain a lit bit more about where can I make the changes suggested by you and also how I can understand the code hierarchy of Wikimedia

@Hashraf743: Again: Please do read and follow T327007#8539544, as Phabricator is not a support forum for coding. Thanks for your understanding.

Just wanted to mention that there are some wikifarms for which this functionality is quite important and an extension that is currently broken as a result.

Since the user assigned has not worked on this for around 9 months I think it's fair to unassign in case some else wants to work on it.

an extension that is currently broken as a result.

Which extension? I can't reproduce the issue

ImportDump is one that uses it, it's completely broken on 1.40+

When was the last time that extension worked? I didn't think this was a new bug

It worked prior to upgrading to MediaWiki 1.40. It worked a few days ago on Miraheze prior to the upgrade to 1.40 and it worked fine on WikiTide too until they upgraded.

Looks like this is caused by https://github.com/wikimedia/mediawiki/commit/2b0b187bae8a42b4dca68a446ba5050bb7de6c50. Default value if not set is a null per getDefault(). Using 'default' => 'File' seemed to fix it but feel like it's a hack.

Change 981660 had a related patch set uploaded (by Ammarpad; author: Ammarpad):

[mediawiki/core@master] htmlform: Correct validation for file input field

https://gerrit.wikimedia.org/r/981660

Change 981660 merged by jenkins-bot:

[mediawiki/core@master] htmlform: Correct validation for file input field

https://gerrit.wikimedia.org/r/981660

Change 983743 had a related patch set uploaded (by Paladox; author: Ammarpad):

[mediawiki/core@REL1_41] htmlform: Correct validation for file input field

https://gerrit.wikimedia.org/r/983743

Change 983744 had a related patch set uploaded (by Paladox; author: Ammarpad):

[mediawiki/core@REL1_40] htmlform: Correct validation for file input field

https://gerrit.wikimedia.org/r/983744

Change 983743 merged by jenkins-bot:

[mediawiki/core@REL1_41] htmlform: Correct validation for file input field

https://gerrit.wikimedia.org/r/983743

Change 983744 merged by jenkins-bot:

[mediawiki/core@REL1_40] htmlform: Correct validation for file input field

https://gerrit.wikimedia.org/r/983744