-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetWMML.php
173 lines (145 loc) · 5.06 KB
/
getWMML.php
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
<?php
/**
* getWMML.php :: All-in-One file
*
* Get Wikimedia Mailing Lists
* Created on February 1st, 2011
*
* Copyright 2011 Krinkle <[email protected]>
*
* This file is released in the public domain.
*/
/*
Shortened:
Wikitech-l: <http://bit.ly/wikitechLast> / <http://bit.ly/wikitechLatest>
<http://bit.ly/wikitechMonth>
Toolserver-l: <http://bit.ly/toolserverLast> / <http://bit.ly/toolserverLatest>
<http://bit.ly/toolserverMonth>
Commons-l: <http://bit.ly/toolserverLast>
<http://bit.ly/toolserverMonth>
*/
/** BEWARE: Ugly hacks ahead. Caution proceeding. **/
/**
* Configuration
* -------------------------------------------------
*/
require_once( 'CommonStuff.php' );
$c['revID'] = '0.0.2';
$c['revDate'] = '2011-02-01';
$c['title'] = 'Get Wikimedia Mailing Lists';
$c['baseurl'] = $c['tshome'] .'/getWMML.php';
/**
* Functions
* -------------------------------------------------
*/
function injectScript( $scriptTag, $source ) {
if ( !is_string( $scriptTag ) || !is_string( $source ) ) {
die( 'Error while loading script.' );
}
return str_ireplace( '</body>', $scriptTag . '</body>', $source );
}
function injectJQuery( $source ) {
return injectScript( '<script src="' . krGetjQueryURL() . '"></script>', $source );
}
function downloadListPage( $list = false, $path = '' ) {
$url = 'http://lists.wikimedia.org/pipermail/' . rawurlencode( $list ) . '/' . $path;
$sourceCode = file_get_contents( $url );
if ( $sourceCode ) {
return $sourceCode;
} else {
die( 'Error while retrieving list index.' );
}
}
function injectGoToCurrMonth( $source ) {
global $params;
$replace = '$1';
$base = 'http://lists.wikimedia.org/pipermail/' . rawurlencode( $params['list'] ) . '/' . $replace;
$script = <<<SCRIPT
<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
var currMonthLocation = $( 'a' ).eq( 4 ).attr( 'href' );
location.href='$base'.replace( '$replace', currMonthLocation );
} );
</script>
SCRIPT;
return injectScript( $script, $source );
}
function injectGoToLastEntry_StepOne( $source ) {
global $params;
$p = array_merge( $params, array(
'action' => 'lastentry-processing',
'tmp' => '$1',
) ) ;
$replace = rawurlencode( '$1' );
$base = generatePermalink( $p );
$script = <<<SCRIPT
<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
var currMonthLocation = $( 'a' ).eq( 4 ).attr( 'href' );
location.href='$base'.replace( '$replace', currMonthLocation );
} );
</script>
SCRIPT;
return injectScript( $script, $source );
}
function injectGoToLastEntry_StepTwo( $source ) {
global $params;
$replace = rawurlencode( '$1' );
$base = 'http://lists.wikimedia.org/pipermail/' . rawurlencode( $params['list'] ) . '/' . rawurlencode( str_replace( '/date.html', '', $params['tmp'] ) ) . '/' . $replace;
$script = <<<SCRIPT
<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
var lastEntryLocation = $( 'ul:eq(1) > li:last > a:first' ).attr( 'href' );
location.href='$base'.replace( '$replace', lastEntryLocation );
} );
</script>
SCRIPT;
return injectScript( $script, $source );
}
/**
* Settings
* -------------------------------------------------
*/
$s = array();
$s['validActions'] = array( 'index', 'thismonth', 'lastentry', 'lastentry-processing' );
/**
* Parameters
* -------------------------------------------------
*/
$params['list'] = getParamVar( 'list' );
$params['action'] = getParamVar( 'action' );
$params['tmp'] = getParamVar( 'tmp' );
if ( !is_string( $params['list'] ) || $params['list'] == '' ) {
die( 'Missing list parameter.' );
}
if ( !in_array( $params['action'], $s['validActions'] ) ) {
die( 'Invalid action.' );
}
/**
* Do it
* -------------------------------------------------
*/
if ( $params['action'] == 'index' ) {
$html = downloadListPage( $params['list'] );
$html = injectJQuery( $html );
echo $html;
die;
}
if ( $params['action'] == 'thismonth' ) {
$html = downloadListPage( $params['list'] );
$html = injectJQuery( $html );
echo injectGoToCurrMonth( $html );
die;
}
if ( $params['action'] == 'lastentry' ) {
$html = downloadListPage( $params['list'] );
$html = injectJQuery( $html );
echo injectGoToLastEntry_StepOne( $html );
die;
}
if ( $params['action'] == 'lastentry-processing' ) {
$html = downloadListPage( $params['list'], $params['tmp'] );
$html = injectJQuery( $html );
echo injectGoToLastEntry_StepTwo( $html );
die;
}