[첫화면으로]UseModWiki소스수정/링크를별도의화일로관리

마지막으로 [b]

페이지에 들어 있는 링크 목록을 별도로 보관하게 함

wiki.pl?action=links&page=1                 # 1 - 내부링크 출력, 0 - 출력하지 않음 (기본값 1)
wiki.pl?action=links&inter=1                # 1 - 인터링크 출력, 0 - 출력하지 않음 (기본값 0)
wiki.pl?action=links&url=1                  # 1 - 외부URL 출력, 0 - 출력하지 않음 (기본값 0)
wiki.pl?action=links&unique=1               # 1 - 중복되는 링크를 한 번만 출력, 0 - 중복 횟수만큼 출력 (기본값 1)
wiki.pl?action=links&sort=1                 # 1 - 링크들을 정렬하여 출력, 0 - 정렬하지 않음 (기본값 1)
wiki.pl?action=links&exists=2                # 0 - 내용이 없는 링크만 출력, 1 - 내용이 있는 링크만 출력, 2 - 모두 출력 (기본값 2)
wiki.pl?action=links&empty=1                # 1 - 링크가 하나도 없는 페이지도 출력, 0 - 출력하지 않음 (기본값 0)
wiki.pl?action=links&search=string          # 링크 목록 중에 "string" 이라는 문자열이 포함되어 있는 경우만 출력
wiki.pl?action=links&reverse=string         # 링크 목록 중에 "string" 이라는 링크가 있는 경우만 출력 (즉, 역링크)

wiki.pl?action=links&page=1&inter=1&exists=1   # 이런 식으로 여러 파라메터를 조합할 수 있다

config.pl 화일에 다음을 추가한다
...
$RcOldFile   = "$DataDir/rclog.old"; # Old RecentChanges logfile
$IndexFile   = "$DataDir/pageidx";  # List of all pages
# 다음 라인 추가
$LinkDir     = "$DataDir/link";    # Stores the links of each page
...

이하는 wiki.pl 의 수정
...
### 패치를 위해 추가된 환경설정 변수
### $LinkDir 을 추가
use vars qw(
    $UserGotoBar $UserGotoBar2 $UserGotoBar3 $UserGotoBar4
    $ConfigFile $SOURCEHIGHLIGHT %SRCHIGHLANG $LinkFirstChar
    $EditGuideInExtern $SizeTopFrame $SizeBottomFrame
    $LogoPage $CheckTime $LinkDir
    );
###
...

...
$IndexFile   = "$DataDir/pageidx";  # List of all pages
### 다음 라인 추가
$LinkDir     = "$DataDir/link";    # Stores the links of each page
###
# added by luke

$UseEmoticon    = 1;        # 1 = use emoticon, 0 = not use
...

sub GetFullLinkList {
    ...
            %seen = ();
        }
###############
### replaced by gypark
### 링크 목록을 별도로 관리
#       @links = &GetPageLinks($name, $pagelink, $interlink, $urllink);
        @links = &GetPageLinksFromFile($name, $pagelink, $interlink, $urllink);
###
###############

        foreach $link (@links) {
            $seen{$link}++;
   ...
}

sub DoPost {
    ...
    &SaveDefaultText();
    &SavePage();
###############
### added by gypark
### 링크 목록을 별도로 관리
    &SaveLinkFile($id);
###
###############
    &WriteRcLog($id, $summary, $isEdit, $editTime, $user, $Section{'host'});
    ...
}

sub DoMaintain {
    ...
    foreach $name (&AllPagesList()) {
        &OpenPage($name);
        &OpenDefaultText();
        &ExpireKeepFile();
###############
### added by gypark
### 링크 목록을 별도로 관리
        &SaveLinkFile($name);
###
###############
        print ".... "  if ($name =~ m|/|);
        print &GetPageLink($name), "<br>\n";
    }
    ...
}

sub BuildLinkIndexPage {
    ...
    my ($page) = @_;
    my (@links, $link, %seen);

###############
### replaced by gypark
### 링크 목록을 별도로 관리
#   @links = &GetPageLinks($page, 1, 0, 0);
    @links = &GetPageLinksFromFile($page, 1, 0, 0);
###
###############
    %seen = ();
    ...
}

sub RenameTextLinks {
    ...
        if ($changed) {
            $file = &GetPageFile($page);
            &WriteStringToFile($file, join($FS1, %Page));
###############
### added by gypark
### 링크 목록을 별도로 관리
            &SaveLinkFile($page);
###
###############
        }
    ...
}

