r34873 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34872‎ | r34873 | r34874 >
Date:17:51, 15 May 2008
Author:ashley
Status:old
Tags:
Comment:
DPLforum:
*standard coding style
*split the i18n stuff into its own file & use wfLoadExtensionMessages() to load i18n
Modified paths:
  • /trunk/extensions/DPLforum/DPLforum.i18n.php (added) (history)
  • /trunk/extensions/DPLforum/DPLforum.php (modified) (history)

Diff [purge]

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
121 + native
Index: trunk/extensions/DPLforum/DPLforum.php
@@ -26,53 +26,44 @@
2727 http://www.gnu.org/copyleft/gpl.html
2828
2929 To install, add following to LocalSettings.php
30 - include("extensions/forum.php");
 30+ require_once("extensions/DPLforum/DPLforum.php");
3131
3232 */
3333
34 -$wgExtensionFunctions[] = "wfDPLforum";
 34+$wgExtensionFunctions[] = 'wfDPLforum';
3535 $wgHooks['LanguageGetMagic'][] = 'wfDPLmagic';
3636 $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'
4242 );
4343
44 -function wfDPLforum()
45 -{
46 - global $wgParser, $wgMessageCache;
 44+$dir = dirname(__FILE__) . '/';
 45+$wgExtensionMessagesFiles['DPLforum'] = $dir . 'DPLforum.i18n.php';
4746
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;
5549
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'));
5853 }
5954
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;
6760 }
6861
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);
7365 }
7466
75 -class DPLForum
76 -{
 67+class DPLForum {
7768 var $minCategories = 1; // Minimum number of categories to look for
7869 var $maxCategories = 6; // Maximum number of categories to look for
7970 var $maxResultCount = 50; // Maximum number of results to allow
@@ -100,13 +91,10 @@
10192 var $sOmit;
10293 var $vMarkNew;
10394
104 - function cat(&$parser, $name)
105 - {
 95+ function cat(&$parser, $name) {
10696 $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) {
11199 $title = Title::newFromText($parser->replaceVariables(trim($cat)));
112100 if( !is_null( $title ) )
113101 $cats[] = $title;
@@ -115,10 +103,8 @@
116104 return $cats;
117105 }
118106
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)) {
123109 $arg = trim($matches[1]);
124110 if(is_int($value)) return intval($arg);
125111 else if(is_null($parser)) return htmlspecialchars($arg);
@@ -127,14 +113,12 @@
128114 return $value;
129115 }
130116
131 - function link(&$parser, $count, $page='', $text='')
132 - {
 117+ function link(&$parser, $count, $page='', $text='') {
133118 $count = intval($count);
134119 if($count<1) return '';
135120
136121 if($this->requireCache) $offset = 0;
137 - else
138 - {
 122+ else {
139123 global $wgRequest;
140124 $parser->disableCache();
141125 $offset = intval($wgRequest->getVal('offset',''));
@@ -152,14 +136,11 @@
153137 return '[{{fullurl:{{FULLPAGENAME}}|offset='.$page.'}} '.$text.']';
154138 }
155139
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)) {
160142 $m[1] = strtr($m[1], array(('&l'.'t;')=>'<', ('&g'.'t;')=>'>'));
161143 $m[2] = intval($m[2])-1;
162 - switch($m[1])
163 - {
 144+ switch($m[1]) {
164145 case '<': return ($page >= $m[2]);
165146 case '>': return ($page <= $m[2]);
166147 case '<=': return ($page > $m[2]);
@@ -169,14 +150,12 @@
170151 return ($page < 0);
171152 }
172153
173 - function msg($type, $error=NULL)
174 - {
 154+ function msg($type, $error=NULL) {
175155 if($error && ($this->get('suppresserrors')=='true')) return '';
176156 return htmlspecialchars(wfMsg($type));
177157 }
178158
179 - function parse(&$input, &$parser)
180 - {
 159+ function parse(&$input, &$parser) {
181160 global $wgContLang;
182161
183162 $this->sInput =& $input;
@@ -188,16 +167,14 @@
189168 $this->bAddLastEditor = ($this->get('addlasteditor')=='true');
190169 $this->bAddCreationDate = ($this->get('addcreationdate')=='true');
191170
192 - switch($this->get('historylink'))
193 - {
 171+ switch($this->get('historylink')) {
194172 case 'embed':
195173 case 'true': $this->bEmbedHistory = true;
196174 case 'append':
197175 case 'show': $this->bLinkHistory = true;
198176 }
199177 $sOrder = 'rev_timestamp';
200 - switch($this->get('ordermethod'))
201 - {
 178+ switch($this->get('ordermethod')) {
202179 case 'categoryadd':
203180 case 'created':
204181 $sOrder = 'first_time';
@@ -213,8 +190,7 @@
214191
215192 $arg = $this->get('namespace','',$parser);
216193 $iNamespace = $wgContLang->getNsIndex($arg);
217 - if(!$iNamespace)
218 - {
 194+ if(!$iNamespace) {
219195 if(($arg) || ($arg==='0')) $iNamespace = intval($arg);
220196 else $iNamespace = -1;
221197 }
@@ -226,10 +202,9 @@
227203 $sStartItem = $sEndItem = '';
228204 $bCountMode = false;
229205 $arg = $this->get('mode');
230 - switch($arg)
231 - {
 206+ switch($arg) {
232207 case 'none':
233 - $sEndItem = '<br/>';
 208+ $sEndItem = '<br />';
234209 break;
235210 case 'count':
236211 $bCountMode = true;
@@ -262,23 +237,19 @@
263238 $start = $this->get('start',0);
264239 $title = Title::newFromText($parser->replaceVariables(
265240 trim($this->get('title'))));
266 - if(!($bCountMode || $this->requireCache || $this->get('cache')=='true'))
267 - {
 241+ if(!($bCountMode || $this->requireCache || $this->get('cache')=='true')) {
268242 $parser->disableCache();
269243
270 - if(is_null($title))
271 - {
 244+ if(is_null($title)) {
272245 global $wgRequest;
273246 $start += intval($wgRequest->getVal('offset'));
274247 }
275248 }
276249 if($start < 0) $start = 0;
277250
278 - if(is_null($title))
279 - {
 251+ if(is_null($title)) {
280252 $count = $this->get('count',0);
281 - if($count > 0)
282 - {
 253+ if($count > 0) {
283254 if($count > $this->maxResultCount)
284255 $count = $this->maxResultCount;
285256 }
@@ -298,21 +269,17 @@
299270 $arg = " FROM $sPageTable INNER JOIN $sRevTable"
300271 . " AS r ON page_latest = r.rev_id";
301272
302 - if($bCountMode)
303 - {
 273+ if($bCountMode) {
304274 $sSqlSelectFrom = "SELECT COUNT(*) AS num_rows FROM $sPageTable";
305275 }
306276 else if(($this->bAddAuthor || $this->bAddCreationDate ||
307277 ($sOrder=='first_time')) && ((!$this->restrictNamespace) ||
308 - ($iNamespace>=0 && !in_array($iNamespace,$this->restrictNamespace))))
309 - {
 278+ ($iNamespace>=0 && !in_array($iNamespace,$this->restrictNamespace)))) {
310279 $sSqlSelectFrom .= ", o.rev_user_text AS first_user, o.rev_timestamp AS"
311280 . " first_time" . $arg . " INNER JOIN $sRevTable AS o"
312281 . " ON o.rev_id =( SELECT MIN(q.rev_id) FROM $sRevTable"
313282 . " AS q WHERE q.rev_page = page_id )";
314 - }
315 - else
316 - {
 283+ } else {
317284 if($sOrder=='first_time') $sOrder = 'page_id';
318285 $sSqlSelectFrom .= $arg;
319286 }
@@ -321,16 +288,14 @@
322289 if($iNamespace >= 0)
323290 $sSqlWhere = ' WHERE page_namespace='.$iNamespace;
324291
325 - if($sPrefix!=='')
326 - {
 292+ if($sPrefix!=='') {
327293 // Escape SQL special characters
328294 $sPrefix = strtr($sPrefix, array('\\'=>'\\\\\\\\',
329295 ' '=>'\\_', '_'=>'\\_', '%'=>'\\%', '\''=>'\\\''));
330296 $sSqlWhere .= " AND page_title LIKE BINARY '".$sPrefix."%'";
331297 }
332298
333 - switch($this->get('redirects'))
334 - {
 299+ switch($this->get('redirects')) {
335300 case 'only':
336301 $sSqlWhere .= ' AND page_is_redirect = 1';
337302 case 'include':
@@ -356,8 +321,7 @@
357322 $n++;
358323 }
359324
360 - if(!$bCountMode)
361 - {
 325+ if(!$bCountMode) {
362326 $sSqlWhere .= " ORDER BY $sOrder ";
363327 if($this->get('order')=='ascending') $sSqlWhere .= 'ASC';
364328 else $sSqlWhere .= 'DESC';
@@ -373,32 +337,24 @@
374338 $this->vMarkNew = $dbr->timestamp(time() -
375339 intval($this->get('newdays',7) * 86400));
376340
377 - if($bCountMode)
378 - {
 341+ if($bCountMode) {
379342 if($row = $dbr->fetchObject( $res )) $output .= $row->num_rows;
380343 else $output .= '0';
381344 }
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 )) {
386347 $title = Title::makeTitle($row->page_namespace, $row->page_title);
387348 $output .= $sStartItem;
388349 $output .= $this->buildOutput($title, $title, $row->rev_timestamp,
389350 $row->rev_user_text, $row->first_user, $row->first_time);
390351 $output .= $sEndItem . "\n";
391352 }
392 - }
393 - else
394 - {
 353+ } else {
395354 $output .= $sStartItem;
396 - if($row = $dbr->fetchObject( $res ))
397 - {
 355+ if($row = $dbr->fetchObject( $res )) {
398356 $output .= $this->buildOutput(Title::makeTitle($row->page_namespace,
399357 $row->page_title), $title, $row->rev_timestamp, $row->rev_user_text);
400 - }
401 - else
402 - {
 358+ } else {
403359 $output .= $this->buildOutput(NULL, $title, $this->msg('forum_never'));
404360 }
405361 $output .= $sEndItem . "\n";
@@ -407,19 +363,16 @@
408364 }
409365
410366 // 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='') {
413368 global $wgLang, $wgUser;
414369 $sk =& $wgUser->getSkin();
415370 $tm =& $this->bTableMode;
416371 $by = $this->msg('forum_by');
417372 $output = '';
418373
419 - if($this->bAddCreationDate)
420 - {
 374+ if($this->bAddCreationDate) {
421375 if(is_numeric($made)) $made = $wgLang->date($made, true);
422 - if($page && $this->bLinkHistory && !$this->bAddLastEdit)
423 - {
 376+ if($page && $this->bLinkHistory && !$this->bAddLastEdit) {
424377 if($this->bEmbedHistory)
425378 $made = $sk->makeKnownLinkObj($page, $made, 'action=history');
426379 else
@@ -436,22 +389,18 @@
437390 else $text = htmlspecialchars($title->getText());
438391 if(($this->sOmit) && strpos($text, $this->sOmit)===0)
439392 $text = substr($text, strlen($this->sOmit));
440 - if(is_numeric($time))
441 - {
 393+ if(is_numeric($time)) {
442394 if($this->bTimestamp) $query = 't=' . $time;
443395 if($time > $this->vMarkNew) $props = " class='forum_new'";
444396 }
445397 $output .= $sk->makeKnownLinkObj($title, $text, $query, '', '', $props);
446398 $text = '';
447399
448 - if($this->bAddAuthor)
449 - {
 400+ if($this->bAddAuthor) {
450401 $author = Title::newFromText( $author, NS_USER );
451402 if($author) $author = $sk->makeKnownLinkObj($author,$author->getText());
452 - if($tm)
453 - {
454 - if($this->bCompactAuthor)
455 - {
 403+ if($tm) {
 404+ if($this->bCompactAuthor) {
456405 if($author)
457406 $output .= " <span class='forum_author'>$by {$author}</span>";
458407 else $output .= " <span class='forum_author'>&nb"."sp;</span>";
@@ -461,11 +410,9 @@
462411 else if($author) $output .= " $by $author";
463412 }
464413
465 - if($this->bAddLastEdit)
466 - {
 414+ if($this->bAddLastEdit) {
467415 if(is_numeric($time)) $time = $wgLang->timeanddate($time, true);
468 - if($page && $this->bLinkHistory)
469 - {
 416+ if($page && $this->bLinkHistory) {
470417 if($this->bEmbedHistory)
471418 $time = $sk->makeKnownLinkObj($page, $time, 'action=history');
472419 else
@@ -476,14 +423,11 @@
477424 else $text .= "$time ";
478425 }
479426
480 - if($this->bAddLastEditor)
481 - {
 427+ if($this->bAddLastEditor) {
482428 $user = Title::newFromText( $user, NS_USER );
483429 if($user) $user = $sk->makeKnownLinkObj($user, $user->getText());
484 - if($tm)
485 - {
486 - if($this->bCompactEdit)
487 - {
 430+ if($tm) {
 431+ if($this->bCompactEdit) {
488432 if($user)
489433 $output .= " <span class='forum_editor'>$by {$user}</span>";
490434 else $output .= " <span class='forum_editor'>&nb"."sp;</span>";

Status & tagging log