On May 22, 2008, at 9:38 AM, MinuteElectron wrote:
DanTMan wrote:
Tim Starling wrote:
Loading large amounts of code is slow and memory hungry, especially on installations without an opcode cache. So lazy-load your code, by putting everything into autoloaded classes. Use static member functions for hooks.
^_^ I've been creating classes with the name of my extension for awhile and putting all the hooks and extension functions into them and autoloading the class for awhile now. Heh, I just did it because it looked cleaner than using ugly efExtName functions, didn't know it was a design basic.
Of course, this loads the entire class -- even anything you might not need at that time; any extension functions you want in $wgExtensionFunctions could just be put in the global scope anyway since they are always going to be loaded regardless of what code path is chosen.
Being a self-taught amateur, I need an explanation of how to do this...is this what you mean?
Bad: one file: myExtension.php: $wgHooks[the hook][] = efMyExtension; function efMyExtension(){ lots of code ... }
Good: two or more files: 1) myExtension/includes/myExtension.php $wgHooks[the hook][] = efMyExtension; $wgAutoloadClasses['myExtensionClass'] = dirname(__FILE__).myExtensionClass.php;
function efMyExtension(params){ $foo = new myExtensionClass; $foo->execute(params) }
2) myExtension/class.myExtensionClass.php class myExtensionClass{ function __construct(){ } function execute(param){ lots of code } }
Jim
MinuteElectron.
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
===================================== Jim Hu Associate Professor Dept. of Biochemistry and Biophysics 2128 TAMU Texas A&M Univ. College Station, TX 77843-2128 979-862-4054