Полная кастомизация узла Wiki

??? ????????? ?? ???????? ???????????? ??????? ???? ? ?????? ???????????? ???????? ???? ????? ??????? ?? 5 ???????:

1. ???????? SiteDefinition

2. ???????? Feature

3. ???????? ?????? html ??????? ??? WIKI ???????

4. ????????? ??????????? ?? ???????? ????? wiki-????????

5. ????????? ???????? ???? ??????

???????? SiteDefinition

 

1. ??????????? ?? ..\12\TEMPLATE\SiteTemplates ????? Wiki, ????????????? ?? ???????? ? MyWiki.

2. ? ????? MyWiki ??????? ???? onet.xml ???????? ??? ???????? ??? ??????? ?????? ??????????? ???? (?????? SiteFeatures ? WebFeatures).

3. ??????? ??? ?????? Module ? ????????? onet.xml

4. ? ????? ???????? ??????????? (? ?????? ?????? ???????) ..\12\TEMPLATE\1049\XML ??????? ???? webtempMyWiki.xml ?????????? ??????????:

<?xml version="1.0" encoding="utf-8" ?>

<Templates>

  <Template Name="MyWiki" ID="10111">

    <Configuration

      ID="0"

      Title="????"

      ImageUrl="/_layouts/images/stsprev.png"

      Description=""

      SubWebOnly="TRUE"

      DisplayCategory="??? ???????"

      />

  </Template>

</Templates>

???????? Feature

 

1. ? ????? \12\TEMPLATE\FEATURES ???????? ????? feature MyWikiFeature

2. ???????? ???? feature.xml ?????????? ??????????:

<?xml version="1.0" encoding="utf-8" ?>

<Feature Id="BA51868B-AED8-4662-B091-B9A8F8BB6630"

          Title=”????”

          Description=""

          Version="1.0.0.0"

          Scope="Web"

        

xmlns="https://schemas.microsoft.com/sharepoint/"

                  ReceiverAssembly="MyPortal, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c5bb9526235c6eae, processorArchitecture=MSIL"

                  ReceiverClass="MyPortal.FeaturesActivator.WikiFeatureInstaller"

                  >

      <ElementManifests>

                  <ElementManifest Location="Elements.xml"/>

      </ElementManifests>

</Feature>

Feature receiver ?? ???????? ???? ?????. ?????????? ??????? ????? ?????????? PublicKeyToken.

3. ???????? ???? elements.xml:

<?xml version="1.0" encoding="utf-8" ?>

<Elements xmlns="https://schemas.microsoft.com/sharepoint/">

       <ListInstance

       FeatureId="00BFEA71-C796-4402-9F2F-0EB9A6E71B18"

       Title="$Resources:core,WikiWebLibPages;"

      Description=""

      TemplateType="119"

      Url="$Resources:core,WikiWebLibPages_Folder;" />

       <Module Name="Versions" Url="$Resources:cmscore,List_Pages_UrlName;" Path="Pages">

                   <File Url="VersionDiff.aspx" Type="Ghostable">

                   </File>

       </Module>

       <Module Name="WikiTemplate" Url="wikitemplate" Path="Pages">

                   <File Url="wiki_template.aspx" Type="Ghostable">

                   </File>

                   <File Url="default_wiki_template.aspx" Type="Ghostable">

                   </File>

       </Module>

      

       <Module Name="DefaultWikiPages" List="119" Url="$Resources:core,WikiWebLibPages_Folder;" Path="Pages" >

                   <File Url="default.aspx" Name="$Resources:core,nav_Home;.aspx" Type="GhostableInLibrary">

                               <Property Name="Title" Value="$Resources:core,nav_Home;" />

                               <Property Name="WikiField" Value=" " />

                               <NavBarPage Name="$Resources:core,nav_Home;" ID="1002" Position="Start" />

                               <NavBarPage Name="$Resources:core,nav_Home;" ID="1010" Position="Start" />

                   </File>

       </Module>

</Elements>

? ???? ????? ?? ??????? ??? ??? ????????? ???? ?? ???? ?????????? ??????? ?????????? wiki ???????, ? ??? ?? ??????? ??? ????? ?????????? ???????? ???????? ? ?????? ? ??????? ????? wiki ???????.

