-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path20170915.topic_list.js
1646 lines (1451 loc) · 52.9 KB
/
20170915.topic_list.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Add topic list to talk page. 增加討論頁面主題列表。為議論增目錄。トピックリスト 見やすい議題一覧の作成。
jstop cron-20170915.topic_list.zh;
jstop cron-20170915.topic_list.zh-classical;
jstop cron-20170915.topic_list.wikinews;
jstop cron-20170915.topic_list.ja;
jstop cron-20170915.topic_list.en;
jstop cron-20170915.topic_list.test;
jstop cron-20170915.topic_list.wikisource;
jstop cron-20170915.topic_list.wikiversity;
jstop cron-20170915.topic_list.commons;
#jstop cron-20170915.topic_list.moegirl;
jstop cron-20170915.topic_list.wiktionary;
jstop cron-20170915.topic_list.wikibooks;
/usr/bin/jstart -N cron-20170915.topic_list.zh -mem 2g -once -quiet /usr/bin/node /data/project/toc/wikibot/routine/20170915.topic_list.js use_language=zh
/usr/bin/jstart -N cron-20170915.topic_list.zh-classical -mem 2g -once -quiet /usr/bin/node /data/project/toc/wikibot/routine/20170915.topic_list.js use_language=zh-classical
/usr/bin/jstart -N cron-20170915.topic_list.ja -mem 2g -once -quiet /usr/bin/node /data/project/toc/wikibot/routine/20170915.topic_list.js use_language=ja
/usr/bin/jstart -N cron-20170915.topic_list.en -mem 2g -once -quiet /usr/bin/node /data/project/toc/wikibot/routine/20170915.topic_list.js use_language=en
/usr/bin/jstart -N cron-20170915.topic_list.testwiki -mem 2g -once -quiet /usr/bin/node /data/project/toc/wikibot/routine/20170915.topic_list.js use_language=en use_project=test
/usr/bin/jstart -N cron-20170915.topic_list.wikinews -mem 2g -once -quiet /usr/bin/node /data/project/toc/wikibot/routine/20170915.topic_list.js use_project=zh.wikinews
/usr/bin/jstart -N cron-20170915.topic_list.wikisource -mem 2g -once -quiet /usr/bin/node /data/project/toc/wikibot/routine/20170915.topic_list.js use_project=zh.wikisource
/usr/bin/jstart -N cron-20170915.topic_list.wikiversity -mem 2g -once -quiet /usr/bin/node /data/project/toc/wikibot/routine/20170915.topic_list.js use_project=zh.wikiversity
/usr/bin/jstart -N cron-20170915.topic_list.commons -mem 2g -once -quiet /usr/bin/node /data/project/toc/wikibot/routine/20170915.topic_list.js use_project=commons
/usr/bin/jstart -N cron-20170915.topic_list.wiktionary -mem 2g -once -quiet /usr/bin/node /data/project/toc/wikibot/routine/20170915.topic_list.js use_project=zh.wiktionary
/usr/bin/jstart -N cron-20170915.topic_list.wikibooks -mem 2g -once -quiet /usr/bin/node /data/project/toc/wikibot/routine/20170915.topic_list.js use_project=zh.wikibooks
2017/9/10 22:31:46 開始計畫。
2017/9/16 12:33:6 初版試營運。
2017/9/24 13:56:48 using page_configurations
2017/10/10 16:17:28 完成。正式運用。
2019/4/22 10:17:2 分割頁面設定至 './special page configuration.js'。
@see [[w:zh:模块:沙盒/逆襲的天邪鬼/talkpage]], [[wikiversity:zh:模块:Talkpage]], [[w:zh:User:WhitePhosphorus-bot/RFBA_Status]],
[[w:ja:Wikipedia:議論が盛んなノート]],
https://zh.moegirl.org.cn/Widget:TalkToc ($('#toc'))
https://meta.wikimedia.org/wiki/Tech/News/2018/13/zh 已被棄用的#toc和#toctitle CSS ID將會被移除。如果您的wiki仍在使用它們作為假目錄,那麼它們將失去應有樣式。如有需要可以替換為.toc和.toctitle CSS類。
計票機器人:
時間截止時先插入截止標示,預告何時結束選舉、開始計票(過1小時)。讓選民不再投票,開始檢查作業。等到人工檢查沒問題時,確認此段最後的編輯時間超過1小時,再close掉。
若是不想要由機器人處理,您可事先手動處理,或者回覆{{tl|Stop}}模板。
孵化期:提名超過1小時候,等待孵化才開始各種審查作業。
{{投票設定
|支持模板=
|反對模板=
|投票資格=autoconfirmed + 50 edits + registered 7 days <!-- [[en:Wikipedia:Protection policy]], 巡查員, 回退員, [[Wikipedia:人事任免投票資格]], 原作者則不能支持自己的作品 -->
|期限
|延長期=30,30 <!-- 日 -->
|通過處理=
|未通過處理= <!-- 存檔至頁面 存檔至提案條目的討論頁底部。移除替換標籤模板 -->
}}
TODO:
Flow 的問題是不支援繁簡轉換,沒有在大流量頁面嘗試過。長篇內容是否合適Flow還真不清楚。排版還是不夠靈活。難以處理需要修訂版本刪除的編輯。
https://commons.wikimedia.org/wiki/Commons:Bots/Work_requests
https://zh.moegirl.org.cn/Talk:%E8%AE%A8%E8%AE%BA%E7%89%88
'zhwiki:Wikipedia:机器人/提议'
https://zh.wikipedia.org/wiki/Wikipedia:%E6%9C%BA%E5%99%A8%E4%BA%BA/%E6%8F%90%E8%AE%AE
https://en.wikipedia.org/wiki/Wikipedia:Bots/Requests_for_approval
https://en.wikipedia.org/wiki/Wikipedia:Bot_requests
TODO:
討論議題列表可以放在另外一頁,也可以在當前頁面中。
可以在 __TOC__ , __NEWSECTIONLINK__ 之後才開始檢查 main_talk_pages
相關發言者訂閱功能 via ping
get 發言 time via revisions information
自動計算投票票數 [[模板:RFX count]]
[[Template:topic_list]]
archive topics:
可以依照指示存檔到不同的page
存檔可以用編號為主或者以日期,"丁酉年"為主
可以自動把文字分到新的子頁面
存檔完可以留下索引,等到特定的日子/特定的天數之後再刪除
存檔完可以直接刪除,只留下oldid
延遲應該在十數分鐘內。現行設定若寫入失敗2次,程式就會重啟。
已知無法解決問題:目前 MediaWiki 之 link anchor, display_text 尚無法接受"�"這個特殊字元。
@see [[w:zh:Module:Talkpage]] {{ #invoke:Talkpage | analyse | titlelevel=3 |WikiProject_talk:电子游戏 | type=topic | userlink=[[U:$USER|$USER]] }}
*/
'use strict';
// Load CeJS library and modules.
require('../wiki loader.js');
// Load modules.
CeL.run([ 'application.net.wiki.template_functions',
// for CeL.assert()
'application.debug.log' ]);
// Error.stackTraceLimit = 30;
/* eslint no-use-before-define: ["error", { "functions": false }] */
/* global CeL */
/* global Wiki */
login_options.configuration_adapter = adapt_configuration;
var
/** {Object}wiki operator 操作子. */
wiki = Wiki(true),
/** {Object}設定頁面所獲得之手動設定 manual settings。 === wiki.latest_task_configuration */
configuration,
edit_tags = wiki.API_URL.includes('moegirl') ? 'Bot' : '',
// Will get page title from wikidata
botop_sitelinks = {
enwiki : {
title : 'Category:Wikipedia bot operators'
}
}, max_date_length = 34;
// ----------------------------------------------
globalThis.localized_page_configuration = {
zh : {
row_style : general_row_style
}
};
globalThis.localized_page_configuration =
// globalThis.localized_page_configuration[CeL.wiki.site_name(wiki)] ||
globalThis.localized_page_configuration[use_language];
function set_update_timer(page_title, time_ms, callback) {
if (callback) {
setTimeout(function() {
wiki.page(page_title, pre_fetch_sub_pages).run(callback);
}, time_ms);
} else {
setTimeout(wiki.page.bind(wiki, page_title, pre_fetch_sub_pages),
time_ms);
}
}
globalThis.set_update_timer = set_update_timer;
globalThis.FC_vote_configurations = {
vote_closed_listener : function() {
wiki.page(this.title, pre_fetch_sub_pages);
},
};
Object.assign(globalThis, require('../special page configuration.js'));
// ----------------------------------------------
function CSS_toString(CSS) {
if (!CSS)
return '';
var style = [];
if (CSS.style) {
// e.g., "text-decoration: line-through"
style.push(CSS.style);
}
for ( var attribute_name in {
color : true,
'background-color' : true
}) {
if (CSS[attribute_name])
style.push(attribute_name + ': ' + CSS[attribute_name]);
}
return style.join('; ');
}
// 討論議題列表可以挑選的欄位。
var section_column_operators = {
// function: .call(page_data, section, section_index)
NO : function(section, section_index) {
if (/* force */true || !(section_index >= 1)) {
// e.g., [[w:zh:Wikipedia:机器人/申请]]
// CeL.info('NO_counter: ' + this.page.NO_counter);
if (!this.page.NO_counter)
this.page.NO_counter = 0;
// var section_title = section.section_title;
// var page_configuration = this.page.page_configuration;
// console.log([ section_index, section_title, page_configuration
// ]);
section_index = ++this.page.NO_counter;
// section.section_index 序號可能因 section_filter,沒有連號。
if (false && section.section_index >= 1)
section_index = section.section_index;
}
return local_number(section_index);
},
// 議題的標題。
title : function(section) {
// 2023/1/26 在頁面被 transclusion 的時候,空白不會被自動轉為 "_"。
function convert_anchor(link) {
return link.replace(/#[^|]+/, function(all) {
return all.replace(/ /g, '_');
});
}
// [[Template:Small]]
function small_title(title, set_small) {
// call function section_link_toString(page_title, style)
title = title.toString(null, CSS_toString(section.CSS), true);
// console.trace(title);
return set_small ? '<small>' + title + '</small>' : title;
}
var section_title = section.section_title;
var title = section_title.link, adding_link;
// 當標題過長時,縮小標題字型。
var title_too_long = if_too_long(section.section_title.title), style = title_too_long;
// console.trace(CeL.wiki.section_link(title));
// console.trace(section.section_title);
title = small_title(title, title_too_long);
var page_configuration = this.page.page_configuration;
// console.log(section);
if (configuration.closed_style.show_subtopic
// 顯示次級連結。
&& (adding_link = section.adding_link)) {
// console.log(adding_link);
if (adding_link.type === 'section_title') {
// 對於還沒完全結案的議題,箭頭指向還在討論的部分。
title_too_long = if_too_long('→' + adding_link.title);
adding_link = adding_link.link;
} else {
// 對於已經移動的議題,箭頭指向移動的目標頁面。
// assert: is page title
adding_link = adding_link.toString();
if (!adding_link.includes('#')) {
// 嘗試自動添加和章節標題相同的討論段落anchor。
// [1]: hack
// @see section_link_toString() @ CeL.wiki
adding_link += '#' + section.section_title.link[1];
}
adding_link = convert_anchor(adding_link);
var display_text = adding_link.replace(/#.*$/, '');
title_too_long = if_too_long(display_text);
adding_link = CSS_toString(section.CSS) ? '[[' + adding_link
+ '|<span style="' + CSS_toString(section.CSS) + '">'
+ display_text + '</span>]]' : CeL.wiki.title_link_of(
adding_link, display_text);
}
if (title_too_long) {
style = true;
}
title += '<br />→' + small_title(adding_link, title_too_long);
} else if (Array.isArray(page_configuration.level_filter)
&& section_title.level > page_configuration.level_filter[0]) {
title = '\n' + ':'.repeat(section_title.level
// 處理次標題的 indent 縮進。
- page_configuration.level_filter[0]) + ' ' + title;
}
if (style) {
style = 'max-width: ' + (page_configuration.max_title_display_width
// 限制標題欄的寬度。要考慮比較窄的螢幕。
|| configuration.general.max_title_display_width || '24em');
} else
style = '';
// style += CSS_toString(section.CSS);
if (section.has_集中討論重定向模板) {
// [[w:zh:Template:集中討論重定向]]
title = '[[File:Treffpunkt.svg|20px|link=|alt=集中討論重定向|集中討論重定向]] '
+ title;
}
return (style ? 'style="' + style + '" | ' : '') + title;
},
// 子頁面
sub_page : function(section) {
var section_title = section.section_title;
return section_title.sub_page_title;
},
// discussions conversations, 發言次數, 発言数
discussions : function(section) {
var sign_count = section.users.length;
var page_configuration = this.page.page_configuration;
// 其實是計算簽名與日期的數量。因此假如機器人等權限申請的部分多了一個簽名,就會造成多計算一次。
// 發言數量固定減去此數。
var discussion_minus = page_configuration.discussion_minus;
if (sign_count > 0 && discussion_minus > 0) {
sign_count = Math.max(0, sign_count - discussion_minus);
}
return local_number(sign_count,
// 火熱的討論採用不同顏色。
sign_count >= 10 ? 'style="background-color: #ffe;"' : section.archived
|| section.moved || sign_count >= 2 ? ''
: 'style="background-color: #fcc;"');
},
// 參與討論人數 participation
participants : function(section) {
return local_number(section.users.unique().length, section.archived
|| section.moved || section.users.unique().length >= 2 ? ''
: 'style="background-color: #fcc;"');
},
// reply, <small>回應</small>, <small>返答</small>, 返信数, 覆
replies : function(section) {
// 有不同的人回應才算上回應數。
return local_number(section.replies, section.archived || section.moved
|| section.replies >= 1 ? ''
: 'style="background-color: #fcc;"');
},
created : function(section) {
// TODO: the datetime the subpage created
},
// word count
words : function(section) {
return CeL.count_word(section.toString());
}
};
function traversal_all_pages() {
main_talk_pages.forEach(function(page_title) {
wiki.page(page_title, pre_fetch_sub_pages);
});
if (false) {
wiki.run(function() {
CeL.info('traversal_all_pages:');
console.log(main_talk_pages);
});
}
}
// ----------------------------------------------
var had_adapted;
/**
* 由設定頁面讀入手動設定 manual settings。
*
* @param {Object}latest_task_configuration
* 最新的任務設定。
*/
function adapt_configuration(latest_task_configuration) {
configuration = latest_task_configuration;
// console.log(configuration);
// console.log(wiki);
adapt_configuration_to_page(configuration);
// 一般設定
var general = configuration.general
|| (configuration.general = Object.create(null));
if (!general) {
CeL.info('No configuration.');
}
if (general.stop_working && general.stop_working !== 'false') {
CeL.info('stop_working setted. exiting...');
// 加入排程,避免運作到一半出問題的情況。
wiki.run(function() {
process.exit(2);
});
return;
}
// 檢查從網頁取得的設定,檢測數值是否合適。
general.max_title_length |= 0;
if (!(general.max_title_length > 4 && general.max_title_length < 80)) {
delete general.max_title_length;
}
if (!/^\d{1,2}(?:em|en|%)$/.test(general.max_title_display_width)) {
delete general.max_title_display_width;
}
var configuration_now = configuration.list_style
|| (configuration.list_style = Object.create(null));
for ( var attribute_name in configuration_now) {
var style = configuration_now[attribute_name];
if (!/^#?[\da-f]{3,6}$/i.test(style)) {
delete configuration_now[attribute_name];
continue;
}
if (attribute_name in short_to_long) {
short_to_long[attribute_name] = style;
} else if (attribute_name in long_to_short) {
long_to_short[attribute_name] = style;
}
}
configuration_now = configuration.closed_style
|| (configuration.closed_style = Object.create(null));
for ( var attribute_name in {
link_color : true,
link_backgroundColor : true
}) {
var style = configuration_now[attribute_name];
if (!/^#?[\da-f]{3,6}$/i.test(style)) {
delete configuration_now[attribute_name];
continue;
}
}
for ( var attribute_name in {
line_CSS : true,
link_CSS : true
}) {
var style = configuration_now[attribute_name];
// 簡單的檢核,還不夠完善!
if (style && style.includes('"')) {
delete configuration_now[attribute_name];
continue;
}
}
if (configuration_now.show_subtopic === 'false') {
configuration_now.show_subtopic = JSON
.parse(configuration_now.show_subtopic);
} else {
configuration_now.show_subtopic = !!configuration_now.show_subtopic;
}
// setup_list_legend();
function adapt_listen_to_page(page_title) {
var page_config = configuration_now[page_title];
var use_project = CeL.wiki.site_name(wiki);
if (!page_title.startsWith(use_project))
page_title = use_project + ':' + page_title;
if (page_configurations[page_title]) {
// Skip existed page.
return;
}
// console.trace([ page_title, page_config, globalThis.use_project ]);
if (page_config) {
// e.g., {"need_time_legend":false}
if (!globalThis.special_page_configuration[page_config]) {
if (!CeL.is_Object(page_config)) {
CeL.error(
//
'adapt_configuration: Invalid page configuration for '
//
+ CeL.wiki.title_link_of(page_title) + ': ' + page_config);
page_config = null;
}
}
} else if (use_project in globalThis.special_page_configuration) {
page_config = use_project;
}
CeL.info('+ Listen to page: '
+ CeL.wiki.title_link_of(page_title)
+ (page_config ? ' using configuration plan: '
+ (typeof page_config === 'string' ? page_config : JSON
.stringify(page_config)) : ''));
if (globalThis.special_page_configuration[page_config]) {
page_config = globalThis.special_page_configuration[page_config];
}
// console.log(page_config);
page_configurations[page_title] = page_config ? Object.assign(Object
.create(null), general_page_configuration, page_config)
: general_page_configuration;
}
// 顯示主題列表之頁面。
configuration_now = configuration.listen_to_pages
|| (configuration.listen_to_pages = Object.create(null));
if (configuration_now) {
Object.keys(configuration_now).forEach(adapt_listen_to_page);
}
CeL.log('Configuration:');
console.log(configuration);
if (had_adapted) {
// 每次更改過設定之後重新生成一輪討論頁面主題列表。
traversal_all_pages();
} else {
had_adapted = true;
}
}
// ----------------------------------------------
// main talk pages / discussion pages **of this wiki**
var main_talk_pages = [], sub_page_to_main = Object.create(null);
var special_users;
// ----------------------------------------------------------------------------
// main
// 先創建出/準備好本任務獨有的目錄,以便後續將所有的衍生檔案,如記錄檔、cache 等置放此目錄下。
prepare_directory(base_directory);
// CeL.set_debug(6);
// 用戶相關功能,避免延遲回應以使用戶等待。
delete CeL.wiki.query.default_maxlag;
// 設定 `session.max_badtoken_count = 0` ,那麼只要登入一出問題就直接跳出。
wiki.max_badtoken_count = 0;
wiki.run(start_main_work);
function start_main_work() {
// for debug: 僅處理此頁面
if (false) {
page_configurations = {
'zhwiki:Wikipedia:互助客栈/技术' : general_page_configuration
};
}
Object.keys(page_configurations).forEach(function(wiki_and_page_title) {
var matched = wiki_and_page_title.match(/^([^:]+):(.+)$/),
//
use_project = CeL.wiki.site_name(wiki);
if (matched[1] === use_project) {
main_talk_pages.push(matched[2]);
page_configurations[wiki_and_page_title].project = use_project;
}
});
get_special_users.log_file_prefix = base_directory + 'special_users.';
// for debug: 僅處理此頁面
if (false) {
main_talk_pages = [ 'Wikipedia:新条目推荐/候选', 'Wikipedia:典范条目评选/提名区',
'Wikipedia:特色列表评选/提名区', 'Wikipedia:優良條目評選/提名區' ];
}
// main_talk_pages = [ 'Wikipedia:優良條目評選/提名區' ];
// main_talk_pages = [ 'Wikipedia:新条目推荐/候选' ];
// main_talk_pages = [ 'Wikipedia:特色列表评选/提名区' ];
// main_talk_pages = [ 'Wikipedia:典范条目评选/提名区' ];
// main_talk_pages = [ 'Wikipedia:特色圖片評選' ];
// main_talk_pages = [ 'Wikipedia:井戸端' ];
// main_talk_pages = [ 'Wikipedia:削除依頼/ログ/先週', 'Wikipedia:削除依頼/ログ/先々週' ];
// main_talk_pages = [ 'Wikipedia:机器人/申请' ];
// main_talk_pages = [ 'Wikipedia:已删除内容查询' ];
// main_talk_pages = [ 'Wikipedia:互助客栈/其他' ];
// main_talk_pages = [ 'Wikipedia:互助客栈/技术' ];
// main_talk_pages = [ 'Wikipedia:互助客栈/条目探讨' ];
// main_talk_pages = [ 'Wikipedia:Bot/使用申請' ];
// main_talk_pages = [ '萌娘百科 talk:讨论版/页面相关' ];
// main_talk_pages = [ 'Wikipedia:可靠来源/布告板' ];
// main_talk_pages = [ 'Wikipedia:特色列表评选/提名区' ];
// main_talk_pages = [ 'Wikipedia:申请成为管理人员/申请区' ];
// ----------------------------------------------------
// console.trace(main_talk_pages);
if (main_talk_pages.length > 0) {
CeL.info(main_talk_pages.length + ' page(s) to listen for '
+ CeL.wiki.site_name(wiki) + ': '
+ main_talk_pages.map(function(title) {
return CeL.wiki.title_link_of(title);
}).join(', '));
} else {
CeL.error('No talk page to process for ' + CeL.wiki.site_name(wiki)
+ '!');
}
function main_process(_special_users) {
special_users = globalThis.special_users = _special_users;
// 首先生成一輪討論頁面主題列表。
traversal_all_pages();
// return;
wiki.listen(pre_fetch_sub_pages, {
// start : new Date,
// 延遲時間
// [[Wikipedia‐ノート:井戸端#節ごとの発言数・参加者数・最終更新日時などの表(topic list)について]]
// 検出後30秒ほどのタイムラグを設けて
delay : CeL.wiki.site_name(wiki) === 'jawiki' ? '30s' : 0,
// [[w:zh:WikiProject talk:电子游戏]]
namespace : 'project|project talk|talk|WikiProject talk|user talk',
filter : main_talk_pages,
with_content : true,
// language : use_language,
// options.use_SQL: Try to use SQL. Use SQL as possibile.
// commonswiki 得要使用 API 才不會漏。
use_SQL : [ 'commonswiki', 'enwiki' ].includes(CeL.wiki
.site_name(wiki)),
parameters : {
// 跳過機器人所做的編輯。
// You need the "patrol" or "patrolmarks" right to request the
// patrolled flag.
// rcshow : '!bot',
rcprop : 'title|ids|sizes|flags|user'
},
interval : '5s'
});
}
new CeL.wiki(null, null, 'en').page(botop_sitelinks.enwiki, {
redirects : 1
}).data(function(entity) {
// console.log(entity);
// throw 'botop_sitelinks';
get_special_users(main_process, {
botop_sitelinks : entity.sitelinks
});
});
}
// ----------------------------------------------------------------------------
// TODO: 將此功能轉到 wiki.js 中。
// 取得特定使用者名單(hash): 當使用者權限變更時必須重新執行程式!
function get_special_users(callback, options) {
var botop_sitelinks = options && options.botop_sitelinks;
if (!botop_sitelinks) {
throw new Error('No botop_sitelinks get!');
}
var special_users = Object.create(null), full_group_name = {
bureaucrat : 'bureaucrats',
botop : 'bot operators',
bot : 'bots',
admin : 'administrators'
};
function note_special_users(group_name) {
var user_name_list = Object.keys(special_users[group_name]).sort();
CeL.log('All ' + user_name_list.length + ' '
+ (full_group_name[group_name] || group_name) + ' confirmed: '
+ user_name_list.join(', ') + '.');
}
function get_allusers(group_name, augroup, callback) {
// reset
special_users[group_name] = Object.create(null);
wiki.allusers(function(list) {
if (list.next_index) {
throw 'Too many users so we do not get full list of '
+ group_name + '!';
}
// console.log(list);
list.forEach(function(user_data) {
if (group_name === 'bot'
// concrete users, 排除掉所有機器人。
|| !user_data.groups.includes('bot')) {
special_users[group_name][user_data.name] = user_data;
}
});
note_special_users(group_name);
if (callback) {
callback();
}
}, {
augroup : augroup || group_name,
auprop : 'groups',
// The parameters "augroup" and "auexcludegroup" cannot be used
// together.
// auexcludegroup : 'bot',
limit : 'max'
});
}
// 必須先取得bot這個群組以利後續檢查排除掉所有機器人。
get_allusers('bot');
get_allusers('bureaucrat', 'bureaucrat|steward|suppress', function() {
// 行政員以上可利用[[Special:Makebot]]核可機器人權限,為當然成員。
special_users.BAG = Object.clone(special_users.bureaucrat);
});
// 取得管理員列表。
// https://www.mediawiki.org/w/api.php?action=help&modules=query%2Ballusers
get_allusers('admin', 'sysop|bureaucrat|steward|suppress');
// [[WP:BAG]], [[Wikipedia:Bot Approvals Group]], [[維基百科:機器人審核小組]]
// TODO: 這裡的篩選方法會把頁面中所有的使用者都納入這個群體,包括不活躍與離職的。
// TODO: using [[Template:BAG_topicon]]
wiki.page('Project:BAG', function(page_data) {
var title = wiki.title_of(page_data),
/**
* {String}page content, maybe undefined. 條目/頁面內容 =
* CeL.wiki.revision_content(revision)
*/
content = CeL.wiki.content_of(page_data);
if (!content) {
// 沒有特別設置BAG群組。
special_users.no_BAG = true;
return;
}
var user_hash = CeL.wiki.parse.user.all(content);
for ( var user_name in user_hash) {
if (user_name && !is_bot_user(user_name, null, special_users)) {
special_users.BAG[user_name] = true;
}
}
var matched,
// 注意: 這個方法會把不活躍成員和離任成員也都列進去。
PATTERN_template_user = /{{ *user *\| *([^#\|\[\]{}\/]+)/ig;
while (matched = PATTERN_template_user.exec(content)) {
var user_name = CeL.wiki.normalize_title(matched[1]);
if (user_name && !is_bot_user(user_name, null, special_users)) {
special_users.BAG[user_name] = true;
}
}
note_special_users('BAG');
}, {
redirects : 1
});
var botop_page = CeL.wiki.site_name(wiki);
if (botop_page in CeL.wiki.api_URL.wikimedia) {
// e.g., .site of 'commons' is 'commonswiki'
botop_page += 'wiki';
}
botop_page = botop_sitelinks[botop_page];
if (botop_page && (botop_page = botop_page.title)) {
// reset
special_users.botop = Object.create(null);
// TODO: {{bot|bot operator}}, {{Infobox bot}}
wiki.categorymembers(botop_page, function(list) {
if (list.next_index) {
throw 'Too many users so we do not get full list!';
}
// console.log(list);
var user_namespace = CeL.wiki.namespace('user');
list.forEach(function(user_data) {
if (user_data.ns !== user_namespace
|| /[#\|\[\]{}\/]/.test(user_data.title)) {
return;
}
var user_name = user_data.title.replace(/^[^:]+:/, '');
if (user_name && !is_bot_user(user_name, null, special_users)) {
special_users.botop[user_name] = user_data;
}
});
note_special_users('botop');
}, {
limit : 'max'
});
}
wiki.run(function() {
// cache the special users
CeL.fs_write(get_special_users.log_file_prefix
+ CeL.wiki.site_name(wiki) + '.json', JSON
.stringify(special_users));
callback(special_users);
});
}
// ----------------------------------------------
// row_style functions
function general_row_style(section, section_index) {
var topic_status = general_check_section_status.call(this, section);
// archived, move_to 兩者分開,避免{{Archive top}}中有{{Moveto}}
var archived = topic_status.archived || section.archived && 'archived', move_to = topic_status.move_to
|| section.moved && 'moved';
return topic_status.style || '';
}
// ----------------------------------------------
// 討論議題列表依狀態表現不同的背景顏色。
// time → style
var short_to_long = {
// 最近1小時內: 淺綠色。
'1h' : 'efe',
// 超過1小時到最近1日內: 淺藍色。
'1d' : 'eef'
}, long_to_short = {
// 超過一個月: 深灰色。
'1 month' : 'bbb',
// 超過一禮拜到一個月: 淺灰色。
'1w' : 'ddd'
}, list_legend = {
en : {
header : 'Legend',
'1h' : 'In the last hour',
'1d' : 'In the last day',
'' : 'In the last week',
'1w' : 'In the last month',
'1 month' : 'More than one month'
},
zh : {
header : '發言更新圖例',
'1h' : '最近一小時內',
'1d' : '最近一日內',
'' : '一週內',
'1w' : '一個月內',
'1 month' : '逾一個月'
},
ja : {
header : '発言更新の凡例',
'1h' : '一時間以内',
'1d' : '一日以内',
'' : '一週間以内',
'1w' : '一ヶ月以内',
'1 month' : '一ヶ月以上'
}
};
// assert: 多次執行不會再改變其值
function normalize_time_style_hash(time_style_hash) {
// console.log(time_style_hash);
for ( var time_interval in time_style_hash) {
var style = time_style_hash[time_interval];
if (style.includes('style=')) {
continue;
}
if (/^[\da-f]{3,6}$/i.test(style)) {
// treat as RGB color code
style = '#' + style;
}
if (style.startsWith('#')) {
// treat as background-color
time_style_hash[time_interval] = 'style="background-color: '
+ style + ';" ';
}
}
// console.log(time_style_hash);
}
function setup_list_legend_special_status(list_legend_used) {
// @see general_row_style()
var guide = configuration.closed_style.line_CSS ? '| ' + 'style="'
+ configuration.closed_style.line_CSS + '" ' : '';
// TODO: CSS_toString(section.CSS)
if (configuration.closed_style.show_subtopic) {
guide += '| 討論議題' + '<br />→'
// 已移動至目標頁面
+ '<small>已移至頁面/最新討論子項</small>';
} else {
guide += '| 已移動至其他頁面<br />或完成討論之議題';
}
guide = [ '! 特殊狀態', '|-', guide, '|-' ].join('\n');
list_legend_used[list_legend_used.special_status_index] = guide;
}
function get_list_legend(page_configuration) {
// Must run normalize_time_style_hash() for short_to_long, long_to_short
// first!
var localized_list_legend = list_legend[use_language]
// e.g., 'zh-classical'
|| use_language && use_language.startsWith('zh-') && list_legend.zh
// e.g., 'commons'
|| list_legend.en;
// setup list_legend_used
var list_legend_used = [
'{| class="'
+ (page_configuration.list_legend_class
|| general_page_configuration.list_legend_class || '')
+ '" style="'
+ (page_configuration.list_legend_style
|| general_page_configuration.list_legend_style || '')
// {{#if:檢查字串|有值時輸出|無值時輸出}}
+ ';{{#if:{{{no_time_legend|}}}|display:none;|}}' + '"',
// TODO: .header 應該用 caption
// title: 相對於機器人最後一次編輯
'! title="From the latest bot edit" | '
+ localized_list_legend.header, '|-' ];
for ( var time_interval in localized_list_legend) {
if (time_interval === 'header') {
continue;
}
list_legend_used.push('| ' + (short_to_long[time_interval]
//
|| long_to_short[time_interval] || '') + ' |\n* '
+ localized_list_legend[time_interval], '|-');
}
list_legend_used.special_status_index = list_legend_used.length;
list_legend_used.push('');
if (use_language === 'zh') {
setup_list_legend_special_status(list_legend_used);
}
if (configuration.configuration_page_title) {
// @see general_row_style()
list_legend_used.push('! '
//
+ (use_language === 'zh' ? '手動設定' : 'Manual settings'), '|-',
//
'| style="max-width: 12em;" | <small>'
//
+ (use_language === 'zh' ? '當列表出現異常時,<br />請先檢查[['
// 設定頁面
+ configuration.configuration_page_title + '|設定]]是否有誤'
//
: 'When exceptions occur,<br />please check [['
//
+ configuration.configuration_page_title
// the setting page
+ '|the setting]] first.') + '</small>', '|-');
}
// {{clearright}}, {{-}}
list_legend_used.push('|}');
if (!page_configuration.no_tail_clear)
list_legend_used.push('{{Clear}}');
return list_legend_used;
}
// for 討論議題列表可以挑選欄位: (特定)使用者(最後)留言時間
// e.g., last_user_set, last_admin_set
function add_user_name_and_date_set(section, user_and_date_index) {
var user_shown = '', date = '';
if (user_and_date_index >= 0) {
var parsed = this;
date = section.dates[user_and_date_index];
if (true) {
// 採用短日期格式。
date = date.format({
format : (date.getFullYear() === (new Date).getFullYear()
// Skip year?
? '' || '%Y-' : '%Y-')
//
+ '%2m-%2d ' + (CSS_toString(section.CSS)
// 已經設定整行 CSS 的情況下,就不另外表現 CSS。
? '%2H:%2M' : '<span style="color: blue;">%2H:%2M</span>'),
// 採用當個項目最多人所處的時區。
zone : parsed.page.page_configuration.timezone || 0
});
// 因為不確定閱覽者的時區,因此不能夠再做進一步的處理,例如 CeL.date.indicate_date_time() 。
} else {
// 採用簽名的日期格式。
date = CeL.wiki.parse.date.to_String(date, wiki);
}
var date_too_long = if_too_long(date);
date = data_sort_attributes(section.dates[user_and_date_index]) + '| '
// TODO: linking date to [[Special:Diff/]]
+ (date_too_long ? '<small>' + date + '</small>' : date);
// 討論議題列表依狀態表現不同的背景顏色。
var additional_attributes = '', timevalue_diff = (new Date - section.dates[user_and_date_index]);
for ( var time_interval in short_to_long) {
if (timevalue_diff < CeL.to_millisecond(time_interval)) {
// add style
additional_attributes = short_to_long[time_interval];
break;
}
}
if (!additional_attributes) {
for ( var time_interval in long_to_short) {
if (timevalue_diff > CeL.to_millisecond(time_interval)) {
// add style
additional_attributes = long_to_short[time_interval];
break;
}
}
}
var user_name = section.users[user_and_date_index];
// 16: IPv4 user
user_shown = user_name.length < 16 ? user_name
// 縮小太長的使用者名稱。
: '<small style="word-wrap: break-word; word-break: break-all;">'
//
+ (CeL.is_IP(user_name, true)
// shorten IPv6 addresses.
? user_name.replace(
//
/^([\da-f]{1,4}):[\da-f:]+:([\da-f]{1,4}:[\da-f]{1,4})$/i,
//
'$1...$2') : user_name) + '</small>';
// TODO: link to diff
user_shown = (additional_attributes ? '| ' : '')
// 對於匿名IP用戶則顯示編輯紀錄。
+ (CeL.wiki.parse.user.parse_temporary_username(user_name)
//
|| CeL.is_IP(user_name)
//
? '[[Special:Contributions/' : '[[User:') + user_name + '|'
//
+ (CSS_toString(section.CSS) || CeL.is_IP(user_name)
//
? '<span style="'
//
+ (CeL.is_IP(user_name) ? 'color: #f82;' : '')
//
+ CSS_toString(section.CSS) + '">' + user_shown + '</span>'