https://www.mediawiki.org/wiki/Special:Code/MediaWiki/115420
Revision: 115420
Author: maxsem
Date: 2012-05-23 20:13:24 +0000 (Wed, 23 May 2012)
Log Message:
-----------
Add support for redirections for wiktionary, wikinews and wikisource
Modified Paths:
--------------
trunk/debs/squid/redirector.c
Modified: trunk/debs/squid/redirector.c
===================================================================
--- trunk/debs/squid/redirector.c 2012-05-23 19:56:27 UTC (rev 115419)
+++ trunk/debs/squid/redirector.c 2012-05-23 20:13:24 UTC (rev 115420)
@@ -49,10 +49,10 @@
char buff[MAX_BUFF];
struct IN_BUFF in_buff;
- pattern = "^http:\\/\\/(\\w+)\\.wikipedia\\.org[:\\d]*\\/wiki\\/(.*)";
+ pattern =
"^http:\\/\\/(\\w+)\\.(wikipedia|wiktionary|wikinews|wikisource)\\.org[:\\d]*\\/wiki\\/(.*)";
pcre_extra *pe;
- char replacement_url[MAX_BUFF] =
"302:http://%s.m.wikipedia.org/wiki/%s\n";
+ char replacement_url[MAX_BUFF] = "302:http://%s.m.%s.org/wiki/%s\n";
if (argv[1] != NULL) {
char replacement_url_pattern[] = "302:%s\n";
@@ -90,7 +90,7 @@
rc = pcre_exec(
re, /* the compiled pattern */
pe, /* no extra data - we
didn't study the pattern */
- in_buff.url, /* the subject string */
+ in_buff.url, /* the subject string */
subject_length, /* the length of the
subject */
0, /* start at offset 0 in
the subject */
0, /* default options */
@@ -112,6 +112,7 @@
}
char lang[20] = "";
+ char site[100] = "";
char path[MAX_BUFF] = "";
for (i = 0; i < rc; i++) {
@@ -125,9 +126,15 @@
memcpy(lang, substring_start, substring_length);
lang[substring_length] = '\0';
} else if (i == 2) {
- if (substring_length >= MAX_BUFF) {
- substring_length = MAX_BUFF - 2;
+ if (substring_length >= sizeof(site)) {
+ substring_length = sizeof(site) - 2;
}
+ memcpy(site, substring_start, substring_length);
+ site[substring_length] = '\0';
+ } else if (i == 3) {
+ if (substring_length >= sizeof(path)) {
+ substring_length = sizeof(path) - 2;
+ }
memcpy(path, substring_start, substring_length);
path[substring_length] = '\0';
}
@@ -135,7 +142,7 @@
if (strlen(path) > 0) {
printf("%s ", in_buff.chan);
- printf(replacement_url, lang, path);
+ printf(replacement_url, lang, site, path);
}
fflush(stdout);
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs