屁眼火辣辣的疼是什么原因| 日落是什么时辰| 意什么深什么| eb病毒阳性是什么意思| 叶什么什么龙| 支气管哮喘吃什么药| 灰指甲用什么药膏| 兔肉和什么相克| 什么字五行属水| 陈赫什么星座| m代表什么单位| 胃疼想吐是什么原因| 助听器什么牌子最好| 樱桃不能和什么一起吃| 记性不好吃什么药| 猫有什么特点| 梦见吐血是什么预兆| 尿毒症什么症状| 喉结是什么| 血红蛋白偏低是什么原因| 血钙是什么意思| 月经量少发黑是什么原因| 多囊有什么危害| 白细胞中性粒细胞高是什么原因| 你的美丽让你带走是什么歌| 什么是比| 拉拉什么意思| 漂脱是什么意思| 白衬衫太透里面穿什么| 牛什么饭| 副司长是什么级别| 为什么打死不吃骡子肉| 牙齿出血是什么病表现出来的症状| 吃饭睡觉打豆豆是什么意思| 头痛吃什么药效果好| 五行缺什么查询免费| 五个月宝宝可以吃什么水果| 草字头加弓念什么| 勒索是什么意思| 奥斯卡小金人什么意思| 担心是什么意思| 2009年属什么| 阴唇为什么一个大一个小| 屁股沟疼是什么原因| 吃豆腐什么意思| uranus是什么星球| 反酸是什么意思| 肝内胆管结石吃什么药好| 阴囊潮湿什么原因| 碱性磷酸酶偏低是什么意思| 衣柜放什么代替樟脑丸| 漏尿是什么原因造成的| 验光是什么意思| 绿色蛇是什么蛇| 什么样的眼睛形容词| 腊肉炒什么菜最好吃| 胃出血吃什么药好| 巨蟹座女和什么座最配| 防晒什么时候涂| 汽车抖动是什么原因| 沙肝是什么| 格林巴利综合症是什么病| 荷兰豆为什么叫荷兰豆| 超声诊断科是做什么的| 5月16日是什么星座| 丛书是什么意思| 禁欲有什么好处| 窦性心律t波改变是什么意思| 巴适是什么意思| 凝血酶时间是什么意思| 93年是什么年| 孕期阴道炎可以用什么药| 脚酸疼是什么原因引起的吗| 牛奶不能和什么一起吃| 肉包子打狗的歇后语是什么| 昱五行属性是什么| 四月初一是什么星座| 红小豆和赤小豆有什么区别| 检查胸部应该挂什么科| 血涂片检查什么病| 冬天喝什么汤| 大饼是什么意思| 女人鼻子大代表什么| 女人长期做俯卧撑有什么效果| 欲望什么意思| 吃什么食物降低转氨酶| 绿色食品是什么意思| 夏天吃什么水果好| 冬瓜什么时候成熟| 纵隔占位是什么意思| 合是什么生肖| 蚕豆病是什么病有什么症状| 海东青是什么鸟| 梦见自己结婚了是什么意思| 考c1驾照需要什么条件| 二甲苯是什么| 什么的风采| 一九四九年属什么生肖| 天高地厚是什么生肖| 腰间盘突出睡觉什么姿势好| 欲哭无泪什么意思| 官星是什么意思| 更年期吃什么调理| 四大发明有什么| emba是什么| 混合痔什么症状| 病人说胡话是什么征兆| 什么叫原研药| 床塌了有什么预兆| 粉色玫瑰花代表什么意思| dcdc是什么意思| 疯狂动物城狐狸叫什么| tia是什么病| 狂蜂浪蝶是什么意思| 主治医师是什么级别| 女人适合喝什么茶最好| 免疫力低会引起什么病| 天麻治什么病| 蝴蝶长什么样| 人中黄是什么| 颈动脉斑块吃什么药效果最好| 叹服是什么意思| 血沉高是什么意思| 子宫增大是什么原因| 九月28号是什么星座| 戊申五行属什么| 6月14号什么星座| 痱子是什么样的图片| 鲁迅是什么家| 八婆是什么意思| 体感温度是什么意思| 阴道炎吃什么消炎药| 胰腺在人体起什么作用| 真维斯属于什么档次| 孕早期不能吃什么食物| 94狗跟什么属相配最好| 右额头上有痣代表什么| 罗汉局是什么意思| 6月18号是什么日子| 牒是什么意思| 择期什么意思| 京东发什么快递| 乳腺瘤不能吃什么| 护肝喝什么茶| 天空蓝是什么颜色| 6月2日什么星座| 什么的蜡烛| 顺字五行属什么| 尿里面有血是什么原因| 维生素b1有什么作用| 打胎药叫什么| msa是什么| 78岁属什么生肖| 后背痒痒是什么原因| 绿油油的什么| 六字真言是什么| 漂亮的什么| 西洋参有什么用| 老公是什么意思| 糖尿病人早餐吃什么好| 二甲双胍缓释片什么时候吃最好| 人的运气跟什么有关| pep是什么意思| 胎脂是什么原因造成的| 崔字五行属什么| 三文鱼和什么不能一起吃| 子宫动脉阻力高是什么引起的| 什么样的红点是白血病| 金融办是什么单位| 收官之作什么意思| 一个木一个舌读什么| 吃鹅蛋对孕妇有什么好处| 长期喝咖啡有什么好处和坏处| 偏头疼吃什么药| 弟子规是什么意思| 58年属狗是什么命| 内消瘰疬丸主治什么病| 空调为什么不制冷| 心机是什么意思啊| 护士一般什么学历| 狗喜欢吃什么食物| 吃青提有什么好处| 怀孕初期吃什么对胎儿发育好| heineken是什么啤酒| 驼背是什么原因造成的| 梦见好多猪肉是什么意思| 养心吃什么食物好| 随波逐流什么意思| 荨麻疹吃什么药管用| 1975年是什么年| 南瓜是什么形状| 梦到猫是什么意思| 胎菊和金银花一起泡水有什么效果| 下体有异味是什么原因| 血糖降不下来是什么原因导致| 中药和中成药有什么区别| 大腿青筋明显是什么原因| 输血浆主要起什么作用| 更迭是什么意思| 军犬一般是什么品种| 灰指甲是什么| 口腔溃疡喝什么饮料| 吴承恩是什么朝代的| 高处不胜寒是什么意思| 江西的简称是什么| hcv是什么| 电轴右偏是什么意思| 去新加坡买什么| 发财树是什么树| 扁桃体发炎是什么引起的| 天麻有什么作用与功效| 2014属什么生肖| 老死不相往来什么意思| 拿手机手抖是什么原因| 咳嗽吃什么| 什么往什么来| 怀孕做梦梦到蛇是什么意思| 慢性炎伴鳞化是什么意思| 喝完酒头疼吃什么药| 犯太岁是什么意思| 1990年属马的是什么命| 什么动物最聪明| 鹭鸶是什么动物| 公主和郡主有什么区别| 生物闹钟是什么意思| 钙片什么时候吃最好| 女性尿检能查出什么病| 匡威属于什么档次| 缺锌容易得什么病| 3月2日什么星座| 情节是什么| 得意忘形什么意思| 刘备属相是什么生肖| 小孩改姓需要什么手续| 香菇炒什么菜好吃| 第一次做什么感觉| 11月17日是什么星座| 柚子是什么季节| 直肠炎吃什么药效果好| 吴亦凡为什么退出exo| 前列腺增生用什么药好| 凝血四项能查出什么病| 马上风是什么意思| 猴头菇和什么煲汤最好| 小孩拉肚子应该吃什么食物好| 县人民医院是什么级别| 什么叫湿热| 体型最大的恐龙是什么| 牙齿痛是什么原因| 拉拉裤后面的胶片是做什么用的| 胆囊壁毛糙什么意思| 美纹纸是干什么用的| 胃疼喝什么可以缓解| 用纸可以折什么| 梦见挖坟墓预示什么| maggie什么意思| 月经突然停止是什么原因| 婴儿什么时候长牙| 一级军士长什么待遇| 时过境迁是什么意思| 血沉高说明什么问题| 头发汗多是什么原因| 1月26是什么星座| 毛很长的狗是什么品种| 百度Jump to content

