Update contents of a page
Name | Type | Description |
pageid | string | either an integer page ID, "home", or "=" followed by a double uri-encoded page path |
Name | Type | Description |
ordered | bool? | If this is a new hierarchy make it ordered, and put this page at the front |
restriction | string? | Optionally set the restriction of the page |
importtime | string? | If this is an import, the edit timestamp of the imported content (yyyyMMddHHmmss or yyyy-MM-ddTHH:mm:ssZ) |
overwrite | bool? | New page revision is created when no changes are detected when overwrite is true (default: false) |
reltopath | string? | Page used for path normalization. Ignored if relto parameter is defined. (default: none) |
relto | int? | Page used for path normalization (default: none) |
abort | {never, modified, exists}? | specifies condition under which to prevent the save; default is never |
xpath | string? | identifies the portion of the page to update; this parameter is ignored if section is specified |
section | int? | the section number. If zero, append as a new section |
title | string? | the display title (default: use existing title or determine from page path.) |
comment | string? | the edit comment |
edittime | string | the previous revision's edit timestamp (yyyyMMddHHmmss) or "now" to bypass concurrent edit check |
authenticate | bool? | Force authentication for request (default: false) |
redirects | int? | If zero, do not follow page redirects. |
tidy | {remove, convert}? | Determines if invalid content is converted to text or removed (default: 'convert') |
Name | Value | Description |
OK | 200 | The request completed successfully |
Bad Request | 400 | Invalid input parameter or request body |
Forbidden | 403 | Update access to the page is required |
Not Found | 404 | Requested page could not be found |
Input:
Content-type=text/plain
Output:
<edit status="{success|conflict}"> <page id="{int}" href="{uri}"> <title>{text}</title> <path>{text}</path> </page> <page.base id="{int}" revision="{int}" href="{uri}"> <title>{text}</title> <path>{text}</path> <date.edited>{date}</date.edited> <user.author id="{int}" href="{uri}"> <nick>{text}</nick> <username>{text}</username> <email>{text}</email> </user.author> <description>{text}</description> <contents type="{contenttype}" href="{uri}" /> </page.base> <page.overwritten id="{int}" revision="{int}" href="{uri}"> <title>{text}</title> <path>{text}</path> <date.edited>{date}</date.edited> <user.author id="{int}" href="{uri}"> <nick>{text}</nick> <username>{text}</username> <email>{text}</email> </user.author> <description>{text}</description> <contents type="{contenttype}" href="{uri}" /> </page.overwritten> </edit>
If the page does not exist, a new page is created. Otherwise, the existing page is updated.
Use the Abort parameter to control edit conflict behavior. Abort=exists specifies that the save should abort if the page already exists. Similarly, Abort=modified specifies that the save should abort if the page has been modified since the Edittime parameter. Abort=never always allows the save to occur; the system makes no attempt to merge edit conflicts and simply overwrites the existing content. If an edit conflict is detected (ie. someone else edited the page since the value specified in the Edittime parameter), the edit status is set to "conflict" and the page.base/page.overwritten elements are populated. The page.base element displays the revision upon which the changes in the current save were based. The page.overwritten element displays the page revision containing the overwritten content.
It is possible to update a portion of an existing page using either the Section or XPath parameters. The Section parameter contains the integer section number to update. Everything within the specified section is replaced, including the section heading itself. Section=0 specifies to append the new content to the end of the document. The XPath parameter identifies a document node to replace. Refer here for more information on XPath syntax.
The edittime parameter has to be supplied when updating a page!
Create a dekiscript function that can create pages
[DekiExtFunction(Description = "trying to call a dream API (actually to create a wiki page ")] public XDoc xCreatePage([ DekiExtParam("authtoken", true)] string authtoken, [DekiExtParam("path to put ", true)] string path, [DekiExtParam("pagename", true)] string pagename, [DekiExtParam("pagename", true)] string contentstring) { if(contentstring == null) contentstring = ""; //make it so an empty page is created if no content is passed in. Plug p = Plug.New(this.Config["uri.deki"].AsUri); DreamMessage msg = DreamMessage.Ok(MimeType.TEXT, contentstring); var res = p.At("pages", "=" + System.Web.HttpUtility.UrlEncode(path + pagename), "contents") .With("authtoken", authtoken) .With("abort", "never") .With("edittime", DateTime.Now) .Post(msg); return res.ToDocument(); }
<edit status="success"> <page id="892" href="http://mydomain/@api/deki/pages/892redirects=0"> <uri.ui>http://mydomain/Information_Technology/mytestpage2</uri.ui> <title>mytestpage2</title><path>Information_Technology/mytestpage2</path> <namespace>main</namespace></page></edit>
The following code example creates a new page called "Subpage 1" under the page called "Page Title"; it will fail if the page already exists. The new page contents contains two sections:
Plug p = Plug.New("http://deki-hayes/@api/deki"); p.At("users", "authenticate").WithCredentials("admin", "password").Get(); DreamMessage msg = DreamMessage.Ok(MimeType.TEXT, "<h2>Section 1</h2>Section 1 text<h2>Section2</h2>Section 2 text"); p.At("pages", "=Page_Title%252fSubpage_1", "contents").With("abort", "exists").Post(msg);
<edit status="success"> <page id="84" href="http://deki-hayes/@api/deki/pages/84"> <title>Subpage 1</title> <path>Page_Title/Subpage_1</path> </page> </edit> button in the toolbar
The following curl command creates a page named "test" with the data in foo.txt as the page's body.
curl -u username:password -d @foo.txt -i http://mindtouch.address/@api/deki/pages/=test/contents
The following curl command will create a page about our favorite captain of the U.S.S. Enterprise, Jean Luc Picard. "picard.txt" contains the body of the document.
<h2>Captain Jean Luc Picard</h2> Of the U.S.S. Enterprise<br><br> <i>Engage!</i>
curl -u username:password -d @picard.txt -i http://192.168.168.110/@api/deki/pages/=Jean%2520Luc%2520Picard/contents
HTTP/1.1 200 OK Date: Wed, 06 Jan 2010 22:42:06 GMT Server: Dream-HTTPAPI/1.7.0.16080 X-Deki-Site: id="default" Content-Type: application/xml; charset=utf-8 Content-Length: 252 Via: 1.1 dekiwiki
Content-Type: application/xml
<?xml version="1.0"?> <edit status="success"> <page id="51" href="http://192.168.168.110/@api/deki/pages/51?redirects=0"> <uri.ui>http://192.168.168.110/Jean_Luc_Picard</uri.ui> <title>Jean Luc Picard</title> <path>Jean_Luc_Picard</path> <namespace>main</namespace> </page> </edit>
The following Curl command replaces the contents of page named "test" with the contents in file foo.txt
curl -u admin:password -d @foo.txt -i http://mindtouch.address/@api/deki/pages/=test/contents?edittime=2025070355726
foo.txt
<h2> test </h2> This is the test file that will replace the original<br>
Command:
curl -u user:password -d @foo.txt http://mindtouch.address/@api/deki/pages/=test/contents?edittime=20100914123000
This command loads foo.txt to replace the current page called "test". The edittime parameter is necessary for editing a page, the tiestamp must be newer than when the page was created. It is specified using the following format: YYYYMMDDhhmmss
HTTP/1.1 200 OK Date: Tue, 14 Sep 2010 19:26:47 GMT Server: Dream-HTTPAPI/2.1.1.21089 X-Data-Stats: request-time-ms=285; mysql-queries=10; mysql-time-ms=223; cache-ratio=3.50; cache-hit=14; cache-miss=-10; cache-del=1; cache-ins=10; X-Deki-Site: id="default" Content-Type: application/xml; charset=utf-8 Content-Length: 237 Via: 1.1 dekiwiki
Content-Type: application/xml <edit status="success"> <page id="663" revision="1" href="http://192.168.168.104/@api/deki/pages/663?redirects=0"> <uri.ui>http://192.168.168.104/test2</uri.ui> <title>test2</title> <path>test2</path> <namespace>main</namespace> </page> </edit>