4. wiki_template.aspx – ???? ??????? ? ??????? ????? wiki ???????. ??? ???????? ????? ???? ???????? ??? ????? ????????? ???, ??? ??????? ? ???? ?????

5. VersionDiff.aspx – ???????? ? ????????????? ???? ?????? wiki ????????. ?.?. ?? ????? ??????????????? ? ???????? ?? ??????? ??????

6. Default.aspx – ??????? ???????? wiki ????.

 

??????????: ???? ?? ?????? ????? ?? ???????? ?? ????????? ??? ?????-?? ????? ?? ?????? ????????? ?????? ? ???? “WikiField”. ???? ????? ?? ???????, ?? ??? ?????????????, ?????? WIKI ???????? ????? ????????????????? ?? ????????? ? ?? ??????????? ???? ??????.

???????? ?????? html ??????? ??? WIKI ???????

 

1. ? ????? MyWikiFeature ???????? ????? Pages ? ??????? ????? ????????????? ????????.

2. ????????? ? ????? Pages ???? ..\12\TEMPLATE\DocumentTemplates\wkpstd.aspx. ?????? ?? ? ???????????? ? ???????? ??????? ?? ???????? ????????? wiki ????????. ????????????? ???? ????? ????????????? ???????? ? wiki_template.aspx ? ???????? ??? ??? ??? ??? ????.

3. ????????? ???? wiki_template.aspx ? ??????????? ??? ? default.aspx. ??? ? ????? ???? ??????? ????????.

4. ????????? ? ????? Pages ???? ...\12\TEMPLATE\LAYOUTS\VersionDiff.aspx ? ??????? ??? ??? ??? ?????.

5. ????????? ? ????? Pages ???? ...\12\TEMPLATE\LAYOUTS\CreatePage.aspx, ??????????? ??? ? ??????? ??? ??? ??? ?????. ????????????? ???? ??????? MyCreatePage.aspx

????????? ??????????? ?? ???????? ????? wiki ???????? ( MyCreatePage . aspx )

 

???? ??? ??? ????? ??? ????, ????? ??? ??????????? wiki ???????? ??????? ????? ??????? ???????????? ?? ???? ??????????? ?? ??????? ?????????? ? wiki_template.aspx, ? ?? ?? ???????????? ???????.

1. ???????? code behind ???? ??? CreatePage.aspx ?????????? ??????????:

using System;

using System.Collections;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint;

using Microsoft.SharePoint.WebControls;

using Microsoft.SharePoint.ApplicationPages;

using System.Web.UI.WebControls;

using System.Web.UI;

namespace MyPortal.PageHandlers

{

    public class MyCreateWebPage : Page

    {

        protected TextBox Name;

        protected ListFieldIterator fieldIterator;

        protected UrlNameValidator CusValSiteName;

        protected Label Error;

       

        protected override void OnPreRender(EventArgs e)

        {

            base.OnPreRender(e);

           

            if (Request.QueryString["Name"] != null)

                Name.Text = Request.QueryString["Name"];

     }

        protected void SubmitBtn_Click(object sender, EventArgs args)

        {

            Error.Text = string.Empty;

           

            CusValSiteName.Validate();

            if (!CusValSiteName.IsValid)

                return;

           

  using (SPWeb web = fieldIterator.Web)

            {

                SPSecurity.RunWithElevatedPrivileges(delegate()

                {

                    using (SPSite site = new SPSite(web.Url))

                    {

                        using (SPWeb webElevated = site.OpenWeb())

                        {

                            string wikiFieldValue = fieldIterator.ListItem[fieldIterator.ListItem.Fields.GetFieldByInternalName("WikiField").Id].ToString();

                            if (string.IsNullOrEmpty(wikiFieldValue))

                                wikiFieldValue = " ";

                            SPFile template = GetSPFileTemplate(webElevated);

                            SPDocumentLibrary docLib = ((SPDocumentLibrary)fieldIterator.List);

                            Hashtable props = new Hashtable();

                            props[fieldIterator.ListItem.Fields.GetFieldByInternalName("WikiField").Title] = wikiFieldValue;

                            SPFile file = null;

           try

                            {

                                file = fieldIterator.List.RootFolder.Files.Add(Name.Text + ".aspx", template.OpenBinary(), props);

                            }

                            catch (Exception exc)

                            {

  }

                            if (file != null)

                            {

                                SPListItem item = fieldIterator.Web.Lists[fieldIterator.List.ID].Items.GetItemById(file.Item.ID);

          if (item != null)

                                {

                                    item[item.Fields.GetFieldByInternalName("WikiField").Id] = wikiFieldValue;

                                    item.UpdateOverwriteVersion();

    }

                            }

                        }

                    }

                }

                );

                if(Error.Text ==string.Empty)

                    Response.Redirect(fieldIterator.List.ParentWebUrl + "/" + fieldIterator.List.RootFolder.Url + "/" + Name.Text + ".aspx");

            }

        }

