MyBB Community Forums

Full Version: [TEASER] Patches Plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
Released: http://community.mybb.com/thread-87413.html

Here's a new plugin I'm currently working on. It's not useable yet (not even as a beta), so this is just a teaser for you guys. Toungue

[attachment=14986][attachment=15116]

It adds a patch system to MyBB. While plugins add functionality to MyBB in a separate file, Patches modifies MyBB files directly. The exact modifications are described using patch files produced by GNU diff.

This isn't a replacement for plugins. Plugins are much more powerful and flexible, so you should use plugins whenever possible. However, there are some things that can't be easily done in plugins (because there's a bug, or there are no hooks, etc...). In such a case you have no choice but to modify MyBB files directly. In my own forum I have several such modifications, but keeping track of them is a pain, especially when updating MyBB to a new version.

To solve this problem, you make a patch file for each change, and apply or revert this patch as needed. Normally this is done with the GNU patch utility in Linux, but I thought it would be nice to have this functionality directly in MyBB.

This plugin will be Open Source (GPL), as will be the patches themselves - since the MyBB files are pretty much all GPL, modifications to those files must be GPL too.



Current development status:
- Original diff/patch approach CANCELLED
- New approach using PluginLibrary's core_edit()



https://github.com/frostschutz/Patches
This is epic/
So you're saying you can basically edit core files, and then unedit them with a click of a button?

If so...awesome.
That's the general idea. Instead of instructions like these you could make a patch file for it which would look like this (generated by the GNU diff program):

diff -Naur mybb-original/inc/class_parser.php mybb-nofollow/inc/class_parser.php
--- mybb-original/inc/class_parser.php	2009-06-26 06:22:11.000000000 +0200
+++ mybb-nofollow/inc/class_parser.php	2009-08-08 20:47:41.119194600 +0200
@@ -857,3 +857,3 @@
 		$name = preg_replace("#&\#([0-9]+);#si", "&#$1;", $name); // Fix & but allow unicode
-		$link = "<a href=\"$fullurl\" target=\"_blank\">$name</a>";
+		$link = "<a href=\"$fullurl\" target=\"_blank\" rel=\"nofollow\">$name</a>";
 		return $link;

Then you share this patch with others (like how you share plugins) and with the Patches plugin you can apply the change with a click, and if you don't like it revert it with a click too (like how you enable and disable plugins), and if you overwrite the file by accident (during a MyBB upgrade) you can just apply it again to get the change back into the file.

You can already do this without a plugin, if you don't mind editing files or if you know how to use the diff and patch utils and don't mind downloading and uploading the files with FTP; the plugin though works directly with the files on the server.
This is an amazing idea to me - after every mybb maintenance release, some core files need to be edited mannually again and again

myBB Google SEO plugin is 1 great reason to use this
I did something similar with Advanced Modules for MyPlaza. The main issue is that the system needs some way to edit the files (either by requiring the files to be editable by the PHP process, or through some sort of FTP system).
I didn't use patch files however.

Nice work Toungue
Amazing! Great contribution, thank you.

What if MyBB makes important changes to the same lines of code which were patched?
Don't admins still need to be careful to compare freshly modified files with the original and patched ones?

Am I making this overly complex?
Your solution seems "too good to be true."

Is this (basically) correct?
"The patches plugin will make it much easier to modify and revert core files. It will still be important to check if patches are conflicting with (or over-writing) new releases and security updates."

##
Edit: I just need to learn the proper "work flow".

1) Revert custom changes
2) Upgrade to new version of MyBB
3) Re-apply custom patches.

Is that correct? Smile
(2009-08-09, 02:46 AM)seeker Wrote: [ -> ]Amazing! Great contribution, thank you.

What if MyBB makes important changes to the same lines of code which were patched?
Don't admins still need to be careful to compare freshly modified files with the original and patched ones?

Am I making this overly complex?
Your solution seems "too good to be true."

Is this (basically) correct?
"The patches plugin will make it much easier to modify and revert core files. It will still be important to check if patches are conflicting with (or over-writing) new releases and security updates."

##
Edit: I just need to learn the proper "work flow".

1) Revert custom changes
2) Upgrade to new version of MyBB
3) Re-apply custom patches.

Is that correct? Smile

Assuming no code additions in the new file will mess up the line locations for where the patch adds/edits, you're correct.
^^^
OK, I'm catching on, thanks.
This plugin will be a wonderful new tool.
(2009-08-09, 01:18 AM)Yumi Wrote: [ -> ]The main issue is that the system needs some way to edit the files (either by requiring the files to be editable by the PHP process, or through some sort of FTP system).

There'll be two options; either you (permanently or temporarily) chmod the files to be writable and it will modify them directly; or, if write permissions are missing, or if you have security concerns about chmoding files, it will instead generate a downloadable archive (zip file or similar) with the changed files in it which you can then upload yourself.

The FTP system is the worst choice security wise (if the FTP password is stored somewhere - and then obtained by a hacker) and stability wise as FTP is not reliable enough as a protocol. Without a proper FTP client, which handles advanced stuff like automatic reconnects, retrys, resends etc., messing with MyBB core files over FTP is just asking for forum breakage.

(2009-08-09, 02:46 AM)seeker Wrote: [ -> ]What if MyBB makes important changes to the same lines of code which were patched?

In this case the patch will no longer apply and a new patch will have to be made.

Patches can conflict on a line by line basis. However that's still the best system out there (all version control systems like CVS, SVN, Git, etc. use patches to keep track of file changes), and way better than a file by file conflict (e.g. the Google SEO Plugin comes with a ready to use inc/functions.php which has the modifications for Google SEO in it - but that does not help you if you want to have other modifications in your functions.php as well).

(2009-08-09, 02:46 AM)seeker Wrote: [ -> ]Don't admins still need to be careful to compare freshly modified files with the original and patched ones?

The plugin will try to keep track of the changes and check if the modifications made by the Patches are still in place. Actually this keeping track business will be by far the most complicated part of the plugin; this functionality may come only later and not be present in an early beta (which I'm planning to release as soon as the system is able to apply and revert patches).

For upgrading, as long as the MyBB upgrade changes only code, not graphics or other binary files, you could even use an alternate upgrading method... by just applying the MyBB 1.4.8 to 1.4.9 patch...
Pages: 1 2 3 4 5