I wrote the whole paper, but did only a very small part of the research. PhD student wants to be first author, but didn't write. Is this okay? I'm an undergraduate who recently was involved in writing a paper where I did most, if not all, of the work writing the manuscript. The PhD student basically "dumped" his project into my lap after a year of sitting on the results, and asked me to write it. I wasn't really involved in the project, except for a few small things in the beginning.

I'm currently listed as third author on the paper; the second author is completely out of the picture, and has not contributed at all to the paper (the PhD student has at least provided some edits). Should I argue that because I wrote the paper, despite not doing all of the research that the second author did, that I should be listed as second author? 

As the deadline grew nearer, I found myself picking up more and more of the responsibility of the paper. I was initially happy to be third author, but when I found myself writing the entire paper, I think that my contributions are a lot greater than I had initially anticipated.

However, I've never been involved in writing a paper before, so I don't know what the etiquette is for these types of scenarios. Should the second author be listed on the paper at all, or should we swap places in authorship? I don't think that the second author will even read the paper before it's published anyways. Should I talk to the PhD student that I think I should get more recognition for the work I've done on this paper, because I feel like I honestly should be first author considering that if I didn't write this paper, it never would have been written, or should I just be happy where I am?

I'm not really sure what to do! Any advice would be immensely helpful.
Unfortunately, the time to decide these kinds of issues is well in advance of publication, and preferably in advance of doing the work and writing the paper! 

The answer to your question is "it depends". Authorship on academic papers isn't so much about writing text, but about scholarship. Writing text is a part of that, but scholarship is much bigger than simply writing up results. In the guidelines I link below, scholarship is defined as:

Scholarship: Contributes significantly to the conception, design, execution, and/or analysis and interpretation of data.

If your primary contribution is mainly writing the paper, then I would tend to think that you would not be the primary author. If you have substantial contributions above and beyond writing the text of the paper, for example if you were primarily responsible for designing the investigation, or primarily responsible executing the investigation, these put you on much stronger ground to claim primary authorship.

Beyond that, there are special considerations for lead authorship. Though all authors are responsible for verifying the accuracy and integrity of the work, the lead author is the person who is primarily responsible for this. They are the one responsible for obtaining publication approval from all co-authors for publication, and then responsible for certifying the accuracy and integrity to the publisher / journal / conference / etc. Practically, the lead author is the corresponding author who interacts with journal / conference editors and reviewers. They are also typically the person who is responsible for defending the work publicly if it is to be presented at a conference. 

The person primarily responsible for conducting investigations and experiments is typically the lead author for these reasons. They are the person who is most able to certify the accuracy and integrity of the work. They're also the person most familiar with the actual investigation that is being written up, and most able to discuss the details. 

I have a few practical suggestions for you:

1) Most schools have specific authorship guidelines that can help with these kinds of decisions, for example:

http://research.wustl.edu/PoliciesGuidelines/Pages/AuthorshipPolicy.aspx

2) Relevant publishers, professional organizations, journals, conferences, etc. may have their own authorship policies.

Again, if your primary contribution has been writing the paper, that would not seem to indicate to me that you would be the lead author. Unfortunately, in your situation, it sounds like this graduate student has been somewhat exploitative. It makes sense to involve undergraduates in the writing process for many reasons, but it's unreasonable for you to write the entire thing. The primary scholar on a project (the lead author) should be the one responsible for drafting most of the text.