WPAFC / afch

Yet another Articles for creation helper script -- ACTIVE DEVELOPMENT NO LONGER HAPPENS IN THIS REPOSITORY AND HAS MOVED TO
https://github.com/WPAFC/afch-rewrite
9 stars 3 forks source link

Integrate User:Ohconfucius/script/formatgeneral.js similar to AutoEd #47

Closed wikipedia-mabdul closed 10 years ago

wikipedia-mabdul commented 11 years ago

See my thread at https://en.wikipedia.org/wiki/User_talk:Ohconfucius#WP:AFCH_integration_of_formatgeneral - this can't be done at the moment until Ohconfucius changes a few bits in his script.

The integration is as simple as AutoEd's integration.

theopolisme commented 11 years ago

Since Ohconfucius hasn't changed the script, I went ahead and spent a few minutes just writing a little parser that will take the script contents, suck the regexes out of it, and perform the replacements on its own.

This feels quite hacky, however, and I'm not sure about integrating it into the production code...even though security-wise it's fine (since it assembles a regexp object and doesn't use eval()). Your thoughts, @wikipedia-mabdul?

// Run User:Ohconfucius/script/formatgeneral.js automatically... hacky
var text = '==External Links==\n kljdhsajdkjfj 2<sup>nd</sup>'; // this is for testing only
var formatgeneraltext = afcHelper_getPageText('User:Ohconfucius/script/formatgeneral.js');
regexes = /regex\(\/(.*?)(?:\s*\/([igm]*),\s*')(.*?)(?:'\s*\));/ig; // this is the way regexps are stored in the formatgeneral script
while (matchedexpression = regexes.exec(formatgeneraltext)) { // for each regexp in formatgeneral
    text = text.replace(new RegExp(matchedexpression[1],matchedexpression[2]),matchedexpression[3]); // parse it and create a new regexp object, then perform the replacement
}
wikipedia-mabdul commented 11 years ago

I have to think about it.

at least we should filter out the regex which are commented out, e.g. ''' // regex(/
/gi, '
'); ''' (this is commented out for a reason!)

wikipedia-mabdul commented 11 years ago

BTW: nice cherry pick ;-)

wikipedia-mabdul commented 11 years ago

we should also use /igm and detect the regex with ^and $ (see the other ticket)

wikipedia-mabdul commented 11 years ago

your regex can't work. where is matchedexpression[3](so the third bracket pair) in your regex?

I'm still not really shure if that is a good idea... maybe we should "improve" the script and do the coding for Ohconfucius and request either a editprotected or ask him politely to push our changes...

wikipedia-mabdul commented 11 years ago

this would be much faster (our Javascript) and cleaner and not that hackisch... YK

theopolisme commented 11 years ago

I agree with you completely...felt too hacky, even for me ;) Thing is, right now he's using some third party regex() function...but I guess it'd be pretty trivial to refactor it to do all the replacements and then drop them into the edit window.

(An aside: my regex does work, actually. :p Matched expression #3 is the third capture group... remember, .exec() returns an array where the first item ([0]) is the complete match.)

wikipedia-mabdul commented 11 years ago

regex(\/(.?)(?:\s\/([igm]),\s')(.?)(?:'\s)); (.?) --> group 1 ([igm]),\s') --> group 2 (.?) --> group 3

d'oh... yeah didn't recognized the second...

wikipedia-mabdul commented 11 years ago

ok, the code is rather easy to fix if you check the code. I will ask Ohconfucius after modifying a version for his userspace so that we could use a subpage by him and sharing the same code.

wikipedia-mabdul commented 11 years ago

see also thread at https://en.wikipedia.org/wiki/User_talk:Ohconfucius#formatgeneral - my first attempts were successful; so we might getting closer to include the cleanup scrip!

Nathan2055 commented 11 years ago

@theopolisme - Why did you reopen?

wikipedia-mabdul commented 11 years ago

see comment in 108: not in live version onwiki.

@theopolisme and @Technical-13 how to hanle autocloses by the AI as in this ticket? ^

theopolisme commented 11 years ago

@wikipedia-mabdul we have to sigh, smile, and reopen them. ;)

Technical-13 commented 11 years ago

There are autocloses? It's not offering two options? [close & submit] or [submit]? I always see two?

theopolisme commented 11 years ago

it autocloses when you merge a pull request.

Nathan2055 commented 11 years ago

I wish we could just close when it's fixed as opposed to waiting for it to be pushed. Pretty counter-intuitive...

Technical-13 commented 11 years ago

I realize that it is from our perspective, but it's the end user's perspective that is more important here. I've already said (many times over), to feel free to just comment, label, or milestone and I'll come through daily and sync each changed ticket up. :grinning:

Nathan2055 commented 11 years ago

@Technical-13 - I don't really understand why end users would be searching through here. Most of them refuse to even file their tickets on here. xD

theopolisme commented 10 years ago

NOT WORKING

@wikipedia-mabdul: your code did not work; are you sure importScriptURI() accepts a callback function...?

wikipedia-mabdul commented 10 years ago

I just recognized: we should better use: http://www.mediawiki.org/wiki/ResourceLoader/Default_modules#mediaWiki.loader

as importscriptURI is listed under http://www.mediawiki.org/wiki/ResourceLoader/JavaScript_Deprecations/list

I wonder, AUTOED is def. loading. why do you think that formatgeneral is not working? the code itself or the loading?

theopolisme commented 10 years ago

When I tested it last night, it appeared to be trying to use the original regex() function (and getting an error because it couldn't find the editbox), not the one that we redefined.

Technical-13 commented 10 years ago

tmp_download279826352

I'm not convinced that even autoEd is right. This is the only error I get when I try to subit a user's page or mark it as a draft on FF24 on my Android phone.

theopolisme commented 10 years ago

The scripts are probably being loaded asynchronously. We need a better way to do this -- mw.loader.using??

theopolisme commented 10 years ago

Consolidated: #197