Index: trunk/extensions/DPLforum/DPLforum.i18n.php |
— | — | @@ -0,0 +1,19 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalization file for DPLforum extension |
| 5 | + * |
| 6 | + * @addtogroup Extensions |
| 7 | + */ |
| 8 | + |
| 9 | +$messages = array(); |
| 10 | + |
| 11 | +/** English |
| 12 | + * @author Ross McClure |
| 13 | + */ |
| 14 | +$messages['en'] = array( |
| 15 | + 'forum_by' => 'by', |
| 16 | + 'forum_edited' => ' - Last edited', |
| 17 | + 'forum_never' => 'Never', |
| 18 | + 'forum_toofew' => 'DPL Forum: Too few categories!', |
| 19 | + 'forum_toomany' => 'DPL Forum: Too many categories!' |
| 20 | +); |
\ No newline at end of file |
Property changes on: trunk/extensions/DPLforum/DPLforum.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 21 | + native |
Index: trunk/extensions/DPLforum/DPLforum.php |
— | — | @@ -26,53 +26,44 @@ |
27 | 27 | http://www.gnu.org/copyleft/gpl.html |
28 | 28 | |
29 | 29 | To install, add following to LocalSettings.php |
30 | | - include("extensions/forum.php"); |
| 30 | + require_once("extensions/DPLforum/DPLforum.php"); |
31 | 31 | |
32 | 32 | */ |
33 | 33 | |
34 | | -$wgExtensionFunctions[] = "wfDPLforum"; |
| 34 | +$wgExtensionFunctions[] = 'wfDPLforum'; |
35 | 35 | $wgHooks['LanguageGetMagic'][] = 'wfDPLmagic'; |
36 | 36 | $wgExtensionCredits['parserhook'][] = array( |
37 | | -'name' => 'DPLforum', |
38 | | -'url' => 'http://www.mediawiki.org/wiki/Extension:DPLforum', |
39 | | -'description' => 'DPL-based forum extension', |
40 | | -'author' => 'Ross McClure', |
41 | | -'version' => '3.2' |
| 37 | + 'name' => 'DPLforum', |
| 38 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:DPLforum', |
| 39 | + 'description' => 'DPL-based forum extension', |
| 40 | + 'author' => 'Ross McClure', |
| 41 | + 'version' => '3.2' |
42 | 42 | ); |
43 | 43 | |
44 | | -function wfDPLforum() |
45 | | -{ |
46 | | - global $wgParser, $wgMessageCache; |
| 44 | +$dir = dirname(__FILE__) . '/'; |
| 45 | +$wgExtensionMessagesFiles['DPLforum'] = $dir . 'DPLforum.i18n.php'; |
47 | 46 | |
48 | | - $wgMessageCache->addMessages( array( |
49 | | - 'forum_by' => 'by', |
50 | | - 'forum_edited' => ' - Last edited', |
51 | | - 'forum_never' => 'Never', |
52 | | - 'forum_toofew' => 'DPL Forum: Too few categories!', |
53 | | - 'forum_toomany' => 'DPL Forum: Too many categories!' |
54 | | - )); |
| 47 | +function wfDPLforum() { |
| 48 | + global $wgParser; |
55 | 49 | |
56 | | - $wgParser->setHook('forum','parseForum'); |
57 | | - $wgParser->setFunctionHook('forumlink', array(new DPLForum(),'link')); |
| 50 | + wfLoadExtensionMessages('DPLforum'); |
| 51 | + $wgParser->setHook('forum', 'parseForum'); |
| 52 | + $wgParser->setFunctionHook('forumlink', array(new DPLForum(),'link')); |
58 | 53 | } |
59 | 54 | |
60 | | -function wfDPLmagic(&$magicWords,$langCode="en") |
61 | | -{ |
62 | | - switch($langCode) |
63 | | - { |
64 | | - default: $magicWords['forumlink'] = array (0,'forumlink'); |
65 | | - } |
66 | | - return true; |
| 55 | +function wfDPLmagic(&$magicWords, $langCode="en") { |
| 56 | + switch($langCode) { |
| 57 | + default: $magicWords['forumlink'] = array (0,'forumlink'); |
| 58 | + } |
| 59 | + return true; |
67 | 60 | } |
68 | 61 | |
69 | | -function parseForum($input, $argv, &$parser) |
70 | | -{ |
71 | | - $f = new DPLForum(); |
72 | | - return $f->parse($input, $parser); |
| 62 | +function parseForum($input, $argv, &$parser) { |
| 63 | + $f = new DPLForum(); |
| 64 | + return $f->parse($input, $parser); |
73 | 65 | } |
74 | 66 | |
75 | | -class DPLForum |
76 | | -{ |
| 67 | +class DPLForum { |
77 | 68 | var $minCategories = 1; // Minimum number of categories to look for |
78 | 69 | var $maxCategories = 6; // Maximum number of categories to look for |
79 | 70 | var $maxResultCount = 50; // Maximum number of results to allow |
— | — | @@ -100,13 +91,10 @@ |
101 | 92 | var $sOmit; |
102 | 93 | var $vMarkNew; |
103 | 94 | |
104 | | - function cat(&$parser, $name) |
105 | | - { |
| 95 | + function cat(&$parser, $name) { |
106 | 96 | $cats = array(); |
107 | | - if(preg_match_all("/^\s*$name\s*=\s*(.*)/mi",$this->sInput,$matches)) |
108 | | - { |
109 | | - foreach($matches[1] as $cat) |
110 | | - { |
| 97 | + if(preg_match_all("/^\s*$name\s*=\s*(.*)/mi",$this->sInput,$matches)) { |
| 98 | + foreach($matches[1] as $cat) { |
111 | 99 | $title = Title::newFromText($parser->replaceVariables(trim($cat))); |
112 | 100 | if( !is_null( $title ) ) |
113 | 101 | $cats[] = $title; |
— | — | @@ -115,10 +103,8 @@ |
116 | 104 | return $cats; |
117 | 105 | } |
118 | 106 | |
119 | | - function get($name, $value=NULL, $parser=NULL) |
120 | | - { |
121 | | - if(preg_match("/^\s*$name\s*=\s*(.*)/mi",$this->sInput,$matches)) |
122 | | - { |
| 107 | + function get($name, $value=NULL, $parser=NULL) { |
| 108 | + if(preg_match("/^\s*$name\s*=\s*(.*)/mi",$this->sInput,$matches)) { |
123 | 109 | $arg = trim($matches[1]); |
124 | 110 | if(is_int($value)) return intval($arg); |
125 | 111 | else if(is_null($parser)) return htmlspecialchars($arg); |
— | — | @@ -127,14 +113,12 @@ |
128 | 114 | return $value; |
129 | 115 | } |
130 | 116 | |
131 | | - function link(&$parser, $count, $page='', $text='') |
132 | | - { |
| 117 | + function link(&$parser, $count, $page='', $text='') { |
133 | 118 | $count = intval($count); |
134 | 119 | if($count<1) return ''; |
135 | 120 | |
136 | 121 | if($this->requireCache) $offset = 0; |
137 | | - else |
138 | | - { |
| 122 | + else { |
139 | 123 | global $wgRequest; |
140 | 124 | $parser->disableCache(); |
141 | 125 | $offset = intval($wgRequest->getVal('offset','')); |
— | — | @@ -152,14 +136,11 @@ |
153 | 137 | return '[{{fullurl:{{FULLPAGENAME}}|offset='.$page.'}} '.$text.']'; |
154 | 138 | } |
155 | 139 | |
156 | | - function link_test($page, $cond) |
157 | | - { |
158 | | - if(preg_match("/\\d+(\\D+)(\\d+)/",$cond,$m)) |
159 | | - { |
| 140 | + function link_test($page, $cond) { |
| 141 | + if(preg_match("/\\d+(\\D+)(\\d+)/",$cond,$m)) { |
160 | 142 | $m[1] = strtr($m[1], array(('&l'.'t;')=>'<', ('&g'.'t;')=>'>')); |
161 | 143 | $m[2] = intval($m[2])-1; |
162 | | - switch($m[1]) |
163 | | - { |
| 144 | + switch($m[1]) { |
164 | 145 | case '<': return ($page >= $m[2]); |
165 | 146 | case '>': return ($page <= $m[2]); |
166 | 147 | case '<=': return ($page > $m[2]); |
— | — | @@ -169,14 +150,12 @@ |
170 | 151 | return ($page < 0); |
171 | 152 | } |
172 | 153 | |
173 | | - function msg($type, $error=NULL) |
174 | | - { |
| 154 | + function msg($type, $error=NULL) { |
175 | 155 | if($error && ($this->get('suppresserrors')=='true')) return ''; |
176 | 156 | return htmlspecialchars(wfMsg($type)); |
177 | 157 | } |
178 | 158 | |
179 | | - function parse(&$input, &$parser) |
180 | | - { |
| 159 | + function parse(&$input, &$parser) { |
181 | 160 | global $wgContLang; |
182 | 161 | |
183 | 162 | $this->sInput =& $input; |
— | — | @@ -188,16 +167,14 @@ |
189 | 168 | $this->bAddLastEditor = ($this->get('addlasteditor')=='true'); |
190 | 169 | $this->bAddCreationDate = ($this->get('addcreationdate')=='true'); |
191 | 170 | |
192 | | - switch($this->get('historylink')) |
193 | | - { |
| 171 | + switch($this->get('historylink')) { |
194 | 172 | case 'embed': |
195 | 173 | case 'true': $this->bEmbedHistory = true; |
196 | 174 | case 'append': |
197 | 175 | case 'show': $this->bLinkHistory = true; |
198 | 176 | } |
199 | 177 | $sOrder = 'rev_timestamp'; |
200 | | - switch($this->get('ordermethod')) |
201 | | - { |
| 178 | + switch($this->get('ordermethod')) { |
202 | 179 | case 'categoryadd': |
203 | 180 | case 'created': |
204 | 181 | $sOrder = 'first_time'; |
— | — | @@ -213,8 +190,7 @@ |
214 | 191 | |
215 | 192 | $arg = $this->get('namespace','',$parser); |
216 | 193 | $iNamespace = $wgContLang->getNsIndex($arg); |
217 | | - if(!$iNamespace) |
218 | | - { |
| 194 | + if(!$iNamespace) { |
219 | 195 | if(($arg) || ($arg==='0')) $iNamespace = intval($arg); |
220 | 196 | else $iNamespace = -1; |
221 | 197 | } |
— | — | @@ -226,10 +202,9 @@ |
227 | 203 | $sStartItem = $sEndItem = ''; |
228 | 204 | $bCountMode = false; |
229 | 205 | $arg = $this->get('mode'); |
230 | | - switch($arg) |
231 | | - { |
| 206 | + switch($arg) { |
232 | 207 | case 'none': |
233 | | - $sEndItem = '<br/>'; |
| 208 | + $sEndItem = '<br />'; |
234 | 209 | break; |
235 | 210 | case 'count': |
236 | 211 | $bCountMode = true; |
— | — | @@ -262,23 +237,19 @@ |
263 | 238 | $start = $this->get('start',0); |
264 | 239 | $title = Title::newFromText($parser->replaceVariables( |
265 | 240 | trim($this->get('title')))); |
266 | | - if(!($bCountMode || $this->requireCache || $this->get('cache')=='true')) |
267 | | - { |
| 241 | + if(!($bCountMode || $this->requireCache || $this->get('cache')=='true')) { |
268 | 242 | $parser->disableCache(); |
269 | 243 | |
270 | | - if(is_null($title)) |
271 | | - { |
| 244 | + if(is_null($title)) { |
272 | 245 | global $wgRequest; |
273 | 246 | $start += intval($wgRequest->getVal('offset')); |
274 | 247 | } |
275 | 248 | } |
276 | 249 | if($start < 0) $start = 0; |
277 | 250 | |
278 | | - if(is_null($title)) |
279 | | - { |
| 251 | + if(is_null($title)) { |
280 | 252 | $count = $this->get('count',0); |
281 | | - if($count > 0) |
282 | | - { |
| 253 | + if($count > 0) { |
283 | 254 | if($count > $this->maxResultCount) |
284 | 255 | $count = $this->maxResultCount; |
285 | 256 | } |
— | — | @@ -298,21 +269,17 @@ |
299 | 270 | $arg = " FROM $sPageTable INNER JOIN $sRevTable" |
300 | 271 | . " AS r ON page_latest = r.rev_id"; |
301 | 272 | |
302 | | - if($bCountMode) |
303 | | - { |
| 273 | + if($bCountMode) { |
304 | 274 | $sSqlSelectFrom = "SELECT COUNT(*) AS num_rows FROM $sPageTable"; |
305 | 275 | } |
306 | 276 | else if(($this->bAddAuthor || $this->bAddCreationDate || |
307 | 277 | ($sOrder=='first_time')) && ((!$this->restrictNamespace) || |
308 | | - ($iNamespace>=0 && !in_array($iNamespace,$this->restrictNamespace)))) |
309 | | - { |
| 278 | + ($iNamespace>=0 && !in_array($iNamespace,$this->restrictNamespace)))) { |
310 | 279 | $sSqlSelectFrom .= ", o.rev_user_text AS first_user, o.rev_timestamp AS" |
311 | 280 | . " first_time" . $arg . " INNER JOIN $sRevTable AS o" |
312 | 281 | . " ON o.rev_id =( SELECT MIN(q.rev_id) FROM $sRevTable" |
313 | 282 | . " AS q WHERE q.rev_page = page_id )"; |
314 | | - } |
315 | | - else |
316 | | - { |
| 283 | + } else { |
317 | 284 | if($sOrder=='first_time') $sOrder = 'page_id'; |
318 | 285 | $sSqlSelectFrom .= $arg; |
319 | 286 | } |
— | — | @@ -321,16 +288,14 @@ |
322 | 289 | if($iNamespace >= 0) |
323 | 290 | $sSqlWhere = ' WHERE page_namespace='.$iNamespace; |
324 | 291 | |
325 | | - if($sPrefix!=='') |
326 | | - { |
| 292 | + if($sPrefix!=='') { |
327 | 293 | // Escape SQL special characters |
328 | 294 | $sPrefix = strtr($sPrefix, array('\\'=>'\\\\\\\\', |
329 | 295 | ' '=>'\\_', '_'=>'\\_', '%'=>'\\%', '\''=>'\\\'')); |
330 | 296 | $sSqlWhere .= " AND page_title LIKE BINARY '".$sPrefix."%'"; |
331 | 297 | } |
332 | 298 | |
333 | | - switch($this->get('redirects')) |
334 | | - { |
| 299 | + switch($this->get('redirects')) { |
335 | 300 | case 'only': |
336 | 301 | $sSqlWhere .= ' AND page_is_redirect = 1'; |
337 | 302 | case 'include': |
— | — | @@ -356,8 +321,7 @@ |
357 | 322 | $n++; |
358 | 323 | } |
359 | 324 | |
360 | | - if(!$bCountMode) |
361 | | - { |
| 325 | + if(!$bCountMode) { |
362 | 326 | $sSqlWhere .= " ORDER BY $sOrder "; |
363 | 327 | if($this->get('order')=='ascending') $sSqlWhere .= 'ASC'; |
364 | 328 | else $sSqlWhere .= 'DESC'; |
— | — | @@ -373,32 +337,24 @@ |
374 | 338 | $this->vMarkNew = $dbr->timestamp(time() - |
375 | 339 | intval($this->get('newdays',7) * 86400)); |
376 | 340 | |
377 | | - if($bCountMode) |
378 | | - { |
| 341 | + if($bCountMode) { |
379 | 342 | if($row = $dbr->fetchObject( $res )) $output .= $row->num_rows; |
380 | 343 | else $output .= '0'; |
381 | 344 | } |
382 | | - else if(is_null($title)) |
383 | | - { |
384 | | - while($row = $dbr->fetchObject( $res )) |
385 | | - { |
| 345 | + else if(is_null($title)) { |
| 346 | + while($row = $dbr->fetchObject( $res )) { |
386 | 347 | $title = Title::makeTitle($row->page_namespace, $row->page_title); |
387 | 348 | $output .= $sStartItem; |
388 | 349 | $output .= $this->buildOutput($title, $title, $row->rev_timestamp, |
389 | 350 | $row->rev_user_text, $row->first_user, $row->first_time); |
390 | 351 | $output .= $sEndItem . "\n"; |
391 | 352 | } |
392 | | - } |
393 | | - else |
394 | | - { |
| 353 | + } else { |
395 | 354 | $output .= $sStartItem; |
396 | | - if($row = $dbr->fetchObject( $res )) |
397 | | - { |
| 355 | + if($row = $dbr->fetchObject( $res )) { |
398 | 356 | $output .= $this->buildOutput(Title::makeTitle($row->page_namespace, |
399 | 357 | $row->page_title), $title, $row->rev_timestamp, $row->rev_user_text); |
400 | | - } |
401 | | - else |
402 | | - { |
| 358 | + } else { |
403 | 359 | $output .= $this->buildOutput(NULL, $title, $this->msg('forum_never')); |
404 | 360 | } |
405 | 361 | $output .= $sEndItem . "\n"; |
— | — | @@ -407,19 +363,16 @@ |
408 | 364 | } |
409 | 365 | |
410 | 366 | // Generates a single line of output. |
411 | | - function buildOutput($page, $title, $time, $user='', $author='', $made='') |
412 | | - { |
| 367 | + function buildOutput($page, $title, $time, $user='', $author='', $made='') { |
413 | 368 | global $wgLang, $wgUser; |
414 | 369 | $sk =& $wgUser->getSkin(); |
415 | 370 | $tm =& $this->bTableMode; |
416 | 371 | $by = $this->msg('forum_by'); |
417 | 372 | $output = ''; |
418 | 373 | |
419 | | - if($this->bAddCreationDate) |
420 | | - { |
| 374 | + if($this->bAddCreationDate) { |
421 | 375 | if(is_numeric($made)) $made = $wgLang->date($made, true); |
422 | | - if($page && $this->bLinkHistory && !$this->bAddLastEdit) |
423 | | - { |
| 376 | + if($page && $this->bLinkHistory && !$this->bAddLastEdit) { |
424 | 377 | if($this->bEmbedHistory) |
425 | 378 | $made = $sk->makeKnownLinkObj($page, $made, 'action=history'); |
426 | 379 | else |
— | — | @@ -436,22 +389,18 @@ |
437 | 390 | else $text = htmlspecialchars($title->getText()); |
438 | 391 | if(($this->sOmit) && strpos($text, $this->sOmit)===0) |
439 | 392 | $text = substr($text, strlen($this->sOmit)); |
440 | | - if(is_numeric($time)) |
441 | | - { |
| 393 | + if(is_numeric($time)) { |
442 | 394 | if($this->bTimestamp) $query = 't=' . $time; |
443 | 395 | if($time > $this->vMarkNew) $props = " class='forum_new'"; |
444 | 396 | } |
445 | 397 | $output .= $sk->makeKnownLinkObj($title, $text, $query, '', '', $props); |
446 | 398 | $text = ''; |
447 | 399 | |
448 | | - if($this->bAddAuthor) |
449 | | - { |
| 400 | + if($this->bAddAuthor) { |
450 | 401 | $author = Title::newFromText( $author, NS_USER ); |
451 | 402 | if($author) $author = $sk->makeKnownLinkObj($author,$author->getText()); |
452 | | - if($tm) |
453 | | - { |
454 | | - if($this->bCompactAuthor) |
455 | | - { |
| 403 | + if($tm) { |
| 404 | + if($this->bCompactAuthor) { |
456 | 405 | if($author) |
457 | 406 | $output .= " <span class='forum_author'>$by {$author}</span>"; |
458 | 407 | else $output .= " <span class='forum_author'>&nb"."sp;</span>"; |
— | — | @@ -461,11 +410,9 @@ |
462 | 411 | else if($author) $output .= " $by $author"; |
463 | 412 | } |
464 | 413 | |
465 | | - if($this->bAddLastEdit) |
466 | | - { |
| 414 | + if($this->bAddLastEdit) { |
467 | 415 | if(is_numeric($time)) $time = $wgLang->timeanddate($time, true); |
468 | | - if($page && $this->bLinkHistory) |
469 | | - { |
| 416 | + if($page && $this->bLinkHistory) { |
470 | 417 | if($this->bEmbedHistory) |
471 | 418 | $time = $sk->makeKnownLinkObj($page, $time, 'action=history'); |
472 | 419 | else |
— | — | @@ -476,14 +423,11 @@ |
477 | 424 | else $text .= "$time "; |
478 | 425 | } |
479 | 426 | |
480 | | - if($this->bAddLastEditor) |
481 | | - { |
| 427 | + if($this->bAddLastEditor) { |
482 | 428 | $user = Title::newFromText( $user, NS_USER ); |
483 | 429 | if($user) $user = $sk->makeKnownLinkObj($user, $user->getText()); |
484 | | - if($tm) |
485 | | - { |
486 | | - if($this->bCompactEdit) |
487 | | - { |
| 430 | + if($tm) { |
| 431 | + if($this->bCompactEdit) { |
488 | 432 | if($user) |
489 | 433 | $output .= " <span class='forum_editor'>$by {$user}</span>"; |
490 | 434 | else $output .= " <span class='forum_editor'>&nb"."sp;</span>"; |