Posted by ErichSteinboeck on 28 Mar 2009 09:55, last edited by GoVegan on 24 Mar 2013 13:05
Tags: count javascript listpages pages
CountPages module
Beginning August 7th, 2009, the instructions contained on this page are no longer recommended, and simply will not work for sites with more than 250 pages due to a pagination limit imposed by Wikidot to reduce server stress.
As a much better alternative, a new module has been created specifically for the task of counting pages! It is the CountPages module!
This new module works in a similar way to ListPages but only has one variable available — %%count%%.
Did you ever wish to count the number of pages in a category? Or count all pages of your wiki?
Find out how you can do it.
Step by Step
Step 1
Create a page inc:page-count-prepend with the following code.
Note:
- Replace community (first line of code) with the name of your Wiki
- Otherwise copy/paste the code exactly as-is, don't remove or change anything
[[embed]]<iframe src="http://community.wdfiles.com/local--code/inc:page-count-prepend/1#\
[!--">
[[code type="html"]]
<html>
<head><title>Page Count</title>
<style type="text/css">
@import url("http://www.wikidot.com/common--theme/base/css/style.css");
</style>
</head>
<body>
<script type="text/javascript">
// (…#) XXXXX... # prepend # append (#…)
var params = /^[^#]*#([^#]*)#?([^#]*)#?([^#]*)#?.*$/;
var match = params.exec(unescape(window.location.href)); // #'s may be escaped
if (match) {
var prepend = '';
var append = '';
if (match[2] && match[2] != '{$prepend}')
prepend = match[2] + ' ';
if (match[3] && match[3] != '{$append}')
append = ' ' + match[3];
document.write(prepend + match[1].length + append);
}
else
document.write('<i>(none)</i>');
</script>
<noscript>
<i>(cannot count)</i>
</noscript>
</body>
</html>
[[/code]]
--]
Step 2
Create a page include:page-count-append with the following code.
Note: Copy/paste the code exactly as-is, don't remove or change anything
#{$prepend}#{$append}" frameborder="0" scrolling="no" width="100%" height="18px"></iframe>[[/embed]]
Step 3
Use the following code on your page where you want to show a count of pages.
[[module ListPages criteria separate="no" perPage="10000" prependLine="[[include inc:page-count-prepend]]" appendLine="[[include inc:page-count-append prepend=leading-text | append=trailing-text]]"]]
X[[/module]]
where
- criteria is any ListPages selection criteria, like category="howto"
- leading-text is any text that should be shown immediately in front of the the number of pages. It may include HTML (no Wikidot) tags, e. g. “Category <em>howto</em>:”. prepend=leading-text is optional.
- If you want to include a double quote (“"”) it must be escaped as “%22”.
- “#” cannot be used within leading-text, neither as-is, nor in its escaped form “%23”
- currently Cyrillic text doesn't work in Firefox or Safari; works in Opera though
- If you'd like to add a link to leading-text (as discussed before, if would have to be an HTML <a href="…">…</a> and not a Wikidot [[[…|…]]] tag) it will only work in the scope of the displayed page if you add target=_parent to the <a ... tag. Find an example for this below.
- trailing-text is any text that should be shown immediately after the number of pages. As above it may include HTML and any double quotes must be escaped as “%22”. The above notes about double quotes, “#” and adding links applies here too. append=trailing-text is optional.
Examples
What you type … | What you get … |
[[module ListPages category="howto" separate="no" limit="250" perPage="250" |
Sorry, no match for the embedded content.
|
[[module ListPages category="*" separate="no" limit="250" perPage="250" |
Sorry, no match for the embedded content.
|
[[module ListPages category="*" separate="no" limit="250" perPage="250" |
Limitations
Wrong totals
As this page count code depends on module ListPages, and ListPages currently does not list any pages starting with underscore (e. g. _template or howto:_style), the displayed totals are off by the number of these pages in the ListPages selection.
On 5. August 2009 the ListPages Module was changed for performance reasons:
If you use the Page count on a site with more than 250 pages over a given category ( or over all) - than you will get pagination!
Browser support
The JavaScript-based solution described here may not be supported by all browsers.
Although this JavaScript-based solution tries to degrade as gracefully as possible if a browser doesn't support or has disabled JavaScript, the best it can do is display “(cannot count)” instead of displaying the actual count.
Please post your browser name and version if you are successfully using it or if you find that it doesn't work.
Browsers successfully tested: Firefox 2 & 3, Google Chrome, Internet Explorer 6 & 7, Opera 9.6, Safari 3 & 4
Browsers that do not work: None reported yet, but any browsers without JavaScript (e. g. Lynx) or browsers with deactivated JavaScript will not work
Backlinks
Author
ErichSteinboeck. Please visit his/her userPage.
Erich,
You are amazing, awesome !
gerdami - Visit Handbook en Français - Rate this howto:import-simple-excel-tables-into-wikidot up!
Erich,
You might also give an example with pipes and brackets to make working this:
appendLine="[[include include:page-count-append prepend=<strong>Community [[[system:pagecalendar|pages]]]: | append=in total</strong>]]"
gerdami - Visit Handbook en Français - Rate this howto:import-simple-excel-tables-into-wikidot up!
> give an example with pipes and brackets to make working this
I've done so. You cannot add Wikidot tags to prepend=…, just HTML tags. And for an <a … you need to add the magic target=_parent to make it work properly — addressing the main window from within the iframe
I just notice that this will make it "trivial" to implement properly working file:// (or other non-supported) links via the same iframe method as here
Thanks for the third example.
I was just wondering whether you could intercept the result of this
and within your javascript, store, count, order and printout the existing categories of a wiki.
gerdami - Visit Handbook en Français - Rate this howto:import-simple-excel-tables-into-wikidot up!
> store, count, order and printout the existing categories of a wiki
Yes, should work — add a unique identifier between all the categories and write some JavaScript to split it, discard duplicates, sort, and display.
If you'd just like to see a list of all your Categories, consider using undocumented module Categories. As far as I know there's no way to configure its output.
When did you find this module Categories ?
I posted a wish http://pro.wikidot.com/ticket:274 for a PageCategory module on 22 March …
gerdami - Visit Handbook en Français - Rate this howto:import-simple-excel-tables-into-wikidot up!
> I just notice that this will make it "trivial" to implement properly working file://
Never ever say “trivial”: I've implemented a method to code unsupported URL schemes (see my How-To) and — believe it or not — it works, except for file://.
This may be an intended (cross-site scripting) restriction, but I'm not knowledgeable enough in this area. Can anyone of you shed more light on this?
> When did you find this module Categories ?
Quite some time — maybe a year or more ago.
> I posted a wish http://pro.wikidot.com/ticket:274
I won't notice anything going on on pro.wikidot as it's locked for non-pro members.
It doesn't work in Safari 4.0 Beta.
> doesn't work in Safari 4.0 Beta
What does it do? Can you please explain details or post a screenshot? Does the console (do you have one on Safari) show JavaScript errors?
Oh sorry, that was really stupid of me. I usually get angry at other people who mention problems without describing them.
The HTML source code compared with Firefox 3 and Safari 4.0 beta is identical. The iframes still appear, however there is no text displayed. It's as though the javascript wasn't run/initiated. Here's an image where I have highlighted one of the iframes:
I have tried adjusting the height of the iframe to 100 pixels, just in case the text was there but simply displaced in the iframe. But that didn't work. It appears there is simply no text rendered by the javascript at all. I do not know if this is the case for Safari 3.
EDIT: The Safari debugging console says:
UPDATE: It is the same with Safari 3 as it is for Safari 4.
> Unsafe JavaScript attempt to access frame with URL …wdfiles…include:page-count-prepend/1 from frame with URL …howto:page-count
An iframe from a different domain cannot run JavaScript? Do I correctly read this? Does Safari work like this?
I'm absolutely no expert here, but as I understand, the whole reason that Wikidot development implemented this with two different domains was security. Any iframed JavaScript would be totally separated from the main page.
thats how i understand it.
so now im confused a bit, because there are lots of times when htmling something wont work because its calling for info from the original main page. So if it works on ff and ie it should in safari.
So if it doesn't work in safari then neither should this:
http://community.wikidot.com/blog:html-within-wikidot
but it does.
James, can you try to replace
just to test what is causing the problem? I assume that Safari restricts cross-domain scripts to read a different frame's URL. The reason could be security: an unexpected script could spy on which pages you're browsing.
> So if it doesn't work in safari then neither should this: http://community.wikidot.com/blog:html-within-wikidot
I guess most iframed stuff doesn't try to read its URL, so it would work in Safari.
Please create a new page — otherwise there might be problems with caching (the old code still being used although you changed it). Please let me know.
I've fixed both the Page Count and the Iframe Link How-To's to work with Safari. Actually, I've just tested Safari 4, so James if you could test it with Safari 3 (just to confirm) please.
It was a nasty incompatibility between (supposedly equivalent) …wiki-name.wikidot.com/page-name/code/1#anchor-part and …wiki-name.wdfiles.com/local--code/page-name/1#anchor-part with Safari only correctly supporting the latter.
Can anyone please test both How-To's with IE7 & 8 and report back?
Hey, you DID fix it! How did you figure that one out?
How do I make this work inline? I'm trying to display the counter at a collapsible block "SHOW / HIDE" field.
Does this also count redirect pages?
And if so, would it be possible not to count them?
The Spambot Death Wall
Arcana Wiki - Distilling the Real World for Gaming
Urbis - A World of Cities - an urban fantasy setting of industrial magic
LiveJournal
It counts all pages that do not start with an underscore (_).
It does use the ListPages module, so you would be able to restrict pages if you wish (such as redirect pages). This is possible if you tag all of your redirect pages with the tag "redirect"
Then, where you want the pages to be counted, put the attribute tags="-redirect". For example:
In the inc:page-count-prepend page, is this code:
In the first line above, is it necessary to initiate the 'url' variable when it's never used? Or is there something I missed?
Another thing:
You could eliminate the code replacement step by using relative urls. I believe changing the code to this would work on any wiki:
[[embed]]<iframe src="/include:page-count-prepend/code#[!—">
This does direct it to http://yourwiki.wikidot.com/include:page-count-prepend/code, however. But this is not a problem, because Wikidot automatically redirects it to http://yourwiki.wdfiles.com/local--code/include:page-count-prepend, and the javascript code works in the "wdfiles" domain.
In case you weren't already aware, the suffix "/code" is automatically interpreted as "/code/1" in the wikidot domain, just as having no suffix is equivalent to "/1" in the wdfiles domain.
> You could eliminate the code replacement step by using relative urls
That's exactly what I had also thought when I developed the code. But if you use the http://wiki-name.wikidot.com/include:page-count-prepend/code style iframe URL instead of the http://wiki-name.wdfiles.com/local—code/include:page-count-prepend URL, you'll find that Safari doesn't render the iframe — the problem you detected.
See the example on Sandbox — most browsers are OK, but Safari fails.
Arg, you're right! The iframe still loads in Safari, but without the appending string (/code/1#appending_string). Hence (none) is displayed, as there is no appending string.
> is it necessary to initiate the 'url' variable when it's never used?
No, it's not. I had jointly developed the two How-To's Page Count and Iframe Link and this line of code went dead for the Page Count How-To.
I've already removed it from the How-To. Thanks for finding this.
The only problem I had with this was that when I use a rss feed, it will take forever to propagate all the changes throughout. I added a test post, and it still shows that I have 2 posts, and not 3.
> The only problem I had with this was that when I use a rss feed, it will take forever
> I added a test post, and it still shows that I have 2 posts, and not 3
Can you give us more details? What exactly happens where? Maybe a link so that we can test?
Sure, here:
http://macfire.wikidot.com/sandbox:rsscount
It still only shows 2 pages. I have done 3 posts.
Ahh, a small misunderstanding here: the page count module is designed to count pages, not forum posts.
The reason it gives the number 2 on your page, is because you didn't specify a category in your ListPages module. If you don't specify a category, Wikidot assumes you're talking about that page's category (in this case, sandbox). Low and behold, how many pages are in the sandbox category? 2
At the moment I'm trying to find a way to count forum posts/comments for you…
Must I put the name of the pages include:include….? Can i put some other category?
If slaughterhouses had glass walls, everyone would be vegan. - Paul McCartney
I personally HATE having pages to be included in a category called “include”:
Why? Because when it comes to programming, my thought processes are going “Now, we need to include the page-count-prepend page. Lets type that in…” and this is what I type:
When my page doesn't work because Wikidot claims that my page doesn't exist, I am very confused. My brain thinks “Okay, did I type the page name wrong? Nope. Did I forget to write include? Nope”
That last thought process is wrong, I DID forget to write “include”, but when my brain was scanning the code, it registered that it is there.
When it comes to includes, I think its necessary to have them all in a category, but I call the category “inc”, short for “include”:
Your answer in short Brunhilda, yes, you can change the name of your include pages. But on your include:page-count-prepend page, don't forget to change in the first line of code /local—code/include:page-count-prepend/1# to the correct name of your page.
> When it comes to includes, I think its necessary to have them all in a category
You don't have to put all includes in a single category, just by convention we usually put them into “include”
I did everything by instructions (including the include category!), but the code does not work. It shows more pages of ART category than there are. There are 274 pages and it shows 294 pages.
Here, include:sandbox where the code is put:
http://istorijska-biblioteka.wikidot.com/include:sandbox
You shall also see that it does not support Cyrillic, and that is strange since there are lot of modules where I can change to Cyrillic the anchor text.
And here are two include pages. I will open the include category for you to be able to edit it.
http://istorijska-biblioteka.wikidot.com/include:page-count-prepend
http://istorijska-biblioteka.wikidot.com/include:page-count-append
If slaughterhouses had glass walls, everyone would be vegan. - Paul McCartney
I know why there are more pages! It counts also redirects! I must add somewhere tag="-преусмерење", because this prevents the module to count redirects. Is this possible, James?
EDIT: OK, I added it and now the number is ok. The only thing is that it does not support cyrillic.
Now, is it possible to avoid any kind of text? To have only a number, and the text in Cyrillic can be written outside of the module…
If slaughterhouses had glass walls, everyone would be vegan. - Paul McCartney
Yes, very easy =)
For this:
Don't add any leading-text or trailing-text
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server | NEW: Wikiroo, backup tool (in development)
Hmm, the text in Cyrillic should work. Could you give us an example of some text that does not?
Simply, yes. Just put a space in the prepend and append values. But the text you put outside the number would not be on the same line (it would be on the lines before and after)
Edit: Leiger beat me to it!
If you edit the Sandbox page, you'll see Текстови:.
Can you do that? I do not understand where I should do that exactly. You can edit the sandbox page, as a matter of fact I put all include category open to edit for all Wikidot members. But this only if it does not accept Cyrillic…
If slaughterhouses had glass walls, everyone would be vegan. - Paul McCartney
OK, I did that too… And it really seems that Cyrillic doesn't work… But, now, I would like to give size and color to that number… Is it possible? I tried to wrap it in div, but it did not work. I tried to add inside te module font-size but it didn't work…
EDIT:It seems that nothing works with this. You cannot put any design in it! Square brackets for centering to the page don't work with this either…
If slaughterhouses had glass walls, everyone would be vegan. - Paul McCartney
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server | NEW: Wikiroo, backup tool (in development)
> it really seems that Cyrillic doesn't work
Unfortunately, Cyrillic text in prepend/append doesn't work in e. g. Firefox or Safari, although it works in Opera. I don't know yet how to solve this.
Does anyone of you JavaScript gurus know what JavaScript code would convert the (e. g.) “%D0%A2” in <iframe src="…include:page-count-prepend/1#X#%D0%A2" …"></iframe> so that it appears as Cyrillic text? The current code uses a simple unescape() which doesn't do the trick. I had also thought of adding <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> but that didn't help.
> give size and color to that number… Is it possible
To style the page count use HTML (not Wikidot) tags with prepend= and append=
Note that in e. g. <span style="font-size:75%; color:red"> any double quotes need to be escaped as %22, giving <span style=%22font-size:75%; color:red%22>
Color specifications like e. g. “color:#877E3D” do not work, as “#” cannot be used (neither as-is nor escaped as %23) within prepend= / append=
Note that if you want larger text, you may have to increase the iframe “height="18px"” in include:page-count-append, otherwise the text will get clipped by the iframe
> Square brackets for centering to the page don't work with this either
What you can do is, float it with [[div style="float:right"]]
Thank you Erich, so much, I have just seen what you've done at include:sandbox, but it seems so complicated, and I wanted to put counts for three caategories… I don't know if it is possible at all in a way I want… :(
The question is:
Where is that iframe? And how do I include the height? How do I put it bold, and how do I put it in golden color?
PS: "float" inside div does not work if I want to put it in the center…
If slaughterhouses had glass walls, everyone would be vegan. - Paul McCartney
> Where is that iframe?
(For technical reasons) the iframe code is split between the two includes
> And how do I include the height?
The height="18px" is hardcoded in include:page-count-append, because I didn't want to make the code even more complex than it already is. You could easily change height="18px" to height="{$height}px" so that you can set the height individually on each include call appendLine="[[include include:page-count-append height=18 | prepend=… | append=…]]
> How do I put it bold
By using prepend=<strong> | append=</strong>. You can find an example for a bold page count in the How-To.
> how do I put it in golden color?
by using prepend=<span style=%22color:color-name%22> | append=</span>, where color-name can be one of the 16 Web Standard Color Names aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow or any of the Cross-Browser Color Names if the browsers you want to support, support them.
Ok… Now I managed to make it bold and to amplify the iframe, the color will stay black since there is no color that corresponds to my golden…
The only thing that stays is the position in the page… It seems that float:center doesn't work. I also tried page center and page-center, and it does not work…
If slaughterhouses had glass walls, everyone would be vegan. - Paul McCartney
Brunhilda, in the div try margin: 0 auto; text-align: center; (which is the same syntax I gave you a couple of days ago for a similar div centering issue :) )
Rob
Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.
My dear Rob! :D
I am hopeless case, I know, and I am so sorry, but I simply don't get very well what all those margins are for … :(
I put it in the div what you told me, but it does not work… The number is still on the left side….
http://istorijska-biblioteka.wikidot.com/include:sandbox
If slaughterhouses had glass walls, everyone would be vegan. - Paul McCartney
Hmmm you're right. It must be to do with all that other stuff around it. I did manage to center the number with margin: 0 0 0 40%; (and leave out the text-align) but it's not exactly centered.
Rob
Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.
Now it works!!!! I put 47.5% and it is exactly in the middle…. :D
http://istorijska-biblioteka.wikidot.com/include:sandbox
Oh, Rob, thank you very much!!!!! And you too, Erich, for inventing this!!!
EDIT: Hm, it still has problems when i include that page into other page… But never mind, now I know how it works, so I'll find it the use…. :D
If slaughterhouses had glass walls, everyone would be vegan. - Paul McCartney
WOW !
We have the same problem with the "page count - do not center" on the handbook start page!
We put it in a table, in a second div, in a…
all did not help , the internal structure of the inlcude output destroys all what we have tried…..
Now - this is OVER!
Thanks Rob - and Brunhilda (you insisted on a solution of this problem) !
@Brunhilda: if you want to know the margin: styke attributes have a look on our new howto:
http://community.wikidot.com/howto:table-attributes
which explains the style="margin: 0 0 0 40%;" in a short way:
if the overall attribute "margin" is used than the following 4 numbers have this meaning:
1. margin-top
2 .margin-right
3. margin-bottom
4. margin-left ( = 40 % from left border of the "screen, frame, cell, window, a.s.o;
- easy to remember - from top clockwise around…
( this is the same with padding: ! )
for centering "something" you have to add the length of the included text!
Hope this helps?
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 ?
I am familiar with most of those, but sometimes i don't get very well the padding… Sometimes, it simply does not behave as I expect :D…
Thanks, Helmuti, you're so helpful!
If slaughterhouses had glass walls, everyone would be vegan. - Paul McCartney
I think - the module counts only "250" documents before automatic pagination starts … have a look on the examples here above on the "howto" and on my output on the Handbook:
http://community.wikidot.com/forum/t-173885/listpages-works-differently-sinve-this-morning#post-553844
Something has changed in the internal counting/pagination process!
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 ?
Pieter explained the reason for this:
http://community.wikidot.com/forum/t-173885/listpages-page-count-works-differently-sinve-this-morning#post-553884
I think this is ok and necessary…
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 ?
On 5. August 2009 the ListPages Module has changed for security reasons:
If you use the Page count on a site with more than 250 pages over a given category ( or over all) - than you will get pagination!
I will insert the limit in the page too.
http://community.wikidot.com/syntax-changes is changed..
Now I know why the start page of handbook is so fast now!
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 ?
No, it's not SECURITY reasons… that would mean Wikidot had a security hole that could allow hackers to exploit the system through the ListPages module.
They changed it for PERFORMANCE reasons; too many resources were being taken up by this module — hence slowing down page compilation.
Of course - you are correct ..
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 ?
Language barrier, I gather?