        public SPFile GetSPFileTemplate(SPWeb web)

        {

            SPFile template = null;

            foreach (SPFile file in web.RootFolder.SubFolders["wikitemplate"].Files)

            {

                if (file.Name == "wiki_template.aspx")

                {

                    template = file;

                    break;

                }

            }

            return template;

        }

    }

}

2. ??????? MyCreatePage.aspx ? ?????? ?????? ??? ????????? ?????

<% @ Assembly Name="MyPortal, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c5bb9526235c6eae"%>

<% @ Page Language="C#" Inherits="MyPortal.PageHandlers.MyCreateWebPage" MasterPageFile="~/_layouts/application.master"%>

<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>

<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %>

<%@ Register TagPrefix="wssuc" TagName="InputFormSection" src="~/_controltemplates/InputFormSection.ascx" %>

<%@ Register TagPrefix="wssuc" TagName="InputFormControl" src="~/_controltemplates/InputFormControl.ascx" %>

<%@ Register TagPrefix="wssuc" TagName="ButtonSection" src="~/_controltemplates/ButtonSection.ascx" %>

<%@ Register TagPrefix="wssuc" TagName="ToolBar" src="~/_controltemplates/ToolBar.ascx" %>

<%@ Register TagPrefix="wssuc" TagName="ToolBarButton" src="~/_controltemplates/ToolBarButton.ascx" %>

<%@ Register Tagprefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<asp:Content ID="Content1" contentplaceholderid="PlaceHolderPageTitle" runat="server">

<SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,webpagecreation_newwk_pagetitle%>" EncodeMethod='HtmlEncode'/>

</asp:Content>

<asp:content ID="Content2" contentplaceholderid="PlaceHolderPageTitleInTitleArea" runat="server">

<SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,webpagecreation_newwk_pagetitle%>" EncodeMethod='HtmlEncode'/>

</asp:Content>

<asp:content ID="Content3" contentplaceholderid="PlaceHolderAdditionalPageHead" runat="server">

<SharePoint:ScriptLink name="form.js" language="javascript" runat="server" />

<style type="text/css">

.ms-bodyareaframe {

   background-color: #ffffff;

   padding: 8px;

   border: none;

   width: 0%;

}

.ms-rightareacell {

   width: 100%;

}

</style>

</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderId="PlaceHolderPageImage" runat="server"/>

