Menu

[r41]: / trunk / wikibot.php  Maximize  Restore  History

Download this file

249 lines (198 with data), 9.9 kB

  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
<?php
# =========================================================================== #
#
# Experimental bot script, by Grigor Gatchev.
#
# Relying on the Bgbot mechanisms, created by Borislav Manolov.
#
# =========================================================================== #
require_once 'page_history.php';
require_once 'page_edit.php';
function editors_names_until_page_creation (
$bot_orig, $page_orig, $bot_copy, $page_copy, $majoronly ) {
$orig_page = new Page_History ( $bot_orig, $page_orig );
return $orig_page->editors_names_until_page_creation (
$bot_copy, $page_copy, $majoronly );
}
function editors_names_until_date ( $bot_orig, $page_orig, $date, $majoronly ) {
$orig_page = new Page_History ( $bot_orig, $page_orig );
return $orig_page->editors_names ( MIN_DATETIME, $date, $majoronly );
}
function bases_from_inserted_originals ( $bot_orig, $page_orig ) {
$bases = array();
if ( $bot_orig->edit ( $page_orig ) ) {
$count = preg_match_all ( '/\{\{Производна-Уикипедия(.*)\}\}/Us',
$bot_orig->page_content, $matches );
for ( $i=0; $i<$count; $i++ ) {
$basetext = $matches[1][$i];
$base = array();
$base['lang'] = trim (
extract_element ( '/\|\s*език\s*=\s*(.*)\|/Us', $basetext ) );
$base['page'] = trim (
extract_element ( '/\|\s*страница\s*=\s*(.*)\|/Us', $basetext ) );
$base['date'] = trim (
extract_element ( '/\|\s*дата\s*=\s*(.*)\|/Us', $basetext ) );
$base['list'] = trim (
extract_element ( '/\|\s*съавтори\s*=\s*(.*)$/Us', $basetext ) );
$base['date'] = str_replace ( '[[', '', $base['date'] );
$base['date'] = str_replace ( ']]', '', $base['date'] );
$base['list'] = str_replace ( 'Редактори: ', '', $base['list'] );
$bases[] = $base;
}
} else {
$bot_orig->log ( "Original \"$page_orig\" NOT fetched for editing - cannot extract info about its base" );
}
return $bases;
}
function original_authors_template ( $descendance_type, $descendance_date, $descendance_link,
$original_wiki, $original_wiki_link, $original_page, $original_page_link,
$original_history_link, $authors_names, $original_licence, $original_bases ) {
$template = "{{Производна статия от статия\n";
$template .= "| вид-производност = $descendance_type\n";
$template .= "| производност-дата = $descendance_date\n";
$template .= "| производност-линк = $descendance_link\n"; // към точната версия
$template .= "| оригинал-уики = $original_wiki\n";
$template .= "| оригинал-уики-линк = $original_wiki_link\n";
$template .= "| оригинал-име = $original_page\n";
$template .= "| оригинал-име-линк = $original_page_link\n"; // към актуалната страница
$template .= "| оригинал-история-линк = $original_history_link\n";
$template .= "| оригинал-автори = $authors_names\n";
$template .= "| оригинал-лиценз = $original_licence\n";
$template .= "| оригинал-база = $original_bases\n";
$template .= "}}";
return $template;
}
function origin_template ( $original_wiki, $original_wiki_name,
$original_page, $original_oldid, $authors_list, $descendance_date, $original_base ) {
global $base_pages, $wiki_sites;
$original_wiki_link = 'http://' . $original_wiki;
$original_page_link = $original_wiki_link . '/' .
(isset($base_pages[$wiki]) ? $base_pages[$wiki] : 'w/index.php') .
'?title=' . $original_page;
$original_page_link = str_replace ( " ", "_", $original_page_link );
$original_history_link = $original_page_link . '&action=history';
if ( $original_oldid ) {
$descendance_link = $original_page_link . "&oldid=" . $original_oldid;
}
$descendance_type = "е производна от";
$original_licence = "[[БГ-Фантастика:Лиценз за свободна документация на ГНУ|Лиценз за свободна документация на ГНУ]]";
return original_authors_template ( $descendance_type, $descendance_date, $descendance_link,
$original_wiki, $original_wiki_link, $original_page, $original_page_link,
$original_history_link, $authors_list, $original_licence, $original_base );
}
function bg_wikipedia_base_origin_template ( $base ) {
global $wiki_sites;
$original_wiki = $wiki_sites[$base['lang']];
$original_page = $base['page'];
$authors_list = $base['list'];
$descendance_date = $base['date'];
$original_oldid = false;
switch ( $base['lang'] ) {
case 'bg' : $original_wiki_name = "българоезичната Уикипедия"; break;
case 'en' : $original_wiki_name = "англоезичната Уикипедия"; break;
case 'de' : $original_wiki_name = "немскоезичната Уикипедия"; break;
case 'fr' : $original_wiki_name = "френскоезичната Уикипедия"; break;
default : $original_wiki_name = "---ЗА ПОПЪЛВАНЕ---"; break;
}
return origin_template ( $original_wiki, $original_wiki_name,
$original_page, $original_oldid, $authors_list, $descendance_date, "" );
}
function insert_original_editors_names (
$bot_orig, $page_orig, $bot_copy, $page_copy, $majoronly = false ) {
global $wiki_month_names;
$copy_edit = new Page_Edit ( $bot_copy, $page_copy );
if ( ! ( $copy_edit->active ) ) {
$bot_copy->log ( "Could not open \"$page_copy\" for editing - nothing changed" );
return;
}
if ( $copy_edit->bgbot->page_is_redirect ) {
$bot_copy->log ( "\"$page_copy\" is redirect - skipping it" );
return;
}
if ( strpos ( $copy_edit->bgbot->page_content, "{{Производна статия от статия" ) ) {
$bot_copy->log ( "\"$page_copy\" already contains this template!" );
return;
}
$copy_history = new Page_History ( $bot_copy, $page_copy );
if ( ! ( $copy_history->active ) ) {
$bot_copy->log ( "Copy \"page_copy\" history not found - can't determine descendance date" );
return;
}
$copy_date = $copy_history->page_created_on();
$descendance_date = date ( "d", $copy_date ) . " " .
$wiki_month_names[$bot_copy->wiki][date ( "n", $copy_date )] . " " .
date ( "Y", $copy_date );
$orig_history = new Page_History ( $bot_orig, $page_orig );
if ( ! ( $orig_history->active ) ) {
$bot_copy->log ( "History of \"$page_orig\" not found; nothing added to \"$page_copy\"" );
return;
}
$authors_array = $orig_history->editors_names ( MIN_DATETIME, $copy_date, $majoronly );
if ( count ( $authors_array ) == 0 ) {
$bot_copy->log ( "\"$page_copy\" apparently created before \"$page_orig\" - not based on it" );
return;
}
$original_oldid = $orig_history->rev_oldid (
$orig_history->page_last_updated_no ( $copy_date )
);
for ( $i=0; $i<count($authors_array); $i++ ) {
if ( ! ( ( $authors_array[$i] == "Bgbot" ) ||
( $authors_array[$i] == "JAnDbot" ) ||
( $authors_array[$i] == "Escarbot" ) ||
( $authors_array[$i] == "Thijs!bot" ) ) ) {
if ( $i ) { $authors_list .= ", "; }
$authors_list .= $authors_array[$i];
}
}
$sources_section_no = $copy_edit->section_header_pos ( "Източници" );
if ( is_bool ( $sources_section_no ) ) {
$sources_section_no =
$copy_edit->append_section ( 1, "Източници", "" );
}
$bases_list = bases_from_inserted_originals ( $bot_orig, $page_orig );
foreach ( $bases_list as $base ) {
$original_bases .= str_replace ( "\n|", "\n |",
bg_wikipedia_base_origin_template ( $base ) );
}
$section_text = $copy_edit->section_text ( $sources_section_no ) . "\n" .
origin_template ( $bot_orig->sites[$bot_orig->wiki], "българоезичната Уикипедия",
$page_orig, $original_oldid, $authors_list, $descendance_date,
$original_bases ) .
"\n";
$copy_edit->section_text ( $sources_section_no, $section_text );
#echo $copy_edit->parts_to_wikitext ();
$copy_edit->submit ( "Бот - Шаблон за производност на статията", false );
$bot_copy->log ( "Base of \"$page_orig\" inserted as a template in \"$page_copy\"" );
}
function insert_original_editors_names_inpage ( $pagename, $namespace ) {
global $wiki_special_words;
if ( ! empty ( $namespace ) ) { $divider = ":"; }
$bgf = new Bgbot ( 'bgf', 'Ботчо', '***' );
$bgw = new Bgbot ( 'bg', 'Григор Гачев', '***' );
insert_original_editors_names (
$bgw, $wiki_special_words[$bgw->wiki][$namespace] . $divider . $pagename,
$bgf, $wiki_special_words[$bgf->wiki][$namespace] . $divider . $pagename
);
}
function insert_original_editors_names_bylist ( $listfile, $namespace, $restsecs = 60 ) {
global $wiki_special_words;
if ( ! empty ( $namespace ) ) { $divider = ":"; }
$lf = fopen ( $listfile, "r" );
$bgf = new Bgbot ( 'bgf', 'Ботчо', '***' );
$bgw = new Bgbot ( 'bg', 'Григор Гачев', '***' );
while ( ! feof ( $lf ) ) {
$pagename = trim ( fgets ( $lf ) );
if ( ! ( feof ( $lf ) ) || ( empty ( $name ) ) ) {
$bgf->log ( "Processing \"" . $wiki_special_words[$bgf->wiki][$namespace] .
"$divider $pagename\"..." );
insert_original_editors_names (
$bgw, $wiki_special_words[$bgw->wiki][$namespace] . $divider . $pagename,
$bgf, $wiki_special_words[$bgf->wiki][$namespace] . $divider . $pagename
);
sleep ( $restsecs );
}
}
}
insert_original_editors_names_bylist ( 'bgf-articles.list', 'wiki' );
# insert_original_editors_names_inpage ( 'Пясъчник', 'wiki' );
?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.