香港特区政府:公布2016人口统计结果 普通话更普及

From Wikipedia, the free encyclopedia
百度 金山岭长城河谷·湾语墅位于北京市与河北省交接处,紧邻金山岭长城,南靠101国道,东西北三面环绕潮河及燕山山脉,处于京、津、冀“金三角”交汇点,是连接京津冀的交通要冲。

There are some advanced template coding techniques to improve the display or editing of templates in Wikipedia. There are also some tactics for debugging template parameters in the MediaWiki markup language. It is preferable that any templates requiring intricate control structures or conditional expressions be written in or converted to Lua modules because wikitext is not well-designed for this purpose.

Many bugs are associated with the difficulty in dealing with some awkward features in the markup language which lead to coding errors. Unbalanced metacharacters are a major source of errors. For example, coding {{1}}} instead of {{{1}}} causes it to act as if it were {{1}} }, thereby invoking Template:1 + "}".

There are some differences of wiki-formatting of contents of parameters when inside #if-expressions, but not when outside. Templates which need to be substituted need special handling. Providing parameter defaults or parameter aliases is covered as well.

Nesting levels limited to 40

[edit]

Inside a single template, the nesting limit is 40 nested expressions, such as 40 multiple "if-then-else-if...". At the 41st nested "if" keyword an error message might appear, as: "Exceeded nesting limit". However, when not nested beyond 40 levels, a template can contain hundreds of if-expressions and switch-branches, but not all nested inside the others.

