Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Plugin hooks
« Reply #15, on November 12th, 2010, 02:41 PM »
Quote from Arantor on November 12th, 2010, 02:26 PM
To a point you're getting into the game of second-guessing the developer intent, and without any secondary information, it's hard to be sure.
I have a neat feeling that it can be considered a bug...
But really, it's hard to draw a line between power and security.
For instance, right now I'm in error_handler... Basically, adding a hook to output_error allows a plugin to get data on what error will be shown. However, it can't change anything in that -- whether it be the message or error level. It's pretty much useless, apart maybe for adding a message that says "The error below is normal, don't worry about it."
But if I give plugins the ability to change the error message, they can actually cancel the error itself. Can't they? For instance if I pass a reference to $file, and the plugin replaces it with 'Unknown', voilà, the function just returns without calling anything...
'Oh my'.
Quote
Remember, the integration functions were originally for linking SMF to a third party app, so reset_pass makes sense there, because what you're doing is when a user changes their password in SMF, you're flagging a routine in A.N.Other system to update the same user's password there too.

I'd argue in that case, there shouldn't be a need for the value to be byref. Other instances, however, yes it should be a byref, particularly if it seems logical for a third party app to want to modify something before SMF has its wicked way with it.
So... Where would you put the references, eh? :^^;:
Quote
We're sort of taking that idea and expanding on it, meaning that any original purpose is likely now somewhat irrelevant. For each hook, look at where it is, what local variables are applicable and make a judgement call as to whether it is reasonable and appropriate for third party code (of any kind) to be modifying that. reset_pass is one case it shouldn't be necessary, for example.
I'll let you think about it, too.
There are less than 70 hook calls all in all, so it shouldn't take too long. I'll just rename the hooks for now and I'll let you look into the params call by call if you have time.
Re: Plugin hooks
« Reply #16, on November 12th, 2010, 03:08 PM »
Hmm, I'm nearly done and it's overall okay because most of the calls don't really need to pass a reference. And many of them don't even pass any variables.

I'm just a bit bothered with my cleanup. Instead of having $modSettings['integrate_this_shit'], I now have $modSettings['hooks']['this_shit']. But I was pretty sure $modSettings entries could be arrays, and were serialized and unserialized at load/write time. Apparently, this isn't the case. I can fix that in updateSettings by adding a single is_array() followed by serialize, but is it useful or not? I think it's useful, because modders might find it useful to store arrays into $modSettings at load time, but... Well, I'm just not sure about that particular change.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Plugin hooks
« Reply #17, on November 12th, 2010, 03:46 PM »
There are instances where arrays are stored in $modSettings. None of them are consistent (e.g. the signature settings is a comma-separated value list, the censored words good/bad lists are newline-separated items, as are news items)

Storing an array is fine, but I personally wouldn't make it automatic, because you only have to unserialise it again later - and unless you're going to maintain a list of those things, you won't know what to unserialise en masse at the start.

Better would be to manage individual items yourself as and when.
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Plugin hooks
« Reply #18, on November 12th, 2010, 04:58 PM »
Quote from Arantor on November 12th, 2010, 03:46 PM
There are instances where arrays are stored in $modSettings. None of them are consistent (e.g. the signature settings is a comma-separated value list, the censored words good/bad lists are newline-separated items, as are news items)
Hmm... More afterthoughts, eh? ;)
Quote
Storing an array is fine, but I personally wouldn't make it automatic, because you only have to unserialise it again later - and unless you're going to maintain a list of those things, you won't know what to unserialise en masse at the start.
Yeah, all right, I just unserialize hooks from reloadSettings (in the precache code), and then I serialize them again in add_hook(). I'm making sure to save the hooks before calling updateSettings, because otherwise $modSettings['hooks'] would suddenly be serialized. (I suppose it's faster to save the value beforehand rather than unserializing it afterwards.)

Other issues: 'buffer', 'pre_include' are strange beasts... They're undocumented (except by you!), but they're pretty necessary, at least pre_include because without it, you can't call hooks within another file. (I'm considering adding the ability to specify an include file in the hook string... What do you think? It might lead to more include_once than necessary, though.)

Okay, I think I'm ready to commit... Too bad I don't have any hooks under the hand to test it, ahah!
Posted: November 12th, 2010, 04:57 PM

Also of note: $modSettings['integrate_magic_quotes'] is never used.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Plugin hooks
« Reply #19, on November 12th, 2010, 05:37 PM »
Neither is integrate_eggnog but hey, who's counting?

