From a0a7b2536d1c64c18a53276aed7c0ba01d63a5ba Mon Sep 17 00:00:00 2001 From: wp Date: Sat, 20 Jun 2015 16:52:08 +0000 Subject: [PATCH] wiki: Fix links to wiki categories in wikiconvert git-svn-id: trunk@49373 - --- components/wiki/chm/wiki.css | 9 +++ components/wiki/html/wiki.css | 10 +++ components/wiki/lazwiki/wiki2xhtmlconvert.pas | 75 ++++++++++++++++--- components/wiki/lazwiki/wikiformat.pas | 3 + components/wiki/wikiconvert.lpr | 14 +++- components/wiki/xhtml/wiki.css | 9 +++ 6 files changed, 109 insertions(+), 11 deletions(-) diff --git a/components/wiki/chm/wiki.css b/components/wiki/chm/wiki.css index 564db11208..5f1c1580a6 100644 --- a/components/wiki/chm/wiki.css +++ b/components/wiki/chm/wiki.css @@ -179,6 +179,15 @@ span.keypress { white-space: nowrap; } +div.categories { + background-color: #F9F9F9; + border: 1px solid #2F6FAB; + color: black; + padding: 1em; + padding-top: 0.75em; + line-height: 1.25em; +} + /* images */ diff --git a/components/wiki/html/wiki.css b/components/wiki/html/wiki.css index 564db11208..4f7b43a841 100644 --- a/components/wiki/html/wiki.css +++ b/components/wiki/html/wiki.css @@ -179,6 +179,16 @@ span.keypress { white-space: nowrap; } +div.categories { + background-color: #F9F9F9; + border: 1px solid #2F6FAB; + color: black; + padding: 1em; + padding-top: 0.75em; + line-height: 1.25em; + font-color: #2F6FAB; +} + /* images */ diff --git a/components/wiki/lazwiki/wiki2xhtmlconvert.pas b/components/wiki/lazwiki/wiki2xhtmlconvert.pas index ffb89ea5b2..93e040a704 100644 --- a/components/wiki/lazwiki/wiki2xhtmlconvert.pas +++ b/components/wiki/lazwiki/wiki2xhtmlconvert.pas @@ -69,6 +69,8 @@ type FMaxH: integer; FPageFileExt: string; FUseTemplateIcons: Boolean; + FAddCategories: Boolean; + procedure DoAddCategories(Page: TW2XHTMLPage); procedure DoAddLinksToTranslations(Page: TW2XHTMLPage); procedure DoAddLinkToBaseDocument(Page: TW2XHTMLPage); procedure OnHeaderToken(Token: TWPToken); @@ -105,11 +107,16 @@ type function PageToFilename(Page: string; IsInternalLink, Full: boolean): string; virtual; function PageToFilename(Page: TW2XHTMLPage; Full: boolean): string; virtual; property PageFileExt: string read FPageFileExt write SetPageFileExt; - property LinkToBaseDocument: string read FLinkToBaseDocument write FLinkToBaseDocument; - property AddLinksToTranslations: boolean read FAddLinksToTranslations write FAddLinksToTranslations default true; - property AddTOCIfHeaderCountMoreThan: integer read FAddTOCIfHeaderCountMoreThan - write FAddTOCIfHeaderCountMoreThan default 2; - property UseTemplateIcons: Boolean read FUseTemplateIcons write FUseTemplateIcons; + property LinkToBaseDocument: string + read FLinkToBaseDocument write FLinkToBaseDocument; + property AddLinksToTranslations: boolean + read FAddLinksToTranslations write FAddLinksToTranslations default true; + property AddTOCIfHeaderCountMoreThan: integer + read FAddTOCIfHeaderCountMoreThan write FAddTOCIfHeaderCountMoreThan default 2; + property AddCategories: Boolean + read FAddCategories write FAddCategories default true; + property UseTemplateIcons: Boolean + read FUseTemplateIcons write FUseTemplateIcons; end; implementation @@ -126,6 +133,48 @@ begin FCSSFilename:=AValue; end; +procedure TWiki2XHTMLConverter.DoAddCategories(Page: TW2XHTMLPage); +var + doc: TXMLDocument; + CategoriesNode: TDOMElement; + node: TDOMElement; + category, url, txt: String; + i: Integer; +begin + if FCategoryList.Count = 0 then + exit; + + doc := Page.XHTML; + url := Page.WikiPage.BaseURL; + if (url <> '') and (url[Length(url)] <> '/') then + url += '/'; + + CategoriesNode := doc.CreateElement('div'); + CategoriesNode.SetAttribute('class', 'categories'); + Page.BodyDOMNode.AppendChild(CategoriesNode); + + // Add "Categories:" + node := doc.CreateElement('a'); + node.SetAttribute('href', url+'Special:Categories'); + CategoriesNode.AppendChild(node); + CategoriesNode.AppendChild(doc.CreateTextNode('Categories: ')); + + for i:=0 to FCategoryList.Count-1 do begin + category := FCategoryList[i]; + // Add link to category + node := doc.CreateElement('a'); + node.SetAttribute('href', url + category); + txt := Copy(category, pos(':', category)+1, MaxInt); + node.AppendChild(doc.CreateTextNode(txt)); + CategoriesNode.AppendChild(node); + + // Add separator + if i < FCategoryList.Count-1 then + CategoriesNode.AppendChild(doc.CreateTextNode(' | ')); + end; +end; + + procedure TWiki2XHTMLConverter.DoAddLinksToTranslations(Page: TW2XHTMLPage); var TranslationPage: TW2XHTMLPage; @@ -186,21 +235,23 @@ end; procedure TWiki2XHTMLConverter.DoAddLinkToBaseDocument(Page: TW2XHTMLPage); var Link: String; + MainNode: TDOMElement; Node: TDOMElement; doc: TXMLDocument; begin // add LinkToBaseDocument
doc:=Page.XHTML; + MainNode := doc.CreateElement('p'); + Page.BodyDOMNode.AppendChild(MainNode); + Node:=doc.CreateElement('a'); - Page.BodyDOMNode.AppendChild(Node); + MainNode.AppendChild(Node); Link:=Page.WikiPage.BaseURL; if (Link<>'') and (Link[length(Link)]<>'/') then Link+='/'; Link+=Page.WikiDocumentName; Node.SetAttribute('href', Link); Node.AppendChild(doc.CreateTextNode(LinkToBaseDocument)); - Node:=doc.CreateElement('br'); - Page.BodyDOMNode.AppendChild(Node); end; procedure TWiki2XHTMLConverter.OnHeaderToken(Token: TWPToken); @@ -469,7 +520,9 @@ var exit; end else if Scheme='category' then begin - URL:=''; // show category without link + FCategoryList.Add(URL); + URL:=''; + Caption := ''; exit; end else if (Scheme='image') or (Scheme='file') then begin @@ -637,6 +690,9 @@ begin Page.WikiPage.Parse(@OnWikiToken,Page); + if FAddCategories then + DoAddCategories(Page); + if LinkToBaseDocument<>'' then DoAddLinkToBaseDocument(Page); @@ -1160,6 +1216,7 @@ begin ShortFilenameToPage:=TFilenameToPointerTree.Create(false); UsedImages:=TFilenameToPointerTree.Create(false); fLinkToBaseDocument:='Online version'; + FAddCategories := true; FAddLinksToTranslations:=true; FAddTOCIfHeaderCountMoreThan:=2; FUseTemplateIcons := true; diff --git a/components/wiki/lazwiki/wikiformat.pas b/components/wiki/lazwiki/wikiformat.pas index bc8ee216b9..8d767194b7 100644 --- a/components/wiki/lazwiki/wikiformat.pas +++ b/components/wiki/lazwiki/wikiformat.pas @@ -72,6 +72,7 @@ type fPagesSortFilename: TAvgLvlTree; // TW2FormatPage sorted for WikiFilename fPagesSortDocumentName: TAvgLvlTree; // TW2FormatPage sorted for WikiDocumentName FPageClass: TW2FormatPageClass; + FCategoryList: TStringList; function GetPages(Index: integer): TW2FormatPage; procedure SetOutputDir(AValue: string); procedure SetImagesDir(AValue: string); @@ -168,11 +169,13 @@ begin FTitle:='FPC/Lazarus Wiki (offline, generated '+DatetoStr(Now)+')'; FImagesDir:='images'; FNoWarnBaseURLs:=TStringToStringTree.Create(true); + FCategoryList := TStringList.Create; end; destructor TWiki2FormatConverter.Destroy; begin Clear; + FreeAndNil(FCategoryList); FreeAndNil(FNoWarnBaseURLs); FreeAndNil(fPagesSortFilename); FreeAndNil(fPagesSortDocumentName); diff --git a/components/wiki/wikiconvert.lpr b/components/wiki/wikiconvert.lpr index 23d45fe25e..13ef637767 100644 --- a/components/wiki/wikiconvert.lpr +++ b/components/wiki/wikiconvert.lpr @@ -169,7 +169,16 @@ begin if ParamName='css' then begin TWiki2XHTMLConverter(Converter).CSSFilename:=ParamValue; continue; - end + end; + if ParamName='wikicategories' then begin + case ParamValue of + 'yes', 'true': TWiki2XHTMLConverter(Converter).AddCategories := true; + 'no', 'false': TWiki2XHTMLConverter(Converter).AddCategories := false; + else + E('Incorrect parameter value ('+Param+')'); + end; + Continue; + end; end; if Converter is TWiki2CHMConverter then begin // CHM parameters @@ -177,7 +186,7 @@ begin ParamValue:=TrimAndExpandFilename(ParamValue); if (ParamValue='') or (not DirPathExists(ExtractFilePath(ParamValue))) then begin - E('directory of chm file does not exists: '+ParamValue); + E('directory of chm file does not exist: '+ParamValue); exit; end; TWiki2CHMConverter(Converter).CHMFile:=ParamValue; @@ -324,6 +333,7 @@ begin writeln; writeln('Options for --format=xhtml,html,chm :'); writeln(' --css= : default: ',XHTMLConverter.CSSFilename); + writeln(' --wikicategories= : default: ', XHTMLConverter.AddCategories); writeln; writeln('Options for --format=chm :'); writeln(' Note: the default page is the first page'); diff --git a/components/wiki/xhtml/wiki.css b/components/wiki/xhtml/wiki.css index 564db11208..5f1c1580a6 100644 --- a/components/wiki/xhtml/wiki.css +++ b/components/wiki/xhtml/wiki.css @@ -179,6 +179,15 @@ span.keypress { white-space: nowrap; } +div.categories { + background-color: #F9F9F9; + border: 1px solid #2F6FAB; + color: black; + padding: 1em; + padding-top: 0.75em; + line-height: 1.25em; +} + /* images */