Some templates have contained complex conditional calculations nested over 23 levels deep, for years. Also, some templates have contained hundreds of if-expressions, for years, just NOT all nested as one, giant: if-then-else-else-else-else-else....

MediaWiki wiki-formats the clauses inside #if

[edit]

An issue which complicates template processing, for parameters, is the wiki-formatting of parameter contents when inside of if-logic (such as #if or #ifeq) or #switch (or lc:, lcfirst:, uc:, ucfirst:). As of May 2012, the MediaWiki markup parser is still wiki-formatting the contents of parameters when inside #if-expressions (but not outside). This means that parameters containing spaces, lead semicolon, colon (":") or pound sign ("#") can change their values while inside the if-clauses (surprise!). So, for example, a parameter {{{4}}} when outside an #if can display differently than inside {{#ifeq:{{{1}}}=0|{{{4}}} ...}}. The worst shock is when parameter 4 contains a leading semicolon, which triggers formatting to become ye-olde bolded semicolon-header line:

TEST 1: {{#if:{{{4|}}}|{{{4|;}}} <== yes, semicolon|no, 4=empty}}
TEST 2: {{#if:{{{4|;}}}|{{{4|;}}} <== yes, semicolon|no, 4=empty}}
TEST 1: no, 4=empty
TEST 2:
<== yes, semicolon
<== Separate example of semicolon-header

The problem occurs whether inside of #if, #ifexpr, #ifeq or #switch markup expressions. If the parameter is preceded by text, in either of the then/else clauses, then the wiki-formatting inside the parameter does not occur.

TEST 3: {{#ifexpr:{{{1|7}}}=7|<b></b>{{{4|;}}} equals 7|not 7}}
TEST 4: {{#ifexpr:{{{1|7}}} < 9|{{{4|#}}} LESS THAN 9|not<9}}
TEST 5: {{#ifexpr:{{{1|7}}} < 9|&#32;{{{4|#}}} LESS THAN 9|not<9}}
TEST 6: "{{#ifexpr:{{{1|7}}} < 9|&#32;{{{4|#}}} LESS THAN 9|not<9}}"
TEST 3: ; equals 7
TEST 4:
  1. LESS THAN 9
TEST 5: # LESS THAN 9
TEST 6: " # LESS THAN 9"

In TEST 4, the leading pound sign "#" triggered auto-numbering of the line (indented with "1."). The situation of having a leading semicolon, colon or "#" might be relatively rare, but this is just a reminder: for showing the true contents of a template parameter, try to display a parameter outside the start of any if-statement clauses, or display other text before the parameter inside the if-logic, or else prepare for some shocking results when a parameter is wiki-formatted for display inside the if-logic.

If the result of #if, etc. is not intended to be formatted, using &#35;, &#58;, and &#59; instead of #, :, and ; will work fine.

TEST 7: {{#ifexpr:{{{1|7}}} < 9|{{{4|&amp;#35;}}} LESS THAN 9|not<9}}
TEST 7: # LESS THAN 9

Debugging

[edit]

Many coding errors can be debugged, more easily, by attempting to isolate the code section where coding errors most likely occurred. Intense proofreading, of the logic flow, is most often the quickest fix, such as checking for typical syntax errors (see below: "Common coding errors"). Sometimes, a section of troublesome code could be copied into a short test page, then by edit-preview, tested there, separately. However, if editing that extra-page window seems like too much effort, then consider merely copying the code to the top of the current template. Similarly, a template could be developed, in the early stages, as multiple sections of code, each to be debugged separately, then eventually joined together, such as nested sections with if-then-else-if.

As a review of those options, consider:

  • Try carefully proofreading troublesome code, matching "{{" with "}}". (consider using Equazcion's syntax highlighter for Notepad++)
  • Copy a template section into a test-page edit-window, for debug.
  • Copy a template section to the top of the template, for debug.
  • Restructure a template so that each section is more separated.

The basic strategy: isolate the code section to be debugged.

Next, the testing, of each section of code, is crucial. There are some age-old adages to heed:

  • If it hasn't been tested, then it doesn't work.
  • You can expect what you inspect. (W. Edwards Deming)

Perhaps put a variety of examples on each template's doc subpage, to help detect problems early in development. However, for complex templates, then the talk-page, or a special subpage "/testcases", should contain a section of numerous examples (a whole lot of them) to demonstrate the full scope of template features.

Defaulting parameters in expressions and if-logic

[edit]

When developing sections of markup that use template parameters, try to always set each parameter with a default value, especially inside expressions or if-logic coding:

  • {{#expr: 109.75 / {{{1|1}}} }} → default {1} as 1 not zero.
  • {{#ifeq: {{{answer|y}}}|y|show yes}}

If a particular parameter is given the same default value across the whole page, then that value could be easily changed, in a text editor, by a global search-and-replace string substitution, to change the default value to some other value, for testing each case.

If those parameters are not given default values, then those sections of code cannot be tested, during edit-preview, while editing the template. Any parameter without a default value will become the literal triple-brace text (such as the literal 7 characters: {{{x}}}), and non-defaulted parameters cannot be evaluated, in expressions or if-logic, during an edit-preview of the template page.

Common coding errors

[edit]

There are several common coding errors which will cause problems when processing templates. The following can be used as a checklist, to help debug problems, when a template seems to be acting bizarre:

  • Too few closing braces: A common problem is to put only 2 closing-braces around a parameter number or name, such as {{{1}}. Having only 2 closing-braces }} might treat the parameter as a template named "Template:1" (preceded by a lone "{" brace).
  • Unopened comments: Forgetting to insert <!-- at the start of an HTML comment can cause bizarre results, with no error message. Forgetting the exclamation point is very common: <-- should be <!--.
  • Unclosed comments: Forgetting to insert --> at the end of an HTML comment can cause bizarre results, with no error message.
  • Omitting colon or "#" on "#ifexpr": Forgetting to insert "#" or colon for "#ifexpr:" or "#expr:" can produce bizarre results, when passed into other subtemplates.
Omitting colon becomes literal text: {{#ifexpr {{{1|y}}}=0|then zero|else not}}

Note that those common coding errors could have been easily spotted by a simple syntax checker, such as warning that 3&2 braces could be trouble: {{{size|180px}} is treated as "{Template:Size" trying to pass 180px as the parameter because of only 2 end-braces.

Again, always checking first for common errors, as the first step, can avoid time hunting for "complex errors" which never really existed. Remember: the MediaWiki markup language is extremely error-prone, so that's why so many coding errors occur, and that's why:

Consider the above as a checklist to try first, as a type of sanity-check for the template.

Many hideous problems truly are merely 1-minute syntax fixes.

Coding a template to allow WP:SUBST substitution

[edit]

In rare cases, a template might need to be rewritten to allow text substitution (per WP:SUBST), where the results of running a template will be saved into the page during an edit-SAVE operation. In that case, the safesubst-prefix must be inserted into every markup function used inside that template, at every level of nested logic. Also, every HTML comment must be surrounded by "noinclude" tags: <noinclude><!--HTML comment HERE--></noinclude>.[a] Otherwise, all of the triggered HTML comments will be stored inside the SAVEd page, in the sequence executed by running the template. NOTE: All the extra "noinclude" and safesubst:<noinclude/> keywords will likely require the template's markup to be re-indented inside, to fit all that extra inserted text, which will widen and clutter the original markup style.

Specifically, to alter a template to allow text substitution, then the prefix safesubst:<noinclude/> must be inserted inside the opening double-brace {{ of each markup function inside that template. Some examples of inserting the safesubst-prefix inside a template's markup:

  • Total articles now: {{NUMBEROFARTICLES}} → 7,034,779
  • Total articles was: {{ subst:NUMBEROFARTICLES}} → 3,953,715
  • {{ safesubst:<noinclude/>#ifeq:{{{1|AX}}}|AX|yes}}
  • {{ safesubst:<noinclude/>lc:THIS LOWERCASE TEXT}} → this lowercase text

In general, every markup function which starts with double-brace {{ must be altered to insert the long safesubst-prefix safesubst:<noinclude/> (with no space afterward).[b] The action of keyword "safesubst" is to allow conditional substitution of markup, when the whole template is invoked as {{subst:MyTemplate|...}}. In essence, the keyword "safesubst" could be called "ifsubst" as meaning, "if 'subst:' was used to invoke this template, then substitute here as well".

Remember: The safesubst-prefix must be inserted into every markup function inside that template, except for test logic never used in an actual page. Any markup which omits "safesubst" will fail if the template is executed by the subst mode, "{{subst:MyTemplate|...}}". Parameters are not changed, so {{{1}}} would remain unchanged, without a safesubst-prefix.

Exceptions: Only logic which would never be stored in a page could omit "safesubst", such as test-logic which is triggered by special parameter values never used inside a stored page. Any markup which omits "safesubst" will only work during regular transclusion but fail if the template is executed by using the subst-mode prefix "subst:". For more examples, and further technical explanations, see: WP:Substitution.

Indenting the long lines: All of the added safesubst-prefix text will widen lines, so to improve readability, they could be split and indented before any of the safesubst:<noinclude/> prefixes. For example:

  • {{ safesubst:<noinclude/>#ifeq:{{
           safesubst:<noinclude/>padleft:|1|{{{1}}} }}|A|Begins with "A"}}

In that indentation style, the text "safesubst:<noinclude/>" begins the next line. Avoid wrapping a line after the prefix safesubst:<noinclude/> because several markup functions might fail to work correctly unless the safesubst prefix is immediately attached before the keyword, such as {{&nbsp;safesubst:<noinclude/>#ifeq:...}}

Examples of very large templates

[edit]

When trying to perform more-complex, or intricate, operations, there might be an instinctive fear that templates cannot be as large as needed. However, there are many very large templates which have been running, for years, on Wikipedia, for example:

The source-footnote formatter, Template:Citation/core, displays a standardized citation format, as invoked by several wrapper templates which pass hundreds of parameters, where the core logic checks 621 parameter values, in the conditional markup expressions.

Try some programming

[edit]

The Special:ExpandTemplates page takes some wikitext and expands everything in double braces recursively: templates, parser functions like {{#if:...}}, and variables like {{CURRENTDAY}}

See also

[edit]

Notes

[edit]
  1. ^ But if you want the HTML comment to appear, as is the case, for example, with User warning templates, then do not enclose the HTML comment in <noinclude> tags.
  2. ^ If you are familiar with regular expressions, you can do this like this:
    • Search for pattern ([^{]){{([^{]) and replace it with \1{{ safesubst:<noinclude/>\2
    Or, in one step, for one style of regex :
    • s/([^{]){{([^{])/\1{{ safesubst:<noinclude/>\2/g
    You might need to break up long lines; see "Indenting the long lines" in this section. As a practical matter, it's easier to join lines of code than to break them, so if you replace the blank in the replace-pattern above with a newline (plus optional white space) instead, it will break lines with every substitution; when it's done, just go back and join any lines that are too short.


凤毛麟角是什么生肖 地果是什么 着重号是什么符号 一声什么 鹿几念什么
为什么会过敏 入职是什么意思 熠五行属什么 乙型肝炎病毒表面抗体阳性是什么意思 派对是什么意思
必承其重上一句是什么 氢化植物油是什么 一纸空文是什么意思 眼角膜是什么 议员在中国相当于什么
尿尿疼是什么原因 人瘦是什么原因造成的 梦到狗什么意思 6月16日是什么星座 四维什么时候做最佳
囟门凹陷是什么原因hcv9jop0ns8r.cn 去医院测血糖挂什么科hcv8jop9ns6r.cn 咽炎吃什么药0735v.com 申时属什么生肖hebeidezhi.com maxco是什么牌子hcv9jop5ns2r.cn
反流性咽喉炎吃什么药hcv9jop4ns3r.cn 9月15号是什么日子hcv9jop6ns9r.cn pp材质是什么意思xinjiangjialails.com 含蓄什么意思hcv9jop5ns6r.cn 日金念什么hcv8jop8ns7r.cn
羊的五行属什么hcv9jop4ns2r.cn 先天性心脏病是什么原因造成的hcv9jop6ns1r.cn 黄片是什么hcv7jop7ns3r.cn 手足口病用什么药最好hcv9jop0ns1r.cn 吃生花生有什么好处wzqsfys.com
恻隐之心什么意思0735v.com 湄公鱼是什么鱼hcv7jop6ns8r.cn 子宫结节是什么意思hcv8jop4ns0r.cn 口琴买什么牌子好hcv7jop9ns0r.cn 乐高为什么这么贵onlinewuye.com
百度