sub RenamePage {
    ...
###############
### added by gypark
### 링크 목록을 별도로 관리
    my ($oldlink, $newlink);
    $oldlink = &GetLinkFile($old);
    if (-f $oldlink) {
        $newlink = &GetLinkFile($new);
        &CreatePageDir($LinkDir, $new);  # It might not exist yet
        rename($oldlink, $newlink) || die "error while renaming link file";
    }
###
###############
    &EditRecentChanges(2, $old, $new)  if ($doRC);
    if ($doText) {
        &BuildLinkIndexPage($new);  # Keep index up-to-date
        &RenameTextLinks($old, $new);
    }
}

### 다음 세 함수를 통채로 추가
sub GetLinkFile {
    my ($id) = @_;

    return $LinkDir . "/" . &GetPageDirectory($id) . "/$id.lnk";
}

sub SaveLinkFile {
    my ($page) = @_;
    my (%links, @pagelinks, @interlinks, @urllinks, @alllinks, $link);

    @alllinks = &GetPageLinks($page, 1, 1, 1);

    foreach $link (@alllinks) {
        if ($link =~ /^$InterLinkPattern$/) {
            push(@interlinks, $link);
        } elsif ($link =~ /^$UrlPattern$/) {
            push(@urllinks, $link);
        } else {
            push(@pagelinks, $link);
        }
    }
    $links{'pagelinks'} = join($FS2, @pagelinks);
    $links{'interlinks'} = join($FS2, @interlinks);
    $links{'urllinks'} = join($FS2, @urllinks);

    &CreatePageDir($LinkDir, $page);
    &WriteStringToFile(&GetLinkFile($page), join($FS1, %links));
}

sub GetPageLinksFromFile {
    my ($name, $pagelink, $interlink, $urllink) = @_;
    my ($status, $data, %links, @result, $fname);

    @result = ();
    $fname = &GetLinkFile($name);

    if (!(-f $fname)) {
        &SaveLinkFile($name);
    }

    ($status, $data) = &ReadFile($fname);

    if (!($status)) {
        return &GetPageLinks($name, $pagelink, $interlink, $urllink);
    }

    %links = split($FS1, $data, -1);
    push (@result, split($FS2, $links{'pagelinks'}, -1)) if ($pagelink);
    push (@result, split($FS2, $links{'interlinks'}, -1)) if ($interlink);
    push (@result, split($FS2, $links{'urllinks'}, -1)) if ($urllink);

    return @result;
}
### 통채로 추가한 함수들의 끝
###############

&DoWikiRequest()  if ($RunCGI && ($_ ne 'nocgi'));   # Do everything.
1; # In case we are loaded from elsewhere
# == End of UseModWiki script. ===========================================

sub DeletePage {
    ...
#########################################################3
### added by gypark
### lck 화일도 같이 삭제
    $fname = &GetLockedPageFile($page);
    unlink($fname) if (-f $fname);
### cache 화일도 같이 삭제
    &UnlinkHtmlCache($page);
###
#########################################################3
###############
### added by gypark
### 링크 목록을 별도로 관리
    $fname = &GetLinkFile($page);                 # 이 두 줄을 추가
    unlink($fname) if (-f $fname);
###
###############
    unlink($IndexFile)  if ($UseIndex);
    ...
}

Notes

페이지 삭제 시에 링크 화일도 삭제하는 루틴을 추가했습니다. 위의 마지막 박스를 별도로 적용하면 됩니다.
-- Raymundo 2003-2-25 11:24 am


위키위키분류
Tweak in order to not create file .lnk if file doesn't exist.

 sub GetPageLinksFromFile {
 ...
 - if (!(-f $fname)) {
 + if (!(-f $fname) && (-f &GetPageFile($name))) {
		&SaveLinkFile($name);
	}
--JuanmaMP

Tweak in order to not create file .lnk if links doesn't exist.

sub SaveLinkFile {

    my ($page) = @_;
    my (%links, @pagelinks, @interlinks, @urllinks, @alllinks);

    @alllinks = &GetPageLinks($page, 1, 1, 1);
   + if (@alllinks) {
    foreach my $link (@alllinks) {
        if ($link =~ /^$InterLinkPattern$/) {
            push(@interlinks, $link);
        } elsif ($link =~ /^$UrlPattern$/) {
            push(@urllinks, $link);
        } else {
            push(@pagelinks, $link);
        }
    }
    $links{'pagelinks'} = join($FS2, @pagelinks);
    $links{'interlinks'} = join($FS2, @interlinks);
    $links{'urllinks'} = join($FS2, @urllinks);

    &CreatePageDir($LinkDir, $page);
    &WriteStringToFile(&GetLinkFile($page), join($FS1, %links));
   }
}
--JuanmaMP

How are you? :-) That's very reasonable idea. Thanks!
-- Raymundo 2013-5-3 12:17 am

I'm fine, thanks; but don't ask me a time ago :) I hope that you're fine too.


마지막 편집일: 2013-5-3 6:34 am (변경사항 [d])
873 hits | Permalink | 변경내역 보기 [h] | 페이지 소스 보기