API for creating pages

54 views
Skip to first unread message

wwwald

unread,
Jan 22, 2015, 4:51:28 AM1/22/15
to wikidpa...@googlegroups.com
Hi,

I'm working on a little plugin that can auto-create wiki pages in a journal-like structure. Sometimes, these newly created pages are nested (day-, month-, year-specific wikiwords). 
Example:
 1 - check if wikiword "[-201502-]" exists ("month" page)
 2 - if not, create the wikiword "[-201502-]" in an existing page (using replaceLiveText() on that existing page)
 3 - check if wikiword "[-20150226-]" exists ("day" page)
 4 - if not, create wikiword "[-20150226-]" right inside the "month" wikiword created in step 2

My problem is in step 2: creating the "month" wikiword by adding it using replaceLiveText(), does not seem to create the actual wikiword entity in the wiki. After the adding, isDefinedWikiPage('-201502-') still gives me "False", so creating the day page in steps 3 and 4 obviously won't work.

How can I make sure that the "[-201502-]" month wikiword is actually created in step 2?
Additionally: if there is way to "really" create this wikiword, will it also apply the template that I have for this type of page?

Thanks a lot for any advice,
wwwald

Michael Butscher

unread,
Feb 4, 2015, 4:42:56 PM2/4/15
to wikidpa...@googlegroups.com
On 22.01.2015 10:51, wwwald wrote:
> Hi,
>
> I'm working on a little plugin that can auto-create wiki pages in a
> journal-like structure. Sometimes, these newly created pages are nested
> (day-, month-, year-specific wikiwords).
> Example:
> 1 - check if wikiword "[-201502-]" exists ("month" page)
> 2 - if not, create the wikiword "[-201502-]" in an existing page (using
> replaceLiveText() on that existing page)
> 3 - check if wikiword "[-20150226-]" exists ("day" page)
> 4 - if not, create wikiword "[-20150226-]" right inside the "month"
> wikiword created in step 2
>
> My problem is in step 2: creating the "month" wikiword by adding it using
> replaceLiveText(), does not seem to create the actual wikiword entity in
> the wiki. After the adding, isDefinedWikiPage('-201502-') still gives me
> "False", so creating the day page in steps 3 and 4 obviously won't work.

Creating a link to a page intentionally doesn't create that page.

After step 2 use createPage() of WikiDataManager to retrieve a DocPages.WikiPage
object.

You can then call getLiveText() on it to retrieve the page's contents (normally
only the automatically generated header line) and appendLiveText() or
replaceLiveText() to modify it.

After modification call PersonalWikiFrame.saveDocPage() with the page object if
you want to ensure it is saved to disc immediately (otherwise it would be saved
at least when the wiki is closed but not if a crash occurs in the meantime).

>
> How can I make sure that the "[-201502-]" month wikiword is actually
> created in step 2?
> Additionally: if there is way to "really" create this wikiword, will it
> also apply the template that I have for this type of page?

To do that retrieve the page object of the parent page (the one containing the
"[template: ...]" attribute) with WikiDataManager.getPage(), then modify it by
adding the wiki link on it to the new page which should use the template (this
is probably your step 2).

Finally the meta-data must be updated. This normally is done in background
automatically but it would happen too late here. With the page object "page" do
roughly the following:

for i in range(10): # A "while True" may lead to an endless loop
if not page.runDatabaseUpdate(Consts.WIKIWORDMETADATA_STATE_DIRTY):
continue
if not page.runDatabaseUpdate(Consts.WIKIWORDMETADATA_STATE_ATTRSPROCESSED):
continue

# If this point is reached all went well
break
else:
# Even after 10 tries it didn't work



Now you can continue with the creation of a new page as described above.


Michael

wwwald

unread,
Feb 5, 2015, 7:15:03 AM2/5/15
to wikidpa...@googlegroups.com
Great info!
Thanks a bunch!

wwwald
Reply all
Reply to author
Forward
0 new messages