Integrating MediaWiki With CakePHP

Hi Folks. As you might have guessed from the title, I was up trying to integrate MediaWiki with a CakePHP application of mine. Yeah, all hell did break loose while I was at it. As naive as it may sound, I was dreaming something like an API bridge between the MediaWiki and CakePHP. But like I said, it was a dream, and as the notion suggests, "so you wanna build an API bridge between MediaWiki and CakePHP in one night ?" - "DREAM ON SUCKER !" because you'll never find the time and the nerve to do it ... doh !

May be some day, if no one beats me to it, I'd get that bridge up and running. But till then let me explain a nifty way of doing this.

Your best chance to include a MediaWiki with your CakePHP application is via some RewriteRule magic in your .htaccess file. You simply need to specify which URL you want to be pointed to your wiki application. In my case, I simply wanted all http://mysite.com/wiki/ requests to map to /doc-root/wiki instead of /doc-root/app.

I usually don't keep the App folder type of structure in my CakePHP apps but this particular application was an exception. The concept is to:

"read the URL you want pointing to the MediaWiki and change your document root to the folder where you are keeping the MediaWiki"

Now, here is the file structure of my the application I was working on:

  • / < app_name >
    • / branches
      • / sohaib
        • / app
        • .htaccess
      • / wiki
        • index.php
        • .htaccess
        • ....

Say, like me, you want to get all URLs with "/wiki" to be directed to the MediaWiki app, then a small change you'll make int the .htaccess file highlighted in red above would be:


RewriteEngine on
RewriteRule ^(.*)/wiki/(.*) wiki/ [NC]
RewriteRule ^(.*)/wiki/(.*) wiki/$1 [NC]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]

This tells Apache to first look for URLs containing /wiki - and redirect these to to the /sohaib/wiki folder where another .htaccess file awaits the request (highlighted in green above). This file is identical to the one you can find in /webroot folder of your app. You can copy paste this file to your wiki folder.


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

This connects your /wiki requests to the index.php file of your media wiki. And thats it as non-technical as I could be in trying to explain what you can do. I am not going into the exaplaination of the code in the .htaccess files. You'd be able to find good resources via google. But if you're like me, you'll settle for the documentation on mod_rewrite on Apache.org

But let me tell you, this is a very simple demonstration of what you can achieve with mod_rewrite ... this thing is COMPLEX and way too much voodoo, especially when regular expressions come into play. So be careful, it's addictive :P - Hope this helps anyone out there trying to integrate a MediaWiki with their App. Over and OUT !

Free WordPress Themes by WooThemes

I just changed my blog theme to a really cool theme by WooThemes. At last ! I've found a decent theme and got rid of the all-black look I was using to protest my procrastination. At least this one has a simple and fresh look. So these are the downsides of not being a designer. But I find it odd some times. Though I don't design but do I have an eye for it. Wonder which category I'd fall into ? - Some kind of warp zone between a design itself and a designer ... huh ?

I've gotta say, these guys have some really excellent themes. They are giving away some themes for free, I suggest you try em ! ... these guys got talent :P - And also check out thier premium themes, they're really worth it. Hope you like em'

Here is a list of the free themes as of Thursday, April 16th, 2009:

Irresistable

irresistable

Blog Theme

blog-theme

Snapshot

snapshot

The Premium News

the-premium-news

Typebased

typebased

Technorati Profile

Wall Street And Auto Industry by Calvin & Hobbs

So I received an email from a friend explaining the plight of Wall street and the auto industry in a nutshell by Calvin and Hobbs. And this was published about 15 years ago !

calvin-n-hobbs

Why Avoid The “else” Construct ?

Till now I have seen a fair amount of code, the good, the bad and o yes! the ugly and the really really ugly. Ok, so you are a programmer, what makes you think a chunk of code is "good" or "bad" ? - I haven't had the opportunity to discuss this with fellow programmers in detail, so I think the best way to air this would be to document this.

First thing that comes to my mind about good code is READABILITY ... it's imperative the code should be readable and understandable. This however, is automatically achieved when you follow the most optimum way of execution and is even prettier in OOP. Structured code provokes ugliness. And I have noticed that the code gets uglier when there are more and more if-elseif-else construct nesting. I have seen programmers abusing this construct a lot ! You are better off using a SWITCH-CASE construct (which should also be used if and only if necessary).

