Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Hacking movable type
Nội dung xem thử
Mô tả chi tiết
TEAM LinG
Hacking Movable Type
01_57499x ffirs.qxd 6/17/05 7:55 PM Page i
TEAM LinG
01_57499x ffirs.qxd 6/17/05 7:55 PM Page ii
TEAM LinG
Hacking Movable Type
Jay Allen, Brad Choate, Ben Hammersley,
Matthew Haughey, & David Raynes
01_57499x ffirs.qxd 6/17/05 7:55 PM Page iii
TEAM LinG
For general information on our other products and services or to obtain technical support, please contact our Customer Care Department
within the U.S. at (800) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.
Library of Congress Cataloging-in-Publication Data
Hacking Movable Type / Jay Allen ... [et al.].
p. cm.
Includes index.
ISBN-13: 978-0-7645-7499-3 (paper/website)
ISBN-10: 0-7645-7499-X (paper/website)
1. Movable Type (Computer file) 2. Web sites--Design. 3. Weblogs.
I. Allen, Jay, 1970- .
TK5105.8885.M67H34 2005
006.7--dc22
2005012598
Trademarks: Wiley, the Wiley logo, and related trade dress are registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the
United States and other countries, and may not be used without written permission. ExtremeTech and the ExtremeTech logo are
trademarks of Ziff Davis Publishing Holdings, Inc. Used under license. All rights reserved. All other trademarks are the property of their
respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.
Hacking Movable Type
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2005 by Jay Allen, Brad Choate, Ben Hammersley, Matthew Haughey, & David Raynes. All rights reserved.
Published by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN-13: 978-0-7645-7499-3
ISBN-10: 0-7645-7499-X
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
1B/QX/QX/QV/IN
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic,
mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States
Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy
fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the
Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN
46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO
REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE
CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT
LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR
EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN
MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE
PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF
PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON
SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES
ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A
CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE
AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY
PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET
WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK
WAS WRITTEN AND WHEN IT IS READ.
01_57499x ffirs.qxd 6/17/05 7:55 PM Page iv
TEAM LinG
About the Authors
Jay Allen has been hacking Movable Type since before its first public release and has deployed
MT on over a billion and a half systems, give or take a few orders of magnitude. He created the
first MT plugin, called MT-Search, as well as one of the most necessary plugins, MT-Blacklist.
He currently resides in the ever beautiful and weird San Francisco and works at Six Apart as
Product Manager for Movable Type. He spends his off hours split almost evenly between spinning true house music, recharging personal electronic devices, and trying to find his keys.
Brad Choate has been hacking Movable Type since it was first released. He is now a Six Apart
software engineer where he hacks Movable Type for a living, supporting his incredibly understanding wife and three little hackers.
Ben Hammersley is an English journalist and writer, and has been using Movable Type since
version 1. He lives in Florence, Italy, with his beautiful wife and three greyhounds and is currently tending his cigar and dressing gown habit with little success. He invites you to visit.
Matthew Haughey is closing in on ten years of building websites and runs the popular
MetaFilter weblog as well as half a dozen smaller weblog projects. He’s been tinkering
with Movable Type since the very first private alpha that his friends, Ben and Mena Trott,
let him test out. He’s been hacking away at it ever since.
David Raynes got his first taste of blogs in the first half of 2002, and was running his own
by summer’s end that same year. Shortly after, his first plugin, MTSearches, was released,
and the rest is history. One of his most popular plugins, SubCategories, was even integrated
into Movable Type as of version 3.1. David works as a software engineer in Maryland, where
he lives with his wife, Jenn, and their four cats (two his and two hers): Hans, Franz, Tim,
and Gizmo. Eventually the feud between Tim and Franz will be resolved and there shall be
only three.
01_57499x ffirs.qxd 6/17/05 7:55 PM Page v
TEAM LinG
Credits
Executive Editor
Chris Webb
Development Editors
Marcia Ellett
Sharon Nash
Production Editor
William A. Barton
Copy Editor
Luann Rouff
Production Manager
Tim Tate
Editorial Manager
Mary Beth Wakefield
Vice President & Executive Group
Publisher
Richard Swadley
Vice President and Publisher
Joseph B. Wikert
Project Coordinator
Ryan Steffen
Graphics and Production Specialists
Jennifer Heleine
Stephanie D. Jumper
Melanee Prendergast
Amanda Spagnuolo
Mary Gillot Virgin
Quality Control Technicians
Leeann Harney
Jessica Kramer
Carl William Pierce
Dwight Ramsey
Book Designer
Kathie S. Rickard
Proofreading and Indexing
TECHBOOKS Production Services
01_57499x ffirs.qxd 6/17/05 7:55 PM Page vi
TEAM LinG
Foreword
Almost four years ago, my husband, Ben, and I decided to create a weblogging tool for one
simple reason: I had my own weblog, dollarshort.org, and I wanted a better blogging tool for
myself. As luck would have it, Ben and I were in between jobs (this was 2001 after all and the
tech industry wasn’t exactly booming) and we had some free time to work on a software project
as a hobby.
The more we worked on Movable Type—our ideal blogging tool—the more ambitious Ben
and I became in our goals. We not only wanted to create great software for us and our
friends—fellow engineers, web designers, and writers—to use, but we wanted to give all sorts
of bloggers the power to easily create professional-looking weblogs. The code needed to be
modular and extensible, and the design needed to be clean and simple. What we couldn’t have
imagined is how Movable Type would grow past our own initial ambitions and how it would
be shaped into a platform used by thousands of people worldwide.
Fast-forward to the present day as I sit here writing the foreword to Hacking Movable Type, the
book you now hold in your hands. The fact that this book exists today is a testament not just to
Movable Type itself, but also to the community that has helped grow the platform into what it
is today.
The authors of this book, Jay Allen, Brad Choate, Ben Hammersley, Matt Haughey, and David
Raynes, represent some of the earliest, most passionate, and talented members of the Movable
Type community. While Ben and I were responsible for the core Movable Type product for the
first couple of years in the life of Six Apart, it is these people who helped spread the word
about the power of the platform and helped us learn about what the platform could do.
This team of authors has written tutorials, introduced the product to clients, written plugins,
and helped shape the product’s direction. When Movable Type was first released, the blogging
industry didn’t exist. Today, because of these authors and because of people like you (people
who want to take advantage of Movable Type’s potential to take their projects and their clients’
projects to the next level), we have great resources such as this book to help expand what blogging can do.
Jay Allen and Brad Choate, two of the Hacking Movable Type authors, have been especially pivotal in Movable Type’s development: Jay, with his work on MT-Blacklist, and Brad with his
substantial plugin development. It is only fitting that because of their dedication to Movable
Type and because of their talent, they have since (over the course of this book’s development)
become members of the Six Apart staff, working on the Movable Type team to improve the
platform itself.
The generosity that all of these authors have shown by sharing their ideas and code reflects the
values that have grown the Movable Type community over the past few years. That generosity
continues with the sample code, documentation, and most important, the ideas that this talented group of authors shares in the pages that follow.
01_57499x ffirs.qxd 6/17/05 7:55 PM Page vii
TEAM LinG
With Movable Type’s rise in popularity comes the rise in demand for talented developers,
designers, and consultants who really understand the software and weblog integration with an
existing website. While this book is great for the early adopters and tinkerers who were the
original target audience for Movable Type, it is essential reading for anyone who wishes to earn
a living or make a career in providing weblogging solutions in today’s business world.
Hacking Movable Type should serve as your guide to what you can accomplish with the software.
As you read this book, you’ll discover why Movable Type has become the leading weblog publishing platform. We can’t wait to see the creativity your contributions bring to the community.
Mena Trott
Co-founder and president of Six Apart
viii Foreword
01_57499x ffirs.qxd 6/17/05 7:55 PM Page viii
TEAM LinG
Acknowledgments
All of the authors would like to thank Chris Webb, Sharon Nash, and Marcia Ellett of Wiley
for their superhuman patience, indulgence, and skill. Thanks, guys.
Jay Allen:I’d like to thank the following wonderful people and random inanimate things:
Ezra Cooper and Anil Dash for helping us when we were helpless, Six Apart for making love
in the form of software, my mom for the love, support, and coffee from home, to my Budapesti
baratok for the Unicum and the distractions, és végül de nem utolsósorban, a kisbogaramnak
es a masodik anyukamnak, Gabi: Köszönöm mindent hogy nekem csináltatok. Mindig foglak
szeretni.
Brad Choate: For my family, Georgia, Savannah, Seth, and Arwen.
Ben Hammersley: My part of this book is, as always, thanks for the patience and love of my
wife, Anna: Jag älskar dig. Thanks and love, too, to Lucy, Mischa, and Pico for their ambulatory breaks, and Ben and Mena Trott for making their hobby my livelihood. And cheers to my
fellow writers, the sort of men-gods that put the Thor into co-author: it’s been an honor.
Matthew Haughey: I’d like to thank co-authors Jay Allen and Ben Hammersley for carrying
the brunt of the workload on this project. I’d like to thank my wife for going to sleep alone
while I stayed up until 2 A.M. every night as a chapter approached deadline. I’d like to thank
the folks at Wiley for taking the risk and letting us share our knowledge of MT with the
world. And, most of all, I want to thank that wacky duo, Ben and Mena Trott, for taking a
little weblog application they wrote for themselves and turning it into an empire.
David Raynes: For both of my parents, who sacrificed so much to give me the education that
got me where I am today. For my father, who first introduced me to the wondrous feats that
can be performed by typing a few choice magic words into that little box hooked up to our
television. And to my lovely wife, who puts up with all the time I spend doing this stuff.
01_57499x ffirs.qxd 6/17/05 7:55 PM Page ix
TEAM LinG
01_57499x ffirs.qxd 6/17/05 7:55 PM Page x
TEAM LinG
Introduction
Welcome to Hacking Movable Type. Inside this book you will find everything you need to know
to take an ordinary installation of Movable Type and turn it into something extraordinary.
Movable Type?
Movable Type is the world’s most advanced personal publishing application. Designed by Six
Apart, originally the husband and wife team of Ben and Mena Trott and now one of the
world’s most dynamic software houses, Movable Type brings professional-quality content management to the masses. Thousands of users, from webloggers to professional online publications, are using Movable Type to display their content. It’s one of the greatest Internet success
stories of this century.
Hacking Movable Type?
You might be familiar with Movable Type from the weblogging world. You may well have
installed and used it yourself, but did you know that Movable Type is also perfect fodder for
hacking on?
Nestled inside that sturdy but unassuming exterior is a framework for an exceptionally powerful publishing system, and one that bristles with the latest interfaces, standards, and Internet
thinking.
This book teaches you everything you need to know about the internal features of Movable
Type, and how to extend, stretch, push, and pummel the application from something already
superpowerful into something almost unbelievable.
What’s in This Book?
Luckily, this isn’t some Proustian epic requiring you to plow through from beginning to end.
It’s separated into parts, and you’re free to skip around. But here’s a taste of what we have in
store for you:
Hacking the Perfect Installation
Hacking the Database
XML-RPC API
01_57499x ffirs.qxd 6/17/05 7:55 PM Page xi
TEAM LinG
Atom API
Perl API
Advanced Plugin Writing
Dynamic Publishing
Hacking Together Powerful Blog Applications
Advanced skills
Of course, also included are pages of reference material, recipes for great uses of the Movable
Type system, complete rundowns of the internal structure of the application, the databases, and
the APIs, and clear and concise instructions on just about every aspect of the system.
Hacking Carefully
We know you’re sensible people. Hey, you bought this book, right? So you should know to back
up your data. A lot of things we do in here are potentially hazardous to your stuff, not in a horrible, screaming, bloodcurdling sort of way—it’s all fixable if you make a false move—but to fix
stuff you are going to need backups. Both Jay and Ben’s hard drives died during the writing of
this book, and the wailing and gnashing of teeth was something to behold. So do us a favor, as
we don’t want to see that sort of thing again, for the sake of all that is good and proper, BACK
UP YOUR WEBLOGS BEFORE YOU DO ANYTHING.
Our lawyers would like to point out that we take no responsibility for anything you do. They
do this more formally elsewhere.
Companion Website
For links and updates, please visit this book’s companion website at www.wiley.com/
compbooks/extremetech.
Conclusion
Pablo Picasso once said, “I’m always doing things I can’t do, it’s how I get to do them.” And so
it is with Movable Type. This is a powerful piece of software, and by reading this book you will
be in a position to take full advantage of it. We can’t wait to see what you build. Have fun.
xii Introduction
01_57499x ffirs.qxd 6/17/05 7:55 PM Page xii
TEAM LinG
01_57499x ffirs.qxd 6/17/05 7:55 PM Page xiii
TEAM LinG
Contents at a Glance
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Part I: Hacking the Perfect Installation . . . . . . . . . . . . . . . . . . . . 1
Chapter 1: Preparing Your Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Chapter 2: Tweaking the Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Part II: Hacking the Database . . . . . . . . . . . . . . . . . . . . . . . . 29
Chapter 3: MT and Database Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Chapter 4: Tables in the MT Database . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Chapter 5: Absolutely Necessary Database Tricks . . . . . . . . . . . . . . . . . . . . . . 67
Part III: Hacking with APIs . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Chapter 6: XML-RPC API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Chapter 7: Atom API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Chapter 8: Perl API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Part IV: Hacking with Plugins. . . . . . . . . . . . . . . . . . . . . . . . 143
Chapter 9: The Wonderful World of Plugins. . . . . . . . . . . . . . . . . . . . . . . . 145
Chapter 10: Writing Plugins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Chapter 11: Advanced Plugin Writing . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Chapter 12: Hacking Dynamic Publishing . . . . . . . . . . . . . . . . . . . . . . . . . 215
Part V: Hacking Powerful Blog Applications Together . . . . . . . . . . 235
Chapter 13: Photo Blogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Chapter 14: Linklogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Chapter 15: Blogroll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Chapter 16: Events, Reminders, To-Dos . . . . . . . . . . . . . . . . . . . . . . . . . . 265
Chapter 17: Polls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Chapter 18: LazyWeb. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
Chapter 19: Creating a Community-Authored Website . . . . . . . . . . . . . . . . . . 295
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
02_57499x ftoc.qxd 6/17/05 7:53 PM Page xiv
TEAM LinG