Extended NewPage Module

By James Kanjo James Kanjo

Please Note:
The code for this snippet was updated in May 2014.
There is now an enablebutton attribute which you need to set to true if you want the button to be displayed.

Description

Quite similar to the built-in NewPage Module, this snippet provides a way for you to create (or jump to) new pages.

The built-in module has seven limitations:

  1. The inability to create hidden pages;
  2. The inability to create new pages on other wikis;
  3. The inability to type in a page, and automatically jump to it;
  4. The inability to specify the syntax of the new page's URL name (UNIX name);
  5. The inability to specify the syntax of the new page's title;
  6. The inability to specify pre-filled text;
  7. The inability to open new pages in a new window.

These limitations don't exist with the Extended NewPage Module, which allows the use for a more powerful Wikidot applications.

This module comes with one shortage of the native NewPage Module:

  • The ability to specify static templates

The Extended NewPage Module uses the following code:

<html><head><title>Wikidot Extended NewPage Module</title><!-- © James Kanjo 2010 --><styletype="text/css">
 @import url("/common--theme/base/css/style.css");
 </style><scripttype="text/javascript">
 str_raw = /^#(\d)(\d)(.+)\|(.+)\|(\/.+\/)\|(.+)\|$/.exec(unescape(window.location.hash));
 bln_window = eval(str_raw[1]);
 str_syntax = unescape(str_raw[5]);
 str_url = str_raw[6];
 
 bln_userinput = false;
 
 function textbox_focus() {
 document.newpage.textbox.style.color = "#000";
 document.newpage.textbox.style.fontStyle = "normal";
 if (!bln_userinput) {
 document.newpage.textbox.value = "";
 bln_userinput = true;
 }
 }
 
 function validation() {
 str_userinput = document.newpage.textbox.value;
 str_redirect = str_url.replace(/#/g, str_userinput);
 try {
 if (eval(str_syntax + ".test(str_userinput)")) {
 if (bln_window) {
 window.open(str_redirect);
 } else {
 window.parent.location = str_redirect;
 }
 } else {
 alert("Please note:\nYour input is not correct. Please fix it and try again.");
 }
 } catch(error) {
 alert("Please note:\nThe provided regular expression in the "format" attribute of this module is invalid.");
 }
 return false;
 }
 </script></head><body><formname="newpage"onsubmit="return validation();"style="padding: 2px; width: 100%;"><inputname="textbox"type="text"class="text"style="width: 60%; margin: 0; background-color: #fff; color: #333; font-style: italic;"onfocus="textbox_focus();"><inputname="submitbutton"type="submit"onclick="return validation();"style=""value=""></form><scripttype="text/javascript">
 document.newpage.textbox.value = /^#\d\d(.+)\|.+\|\/.+\/\|.+\|$/.exec(unescape(window.location.hash))[1];
 document.newpage.submitbutton.value = /^#\d\d.+\|(.+)\|\/.+\/\|.+\|$/.exec(unescape(window.location.hash))[1];
 if (eval(/^#\d(\d).+\|.+\|\/.+\/\|.+\|$/.exec(unescape(window.location.hash))[1])==0) {
 document.newpage.textbox.style.width = "95%";
 document.newpage.submitbutton.style.display = "none";
 }
 </script></body></html>

Don't worry if looking at that scares you. You shouldn't need to use it in your wiki at all.

Attributes

The Extended NewPage Module extends upon the NewPage module — therefore, it has identical attributes to the built-in NewPage Module:

attribute required allowed values default description
category no name of a page category none forces the given page category by prepending the page name by the categoryname:
size no em, % or px 200px size of the displayed input field
button no any string without "double quotes" Create Page

(however, is turned off if left blank)
changes the text of the button
format no any valid regular expression none forces the input value to match the required format
tags no space-separated list of tags none automatically adds given tags to created pages
parent no name of a page or category:page none automatically adds parent page to created pages
Extended Attributes
mode no manual none allows you to nest the Extended NewPage Module within other modules (read more)
window no new, false false if new, will jump to new page in a new window
enablebutton no true, false true if "button" field is not empty,
false if "button" field is empty
if true, the button is visible
if false, will prevent the button from appearing;
text no any string without "double quotes" none pre-fills textbox with custom text
site no full site name (i.e. http://www.wikidot.com/) current site creates new pages to the given website
name no any string, # optional page title (as specified by the user) sets the syntax of the UNIX page name
edit no true, false true if false, will jump to the page without force editing it
title no any string or false # optional page title (as specified by the user) sets the syntax of the page title. If "false", the /title/ will be removed from the URL
url_end no any string none appends the string you specify to the end of the URL (for advanced users)
style no any styling attribute none changes the style of the iframe (the NewPage textbox)
prepend no anything you want before the include code [[module ListPages range="."]] for advanced users
append no anything you want after the include code [[/module]] for advanced users

The optional # character is replaced with the text that the user types in.
For example, if your code contained |title=You are # and the user typed in "silly", then the created page would have the title: You are silly.

Important Note on Escaping Characters

Character Replace With Reason
|
Pipe
%7C
Escaped Version
As the include syntax parses this character as variable delimiters, this character must be escaped in order to be used
#
Hash
%2523
Escaped Version of an Escaped Version
As a feature of this CSI is that this character gets replaced with the user's text-box input, this character needs to be escaped in order to be displayed literally

Code

This code will attempt to create the page "wikidot". The page's title must contain the word "smile" in it.

[[include :snippets:newpage
|name=wikidot
|format=/smile/
|edit=false
|text=Type in 'smile'
|button=Jump!
]]

In action

Manual Mode

The Extended NewPage Module uses technologies from the ListPages Module to automatically identify your website's address. Sadly, Wikidot doesn't yet allow nesting modules (such as having a ListPages module inside another ListPages module). This means that under normal circumstances, you can't use the NewPage module inside of a ListPages module.

However! You CAN use the Extended NewPage Module inside other modules, but only through the use of "Manual Mode". Manual Mode removes the inbuilt ListPages Module from the Extended NewPage Module. Doing this means that you need to manually specify the website address that you wish to create pages on:

[[include :snippets:newpage
|mode=manual
|site=http://www.wikidot.com/
]]

Thanks to tsangk for this great snippet: conditional-blocks


text above inserted with:

[[include :snippets:if START |unique=1|type=equal|var1=%%name%%|var2=conditional-blocks]]
**##red|Thanks to tsangk for this great snippet:##** [[[code:conditional-blocks]]]
[[include :snippets:if END]]



Other snippets posted by James Kanjo


Rate this solution

If you think this solution is useful — rate it up!

rating: +18
page 1 of 21
2 pages at once?
Jsimmons17 Jsimmons17 04 Jun 2017 22:59

Would it be possible to create 2 pages at once using this module? I'm trying to create a way for users to name their own categories, and to give each category it's own live template (using a static default template)

If I were to put
[[include :snippets:newpage
|name=#:story
|name=#:_template
|button=Admin Only
|size=30
|edit=no
]]

Would this be able to create two pages with the name typed in the box?

by Jsimmons17 Jsimmons17 , 04 Jun 2017 22:59
Re: 2 pages at once?
Helmut_pdorf Helmut_pdorf 05 Jun 2017 11:48

I am affraid, without changing the script behind it this is not working.

It makes sense to create a live_template for each user-category, but this is better done in an extra step on a "new-user" page ( perhaps with iftags and stand alone buttons ), a new story is creatd mor often tha the template.


Service is my success. My webtips:www.blender.org (Open source), Wikidot-Handbook.

Sie können fragen und mitwirken in der deutschsprachigen » User-Gemeinschaft für WikidotNutzer oder
im deutschen » Wikidot Handbuch ?

by Helmut_pdorf Helmut_pdorf , 05 Jun 2017 11:48
Re: 2 pages at once?
Jsimmons17 Jsimmons17 06 Jun 2017 04:29

thank you for your help, I will continue to think on the issue.

by Jsimmons17 Jsimmons17 , 06 Jun 2017 04:29
FYI: ENP Module Now Includes Button!
GoVegan GoVegan 10 May 2014 05:44

FYI: ENP Module Now Includes Button!

What's that? There's a button now?

So rather than hitting the "Enter" key after typing in input, I can instead lift one hand from the keyboard to the mouse, position the cursor on the button, and click it! Awesome! Much more efficient!

by GoVegan GoVegan , 10 May 2014 05:44
please help
skydiver000 skydiver000 16 Aug 2012 16:24

I seem to read all documentation and spent hours trying to fix it, now I'm stuck, please help

here is what i'm tryign to do: I have parent page, which should show its children. Then user should be able to add a child. Child should be added to current page as "parent".
I tried NewPage module as

[[module NewPage category="testchild" button="add child" parent="%%fullname%%" tags="open" align="left" size="15" preview="true"]]

and it works fine. Here http://sky-tests.wikidot.com/test:page-two I created pages "child1" and "child2".
Then I create one more parent page http://sky-tests.wikidot.com/test:page-three and tried to add a child with same name "child1". it complained with error:
"The page testchild:child1 already exists. Jump to it if you wish."

Therefore I need not only create child pages, but with some uniqness in it's name.
so, i found page when it is actually working http://vineyard.wikidot.com/band:queen
there the one can add band members and they never collide with other bands
the code looks like

[[include :snippets:newpage
|size=400px
|name=%%title%%
|category=bandmember
|parent=%%fullname%%
|button=Add band member
|tags=
]]

I added that code to my page, but unfortunately it does not work: it creates one child page and then any other attempts to create new child page will result editing the first one.

the question: how can i create child page with will either:
1. have some unique number / name or
2. have name like "parent-page + text user typed in the edit box"

this should be something simple but i stuck. It would be nice to have more code samples in the original description
thank you in advance.

P.S.

I tried to use

[[include :snippets:newpage-button NewPage
|category=wo
|name=new-page
|parent=%%fullname%%
|tags=open
|button=Add Work-Order
]]

but it also will always create one page named "new-page".

is it possible to generate new page name based on
"parent-page title (name) + text what user typed in the edit box?

Last edited on 16 Aug 2012 16:34 by skydiver000
by skydiver000 skydiver000 , 16 Aug 2012 16:24
Re: please help
Helmut_pdorf Helmut_pdorf 16 Aug 2012 16:35

I beleive the category "testchild" should be set to "autonumbered" in the site manager! than ever ynew page is autonumbered with the standard page name 1, 2, 3, 4 a.s.o and the title as the creator wished…


Service is my success. My webtips:www.blender.org (Open source), Wikidot-Handbook.

Sie können fragen und mitwirken in der deutschsprachigen » User-Gemeinschaft für WikidotNutzer oder
im deutschen » Wikidot Handbuch ?

by Helmut_pdorf Helmut_pdorf , 16 Aug 2012 16:35
Re: please help
skydiver000 skydiver000 16 Aug 2012 17:31

thank you that helped!

by skydiver000 skydiver000 , 16 Aug 2012 17:31
other languages is not suported
skydiver000 skydiver000 16 Aug 2012 15:44

thank you for your snippet. Unfortunately it is not support any language except English

for example, this code

[[include :snippets:newpage
|size=400px
|category=testchild
|parent=%%fullname%%
|button=hello in russian is == привет
|tags=
]]

will now result string "hello in russian is == привет" as hint, but will generate garbage text

sorry for dublication please remove message above

Last edited on 16 Aug 2012 15:45 by skydiver000
by skydiver000 skydiver000 , 16 Aug 2012 15:44
Re: other languages is not suported
GoVegan GoVegan 16 Aug 2012 15:53

I'm not sure why that happens… I'll look into it

by GoVegan GoVegan , 16 Aug 2012 15:53
GoVegan GoVegan 22 May 2011 05:51

At the time of this post (469 days after the birth of ENP), there are 175 pages on Wikidot using this technology!

by GoVegan GoVegan , 22 May 2011 05:51
Minor Improvement
GoVegan GoVegan 01 Dec 2010 12:33

I noticed that in cases where the user types in a regular expression that is incorrect, the module will fail to work when the user submits the input.

Now there is an implemented solution to this: an error message lets the user know that an invalid regular expression was used to construct the module.

by GoVegan GoVegan , 01 Dec 2010 12:33
Question: ist it not a good idea to BLOCK the pages?
Helmut_pdorf Helmut_pdorf 30 Nov 2010 12:59

I have the feeling - all CSI-used "snippets" ( and their codes) should be blocked by the authors when working well and sre finished in the creating setup - to make them secure against trolls or changes wihtout any need…
Means - even a new version by the author himsels should be copied to a new version-numbering to secure the running version of codes?

What is your oppinion?


Service is my success. My webtips:www.blender.org (Open source), Wikidot-Handbook.

Sie können fragen und mitwirken in der deutschsprachigen » User-Gemeinschaft für WikidotNutzer oder
im deutschen » Wikidot Handbuch ?

by Helmut_pdorf Helmut_pdorf , 30 Nov 2010 12:59
Re: Question: ist it not a good idea to BLOCK the pages?
GoVegan GoVegan 30 Nov 2010 13:21

Hmm.

I suppose restrict the permissions to "only edit pages owned by me". That way anyone can create pages, but they can't edit other people's pages. Perhaps only members of Snippets should be able to edit other people's snippets.

This is a good idea, seeing as some of the CSIs here are quite heavily used.

by GoVegan GoVegan , 30 Nov 2010 13:21
bcammo bcammo 24 Nov 2010 06:16

James (or other guru), is it possible to include the current date and/or time in the url output?? So that if the user's input is this is my page, the url becomes something like…

http://www.wikidot.com/2010-11-24-this-is-my-page/edit/true/title/this-is-my-page

Thanks,
Bryce

by bcammo bcammo , 24 Nov 2010 06:16
GoVegan GoVegan 01 Dec 2010 12:29

Sorry, I don't think that is possible…

by GoVegan GoVegan , 01 Dec 2010 12:29
bcammo bcammo 01 Dec 2010 12:37

Oh really? Well how about this then! Ah ha!

May I warn you to prepare to cringe at my very rudimentary, nigh nearly non-existent Javascript skills. Yet my determination to make this work somehow produced a semi-alright result. Critique welcome…

by bcammo bcammo , 01 Dec 2010 12:37
GoVegan GoVegan 01 Dec 2010 19:50

Oh sorry! I misunderstood you! I thought you meant creating pages based on the current page's creation date!

Very neat and tidy javascript, by the way :)

by GoVegan GoVegan , 01 Dec 2010 19:50
bcammo bcammo 08 Sep 2010 09:24

This may be blatantly obvious, but it was a big 'ah hah!' moment for me…

If you want the user's input to also be created as a page tag, just put:

[[include :snippets:newpage
|tags=#
]]

This is particularly useful for selecting pages with the ListPages module. And it just made my life a whole lot easier.

Cheers,
Bryce

by bcammo bcammo , 08 Sep 2010 09:24
RobElliott RobElliott 08 Jun 2010 14:48

Have you done something to break this snippet James? At the page here I just get a "No such page" error message whenever I try to create a page using

[[include :snippets:newpage
|category=acquisitions
|name=acquisition
|tags=2004
]]

It should create a page with a dataform on it. I tried it on another site with a standard page but still get that message. I'll go back to using the buttons for the time being.


Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.

by RobElliott RobElliott , 08 Jun 2010 14:48
GoVegan GoVegan 09 Jun 2010 00:10

Sorry, I was trying to add functionality, but I failed. Reverted to old version for now.

by GoVegan GoVegan , 09 Jun 2010 00:10
RobElliott RobElliott 09 Jun 2010 09:33

Thanks James, that's now working well.


Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.

by RobElliott RobElliott , 09 Jun 2010 09:33
page 1 of 21
page revision: 119, last edited: 15 Jul 2014 15:08
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License
Click here to edit contents of this page.
Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.
Append content without editing the whole page source.
Check out how this page has evolved in the past.
If you want to discuss contents of this page - this is the easiest way to do it.
View and manage file attachments for this page.
A few useful tools to manage this Site.
Change the name (also URL address, possibly the category) of the page.
View wiki source for this page without editing.
View/set parent page (used for creating breadcrumbs and structured layout).

AltStyle によって変換されたページ (->オリジナル) /