Skip to content
This repository has been archived by the owner on Feb 4, 2021. It is now read-only.

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

Closed
wikipedia-mabdul opened this issue Jul 14, 2013 · 24 comments
Closed

Comments

@wikipedia-mabdul
Copy link
Member

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
Copy link
Contributor

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
Copy link
Member Author

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
Copy link
Member Author

BTW: nice cherry pick ;-)

@wikipedia-mabdul
Copy link
Member Author

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

@wikipedia-mabdul
Copy link
Member Author

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
Copy link
Member Author

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

@theopolisme
Copy link
Contributor

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
Copy link
Member Author

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

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

@wikipedia-mabdul
Copy link
Member Author

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
Copy link
Member Author

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 pushed a commit that referenced this issue Sep 9, 2013
@theopolisme theopolisme reopened this Sep 11, 2013
@Nathan2055
Copy link
Member

@theopolisme - Why did you reopen?

@wikipedia-mabdul
Copy link
Member Author

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
Copy link
Contributor

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

@Technical-13
Copy link
Contributor

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

@theopolisme
Copy link
Contributor

it autocloses when you merge a pull request.

@Nathan2055
Copy link
Member

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

@Technical-13
Copy link
Contributor

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. 😀

@Nathan2055
Copy link
Member

@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
Copy link
Contributor

NOT WORKING

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

@wikipedia-mabdul
Copy link
Member Author

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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

@theopolisme
Copy link
Contributor

Consolidated: #197

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants