Шаблон:Автоматично архивиране/doc

от Уикипедия, свободната енциклопедия

Употреба

Този шаблон може да бъде поставен в началото на беседи, които ботът Kerberizer ще архивира автоматично, без да е нужна човешка намеса. Архивирането се извършва всеки ден в интервала 04:00 – 05:00 българско време.

Шаблонът трябва да бъде поставен директно в началото на беседата. Не се поддържа поставяне в подстраница на беседата (/header, /начало и т.н.), която да бъде включена (transcluded) в беседата.

Бързо начало

Сложете следния код в началото на беседата, която желаете да бъде автоматично архивирана.

{{Автоматично архивиране
| archive             = {{subst:FULLPAGENAME}}/Архиви/%(year)d
| algo                = old(30d)
| counter             = 1
| archiveheader       = {{архив беседа2}}
| minthreadsleft      = 0
| minthreadstoarchive = 1
}}{{архиви2}}
<!-- МОЛЯ, НЕ РЕДАКТИРАЙТЕ ПРЕДИ ТОЗИ РЕД! БЛАГОДАРИМ ВИ! -->
  • Ако променяте параметъра archive, помнете, че той задължително трябва да указва към подстраница (с произволна дълбочина) на беседата, която се архивира. Не е допустимо архивиране под други страници.
  • Ако беседата е в именно пространство „Уикипедия“, заменете {{архив беседа2}} с {{архив уикипедия беседа2}}. ВАЖНО: Не използвайте шаблоните {{архив беседа}} и {{архив уикипедия беседа}}!
  • Ще бъдат архивирани теми, по които не е имало нови реплики повече от 30 дни. Ако предпочитате различен срок, вижте по-долу как можете да промените параметъра algo.
  • Архивите ще бъдат групирани по години. Ако предпочитате групиране по месеци или друг период, вижте по-долу с какви променливи можете да замените %(year)d.
  • Ако предпочитате на беседата винаги да има поне една тема, независимо колко остаряла е, променете параметъра minthreadsleft на 1.

Техническа информация

Бот

В случай на проблеми с Kerberizer архивирането може да се изпълнява от всеки друг бот или дори обикновен потребител.

За самото архивиране са нужни Python и Pywikibot. След като се настрои логването, от директорията на Pywikibot e достатъчно просто да се изпълни:

core/scripts/archivebot.py 'Автоматично архивиране'

Автоматизацията на архивирането може да се реализира по различни начини в зависимост от това къде би работил ботът. По-долу е приведен пример със systemd, като в примера Pywikibot е инсталиран в /opt/pywikibot, а user-config.py е поставен в директория /home/kerb/.pywikibot/Kerberizer. Услугата е конфигурирана на потребителско, не на системно ниво (systemctl --user ...).

# ~/.config/systemd/user/wm-kerberizer-daily.service
[Unit]
Description=Daily tasks for Kerberizer in the Wikimedia projects

[Service]
Type=oneshot
Environment=PYTHONPATH=/opt/pywikibot/core:/opt/pywikibot/core/externals:/opt/pywikibot/core/scripts:${PYTHONPATH}
Environment=PYWIKIBOT_DIR=/home/kerb/.pywikibot/Kerberizer
Environment=PYTHONUNBUFFERED=1
WorkingDirectory=/tmp
ExecStart=/opt/pywikibot/core/scripts/archivebot.py 'Автоматично архивиране'
# ~/.config/systemd/user/wm-kerberizer-daily.timer
[Unit]
Description=Daily tasks for Kerberizer in the Wikimedia projects

[Timer]
OnCalendar=*-*-* 04:00:00
RandomizedDelaySec=3600
Persistent=true

[Install]
WantedBy=timers.target

Ръководство

For current version, see https://github.com/wikimedia/pywikibot/blob/master/scripts/archivebot.py

usage:

    python pwb.py archivebot [OPTIONS] [TEMPLATE_PAGE]

Several TEMPLATE_PAGE templates can be given at once. Default is
`User:MiszaBot/config`. Bot examines backlinks (Special:WhatLinksHere)
to all TEMPLATE_PAGE templates. Then goes through all pages (unless a
specific page specified using options) and archives old discussions.
This is done by breaking a page into threads, then scanning each thread
for timestamps. Threads older than a specified threshold are then moved
to another page (the archive), which can be named either basing on the
thread's name or then name can contain a counter which will be
incremented when the archive reaches a certain size.

Transcluded template may contain the following parameters:

 {{TEMPLATE_PAGE
 |archive =
 |algo =
 |counter =
 |maxarchivesize =
 |minthreadsleft =
 |minthreadstoarchive =
 |archiveheader =
 |key =
 }}

Meanings of parameters are:

 archive              Name of the page to which archived threads will be put.
                      Must be a subpage of the current page. Variables are
                      supported.
 algo                 Specifies the maximum age of a thread. Must be
                      in the form old(<delay>) where <delay> specifies
                      the age in seconds (s), hours (h), days (d),
                      weeks (w), or years (y) like 24h or 5d. Default is
                      old(24h).
 counter              The current value of a counter which could be assigned as
                      variable. Will be updated by bot. Initial value is 1.
 maxarchivesize       The maximum archive size before incrementing the counter.
                      Value can be given with appending letter like K or M
                      which indicates KByte or MByte. Default value is 200K.
 minthreadsleft       Minimum number of threads that should be left on a page.
                      Default value is 5.
 minthreadstoarchive  The minimum number of threads to archive at once. Default
                      value is 2.
 archiveheader        Content that will be put on new archive pages as the
                      header. This parameter supports the use of variables.
                      Default value is {{talkarchive}}
 key                  A secret key that (if valid) allows archives not to be
                      subpages of the page being archived.

Variables below can be used in the value for "archive" in the template
above; numbers are latin digits:

%(counter)d          the current value of the counter
%(year)d             year of the thread being archived
%(isoyear)d          ISO year of the thread being archived
%(isoweek)d          ISO week number of the thread being archived
%(semester)d         semester term of the year of the thread being archived
%(quarter)d          quarter of the year of the thread being archived
%(month)d            month (as a number 1-12) of the thread being archived
%(monthname)s        localized name of the month above
%(monthnameshort)s   first three letters of the name above
%(week)d             week number of the thread being archived

Alternatively you may use localized digits. This is only available for a
few site languages. Refer :attr:`NON_LATIN_DIGITS
<userinterfaces.transliteration.NON_LATIN_DIGITS>` whether
there is a localized one:

%(localcounter)s     the current value of the counter
%(localyear)s        year of the thread being archived
%(localisoyear)s     ISO year of the thread being archived
%(localisoweek)s     ISO week number of the thread being archived
%(localsemester)s    semester term of the year of the thread being archived
%(localquarter)s     quarter of the year of the thread being archived
%(localmonth)s       month (as a number 1-12) of the thread being archived
%(localweek)s        week number of the thread being archived

The ISO calendar starts with the Monday of the week which has at least four
days in the new Gregorian calendar. If January 1st is between Monday and
Thursday (including), the first week of that year started the Monday of that
week, which is in the year before if January 1st is not a Monday. If it's
between Friday or Sunday (including) the following week is then the first week
of the year. So up to three days are still counted as the year before.

See also:
 - https://webspace.science.uu.nl/~gent0113/calendar/isocalendar.htm
 - https://docs.python.org/3/library/datetime.html#datetime.date.isocalendar

Вижте също