383.md 5.8 KB
Newer Older
Lab机器人's avatar
readme  
Lab机器人 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
# Wikis API

> 原文:[https://docs.gitlab.com/ee/api/wikis.html](https://docs.gitlab.com/ee/api/wikis.html)

*   [List wiki pages](#list-wiki-pages)
*   [Get a wiki page](#get-a-wiki-page)
*   [Create a new wiki page](#create-a-new-wiki-page)
*   [Edit an existing wiki page](#edit-an-existing-wiki-page)
*   [Delete a wiki page](#delete-a-wiki-page)
*   [Upload an attachment to the wiki repository](#upload-an-attachment-to-the-wiki-repository)

# Wikis API[](#wikis-api "Permalink")

在 GitLab 10.0 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/13372) .

仅在 APIv4 中可用.

## List wiki pages[](#list-wiki-pages "Permalink")

获取给定项目的所有 Wiki 页面.

```
GET /projects/:id/wikis 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `with_content` | boolean | no | 包含页面内容 |

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/wikis?with_content=1" 
```

响应示例:

```
[  {  "content"  :  "Here is an instruction how to deploy this project.",  "format"  :  "markdown",  "slug"  :  "deploy",  "title"  :  "deploy"  },  {  "content"  :  "Our development process is described here.",  "format"  :  "markdown",  "slug"  :  "development",  "title"  :  "development"  },{  "content"  :  "*  [Deploy](deploy)\n*  [Development](development)",  "format"  :  "markdown",  "slug"  :  "home",  "title"  :  "home"  }  ] 
```

## Get a wiki page[](#get-a-wiki-page "Permalink")

获取给定项目的 Wiki 页面.

```
GET /projects/:id/wikis/:slug 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `slug` | string | yes | Wiki 页面的段(唯一字符串) |

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/wikis/home" 
```

响应示例:

```
{  "content"  :  "home page",  "format"  :  "markdown",  "slug"  :  "home",  "title"  :  "home"  } 
```

## Create a new wiki page[](#create-a-new-wiki-page "Permalink")

使用给定的标题,条目和内容为给定的存储库创建一个新的 Wiki 页面.

```
POST /projects/:id/wikis 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `content` | string | yes | Wiki 页面的内容 |
| `title` | string | yes | 维基页面的标题 |
| `format` | string | no | Wiki 页面的格式. 可用格式为: `markdown` (默认), `rdoc``asciidoc``org` |

```
curl --data "format=rdoc&title=Hello&content=Hello world" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/wikis" 
```

响应示例:

```
{  "content"  :  "Hello world",  "format"  :  "markdown",  "slug"  :  "Hello",  "title"  :  "Hello"  } 
```

## Edit an existing wiki page[](#edit-an-existing-wiki-page "Permalink")

更新现有的 Wiki 页面. 至少需要一个参数才能更新 Wiki 页面.

```
PUT /projects/:id/wikis/:slug 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `content` | string | 是,如果未提供`title` | Wiki 页面的内容 |
| `title` | string | 是,如果未提供`content` | 维基页面的标题 |
| `format` | string | no | Wiki 页面的格式. 可用格式为: `markdown` (默认), `rdoc``asciidoc``org` |
| `slug` | string | yes | Wiki 页面的段(唯一字符串) |

```
curl --request PUT --data "format=rdoc&content=documentation&title=Docs" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/wikis/foo" 
```

响应示例:

```
{  "content"  :  "documentation",  "format"  :  "markdown",  "slug"  :  "Docs",  "title"  :  "Docs"  } 
```

## Delete a wiki page[](#delete-a-wiki-page "Permalink")

删除带有给定子弹的 Wiki 页面.

```
DELETE /projects/:id/wikis/:slug 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `slug` | string | yes | Wiki 页面的段(唯一字符串) |

```
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/wikis/foo" 
```

成功时,HTTP 状态代码为`204`并且不需要 JSON 响应.

## Upload an attachment to the wiki repository[](#upload-an-attachment-to-the-wiki-repository "Permalink")

将文件上传到 Wiki 信息库中的附件文件夹. 附件文件夹是`uploads`文件夹.

```
POST /projects/:id/wikis/attachments 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `file` | string | yes | 要上传的附件 |
| `branch` | string | no | 分支的名称. 默认为 Wiki 存储库默认分支 |

要从文件系统上载文件,请使用`--form`参数. 这将导致 cURL 使用标题`Content-Type: multipart/form-data` . `file=`参数必须指向文件系统上的文件,并以`@`开头. 例如:

```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --form "file=@dk.png" "https://gitlab.example.com/api/v4/projects/1/wikis/attachments" 
```

响应示例:

```
{  "file_name"  :  "dk.png",  "file_path"  :  "uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png",  "branch"  :  "master",  "link"  :  {  "url"  :  "uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png",  "markdown"  :  "![dk](uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png)"  }  } 
```