Page MenuHomePhabricator

$wgSelectCategoryRoot ignored on Special:Upload
Closed, ResolvedPublic

Description

I'm using SelectCategory with:

$wgSelectCategoryRoot = array(

NS_MEDIA                => false, # NS_MEDIA = -2
NS_MAIN                 => "Gartenbau",
NS_TALK                 => false,
NS_USER                 => false,
NS_USER_TALK            => false,
NS_PROJECT              => "Hortipendium",
NS_PROJECT_TALK         => false,
NS_IMAGE                => "Bilder",
NS_IMAGE_TALK           => false,
NS_MEDIAWIKI            => false,
NS_MEDIAWIKI_TALK       => false,
NS_TEMPLATE             => false,
NS_TEMPLATE_TALK        => false,
NS_HELP                 => "Hortipendium",
NS_HELP_TALK            => false,
NS_CATEGORY             => false, # alle
NS_CATEGORY_TALK        => false,
NS_PORTAL               => "Portal",
NS_PORTAL_TALK          => false,

);

This works on editing pages and images, but does not work when uploading images on Special:Upload or, in my case, the german version of it (Spezial:Hochladen). On the upload page, SelectCategory offers _all_ categories.

I'm using SelectCategory from SVN, 1.16 branch, r71217.

According to one of my users it worked before I updated Mediawiki from 1.15 to 1.16 (with SelectCategory from 1.15 branch, r66002). However, I don't see a relevant code change in SelectCategory - maybe the behaviour of Mediawiki changed?


Version: unspecified
Severity: normal

Details

Reference
bz24911

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:04 PM
bzimport set Reference to bz24911.

I just added some debugging code in fnSelectCategoryGetAllCategories after $wgTitle->getNamespace to print out the result.

Results (Mediawiki 1.16):

  • Special:Upload: $m_namespace = -1
  • Edit a File:* page: $m_namespace = 6

That explains it ;-) and makes the fix quite easy - if we are on the upload page, hardcode $m_namespace to NS_IMAGE. I'll attach a patch in a minute.

Created attachment 7646
patch: honor $wgSelectCategoryRoot on Special:Upload

attachment SelectCategory_upload.diff ignored as obsolete

This is indeed caused by a change in MediaWiki. You'll need to edit a MediaWiki core file if you need CategorySelect on upload - see bug 25833 for details.

When done, you have to do a small additional change in SelectCategoryFunctions.php that is not covered by the patch from comment #2:

  • SelectCategoryFunctions.php (Revision 71464)

+++ SelectCategoryFunctions.php (Arbeitskopie)
@@ -125,6 +125,7 @@

  1. If it is an upload we have to call a different method: if ( $m_isUpload ) { $m_pageObj->mUploadDescription .= $m_text;

+ $m_pageObj->mComment .= $m_text;

  $m_pageObj->textbox1 .= $m_text;
}

Maybe you can remove the line with mUploadDescription. However I didn't test that and want to be on the save side (and backward compatible) for now. Additionally, I requested to revert the name change back to mUploadComment in bug 25833 ;-)

*Bulk BZ Change: +Patch to open bugs with patches attached that are missing the keyword*

sumanah wrote:

Adding "need-review" keyword to indicate patch awaits review. I'm sorry for the wait, Christian.

Mark, can you please check this patch and commit it to SVN?

Please check the new version of SelectCategory. As of last June, there is no SelectCategoryFunctions.php and it looks like changes similar to the one you suggest has been made.

Unfortunately the new version (current SVN) still has this bug :-(

The problem is this line:

$allCats = self::getAllCategories( $isUpload ? NS_SPECIAL : $pageObj->mTitle->getNamespace() );

For Special:Upload ($isUpload), NS_IMAGE instead of NS_SPECIAL namespace should be used.

Reason:
With NS_IMAGE, SelectCategory will use the root category for the File: namespace
With NS_SPECIAL, it will display _all_ categories - which doesn't make sense for file uploads

I'll attach an updated one-line patch for current SVN that fixes the issue.

Created attachment 10845
patch (for current SVN version) to honor $wgSelectCategoryRoot on Special:Upload

Attached:

sumanah wrote:

Daniel, looks like you were the last one to work with this extension; could you look at this patch? Thanks.

I know nothing about SelectCategory. I looked at it briefly together with Daniel Werner during the last triage. I think we concluded that the extension is unmaintained and probably not worth the hassle.

sumanah wrote:

Am cc'ing Manuel Schneider who is listed as one of the authors at https://www.mediawiki.org/wiki/Extension:SelectCategory . Manuel, are you maintaining this extension? If not, perhaps we should encourage Christian to start maintaining it?

I also suggest we move the extension into Git/Gerrit. Christian, you can use https://www.mediawiki.org/wiki/Git/Conversion/Extensions_queue to request that.

I am still around and I use this extension on many wikis, as do some of my customers.
As this is just my hobby I haven't put much time in it after the initial development.

If Christian is willing to maintain or if anyone wants to merge her or his patches I would be very happy. That stuff is open source and I made it because someone needed such a feature and I shared it with everyone so everyone can use and improve it.

sumanah wrote:

Christian, sounds like you should request Subversion access to extensions via https://www.mediawiki.org/wiki/Developer_access/Subversion#Requesting_commit_access and start merging your own patches in. I also recommend that you move the extension into Git since the Wikimedia Subversion server is on its way out: https://www.mediawiki.org/wiki/Git/Conversion

I was afraid of that offer ;-)

My situation is similar to Manuel's - I'm using the extension on a customer wiki, and my patches are bugfixes requested by that customer. Besides that, SelectCategory just works[tm], and I'm not planning to do big changes on it.

I'm not sure if getting a handful of patches in is worth the hassle of creating an account, and as I said, I can't and won't promise to do anything besides commiting my own patches.

If you still think I should request an account, I'll do it. Otherwise just commit my patches ;-)

I finally have commit access since some days, and just commited the fix to git.

sumanah wrote:

Great! Can you link to the patchset in a BZ comment, just so we have the record? Thank you!