[첫화면으로]UseModWiki소스수정/Comments와Thread매크로개선

마지막으로 [b]

1. comments 매크로, thread 매크로 개선
1.1. 사용법:
1.2. 부작용
1.3. wiki.pl 수정
1.4. action/comments.pl 수정
1.5. macros/thread.pl 수정
1.6. 추가 업데이트 내역
1.7. 사용자 의견

1. comments 매크로, thread 매크로 개선

/Comments매크로/Thread매크로의 경우 괄호 안에 그 매크로가 들어간 페이지이름을 적어주어야 했다. 이 경우 그 페이지의 내용을 다른 곳에 옮길 때 (횡설수설의 내용 중 오래된 것을 횡설수설/2005로 옮기는 등) 그 매크로가 같이 옮겨질 겨우 일일이 찾아서 페이지이름 파라메터를 고쳐주어야 한다.

이 패치를 적용하면 comments, longcomments, thread 매크로에서 더 이상 페이지 이름을 적어주지 않아도 된다.

1.1. 사용법:

/Comments매크로/Thread매크로 페이지의 사용법 참조할 것.

1.2. 부작용

comments와 longcomments는 상관이 없는데 thread 매크로의 경우 다음 사항을 확인할 것

예를 들어 <thread(1234,5)> 이라는 매크로가 있다면, 이것의 의미가 애매해진다:

이 패치에서는 이런 경우 전자로 해석을 한다. 따라서 후자의 의미로 쓴 경우라면 <thread(5)>로 직접 고쳐 주어야 한다. 즉 페이지이름이 숫자로만 되어 있는 페이지 안에, 파라메터가 두 개의 숫자로 이뤄진 thread매크로가 들어 있는 경우를 찾아서 고쳐 줄 것.

1.3. wiki.pl 수정

기존의 구현을 그대로 두고1, 페이지 이름이 적혀 있지 않은 매크로의 경우 일단 현재 보고 있는 페이지의 이름을 괄호 안에 추가해 준 후, 다시 기존의 루틴을 사용해서 입력폼으로 바꿔주게 하였다.

sub MacroSubst {
    my ($txt) = @_;

### <UploadedFiles>
    $txt =~ s/(\&__LT__;uploadedfiles\&__GT__;)/&MacroUploadedFiles($1)/gei;
### <comments(숫자)>
# 추가
    # 페이지 이름을 쓰지 않음
    $txt =~ s/(&__LT__;(long)?comments\()([-+]?\d+)(\)&__GT__;)/$1$pageid,$3$4/gi;

    $txt =~ s/(\&__LT__;comments\(([^,]+),([-+]?\d+)\)&__GT__;)/&MacroComments($1,$2,$3)/gei;
### <noinclude> </noinclude> from Jof
    ...
}

include 되는 페이지 안에 매크로가 있을 경우는, 그 페이지를 읽어온 직후에 읽은 페이지의 이름을 괄호 안에 추가해 준다.

sub MacroInclude {
    ...
    my %SubSection = split(/$FS2/, $SubPage{"text_default"}, -1);
    my %TextInclude = split(/$FS3/, $SubSection{'data'}, -1);
# 여기서부터 아래부분을 고쳐 줌
    my $txt = $TextInclude{'text'};

    # includenotoc 의 경우
    $txt =~ s/<toc>/$FS_lt."toc".$FS_gt/gei if ($opt eq "notoc");
    # noinclude 처리 from Jof
    $txt =~ s/<noinclude>(.)*?<\/noinclude>//igs;

    # comments 시리즈의 경우 페이지 아이디를 추가해줌
    $txt =~ s/(<(long)?comments\()([-+]?\d+)(\)>)/$1$name,$3$4/gi;
    $txt =~ s/(<thread\()([-+]?\d+(,\d+)?)(\)>)/$1$name,$2$4/gi;

    return $txt;
}

페이지를 저장할 때 comments 나 longcomments 매크로가 있으면 페이지 이름을 자동으로 추가하여 저장을 했는데 이제는 그럴 필요 없다.

### 글을 작성한 직후에 수행되는 매크로들
sub ProcessPostMacro {
    my ($string, $id) = @_;

    ### 여기에 사용할 매크로들을 나열한다
    $string = &PostMacroMySign($string);
    ### 이 자리에 있던 if() 구문을 삭제
    return $string;
}

1.4. action/comments.pl 수정