magic_quotes shouldn't really be needed though (only for those really weird CMSes that do strange mystic things when magic quotes is enabled)

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Plugin hooks
« Reply #20, on November 12th, 2010, 05:44 PM »
Quote from Arantor on November 12th, 2010, 05:37 PM
Neither is integrate_eggnog but hey, who's counting?
Except that 'integrate_magic_quotes' REALLY is tested against in the source code... :^^;:
Quote
magic_quotes shouldn't really be needed though (only for those really weird CMSes that do strange mystic things when magic quotes is enabled)
But from the name of it, it should be a hook, shouldn't it...? Well, it isn't. It's just a hidden setting that just happens to have the same name as a hook function. Uh.

Okay, I'm done, up to you now...
I'm reposting the changelog here for future readers' convenience, since the New Revs topic isn't public yet.

rev 252

* Renaming hook-related functions and variables. Integration functions become call/add/remove_hook for simplicity reasons. Hooks are renamed from $modSettings['integrate_something'] to $modSettings['hooks']['something'], and are now proper arrays. Finally, SMF_INTEGRATION_SETTINGS is renamed to WEDGE_HOOK_SETTINGS. So what? (index.php, Activate.php, Admin.php, Class-Editor.php, Errors.php, Load.php, LogInOut.php, ManageMembers.php, Profile-Actions.php, Profile-Modify.php, Profile.php, Register.php, Reminder.php, Security.php, Subs-Auth.php, Subs-Members.php, Subs-Post.php, Subs.php, Who.php, Display and MessageIndex templates)
* Made sure that the error message can be tampered with by the output_error hook. Otherwise, it's relatively useless. (Errors.php)
* Given that the outgoing_email hook has permission to tamper with e-mail data, personal_message and create_topic hooks should be able to play around with their data, too. Same with $data in the change_member_data hook in updateMemberData. (Subs.php, Subs-Post.php)
Posted: November 12th, 2010, 05:43 PM

Do you think 64KB (the max variable length (TEXT) in wedge_settings) will be enough to store all possible hooks...?
I think so, but what if a forum is modded to death...? I guess it'd stop functioning quickly, anyway. Hmm.
The only issue with my own implementation is that it requires unserializing all entries, while SMF's version explodes the strings only when needed. SMF's may be slightly faster, but I don't know if it's worth filling the settings table with hook names...

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Plugin hooks
« Reply #21, on November 12th, 2010, 05:49 PM »
Quote
Do you think 64KB (the max variable length (TEXT) in wedge_settings) will be enough to store all possible hooks...?
Hmm, good question. Not sure right now... need to think about that.

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Plugin hooks
« Reply #22, on November 12th, 2010, 05:57 PM »
Obviously I can simply store them again in $modSettings['hook_*'] or something, but it'd force me to go through the entire array to find these keys and unserialize them or something. Uh.

Anyway, to reach 64KB, you'd probably need to have about, hmm... a thousand hooks?
That would probably be a bad idea, eheh.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Plugin hooks
« Reply #23, on November 12th, 2010, 09:29 PM »
Don't forget the padding introduced by serialize'ing though, that adds a surprising amount of stuff.

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Plugin hooks
« Reply #24, on November 12th, 2010, 10:57 PM »
Well, I'd taken that into account...
Because I honestly doubt a hook function would take up to 64 characters ;)
More likely around 10 characters...

I chose serialize because it has a reputation for being extremely fast. (It may even be faster than an implode(',')... Haven't tested, though.)
Re: Plugin hooks
« Reply #25, on November 15th, 2010, 07:12 PM »
I'm not 100% happy with the add-on structure, "add-on = mod(ification) or plugin". (mod = source code modification, plugin = something that uses hooks.)
I'd like to discuss changing this to "mod (modULE) = hack or plugin". I think the word "hack" really represents what this would be. Modifying the source code can cause issues, and thus isn't very solid, and is just a plain hack.
"Module" would be fine because people would then say "mods", like they do right now. "Mods" as "modifications" doesn't go well with the plugin system, so I think "mods" as "modules" would be better.

What do you think?

(Sorry, couldn't find where we discussed all of this originally...)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Plugin hooks
« Reply #26, on November 15th, 2010, 11:28 PM »
It's a mindset problem. People think mods, they think of modifications under the hood. They won't see it as modules, no matter how hard we try. We need a clean break to be able to get away from that mentality.

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Plugin hooks
« Reply #27, on November 15th, 2010, 11:51 PM »
I'm just having a hard time with the hyphen in "add-on"... :P
Seriously, I always like "mods". Just wanted to get rid of "packages"...

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Plugin hooks
« Reply #28, on November 15th, 2010, 11:57 PM »
Could always actually call it plugins. Doesn't really matter, as long as it's a little different to be able to break the mindsets of old.

YogiBear

  • Great Britain's Eurovision result...arghhhh !!
  • Posts: 140
Re: Plugin hooks
« Reply #29, on November 16th, 2010, 12:16 AM »
Whatever is chosen someone somewhere will be asking what it means.

I like Modifications or Modules but for originality maybe Additions or Extras would be suitable ?