I know you must be thinking: So what's up with the "else" construct ? and what does this guy have against it ? - Well, in all honesty, I don't have anything against it. It's just that the "else" construct refrains me to write beatiful code :P - Ask yourself, why would you need a lot of else statements anyways ? (do keep in mind that for menu choices you always have the good 'ol switch-case). This may not hold true when you are executing via the structured approach. When using OOP, it just doesn't make much sense. Of course, a simple "if-else" is ok as its simple and readable too. But when you are dwelling into if-elseif { if - else }-else { if - else } it becomes more complex and consequently turns into a nightmare. Imagine yourself trying to debug a 100 lines of code out which at least 40 are consumed by the nested "if" construct. Hehe, I know ! - It scares me too :)

So what does it mean when you have used nested "if-elseif-else" structure a one too many times ? I answer this based on my own code more than a year ago. It means:

1. You are not breaking down problems into smaller chunks, that's for sure! - consequently you have become that greedy Ostrich who swallowed the whole freshly baked potato! so obviously the aftermath is the same. You jump, cry and get frustrated when you need to refactor the code or even worst, debug it.

2. Poor design ! - Yes ! poor design ! I don't care if you agree with me here or not, but you don't have a robust and scalable design before you put your cowboy hat on and went riding that keyboard. You did not think twice before coding. The rationale goes like this: An "if-else" construct denotes a change in variables and you address that change by changing the execution flow. Making the right decisions when a change occurrs. In an OO way, that variable change denotes a "state" change. So you do what you should according to that particular state. Similar to your reactions based on your emotional state,

Happy => Smile || Laugh

, Angry => Frown || Break something || Punch someone

, Sad => Cry || Whiskey++

In OO you can actually encapsulate execution as behaviors according to the change in state. As a result, you design is robust and scalable. All you need to do is invoke the right behavior for the right state. For that you'd probably need a simple IF statement.

3. Obviously either you haven't heard or you aren't interested in the philosophy behind "return home early" - a term coined by Felix from debuggable.com - READ IT as it addresses programming psychology you might make use of.

Doh ! I've run out of time. I'm going to try to put some code slides up. You look at the code and decide for youself.

The Grunts And Groans Of Working From Home

Before starting with me grunts and groans here’s a little note:

To all those who don't have experience of “working from home” try to turn off your judgments while you read. It's a classic example of “you don't know how it's like”. And those who fancy this way of doing business well guess what? you still don’t get to be a slacker.

First off, being human, we have to socialize in some way. For most of us, just having 100+ friends on facebook or any other social network is appealing, but not the real thing. Socializing becomes a challenge when working from home amidst many others. This is the biggest challenge what I have experienced so far, and overcame it too (this part would require a separate post :P). Thank god I don't work alone now. But still, one could rot if one does not step out of the house so very often. To counter this, surely you’d socialize on all those social networks out there, but to get the real thing, here is what I had found useful:

  • - Spend some good 30 minutes outside (and this is for the worst of the introverts out there, it should be an hour or so – no offence). Take a stroll in a park / peaceful place or join a gym. Some fresh air won’t kill ya! But staying inside surrounded by 4 walls will definitely do some damage to your brain.
  • - Try to network up with people who are in the same line of business as you are. And meet up!
  • - Keep an eye out for different events happening out there that are even mildly related to your industry. Try to show up on those. Trust me you’ll feel great when you meet the alike. And probably the best way to do that would be to join a local community.  Finally! You might be able to put all those social networking apps to the right use :P – I’m sure you’d be able to find your local user group through these networks.

