April 2008 Archives

Update: I’ve placed this upgrade script on the wiki, a better place for more people to enjoy and collaborate: wiki.movabletype.org/MT_Shell_Script_Installer

Below code is no longer cutting edge technology. =P

Follow these steps to easily switch between versions of Movable Type.

Requirements

  • Subversion - Movable Type development is kept in a version control system called Subversion. Subversion allow many developers to work on the same code at the same time.
  • shell access - I use Terminal.app on my MacBook Pro.

Development Branches

There is a branch for each development cycle. These branches are worked on for 1-3 weeks, before a branch is closed and passed to QA for testing. If QA finds any bugs, then bugs are fixed in the branch. All subsequent features are implemented in the next branch sequentially. The branch with the highest number is the most current release (as of this writing, release-35)

Stable Tags

Once a particular place in development is tested and approved for release the code at that point is tagged with a release number.

Checkout the Code

These steps will be a little different based upon the setup of the web hosting environment. Here’s a simplified example of how I set-up Movable Type:

www.beausmith.com/
    cgi/
        release-33/
        release-34/
        mt  -> release-34
        mt4.01
        mt4.11
    html/
        blog/
            (archives here)
        index.php
        mt-static -> ../../cgi/mt/mt-static

The items with the arrow -> are symlinks. These allow me to not have to change urls when I update to a new release and also allow me to keep my mt-static directory inside the release folder. When I want to update to release-35, here’s the steps I’ll take:

  1. Navigate to the cgi directory & use the subversion checkout command to get the latest version:

    $ pwd;
    /www.beausmith.com
    $ cd cgi;
    $ svn co http://code.sixapart.com/svn/movabletype/branches/release-35;
    
  2. Issue the make command to build the current release

    $ make;
    
  3. Make the support files writeable

    $ chmod -R 777 release-35/mt-static/support
    
  4. Remove the current symlink and create a new symlink to point to your release branch. I do this in the same step so as to avoid any potential downtime while switching.

    $ rm mt; ln -s release-35 mt;
    

That’s it! Go access you MT installation.

Updating

Since changes will be committed round the clock by the MT teams in San Francisco and Japan, you’ll want to update often to get the latest changes.

    $ cd cgi/release-35;
    $ svn up;
    $ make;

Doing a make is not necessary unless there are *.pre files that need to be rendered for the current language.

Note: If you make changes to the files in the MT code, they may conflict with the updated code. Look forward to a future article about Subversion basics.

Switching Between Movable Type Installs

Is there a bug in release-35 and you want to go back to the stable mt4.11 install? Easy. Remove the mt symlink and then create a new one pointing to the desired MT install:

    $ rm mt; ln -s mt4.11 mt;

View Changes & Code Diffs with Trac

Trac also makes it easy to browse through all the recent changes to any branch of Movable Type. Note the similarity & differences in the urls

  • trac: http://code.sixapart.com/trac/movabletype/browser/branches/release-35/
  • svn: http://code.sixapart.com/svn/movabletype/branches/release-35/

Questions? Please comment below.

The first three lines of this entry’s content is:

<style type="text/css">
#entry-55 ul li { color: blue; }
</style>

Are the items in this unordered list blue?

  • blue
  • blue
  • blue

If so, I’ve added custom styles to this single entry.

  1. Create your entry
  2. Save it as draft
  3. Look in the url of your browser to find the id which is a unique identifier for the entry (careful not to use blog_id as that is a unique id for the blog)

    http://www.beausmith.com/cgi-bin/mt/mt.cgi?__mode=view&_type=entry&id=55&blog_id=2&saved_changes=1
    
  4. Enter the id into your css

  5. Change Status to Published
  6. Save your entry

All this assumes you are using the default templates from MT, if not you’ll have to add <$mt:EntryID$> to a container wrapping each entry in your templates.

By default, assets are placed in the site root as defined in the publishing settings. For example, if the site root was http://beausmith.com/ then the asset image.gif would be uploaded to http://beausmith.com/image.gif.

There are two common ways to change this:

  1. Define a default upload destination folder.
  2. Hard code upload destination and hide it from the form.

Define a default upload destination folder

