01344: Add pagelist iterator

Summary: Add pagelist iterator
Created: 2014-04-21 04:21
Status: Open
Category: Feature
From: VKrishn
Assigned:
Priority: 554
Version:
OS:

Description:

eg. (:pagelist iterator=[+/-]start,[+/-]end,[+/-]step :)
eg. (:pagelist iterator=1,10,1 :)
alternate
eg. (:pagelist for=[+/-]start,[+/-]end,[+/-]step :)
value list
eg. (:pagelist for="a b c" :)
or
e.g. (:pagelist istart=[+/-]startvalue iend=[+/-]endvalue istep=[+/-]stepvalue :)

demo - CopyPasteCalendar-Talk

With a simple pagelist iterator, it becomes easy to do some interesting things with current template directives. Seems very nice to have in core than as a recipe.

Another way might be to use Page List Templates directives, e.g.

(:template iterator istart=n iend=n istep=n:)
(:template iteratorstart:)
!!! {$$istart}
(:template each:)
{$$ivalue}
(:template iteratorend:)
{{$$icount} output from {$$istart} to {{$$iend} with {$$istep}
(:template iteratorend:)

One can use count=num to achieve the same but I believe a pure iterator would be less expensive and faster.

(:pagelist count=10 :)

If it can be done in any other way please do point to the docs.

Thanks. VKrishn April 21, 2014, at 04:30 AM

I'd love such a feature as well. In my CopyPasteCalendar recipe I repeat the same line 28 times instead (plus 3 more times in a slightly modified form). I could have used the page list count feature instead. Anyway I wonder whether this might cause problems in a wiki installation with less than 28 pages in total (could only happen in a wiki with no documentation installed I guess). StefCT April 21, 2014
I'd like this feature, with access to the counter that is not driven by the number of pages encountered by the pagelist, e.g. I'd like to, say, iterate for all years to 2000 to 2010 simon September 18, 2014, at 07:53 PM; e.g.
(:pagelist iterate=2000...2008) fmt=#mylist:)
[[#mylist]]
(:template first {$$Iterator}:)
!! From {$$Iterator}
(:template each:)
(:pagelist name={$$Iterator}* fmt=#titlesummary:)
[[#mylistend]]   

For the alternative suggestion (:pagelist istart=[+/-]startvalue iend=[+/-]endvalue istep=[+/-]stepvalue :) separate variables are proposed so they can be accessed in the template. I'd suggest that istart and iend must both be specified for the iteration to occur, and step defaults to 1 or -1 depending on the value of istart and iend.

The count=start..end parameter accepts more than just a number.
Also {$$request} is under-documented, you can use variables from the page url (request=1 needs to be set).
Other than that, {$$PageCount} can be used with conditionals, and with the 'mod' MarkupExpression to create iterations. (I install the 'mod' MX on every wiki I use, so I believe this could go into the core.) --Petko April 21, 2014, at 05:13 AM

  $MarkupExpr['mod'] = '0 + ($args[0] % $args[1])'; # Wikipedia:Modulo_operation
Markup test page demo pls. VKrishn April 21, 2014, at 06:24 AM

Here you go: --Petko April 21, 2014, at 09:37 AM

[[#iterator]]
(:template first:)
(:table border=1:)
(:template each:)
(:if equal "{(mod {$$PageCount} {$$columns})}" "1":)
(:cellnr align=right:)
(:else:)
(:cell align=right:)
(:if:)
{$$PageCount}. [[{=$Name}]]\\
(:template last:)
(:tableend:)
[[#iteratorend]]

[[#modpair]]
(:if equal {(mod {$$PageCount} 2)} 0:)
* {=$Name} {=$:Summary} 
(:ifend:)
[[#modpairend]]
(:pagelist group=PITS name=PITS.0* fmt=#iterator count=51..100 columns=5 request=1:)
Try with [[({$Name})?columns=2]], [[({$Name})?columns=3]], [[({$Name})?columns=6]], [[({$Name})?columns=11]]

1. 00401

2. 00402

3. 00403

4. 00404

5. 00405

6. 00406

7. 00407

8. 00408

9. 00409

10. 00410

11. 00411

12. 00412

13. 00413

14. 00414

15. 00415

16. 00416

17. 00417

18. 00418

19. 00419

20. 00420

21. 00421

22. 00422

23. 00423

24. 00424

25. 00425

26. 00426

27. 00427

28. 00428

29. 00429

30. 00430

31. 00431

32. 00432

33. 00433

34. 00434

35. 00435

36. 00436

37. 00437

38. 00438

39. 00439

40. 00440

41. 00441

42. 00442

43. 00443

44. 00444

45. 00445

46. 00446

47. 00447

48. 00448

49. 00449

50. 00450

51. 00451

52. 00452

53. 00453

54. 00454

55. 00455

56. 00456

57. 00457

58. 00458

59. 00459

60. 00460

61. 00461

62. 00461-Test

63. 00462

64. 00463

65. 00464

66. 00465

67. 00466

68. 00467

69. 00468

70. 00469

71. 00470

72. 00471

73. 00472

74. 00473

75. 00474

76. 00475

77. 00476

78. 00477

79. 00478

80. 00479

81. 00480

82. 00481

83. 00482

84. 00483

85. 00484

86. 00485

87. 00486

88. 00487

89. 00488

90. 00489

91. 00490

92. 00491

93. 00492

94. 00493

95. 00494

96. 00495

97. 00496

98. 00497

99. 00498

100. 00499

Try with ?columns=2, ?columns=3, ?columns=6, ?columns=11

(:pagelist group=PITS name=PITS.0* fmt=#iterator count=1401..1470 columns=7:)

1. 01406

2. 01407

3. 01408

4. 01409

5. 01410

6. 01411

7. 01412

8. 01413

9. 01414

10. 01415

11. 01416

12. 01417

13. 01418

14. 01419

15. 01420

16. 01421

17. 01422

18. 01423

19. 01424

20. 01425

21. 01426

22. 01427

23. 01428

24. 01429

25. 01430

26. 01431

27. 01432

28. 01433

29. 01434

30. 01435

31. 01436

32. 01437

33. 01438

34. 01439

35. 01440

36. 01441

37. 01442

38. 01443

39. 01444

40. 01445

41. 01446

42. 01447

43. 01448

44. 01449

45. 01450

46. 01451

47. 01452

48. 01453

49. 01454

50. 01455

51. 01456

52. 01457

53. 01458

54. 01459

55. 01460

56. 01461

57. 01462

58. 01463

59. 01464

60. 01465

61. 01466

62. 01467

63. 01468

64. 01469

65. 01470

66. 01471

67. 01472

68. 01473

69. 01474

70. 01475

This example shows the flaw of using count as an iterator, as there has to be at least as many pages to count as the numerical value you wish to work with.

(:pagelist group=PITS name=PITS.01* fmt=#iterator count=1401..1470 columns=7:)
(:pagelist group=PITS name=PITS.0* fmt=#iterator count=14 columns=2:)

1. 00001

2. 00002

3. 00003

4. 00004

5. 00005

6. 00006

7. 00007

8. 00008

9. 00009

10. 00010

11. 00011

12. 00012

13. 00013

14. 00014

(:pagelist group=PITS name=PITS.0* fmt=#iterator count=28 columns=14:)

1. 00001

2. 00002

3. 00003

4. 00004

5. 00005

6. 00006

7. 00007

8. 00008

9. 00009

10. 00010

11. 00011

12. 00012

13. 00013

14. 00014

15. 00015

16. 00016

17. 00017

18. 00018

19. 00019

20. 00020

21. 00021

22. 00022

23. 00023

24. 00024

25. 00025

26. 00026

27. 00027

28. 00028

Only pairs using "name=" (note that only pair pages are found)

(:pagelist group=PITS name=PITS.0*[24680] count=10:)
PITS /
00002  searchresults and pagelist could allow sort= parameter (Closed - added in 2.0.beta33)
00004  Need password protection of action=approvelinks (Closed - fixed for 2.0.devel24)
00006  Need better documentation of WikiStyles in 2.x (Closed - updated for 2.0.0)
00008  $PagePathFmt not functioning properly in Cookbook (Closed - not a bug)
00010  user-based authorization (Closed)
00012  TextFormattingRules is out of date (Closed - fixed in 2.0.devel14)
00014  Call-time pass-by-reference in call to RestorePage (Closed - fixed)
00016  -Blank page- (Closed)
00018  "invalid page name" should contain a link to the home page (Closed - fixed in 1.0.11)
00020  <p> tags are incorrect in PmWiki 1.0 (Closed - fixed in v2)

Go to page:  1  2  3  4  5  6  7  8 

Only pairs using "mod" (note that only pair pages are displayed, from 20 pages found impairs are skipped):

(:pagelist group=PITS name=PITS.0* fmt=#modpair count=20:)
  • 00002 searchresults and pagelist could allow sort= parameter
  • 00004 Need password protection of action=approvelinks
  • 00006 Need better documentation of WikiStyles in 2.x
  • 00008 $PagePathFmt not functioning properly in Cookbook
  • 00010 user-based authorization
  • 00012 TextFormattingRules is out of date
  • 00014 Call-time pass-by-reference in call to RestorePage
  • 00016 -Blank page-
  • 00018 "invalid page name" should contain a link to the home page
  • 00020 <p> tags are incorrect in PmWiki 1.0

Thanks for {(mod)} markup expression, this would also make creation of pagination links easier.

Does (:pagelist fmt=#modpair count=20:) mean it will fetch/read each pmwiki pages and process it, upto count=20 ?

If yes, then what I meant by pure iterator is slightly different and may not fall into pagelist markup.
A pure iterator would not read pages unless some markup in fmt=? calls for,
but would just iterate and parse fmt=?
So from purist point markup (:loop for=1,10,1 fmt=#modpair:) would be better.

VKrishn April 21, 2014, at 10:03 AM

No, the last pagelist does not read all 20 pages (=does not open all 20 files). It only sees the first 20 pagenames. What is read from the disk files depends on the #modpair template, in the example we want to display a {=$:PTV}, then only 10 disk files will be opened from the 20 pagenames. --Petko April 21, 2014, at 10:57 AM

I was wrong, conditional markup is processed after page variables, so all 20 files are open. --Petko April 21, 2014, at 11:33 AM

See Cookbook:BreakPageList for a possible solution and/or a possible starting point for a solution. --Petko April 21, 2014, at 11:33 AM

For the pure iterator, in strict implementation I would not expect variables like {=$Name} {=$:Summary} {=$:PTV} to be available in fmt=? block.
But it would not hurt to read the ls (list) of valid pages available,
thus making the variables parse-able (kinda lazy mode).
One drawback would be loop(iteration) exceeding the number of pages,
in which case the variables stop being available.

VKrishn April 21, 2014, at 11:57 AM

Ok, I think that you want a special (:loop:) markup, capable to repeat a markup template for a specified number of times. This seams unrelated to PageLists, so the Summary, the Category, and the Priority of this entry should probably be corrected. I don't think that this will be required by many wikis so a recipe will probably be better. This way we can see if there are indeed many users. --Petko April 21, 2014, at 12:24 PM

What happens when fmt=? block does not have variables like {=$Name} {=$:Summary}
Does (:pagelist fmt=#modpair3 count=20:) still process 20 wiki pages ? eg.

[[#modpair3]]
(:if equal {(mod {$$PageCount} 2)} 0:)
* {$$PageCount}
(:if:)
[[#modpair3end]]

It might not be a pagelist implementation in strict sense. But still think to be a CoreCandidate. Option pagelist for=? can be added that performs partial functionality of pagelist.

Hmm.. apology for marking category to "CoreCandidate" just picked form the form , thought any new issue could have such status set by user. Now changed to Feature.

VKrishn April 21, 2014, at 12:42 PM

Well, you can test it and see. The following will find only a few pages, less then the 'count' value, and will display the pair ones.

(:pagelist fmt=#modpair3 name=PITS.0134* count=9999999:)
  • 2
  • 4
  • 6
  • 8
  • 10

Yes, the pagelist markup iterates on existing pages only, regardless of the content of the template. If there are fewer pages than the count= parameter, fewer iterations of the template will be displayed. --Petko April 21, 2014, at 12:54 PM

Thanks.
In above test I am assuming this also means it fetches/reads pages PITS.01342 + PITS.01344 . Then definitely a need for a pure iterator ;-) VKrishn April 21, 2014, at 01:01 PM

No, this one #modpair3 does not open the two (2, 4) or five (0, 1, 2, 3, 4) files, because inside the template there is no markup that requires this - no PageTextVars, no includes, no titles, etc. The first one #modpair opens them because it contains {=$:Summary}. --Petko April 21, 2014, at 01:05 PM

hmm... thanks, then would leave it as feature avaiting more votes. VKrishn April 21, 2014, at 01:13 PM