Apart of the social issue, here comes another. People don’t tend to take you seriously when you tell them you work from home. This can be frustrating at times. People are still getting used to the idea and some just reject it. This is especially true for countries like Pakistan and I’m sure India’s in the list too. Like many other countries, we both have a family oriented environment and mostly I find people “branding” themselves based on the companies they work in a one too many times. So after having a couple of these experiences, the idea came like a lightning bolt! Yup ! get yourself a business card!, just shrink the “what you do part” in a single understandable phrase. For instance, I use “Software Engineer” that works for me. The funny part is, I’ve experienced that people don’t really understand the “software” part :P they just calm down when they hear “engineer”, which is actually really cool as I’m always giggling when witnessing this. Ah! On the other hand, this always makes me wonder when the hell we are going to get out of this entire stereo-typical behavioral pattern.
The third evil is keeping loose work timings. This can be cancerous to your work! – seriously! Some people may not realize this until after they find themselves in the middle of a crisis. And I had to find this the hard way … doh ! You have to separate your work timings. Sure sure, you must be thinking I didn’t choose to work from home just so that I work strict timings. Unfortunately, to keep professionalism, discipline is important. Can’t say this for sure about designers and the more creative kind but I can say this certainly for programmers. Although, you might be one of those people who are most creative during specific times of day, then you should time yourself according to that. You see this is where working from home comes in handy. You can choose your own timings.
A few things can help you achieve discipline. You can start off by creating a separate email, IM and phone for your work. It’d be easier to discipline your work this way. Although here I would have to admit that I haven’t been able to implement that yet, but keeping in view my plans, I might not need to. Trust me, it’s really important to keep your private and work contacts separate. The next thing you’d know is that your private email is bombarded by client requests and your private phone is ringing so very often with clients on other end and your folks giving you strange looks.
In essence, the important thing is that you should find time and reflect on other important aspects of your life during the day. I think I know now why there is an 8 hour per day work limit. It helps strike a balance between your private and work life. Honestly, when you are working from home you can cross that work limit very easily without even knowing what you did till later. But there are always exceptions. People who are passionate about something won’t stop at nothing till they achieve it. If you’re not that obsessive about something, then you should strike a balance with discipline.
I’m sure my experiences are quite similar with other people. Let me know if there are any differences you find. That would surely help me understand this better :)

“Stealth Programmers” - A New Species ?

Yes! ... while you sleep, there are those who lurk in the dark. Stay in the shadows and make you applications you can only imagine at best. This is a new breed of programmers here in Pakistan. Finally the plague has formed it's roots here. Yes people, STEALTH has come into the Programmer here now. Let me explain how I got to realize this.

So here I was wondering why the hell I don't have a portfolio up even after 2 years ? and suddenly it struck me three times, almost like three speedy pats hitting my back simultaneously, the words "and you'll be like a *stealth* programmer for us". Yes, I recall clearly about 3 clients of mine saying this to me. So what is a "stealth programmer" anyways ? Simple observation reveals that people who wear masks of different companies (some big names like Apple Inc.) are constantly looking for resources. Reliable and efficient resources. People who not only work just so that they earn their kitchen money, but also because they are passionate about what they do. These people are hired by these companies with a promise (technically known as NDAs : non-disclosure-agreements) that they must not reveal their identity and they must not do anything with the code outside their boundaries, may them be virtual or physical, and code them their ideas.

All this commotion about design patterns followed by great frameworks to address them, in most cases, were designed and developed by the "stealth" breed. Authors of languages like Python (Guido Van Rossum) and Ruby (Yukihiro Matsimuto) were stealth programmers. Heck, Linus Torvald had a "stealth" status when developing the Linux kernel. It was this species that lay the foundations of the "open source" community.

Friends, the Stealth virus has officially hit Pakistan. Me, my friends, and a number of "senior" people I know are living examples. And this virus continues to claim people here, as the awareness grows. And I don't think that I'm referring to "free lancers" here. It's a big term, a super class that encompasses "stealth" programmers too.

And it's about time that this "stealth" community should be consolidated in one place. Because most of these people are best of the best in their fields and passionate therefore well motivated. Several companies in the U.S. made use of this breed in the 80s including Apple Inc. and these companies really owe their success to these people indeed. Entrepenuers here can take a hint :D

ESlavery, The oDesk Experience

The first time I saw oDesk I was pretty excited. I liked their system pretty much at first glance. I thought, "ah ! now here's something that can serve us better !" ... you put in work hours and you'd get paid for it for sure, no chance of being stiffed. However, surprisingly, my experience was quite different. I wouldn't put the blame on oDesk entirely, but about 90% would be justified. Its Just that their system is not friendly for the more creative. Don't get me wrong here, but let me layout my specific experience briefly in points:

1. I didn't have much difficulty in landing a client

2. I wouldn't be that judgemental about the guy, but he did one thing that I still don't understand why. He tried to tell me that $2000 a month is a good salary in the U.S. of A. Naturally, I wasn't that dumb to take his word for it. Coz, most of us live in the U.S. virtually. But I chose not to challenge his false claim.

3. So he did succeed in bringing down my rate, which frankly I did just for the heck of it to try the system out. And of course, I told him that once "we are good" with each other, it was going to go up to my desired mark. I sort of wanted to prove my worth to him.

4. When I started working is when I noticed that I worked about 9 hours and the system logged about 6 or 7. It was eating 2 hours straight ! - so I investigated.