To pre-populate the folder where assets will be placed add this line to the top of MT_BASE/tmpl/cms/include/asset_upload.tmpl and replace “assets” with your preferred folder name:

<$mt:setvar name="extra_path" value="assets"$>

I use “assets” because this is the most generic word to describe all the things that could be placed in this folder: photos, video, documents etc.

Or the second way…

Hard code upload destination and hide it from the form

Open MT_BASE/tmpl/cms/include/asset_upload.tmpl and search for this code (from MT4.0, code from MT4.1.x has a big chunk of javascript in the middle of the second <mtapp:setting> block, but the javascript can safely be removed as well):

<mt:setvarblock name="upload_hint">
    <__trans phrase="_USAGE_UPLOAD" params="<$mt:var name="blog_name" escape="html"$>">
</mt:setvarblock>
<mtapp:setting
    id="folder"
    label_class="top-label"
    label="<__trans phrase="Upload Destination">"
    hint="<$mt:var name="upload_hint"$>"
    show_hint="1">
    <!-- <$mt:var name="blog_url" escape="html"$> -->
    <select name="site_path" onchange="setExtraPath(this)">
        <option value="1">&#60;<__trans phrase="Site Root">&#62;</option>
    <mt:if name="enable_archive_paths">
        <option value="0"<mt:if name="archive_path"> selected="selected"</mt:if>>&#60;<__trans phrase="Archive Root">&#62;</option>
    </mt:if>
    <mt:if name="extra_paths">
        <mt:loop name="extra_paths">
        <option value="<mt:if name="enable_archive_paths">0<mt:else>1</mt:if>" middle_path="<mt:var name="path" escape="html">"<mt:if name="selected"> selected="selected"</mt:if>><mt:var name="label" escape="html"></option>
        </mt:loop>
    </mt:if>
    </select>
    / <input name="extra_path" id="extra_path" value="<mt:var name="extra_path" escape="html">" />
</mtapp:setting>

Replace the code with this code which will set the upload destination to <Site Root>/assets/:

<input type="hidden" name="site_path" id="site_path" value="1" />
<input type="hidden" name="extra_path" id="extra_path" value="assets" />

The “Upload Destination” form elements should now be gone from the upload asset modal.

Note: There are other ways to do this in the Perl code. It’d be nice to just have config directives to handle this.

I was adding more examples to the Movable Type Documentation site today and my lines of code were so long that they went beyond the width of the column… so I implemented some css to use a scrollbar to display longer lines. Shorter lines display without the scrollbar.

Examples (and HTML source)

Short code renders no scroll bar…

<pre><code>short code example</code></pre>

Long code renders scroll bar…

<pre><code>long code example (is it odd that the word "short" is longer that the word "long") long code example long code example</code></pre>

CSS Code

pre {
    overflow: auto;
    width: auto;
    background-color: #f0f6fa;
    border: 1px solid #CCCCCC;
    border-width: 1px 0;
    padding: 10px;
}
  • overflow: auto; - creates the scrollbar if content is wider than container.
  • `width: auto; - .
  • <pre> “preformatted” — all the spaces and carriage returns are rendered exactly as you type them. All other formating (links, code, etc) are preserved.
  • <code> tag renders in mono-spaced font.
  1. login to mysql

    $ mysql -u USERNAME -p DATABASENAME
    
  2. find id of user

    > select author_name, author_id from mt_author;
    +---------------+-----------+
    | author_name   | author_id |
    +---------------+-----------+
    | beau          |         1 |
    | quinn         |         2 |
    | ryan          |         3 |
    | jono          |         4 |
    +---------------+-----------+
    
  3. issue the command using the correct author id from the table

    > update mt_author set author_is_superuser = 1 where author_id = 1;
    
  1. login to mysql

    $ mysql -u USERNAME -p DATABASENAME
    
  2. find id of user

    > select author_name, author_id from mt_author;
    +---------------+-----------+
    | author_name   | author_id |
    +---------------+-----------+
    | beau          |         1 |
    | quinn         |         2 |
    | ryan          |         3 |
    | jono          |         4 |
    +---------------+-----------+
    
  3. issue the command using the correct author id from the table

    > update mt_author set author_password = encrypt('foobar') where author_id = 1;