Changeset 1333

Show
Ignore:
Timestamp:
01/23/08 08:06:50 (22 months ago)
Author:
takayama
Message:

Fixed BugId:65812
* Changed scheme_version to 4.0037
* Added basename column to MT_Author

  • Assigning basename when author saved

* Changed to use MTAuthorBasename instead of MTAuthorDisplayName

Location:
branches/release-29
Files:
10 modified

Legend:

Unmodified
Added
Removed
  • branches/release-29/build/mt-dists/default.mk

    r1194 r1333  
    22 
    33PRODUCT_VERSION = 4.1 
    4 SCHEMA_VERSION = 4.0036 
     4SCHEMA_VERSION = 4.0037 
    55API_VERSION = 4.1 
    66 
  • branches/release-29/lib/MT/Author.pm

    r1174 r1333  
    3636        'auth_type' => 'string(255)', 
    3737        'userpic_asset_id' => 'integer', 
     38        'basename' => 'string(255)', 
    3839    }, 
    3940    defaults => { 
     
    210211    my $auth = shift; 
    211212 
    212     if ((!$auth->id) && ($auth->type == AUTHOR)) { 
    213         # New author, undefined API password. Generate one. 
    214         if (!defined $auth->api_password) { 
    215             my @pool = ('a'..'z', 0..9); 
    216             my $pass = ''; 
    217             for (1..8) { $pass .= $pool[ rand @pool ] } 
    218             $auth->api_password($pass); 
     213    if ($auth->type == AUTHOR) { 
     214        if (!$auth->id) { 
     215            # New author, undefined API password. Generate one. 
     216            if (!defined $auth->api_password) { 
     217                my @pool = ('a'..'z', 0..9); 
     218                my $pass = ''; 
     219                for (1..8) { $pass .= $pool[ rand @pool ] } 
     220                $auth->api_password($pass); 
     221            } 
    219222        } 
     223        # Generate basename 
     224        my $basename = MT::Util::make_unique_author_basename($auth); 
     225        $auth->basename($basename); 
    220226    } 
    221227 
  • branches/release-29/lib/MT/Core.pm

    r1242 r1333  
    496496            'UserpicMaxUpload' => { default => 0 }, 
    497497            'UserpicThumbnailSize' => { default => 100 }, 
     498 
     499            # Basename settings 
     500            'AuthorBansenameLimit' => { default => 30 }, 
    498501        }, 
    499502        upgrade_functions => \&load_upgrade_fns, 
  • branches/release-29/lib/MT/Template/ContextHandlers.pm

    r1308 r1333  
    285285            AuthorNext => \&_hdlr_author_prev_next, 
    286286            AuthorPrevious => \&_hdlr_author_prev_next, 
     287            AuthorBasename => \&_hdlr_author_basename, 
    287288 
    288289            BlogID => \&_hdlr_blog_id, 
     
    23662367    } 
    23672368    my %f = ( 
    2368         'a' => "<MTAuthorDisplayName $dir>", 
    2369         '-a' => "<MTAuthorDisplayName dirify='-'>", 
    2370         '_a' => "<MTAuthorDisplayName dirify='_'>", 
     2369        'a' => "<MTAuthorBasename $dir>", 
     2370        '-a' => "<MTAuthorBasename dirify='-'>", 
     2371        '_a' => "<MTAuthorBasename dirify='_'>", 
    23712372        'b' => "<MTEntryBasename $sep>", 
    23722373        '-b' => "<MTEntryBasename separator='-'>", 
     
    31503151    local $ctx->{__stash}{asset} = $asset; 
    31513152    $builder->build($ctx, $tok, { %$cond }); 
     3153} 
     3154 
     3155sub _hdlr_author_basename { 
     3156    my $author = $_[0]->stash('author') 
     3157        or return $_[0]->_no_author_error('MTAuthorBasename'); 
     3158    my $name = $author->basename; 
     3159    $name = MT::Util::make_unique_author_basename($author) if !$name; 
     3160    return $name; 
    31523161} 
    31533162 
  • branches/release-29/lib/MT/Upgrade.pm

    r1256 r1333  
    776776                    $blog->page_layout($layout); 
    777777                    $blog->save; 
     778                }, 
     779            }, 
     780        }, 
     781        'core_set_author_basename' => { 
     782            version_limit => 4.0037, 
     783            priority => 3.2, 
     784            updater => { 
     785                type => 'author', 
     786                label => 'Assigning author basename...', 
     787                condition => sub { 
     788                    $_[0]->type == 1; 
     789                }, 
     790                code => sub { 
     791                    my ($author) = @_; 
     792                    my $basename = MT::Util::make_unique_author_basename($author); 
     793                    $author->basename($basename); 
     794                    $author->save; 
    778795                }, 
    779796            }, 
  • branches/release-29/lib/MT/Util.pm

    r1233 r1333  
    910910} 
    911911 
     912sub make_unique_author_basename { 
     913    my ($author) = @_; 
     914    my $name = MT::Util::dirify($author->nickname); 
     915    return "author" . $author->id if $name !~ /\w/; 
     916 
     917    my $limit = MT->instance->config('AuthorBasenameLimit'); 
     918    $limit = 15 if $limit < 15; $limit = 250 if $limit > 250; 
     919    my $base = substr($name, 0, $limit); 
     920    $base =~ s/_+$//; 
     921    my $i = 1; 
     922    my $base_copy = $base; 
     923 
     924    my $author_class = ref $author; 
     925    while ($author_class->count({ basename => $base })) { 
     926        $base = $base_copy . '_' . $i++; 
     927    } 
     928    $base; 
     929} 
     930 
    912931sub archive_file_for { 
    913932    MT->instance->publisher->archive_file_for(@_); 
  • branches/release-29/lib/MT/WeblogPublisher.pm

    r1254 r1333  
    28982898    return "" unless $this_author; 
    28992899 
    2900     my $name = dirify( $this_author->nickname ); 
    2901     $name = "author" . $this_author->id if $name !~ /\w/; 
    29022900    if ( !$file_tmpl ) { 
    2903         $file = sprintf( "%s/index", $name ); 
     2901        $file = sprintf( "%s/index", $this_author->basename ); 
    29042902    } 
    29052903    $file; 
  • branches/release-29/php/lib/block.mtarchivelist.php

    r1308 r1333  
    22require_once "archive_lib.php"; 
    33function smarty_block_mtarchivelist($args, $content, &$ctx, &$repeat) { 
    4   $localvars = array('current_archive_type', 'current_timestamp', 'current_timestamp_end', 'entries', 'archive_count', '_archive_list_num', '_archive_list_results','entry','ArchiveListHeader', 'ArchiveListFooter', 'inside_archive_list', 'category'); 
     4  $localvars = array('current_archive_type', 'current_timestamp', 'current_timestamp_end', 'entries', 'archive_count', '_archive_list_num', '_archive_list_results','entry','ArchiveListHeader', 'ArchiveListFooter', 'inside_archive_list', 'category', 'author'); 
    55    global $_archivers; 
     6 
    67    if (!isset($content)) { 
    78        require_once("archive_lib.php"); 
  • branches/release-29/php/lib/block.mtauthornext.php

    r1174 r1333  
    99    static $_next_cache = array(); 
    1010    if (!isset($content)) { 
    11         $ctx->localize(array('author', 'conditional', 'else_content')); 
     11        $next_author = null; 
     12        $ctx->localize(array('author')); 
    1213        $author = $ctx->stash('author'); 
    1314        if ($author) { 
     
    2526                              'need_entry' => 1); 
    2627                list($next_author) = $ctx->mt->db->fetch_authors($args); 
    27                 if ($next_author) $_next_cache[$author_id] = $next_author; 
     28                if ($next_author) { 
     29                    $_next_cache[$author_id] = $next_author; 
     30                    $ctx->stash('author', $next_author); 
     31                } else 
     32                    $repeat = false; 
    2833            } 
    29             $ctx->stash('author', $next_author); 
     34        } else { 
     35            $repeat = false; 
    3036        } 
    31         $ctx->stash('conditional', isset($next_author)); 
    32         $ctx->stash('else_content', null); 
    3337    } else { 
    34         if (!$ctx->stash('conditional')) { 
    35             $content = $ctx->stash('else_content'); 
    36         } 
    37         $ctx->restore(array('author', 'conditional', 'else_content')); 
     38        $ctx->restore(array('author')); 
    3839    } 
    3940    return $content; 
  • branches/release-29/php/lib/block.mtauthorprevious.php

    r1174 r1333  
    99    static $_prev_cache = array(); 
    1010    if (!isset($content)) { 
    11         $ctx->localize(array('author', 'conditional', 'else_content')); 
     11        $prev_author = null; 
     12        $ctx->localize(array('author')); 
    1213        $author = $ctx->stash('author'); 
    1314        if ($author) { 
     
    2526                              'need_entry' => 1); 
    2627                list($prev_author) = $ctx->mt->db->fetch_authors($args); 
    27                 if ($prev_author) $_prev_cache[$author_id] = $prev_author; 
     28                if ($prev_author) { 
     29                    $_prev_cache[$author_id] = $prev_author; 
     30                    $ctx->stash('author', $prev_author); 
     31                } else 
     32                    $repeat = false; 
    2833            } 
    29             $ctx->stash('author', $prev_author); 
    3034        } 
    31         $ctx->stash('conditional', isset($prev_author)); 
    32         $ctx->stash('else_content', null); 
    3335    } else { 
    34         if (!$ctx->stash('conditional')) { 
    35             $content = $ctx->stash('else_content'); 
    36         } 
    37         $ctx->restore(array('author', 'conditional', 'else_content')); 
     36        $ctx->restore(array('author')); 
    3837    } 
    3938    return $content;