5. Viola ! ... turns out, the oDesk's system calculates your performance based on your "keystrokes" ! ... HOW SMART IS THAT ?

6. Anyhow, I tried to talk to my client, who by the way claimed to be a programmer himself. The guy said, "if the system says you worked 6 hours, you worked 6 hours". I don't know, why he was trying to be an a`hole but at that point I lost all interest. I mean, I am in this line of work because I love doing it, not entirely because of money. So naturally, I asked him to spare me the pain.

So in essence, oDesk's system of performance recording is good, BUT only for jobs like data entry etc. Would you imagine that this guy had me "write" down my brainstorming sessions !! ??? .... how the F*** can you write and brainstorm at the same time ? - if you can, then you have a gift ... really ... you do ! In entirety the experience was really annoying for me. After that, since I had a bad experience associated with oDesk, I didn't bother to look back. And thank God I didn't have to either.

Here is what I ask: ** How can you indulge in CREATIVE THINKING / PROCESS when you know that this time won't be accounted for ? ** so in these regards, oDesk is pathetic ! Heck, check the comments of this post and you'll know how oDesk is **bad** for many buyers too. And futhermore, you can go knock yourself out with this google search.

I won't get myself in the "oDesk haters" category ... BUT ... I would consider my self in "prefer to boycott oDesk" kind. Because if I ever pick up a client on oDesk, I would seriously either BILL him based on different milestones OR make sure that we both trust each other so that I can put in offline time and he would authorize it and won't stiff me. Still, day by day I hear about new improvements on how to *track* the employee. And these guys are really pushing it so much that it really sounds more like slavery, or "eslavery" to be exact. (well said by "O Rover" there)

Common sense demands you don't get lost in all the **goodies** marketed by such companies. These guys promise definite pay to the employees and the supposed "power" to the very insecure employers out there so that they could check their eSlave from as many angles as possible. In the end this creates an environment of distrust if you plan to work with more creative individuals. Because the more creative ones WILL take their time to THINK before acting and more importantly they need their space!

It would be highly unlikely to get an intuitive, extendable app unless there is sufficient trust between the employee and the employer. On the other hand, if the programmer drops out in the middle of the project, the employer still has to pay him / her WITHOUT having their work done. And based on these facts I can never agree that oDesk has brought any innovation and / or revolutionized the way of working. They are just using your insecurities to the best of their own interests.

To balance the sarcasm above, I can only do but one thing, and that is to advise anyone planning out on doing business on oDesk to beware, don't get traped in their warp zone of false promises, but lay out your concerns on the table with the client and try to educate him / her that you both are better off trusting each other more rather than the system. Because seriously, the system will make both of you feel like smart asses and un-decievable. Not true in the real world.

Thinking Patterns - Perfectionist huh ?

I have been noticing this habit of mine lately. So I'm working on some code, basically a component in CakePHP and I find my self really frustrated. Obviously reason is the way it's coded. I don't know why but unwillingly I am judging the Author. I might cook up another post dedicated to that subject particularly, something like the "state of mind" of the coder. Basically any experienced developer can tell what the Author of any piece of code had in his / her priority list when coding something. Anyhow, I find my self *refactoring* the *bad* code even when I'm specifically asked by the client NOT to do that, as in don't spend the precious hours on refactoring. Just get to what you're supposed to do, complete the task and scram! - Well ... I just couldn't help it and I ain't invoicing my client for it too. So bad code ticks me off, that's for sure.

Darn ! now I'm confused :( ... what to make of this ? ... am I a *perfectionist* ? or just too weak to keep myself from the knocking on forbidden doors ? - blast ! since I hold a good opinion about myself so I'm showing the latter two fingers up ! Hell ! ... come to think of it ... "knocking on forbidden doors" is something I've been doing for quite a while :P and I enjoy it too :P

I also notice one other thing. Most "legacy" type coders tend to keep stuff a bit tightly coupled. Whereas I'm always looking for loose coupling. Don't get me wrong on this, I do make use of tight coupling sometimes but it's governed by special circumstances. The whole idea is to make things re-usable, and my idea of re-usable is not just in one application but all.