sub action_comments {
    ...

        if (($abs_up >= 100) && ($abs_up <= $threshold2)) { # 커멘트 권한 상속
            $newup = $Now - $threshold2;
        } else {
            $newup = $Now;
        }

# 수정
        $comment_tail = "<thread($newup," . ($threadindent+1) . ")>";

        if ($threadindent >= 1) {
            for (1 .. $threadindent) {
                $comment_head .= ":";
            }
            $comment_head .= " ";
        } else {    # 새글
#           $comment_head = "<thread>\n";
#           $comment_tail .= "\n</thread>";
        }

# 추가
        my $thread_pattern = "\\<thread\\($id,$up(,\\d+)?\\)\\>|\\<thread\\($up(,\\d+)?\\)\\>";

        if (($up > 0) && ($up < $threshold1)) {     # 위로 달리는 새글
# 수정
            $string =~ s/($thread_pattern)/$comment_head$newcomments <mysign($name,$timestamp)>\n$comment_tail\n\n$1/;
        } else {                                    # 리플 or 아래로 달리는 새글
# 수정
            $string =~ s/($thread_pattern)/$1\n\n$comment_head$newcomments <mysign($name,$timestamp)>\n$comment_tail/;
        }
    } elsif ($long) {               # longcomments
        $newcomments =~ s/^\s*//g;
        $newcomments =~ s/\s*$//g;
        $newcomments =~ s/(\n)\s*(\r?\n)/$1$2/g;
        $newcomments =~ s/(\r?\n)/ \\\\$1/g;
# 추가
        my $longcomments_pattern = "\\<longcomments\\($id,$up\\)\\>|\\<longcomments\\($up\\)\\>";

        if ($up > 0) {
# 수정
            $string =~ s/($longcomments_pattern)/\n$newcomments <mysign($name,$timestamp)>\n$1/;
        } else {
# 수정
            $string =~ s/($longcomments_pattern)/$1\n$newcomments <mysign($name,$timestamp)>\n/;
        }
    } else {                        # comments
        $newcomments =~ s/(----+)/<nowiki>$1<\/nowiki>/g;
# 추가
        my $comments_pattern = "\\<comments\\($id,$up\\)\\>|\\<comments\\($up\\)\\>";
        if ($up > 0) {
# 수정
            $string =~ s/($comments_pattern)/* ''' $name ''' : $newcomments - <small>$timestamp<\/small>\n$1/;
        } else {
# 수정
            $string =~ s/($comments_pattern)/$1\n* ''' $name ''' : $newcomments - <small>$timestamp<\/small>/;
        }
    }

    if (((!&UserCanEdit($id,1)) && (($abs_up < 100) || ($abs_up > $threshold2))) || (&UserIsBanned())) {        # 에디트 불가
        $pageid = "";
    }

    ...
}

1.5. macros/thread.pl 수정

thread 도 comments 와 마찬가지로, 페이지 이름이 없다면 먼저 페이지 이름을 삽입한 후 다시 기존의 루틴을 사용하여 입력폼으로 변환.
sub thread {
    my ($txt) = @_;
# 추가
    # 페이지 이름을 쓰지 않음
    $txt =~ s/(&__LT__;thread\()([-+]?\d+(,\d+)?)(\)&__GT__;)/$1$pageid,$2$4/gi;

    $txt =~ s/(&__LT__;thread\(([^,]+),([-+]?\d+),(\d+)\)&__GT__;)/&MacroThread($1,$2,$3,1,$4)/gei;
    $txt =~ s/(&__LT__;thread\(([^,]+),([-+]?\d+)\)&__GT__;)/&MacroThread($1,$2,$3,1,0)/gei;
    $txt =~ s/(&__LT__;thread&__GT__;((.)*?)&__LT__;\/thread&__GT__;)/&MacroThreadBlock($2)/geis;

    return $txt;
}

1.6. 추가 업데이트 내역

1.7. 사용자 의견

이름:  
Homepage:
내용:
 

위키위키분류
각주:
1. 생각 같아서는 기존 구현을 다 갈아엎고 싶은데, 그러면 작업의 양도 양이거니와 이미 작성했던 페이지들의 매크로를 다 찾아주어야 하기 때문에 곤란

마지막 편집일: 2008-6-16 8:48 am (변경사항 [d])
2282 hits | Permalink | 변경내역 보기 [h] | 페이지 소스 보기