Template talk:Test-mode
Template Talk
Add discussion
Proposed enhancement for testing templates
This discussion and its sub-section "New test-mode template" was moved here from David's (my) talk page. It is the discussion that lead to the creation of this template, and it discusses several technical details of this template. I have removed some parts that are not relevant to this page. --David Göthberg (talk) 11:18, 24 January 2010 (UTC)
David, with your background in programming and experience on Wikipedia, I would appreciate any comments/insights you might have for this enhancement I've proposed: bugzilla:22135. stmrlbs|talk 19:51, 17 January 2010 (UTC)
Your suggestion over there seems to be pretty tricky to implement in MediaWiki, it would mean a lot of work for the devs. And we already have other well working methods to test our templates. So I don't think it would be worth the time for the devs to implement, they have more pressing things to fix.
--David Göthberg (talk) 11:07, 18 January 2010 (UTC)
Stmrlbs: Oh! I think I have come up with a method to achieve what you want by only using template code. I'll think more about it and test it before I explain it. (And it might be useful, since as you say it would be very nice to surf around and see how the new version of the template will look on pages.)
--David Göthberg (talk) 11:23, 18 January 2010 (UTC)
So, what did you come up with? Yes, it would be nice to be able to not have to dummy up so much to test - it is always better to try to keep the changes needed to test to a minimum, so that if there is a problem, you can assume with some confidence that it was the changes you made to the template, not the changes you had to make to dummy up a test in your userspace. I've done something similar for some other systems (not wikipedia), and it made it much easier to test. I understand what you are saying about the devs having a lot to do. I've looked at the number of enhancements submitted.. a lot! But then, wikipedia has a lot of users. So, I'm not surprised. However, I always try to submit an idea anyway, if for no reason other than to document it. stmrlbs|talk 00:57, 19 January 2010 (UTC)
Okay, I have done some testing and thinking, so here goes:
(Mostly for others reading this talkpage:) As you and I know we need a method to live-test meta-templates and sub-templates that might be several steps away from the templates placed on the pages, so we can't call the test-version directly. So you suggested a "test mode" that makes our meta-templates display their test-version instead of the normal version, so we can surf around and see how our test-version behaves on real pages.
Stmrlbs: What I came up with is actually three methods, but I am going to package them all in one single template named {{test-mode}}. You use that template by placing it on the template you want to test, like this:
{{test-mode | test version = <!-- New code to test, or a transclusion of the /sandbox with forwarding of your template's parameters. --> | current version = <!-- The currently deployed code that most users see. --> }}<noinclude> {{documentation}} </noinclude>
My {{test-mode}} then normally executes the "current version". But if it detects one of the following three things it instead uses the "test version":
1: When a user with a name beginning with "Test-" views the page in edit preview. So you simply create a sock account named "Test-Your username" and then preview the pages you want to test from that account. This means you can view the pages as they are in one tab, and view them in test mode by edit previewing them in another tab. So it is easy to compare output, and your normal page reading is not affected. If you set your Wikipedia "My preferences - Editing - Show preview on first edit" then test mode is just one click away on every page!
2: If a user who is listed in my template's "/user list" views the page in edit preview. So you simply add your normal user name to {{test-mode/user list}}. Unfortunately that list will have to be protected since its a sub-template of {{test-mode}} which in turn probably will be used in several high-risk templates. So only admins can do the adding of people to that list. (And every time we add or remove a user from that list all pages that depend on it will be dropped from the cache servers.) But your name can be on the list more or less permanently, since as above: This means you can view the pages as they are in one tab, and view them in test mode by edit previewing them in another tab. So it is easy to compare output, and your normal page reading is not affected.
I can make it so that users in the "/user list" can toggle this mode on and off with a personal setting in their user space. I could give that option to all users thus no need for the "/user list", but that might be inefficient, I'll have to think and test more.
3: If the template is placed on a page beginning with "Test-" like "Test-Pagename". So if you want to test how the article "Example" looks in test mode you simply open up "Test-Example" and transclude "Example" onto it like this "{{:Example}}" and then click "Show preview". Note that to transclude articles we must use the colon ":", otherwise MediaWiki tries to transclude "Template:Example" instead. You normally don't need to save the page, but it can be convenient if you want to display the result to other users. Unfortunately we are not allowed to save test versions in article space, so you have to save it in another namespace. I will also make this work on subpages like "Example/Test-subpagename".
Methods 1 and 2 above uses {{REVISIONUSER}}, so those two methods will only work as long as they don't fix bugzilla:19006. Which really isn't a bug, just that some people don't want that magic word to work that way. {{REVISIONUSER}} normally returns the name of the user who last edited the page, but in edit preview it currently instead returns the name of the user currently editing the page.
But method 3 will continue to work. Unfortunately method 1 and 2 are the more practical ones when testing on many pages.
Testing with the {{test-mode}} should of course only be done after normal testing in the /sandbox and /testcases has been done. Since if you have missing braces or extra pipes "|" in the test version, then it will bleed through and become visible to normal readers who are not in test mode.
--David Göthberg (talk) 07:48, 19 January 2010 (UTC)
David, I don't understand.. where does the user put {{test-mode}}? In the article calling the template to be modified? Is that why it is necessary to use edit preview? and can you tell me where Revisionuser is documented? I can't seem to find it (probably am not looking in the right place). Thanks. stmrlbs|talk 04:01, 20 January 2010 (UTC)
{{test-mode}} should be added to the code of the template you want to test, not the article.
{{REVISIONUSER}} is a "magic word", not a template, so it is documented in mw:Help:Magic words. But the documentation there doesn't mention that when in edit preview {{REVISIONUSER}} currently returns the name of the user himself. So in edit preview I can detect who is looking at a page. We have no way in template code to detect who is viewing a page when just viewing a page, only when editing a page. Anyway, I see that the devs now are dead set on removing that feature from {{REVISIONUSER}}, so soon we will not be able to get the user name even in edit preview. So I guess we'll have to forget about methods 1 and 2 above. So all that is left for us is method 3.
In method 3 you can save the result so others can view it too, then we don't have to use only edit preview. (But if only you yourself want to take a look, then there is no reason to save.) Unfortunately method 3 means some more operations for each page we want to look at, so it is not as convenient as methods 1 and 2 would have been.
Anyway, I will create and document {{test-mode}}, so you can just sit back and wait for the result, the documentation and the live examples.
--David Göthberg (talk) 19:14, 21 January 2010 (UTC)
why do they want to remove the feature? Well, I'm looking forward to seeing your test template. I was thinking today that it is too bad there isn't some kind of template footprint on the page that would tell you what pages transclude what. But, I guess that would make some of the pages huge (especially with the multilevel nesting needed sometimes because of the language limitations). And I will assume there isn't an easy database method to check what templates are transcluded in a page. I don't know enough about wikipedia software to know that. If there was, you could add an option to check the database only for those users with the testing option on, and if the test template was found to be transcluded in a page they were viewing (by checking the database), then rerender the page and bring in the test template. or something like that. stmrlbs|talk 02:33, 22 January 2010 (UTC)
There's a minor security issue with being able to detect who is currently reading/editing a page. You can read more about that at bugzilla:19006. But there are other ways an attacker can get the same information, ways we can never really prevent, so I don't think we should bother about it. (But I won't tell more about that, for WP:BEANS reasons.)
Actually, the database knows exactly which templates are currently used on a page, since among other things it needs to update the "What links here" list for all the templates on a page if the page is deleted or modified. So implementing the test mode in MediaWiki probably isn't that hard. But still, it would cost extra server resources to run, and extra developer time to implement and maintain. And currently MediaWiki doesn't check which user is viewing the page area, it is only the front end servers that check who the user is to render the surrounding menus etc. The page area content is fetched from the cache servers and is the same for all users (with some exceptions). The reason that {{REVISIONUSER}} so easily can provide unique output for each user editing a page is that in edit preview the page content is not fetched from the cache, instead the whole page content is re-rendered on each edit preview. So edit preview is pretty much like doing a purge, but without saving the result of the purge.
--David Göthberg (talk) 10:10, 22 January 2010 (UTC)
New test-mode template
I have now created and documented the {{test-mode}} template. I choose the name {{test-mode}} since {{test-template}} kind of was a name collision with an existing redirect at {{test template}}. I have edited all comments above to say {{test-mode}}, to avoid any future confusion.
--David Göthberg (talk) 14:22, 23 January 2010 (UTC)
David, I ran a little test in my user space and it works great! Cool! I tried it calling a very simple (one line) test template directly, and calling another template that called the test-macro, and they both worked. You can see it here, by edit previewing User:Stmrlbs/sandbox#try_test-mode​. David, I did not understand this in your instructions "New code to test, or a transclusion of the /sandbox with forwarding of your template's parameters." What is "forwarding of template parameters"? Do you have an example that I can look at? Thanks. stmrlbs|talk 03:31, 24 January 2010 (UTC)
I see you are using the "personal test1-mode", and your test cases are very nice! :))
I perhaps should add some sub-pages to {{test-mode}} with some examples, and link to those examples from the documentation.
I have removed the comment about "forwarding to the sandbox", since that can cause problems. Since anyone can edit the sandboxes, and if a sandbox is missing the end braces it will bleed through to the current version. And that might be nasty if it is a high-risk template.
But since you asked, below is an example of what I meant. The example is the code for {{mytemp}} which has the sandbox {{mytemp/sandbox}}.
{{test-mode | test1 version = <!--New code to test, calling the /sandbox version--> {{mytemp/sandbox | 1 = {{{1|}}} <!--Forwarding parameter 1 to the /sandbox--> }} | normal version = <!--The currently deployed code that most users see--> ''This project has {{{1|}}} users.'' }}<noinclude> {{documentation}} </noinclude>
--David Göthberg (talk) 04:39, 24 January 2010 (UTC)
ok.. I see what you mean. The bleeding issue, you would have that whether you made that mistake in the sandbox or copying the test code into the template. Hopefully, a person will test for that separately and correct any problem like that before trying this method. That is the only problem is that you do still have to modify the "public" template to be able to use the edit preview to test with article pages without having to dummy up examples. But if you are careful about it.. it is really nice. And, you could have it do this, right? (using your example for public template mytemp):
{{test-mode | test1 version = <!--New code to test, calling the /sandbox version--> {{User:Stmrlbs/Template/mytemp | 1 = {{{1|}}} <!--Forwarding parameter 1 to the User:Stmrlbs/Template/mytemp--> }} | normal version = <!--The currently deployed code that most users see--> ''This project has {{{1|}}} users.'' }}<noinclude> {{documentation}} </noinclude>
stmrlbs|talk 05:16, 24 January 2010 (UTC)
Yes, you understand it correctly. I expect that people sometimes will be leaving the test-mode in templates for weeks while testing and discussing new versions of a template. I think you understand this part, but anyway: Say {{mytemp}}} is a high-risk template used on 300,000 pages. Then a vandal can go editing the unprotected {{User:Stmrlbs/Template/mytemp}} to damage that template for all users, by using the "bleed through" effect. And probably more common: If we forward to {{mytemp/sandbox}} some innocent user might go to that sandbox doing experimental edits, not knowing that his edits might become visible on all those 300,000 pages if he forgets the end-braces, or even just tries to use a wikitable in the /sandbox. (Wikitable markup breaks when fed as a parameter to a template. Then we need to use HTML table markup instead. I will document that in {{test-mode}}.) So to avoid these misstakes it is better to forward to some other page than the /sandbox, to avoid the "accidental" edits. (I usually use a /test1 subpage under the templates as my personal sandbox, so others won't mess with my sandbox versions.) And if the main template is protected then the test-template should also be protected.
By the way, I think we should copy most of our above discussions to the talk page of {{test-mode}}, since others will probably ask the same things.
--David Göthberg (talk) 09:51, 24 January 2010 (UTC)
usually any template that is high risk and is used on that many pages is only going to be able to be edited by an administrator. Kind of a catch 22 in that the templates where you could really use this to do a lot of testing easily, is the type of template that a user like me won't be able to edit. But, like it will be great for the templates that aren't restricted to administrators. stmrlbs|talk 10:31, 24 January 2010 (UTC)
Yeah, and that is one of the reasons why it would be better if MediaWiki had the test-mode built-in, as you suggested in bugzilla:22135.
But I think it can be okay to temporarily forward to say a /test1 sub-template that is semi-protected, when a user like you want to do some test runs. Since most vandals don't know how this works, and they won't know when we do such test runs. And that probably also stops most of the beginners from accidentally damaging the template.
--David Göthberg (talk) 11:02, 24 January 2010 (UTC)
End, paragraphs moved here from my talk page. --David Göthberg (talk) 11:18, 24 January 2010 (UTC)
About ((test-mode))
As can be seen above, Stmrlbs came up with the idea for a template test mode and filed that idea as bugzilla:22135. I (David) realised we could achieve much the same by just using template code. Although if this test mode was implemented in MediaWiki it could be made more convenient and more robust.
This template respects empty but defined "test1 version" parameters on purpose. The reason is that the code being tested might return an empty string, and then we don't want to fall back to the "normal version". So don't leave empty "test1 version =", "test2 version =" or "test3 version =" lines in your code, because then the pages that use your template will break for any user that views them in those test-modes. So don't do this:
{{test-mode | test1 version = Lots of code... <!--Leaving empty parameters like this is bad, don't do it--> | test2 version = <!--Currently not doing any testing, empty--> | test3 version = | normal version = Lots of code... }}
Unless you on purpose want your template to have no output when in those test-modes.
Instead remove the parameters, or disable them like this:
{{test-mode <!--Not doing any testing at the moment, but will soon do more testing, so just disabled the test parameters by adding "t_" in front of them--> | t_test1 version = | t_test2 version = | t_test3 version = | normal version = Lots of code... }}
Using "t_" to disable the parameters is no magic, it just gives them names that this template simply doesn't use. Using "t_" is old programmer tradition, the "t" means "test" or "temporary".
--David Göthberg (talk) 23-24 January 2010 (UTC)
JS and ((test-mode))
Bawolff, Stmrlbs and I (David) have been discussing if we can use javascript in some way to make a test-mode. The below message is the latest discussion about that, I moved it here from my talk page. --David Göthberg (talk) 23:15, 24 January 2010 (UTC)
Thinking about this template, I think js could be used as a quick switch so people can view it in testing mode. (I put together a short script that does that - User:Bawolff/test-mode.js​, by re-rendering the page but with a context title of either test1- test2- or test3- based on user input when they click on a link in the toolbox. Doesn't work that well currently in edit mode, but that could be improved if there is interest). Try it out and tell me what you think. Another thought, currently the template recommends using the show preview on a non-exisistant test1-pagename page to see test mode. Perhaps it should recommend people use special:Expandtemplates to stop the accidental page saves, that are bound to happen. Cheers. Bawolff (talk) 21:32, 24 January 2010 (UTC)
End, message moved here from David's talk page.
Wow! Your script works very well and is very useful, so we should document it and link to it from {{test-mode}}. You understand {{test-mode}} perfectly. And right, it is not so necessary that the javascript works in edit mode, since the javascript would mostly be used so we can surf around and look at existing pages in test-mode. But sure, it could be convenient if it also worked in edit view. If you implement that part, then perhaps you should take a look at User:Js/ajaxPreview since that script uses the content of the edit window when re-rendering the page. By the way, User:Js/ajaxPreview is a wonderful script, it saves a lot of time when editing pages.
And regarding Special:Expandtemplates​: Even experienced users often have trouble using Expandtemplates, they often forget to fill in the "Context title". Expandtemplates doesn't warn when you miss that, and then some things won't render as you expect. Also, Expandtemplates doesn't list which templates are used on the page so we don't see if the meta-template we are testing is actually used on the page. And it doesn't show what categories the page will get, so we can't test categorization. So normal edit preview is better for testing.
But yes, people are bound to accidentally save some test pages every now and then. But since those test pages will have "Test1-", "Test2-" or "Test3-" in their pagenames we can easily find them by using Wikipedia's search function. Using Special:PrefixIndex doesn't work as well here since it can only search one namespace at a time, and some of the test pages will be subpages like "Wikipedia:Example/test1-subpage".
--David Göthberg (talk) 23:15, 24 January 2010 (UTC)
This is very nice, Bawolff.  :) stmrlbs|talk 00:34, 25 January 2010 (UTC)
Thanks. I have updated it, it should now work properly during page edits (with a new button beside show preview). You may need to do a hard refresh. (I stole the code from ajax preview that re-initiates javascript). The original worked by asking the api to parse {{:article name}} as if it had the title test1-, so it wasn't too much trouble to just throw the contents of the text box to the api instead of the transclusion. (I just realized i need to convert it to a POST request to avoid a 400 error on non-short things, but that will just take a minute to fix) Cheers. Bawolff (talk) 02:12, 25 January 2010 (UTC)
OK, now using POST, so no more HTTP 414 errors. Hopefully it all works, let me know what y'all think. Bawolff (talk) 02:17, 25 January 2010 (UTC)
I tried it with the test below.. looks great! stmrlbs|talk 02:27, 25 January 2010 (UTC)
The only thing it really doesn't work with is <source> (added test below). Bawolff (talk) 11:56, 25 January 2010 (UTC)
All seems to work, great stuff!
Bawolff: Your <source> test below actually doesn't "fail". I have noted that before since I use other scripts like User:Js/ajaxPreview. The reason is that when we load this page in edit view it already has the source headers since it already had the <source> tags in it at load time. So your script (and User:Js/ajaxPreview) only "fails" to do source markup if we load a page without <source> tags and then add the tags in the edit window and then click "Preview in testing mode". As a user I am already used to that, in the cases I want to see the source markup I simply do a real "Show preview" load first to get the source headers, then I can do "Ajax preview" and "Preview in testing mode" as much as I want and still see the source markup. But usually I don't bother, since in most cases the source markup is not important for me in edit preview.
--David Göthberg (talk) 15:42, 25 January 2010 (UTC)
Oh, your right. In any case, it looks like that bug will be fixed at some point in the future based on talk on bugzilla. And i'd imagine very few templates use source. Bawolff (talk) 19:15, 25 January 2010 (UTC)
try test-mode
direct
this is the public version of this template

nested
going to call test template:
this is the public version of this template
Biggest problem is with <source>:
select look at, me from WORKS_FINE where testing_mode IS NULL
Ick
Re: 'Create a sub-page under your user page called "/test-mode.css" and put the text "test1"', please don't. "test1" is not CSS so it shouldn't be in a CSS file. It could be, as /*test1*/. — SMcCandlish Talk⇒ ʕ(ÕلōContribs. 19:07, 28 January 2010 (UTC)
The /test-mode.css pages are never loaded and interpreted as CSS by the browsers, so it doesn't matter what we put in them. It is the same thing as if we create a page named /myimage.jpg, it doesn't become a .jpg image just because the page is named /myimage.jpg.
So the /test-mode.css pages are just normal user sub-pages. Except that MediaWiki renders them with syntax highlighting and protects them so only the user himself and admins can edit them.
By the way: MediaWiki even executes any templates and wikimarkup we put on .css pages. Try to put some {{template}} on a .css page, then wait some minutes, then check "what links here" for that template.
Sure, there are technical ways to make the /test-mode.css pages load as CSS pages. But you can use the same methods to load any page, even articles, as CSS in your browser. (But that would be silly.) And even if you make your browser load the /test-mode.css as CSS then the simple text "test1" has no effect, it is just an invalid line of CSS, so nothing bad happens. And just in case someone is silly enough to do that, we choose to use .css for this instead of .js, since loading weird CSS code is less of a problem than loading weird javascript. (Of course, you can use the same methods load any page as javascript...)
--David Göthberg (talk) 20:49, 28 January 2010 (UTC)
Documentation question
David, should I post about this on the Bugzilla report? Or is there a "How to test templates" article where some documentation about this template should be added? stmrlbs|talk 03:37, 29 January 2010 (UTC)
Bugzilla is only for bugs in the MediaWiki software and similar, so definitely not there. But we should "advertise" this testing system at Wikipedia:Template test cases and Wikipedia:Template messages/Template namespace. I'll leave that to you, since I might not be on Wikipedia for some time to come.
--David Göthberg (talk) 05:07, 1 February 2010 (UTC)
Thanks. I will do that this weekend. And thanks again to you and Bawolff for putting this together. stmrlbs|talk 03:27, 3 February 2010 (UTC)
The below message is a copy from my talkpage. --David Göthberg (talk) 22:33, 15 February 2010 (UTC)
David, I added a paragraph for the new test-mode template here. I don't know if that is enough. If you think I should add something else, let me know, but since the page was about test cases, I felt just mentioning that the next step could be setting up {{test-mode}} was enough. I also added a table entry here. However, looking at this table, I was thinking that maybe it might be a good idea to have the template display something in a template that used it. Not to the people calling it, but when you looked at the template page. That way, users would know when looking at the template page that the template had a test-mode version. What do you think? stmrlbs|talk 15:52, 15 February 2010 (UTC)
Your advertising of this template over at Wikipedia:Template test cases and Wikipedia:Template messages/Template namespace looks just right.
I see what you mean that it would be convenient if this template had some kind of visible appearance on the template pages where it is used. But that's hard to do for several reasons:
Say someone wants to test a new version of the meta-template {{dmbox}}. That one is in turn used by {{disambig}} and all the other disambig templates. But there is no automatic way that {{test-mode}} can detect its first transclusion level. So a primitive "solution" would be to make it show when in template space, but then it would show both on {{dmbox}} and {{disambig}}. And it would show in the documentation of those templates if they are demonstrated in their own documentation. Also, some templates might use {{test-mode}} in only parts of the code, and there it might be incorrect to output text, like deep inside some if-cases. So if {{test-mode}} shows some text in template space those templates would break in template space.
Another option is to have a "notice" parameter that tells {{test-mode}} to show its notice. If the parameter is fed with <noinclude> tags like this then it would work:
{{test-mode | test1 version = | normal version = | notice = <noinclude>yes</noinclude> }}
It could output something like this:
If you are going to edit this template, please note that it is currently using {{test-mode}} for some advanced testing.
(Note to us: It should have a "clear all" above itself so right or left-floating templates won't squeeze it.)
Or we could simply provide it as a message box that people can put in the normal <noinclude> area or at the top of the /doc page of templates that use {{test-mode}}. I suggest we call it {{test-mode notice}}. That way there is less code in {{test-mode}}, and people don't need to remember to use the <noinclude> tags, so less things can go wrong.
--David Göthberg (talk) 22:33, 15 February 2010 (UTC)
I see what you mean. Well, I like the little notice that you put up as an example. If you do add it, let me know, and I will add the notice to the template namespace table. stmrlbs|talk 03:18, 16 February 2010 (UTC)
Done - And I added a recommendation to use it in the documentation of this template. But it is probably unnecessary to advertise it at Wikipedia:Template messages/Template namespace, since it is not a general template, it is only used when already using {{test-mode}}.
--David Göthberg (talk) 05:27, 16 February 2010 (UTC)
Last edited on 8 January 2015, at 11:02
Content is available under CC BY-SA 3.0 unless otherwise noted.
Privacy policy
Terms of Use
Desktop
HomeRandom Nearby Log inDonateAbout WikipediaDisclaimers
WatchEdit