Since I am ranting on the subject, so I'd like to voice it out clearly today. Though I am not a regular reader of debuggable but I find my self agreeing to most things with these guys. For instance, looking at an example code, one can really sneak into the thinking patterns of the author. I wish I could lay my finger on it, but I wish I could find some sort of metrics that should at least give me 80 ~ 90% correct results of my hypothesis. So far, I do know this (and I'm sure most seniors would agree in the field) that there are two generic classes of people. One who acutally think in terms of **patterns** and others who display traits of **linear** thinking. Linear thinking is good for an abstract approach to solve problems and it gets most jobs done. But in an efficient way ? ... I would disagree on this. This is because I have witnessed a handful of projects failing due to this. Not to forget that most cases were with developers on CodeIgniter ... but these are not the shortcomings of the framework, but because it's non-mvc-strict policy is abused by most programmers. Infact, I've seen developers running towards CodeIgniter just because it's ok with a hack here and a hack there. Heck! I've seen usage of SQL statements in CakePHP's VIEWS ! ... YES ! ... VIEWS !! ... boy was that a sight ! and dear god I don't want to see that again. I won't name, but it was from the students of a school here in Lahore people are so fond of (kind of a status symbol - arrogant bastards they are indeed). So I see this as a culmination of the typical "just get it done" plus "linear thinking" analogy. I just hope we could escape it's evils.

Alright ... so my question still hangs ... am I a perfectionist ? - Well ... I'd say "yeh sort of" - I mean the obsessive compulsive behavior is there, but not to the extent of his level.

Karan Johar Copy Pastes Snooks Weblog

As of June 25th, 2008 I just saw Karan Johar's weblog and was shocked! Here is why:

Take a look at this snapshot of Karan Johar's weblog taken on June 25th, 2008

And here is a snapshot of Snook's blog, take on June 25th, 2008

See the shocking similarity ? - The design elements are almost the same. Frankly, the designer on Karan Johar's weblog wasn't even "creative" enough to add some cool colors to make it look better. This is really sad. Jonathan Snook has a weblog presence since as long as I can remember.

I really don't have a bias but the truth is, people like Jonathan Snook are an inspiration for me and I am sure for most of the young emerging free lance web developers.  Heck! even Indian movies are copy pastes of good Hollywood movies. Don't they have PRIDE in what they do? I'm sure Karan Johar doesn't even know that his weblog was a copy paste of another and not "just another" guy's weblog, but Jonathan Snook's weblog who is in fact followed by thousands of people in the web development industry. Snook is a mentor of quite a few people like me so obviously this did "shiver me timbers" to write this post.

If these guys take Pride in their work they will never do such a thing. I just can't digest the idea of a media famed person doing something like this ? (or in this case someone doing this TO him) It's true that his show "Coffee with Karan" didn't capture people like me in it's audience ever. But here is a fact: People in the U.S of A and Europe find it hard to differentiate between Pakistanis and Indians because the way we speak / dress and all that - it's quite similar. Anything we do, or they do, pretty much sums up for both of us in the web dev industry. Although there are significant differences between us and our cultures along with "significant" similarities, but one never knows unless he has been in contact with either of us for some time. Anyhow, my verdict of this situation is simple: I am still dying to see some "creative" web designers from India. Any One ? Please .... any one ? .... or all you guys were forced out of India as the Industry got taken over by cheap skates ? Who am I kidding, this seems to be happening over here too but hasn't reached to this extent yet. And I pray it doesn't too.

Karan - although I am not a fan of yours but .... your weblog's design is going to put your "international" web presence in danger. If in a million chances you see this post, DUDE ! get a REAL deisgner !

Bindable now Containable Behavior in CakePHP Core

Behold! One of the coolest behaviors "Bindable" is now included in CakePHP's core. Many thanks to Mariano and Felix for their efforts and including this in CakePHP's core as "Containable" behavior. I have found this behavior to be the most useful by far. I remember the nightmares I used to forgo in controlling model bindings in CakePHP 1.1, specially when coding DustJacketReview. We had to pull up so much data for a single page that we were forced to write custom queries to make it as light weight as possible. But ever since I shifted to CakePHP 1.2, things got a lot better. I have to admit that I had to find some workarounds for some situations when working with CakePHP 1.1 and specially for multiple Ajax paging within a single page. But now these nightmares are over!

Although one thing I am still concerned about is the built in pagination. It's brilliant no doubt but still I can't control the model bindings when paginating any model. I observed the code and found out that it instantiates a new instance of the model when paginating it, so even if I set the bindings to persistent, it has no effect as they are not persistent with the new object. Anyhow, a post on this matter is in the pipeline, I still need some more information to actually formally voice the issue on cake's trac. Currently I have a workaround that's working really good for me. Let's just say that I wanted more than "paginate" function to be specified within a model, and I got it ;)