<asp:Content ID="Content5" ContentPlaceHolderId="PlaceHolderMain" runat="server">

   <TABLE cellpadding=0 cellspacing=0 width=100% style="padding-top: 7px"><tr><td width=100%>

         <wssuc:ToolBar CssClass="ms-formtoolbar" id="toolBarTblTop" RightButtonSeparator="&nbsp;" runat="server">

                     <Template_RightButtons>

                          <asp:button ID="btnCreateTop"

                                text="<%$Resources:wss,multipages_createbutton_text%>"

                                AccessKey="<%$Resources:wss,multipages_createbutton_accesskey%>"

                                CssClass="ms-ButtonHeightWidth"

                                OnClick="SubmitBtn_Click" runat="server"/>

                          <SharePoint:GoBackButton ControlMode="New" runat="server" />

                     </Template_RightButtons>

         </wssuc:ToolBar>

   </td></tr></TABLE>

   <TABLE class="ms-formtable" style="margin-top: 8px;" border=0 cellpadding=0 cellspacing=0 id="formTbl" width=100%>

         <TR>

               <TD valign="top" class="ms-formbody" width="625px">

                          <b><label for="<%=Name.ClientID%>"><SharePoint:FieldLabel FieldName="FileLeafRef" ControlMode="New" runat="server"/></label></b>&nbsp;

                          <asp:TextBox id="Name" name="Name" runat="server" /> <SPAN class="ms-authoringcontrols"></SPAN>

                          <span class="ms-formvalidation"><wssawc:UrlNameValidator ID="CusValSiteName" ControlToValidate="Name" runat="server"/>

                          <br /><asp:Label id="Error" name="Error" runat="server" /></span>

               </TD>

         </TR>

         <SharePoint:ListFieldIterator TemplateName="WideFieldListIterator" ExcludeFields="FileLeafRef" ID="fieldIterator" ControlMode="New" runat="server"/>

   </TABLE>

   <table cellpadding=0 cellspacing=0 width=100%><tr><td class="ms-formline"><IMG SRC="/_layouts/images/blank.gif" width=1 height=1 alt=""></td></tr></table>

   <TABLE cellpadding=0 cellspacing=0 width=100% style="padding-top: 7px"><tr><td width=100%>

         <wssuc:ToolBar CssClass="ms-formtoolbar" id="toolBarTbl" RightButtonSeparator="&nbsp;" runat="server">

                     <Template_RightButtons>

                          <asp:button ID="btnCreate"

                                text="<%$Resources:wss,multipages_createbutton_text%>"

                                AccessKey="<%$Resources:wss,multipages_createbutton_accesskey%>"

                                CssClass="ms-ButtonHeightWidth"

                                OnClick="SubmitBtn_Click" runat="server"/>

                          <SharePoint:GoBackButton ControlMode="New" runat="server" />

                     </Template_RightButtons>

         </wssuc:ToolBar>

   </td></tr></TABLE>

   <script id="onetidPageTitleAreaFrameScript">

         document.getElementById("onetidPageTitleAreaFrame").width="";

         document.getElementById("onetidPageTitleAreaTable").width="";

   </script>

</asp:Content>

<asp:Content ID="Content6" ContentPlaceHolderId="PlaceHolderTitleAreaSeparator" runat="server"/>

3. ?? ??????? ??????????? ???? MyCreatePage.aspx ??????? ? ????? ...\12\TEMPLATE\LAYOUTS\

4. ?? ???? ???? ??????? ?? ???????????. ?????? ?????????? ????????? ??????????? ???????? ??? ???????? Wiki ??????? ????? ????????????? ?????????.

??? ????? ?? ???????? HttpModule ?????????? ??????????:

using System;

using System.Web;

using System.Web.UI;

using System.IO;

using Microsoft.SharePoint.Administration;

using Microsoft.SharePoint;

using Microsoft.SharePoint.Publishing;

using Microsoft.SharePoint.WebControls;

namespace MyPortal.Modules

{

    public class WikiPageModule : IHttpModule

    {

        public void Init(HttpApplication context)

        {

            context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);

        }

        void context_PreRequestHandlerExecute(object sender, EventArgs e)

        {

            if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("/_layouts/createwebpage.aspx"))

            {

                HttpContext.Current.Response.Redirect(SPContext.Current.Web.Url + "/_layouts/mycreatewebpage.aspx" + HttpContext.Current.Request.Url.Query);

            }

        }

      

        public void Dispose()

        {

        }

    }

}

????????, ?? ???????? ????????? HttpModule ? web.config

????????? ???????? ???? ??????

 

?? ?????????? ???????????? ? ??????? ??? ?????? ?? ??????????? wiki ??????????

1. ????????? wiki_template.aspx ?? ?????? ??????? ??? ..\12\TEMPLATE\DocumentTemplateswkpstd.aspx, ???? ??? ?????? ??? ??????? ?????????? ? ???????, ??? ???????? ? ???? ? ???????? TemplateName.

2. ??????? ascx ????, ???????? MyDefaultTemplates.aspx.

3. ???????? ? MyDefaultTemplates.aspx ????????? ? ????? ...\12\TEMPLATE\CONTROLTEMPLATES\DefaultTemplates.aspx ?? TemplateName ??????.

4. ?????? ????????????? RenderTemplate ?? ????? ???????? ID.

5. ???????? ???? MyDefaultTemplates.aspx ? ????? ...\12\TEMPLATE\CONTROLTEMPLATES.

6. ??? ??? ????????? ???? wiki_template.aspx ? ????? ? ???????? TemplateName ??? ???????? ?????????? ?? ?? ?????, ??? ?? ????????? ??? RenderTemplate ID.