r59773 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59772‎ | r59773 | r59774 >
Date:20:05, 6 December 2009
Author:siebrand
Status:deferred
Tags:
Comment:
* improve fethcing of valid projects
* show error message on Special:TaskListByProject if $wgUseProjects was set to false
Modified paths:
  • /trunk/extensions/TodoTasks/SpecialTaskList.i18n.php (modified) (history)
  • /trunk/extensions/TodoTasks/SpecialTaskList_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TodoTasks/SpecialTaskList_body.php
@@ -4,7 +4,7 @@
55 static $messagesLoaded = false;
66 if ($messagesLoaded) return;
77 $messagesLoaded = true;
8 - wfLoadExtensionMessages('TaskList');
 8+ wfLoadExtensionMessages('TaskList');
99 }
1010
1111 function wfMsgTL($key) {
@@ -13,10 +13,10 @@
1414 }
1515
1616 function wfTodoParserFunction_Setup() {
17 - global $wgParser;
 17+ global $wgParser;
1818
19 - # Set a function hook associating the "example" magic word with our function
20 - $wgParser->setFunctionHook( 'todo', 'wfTodoParserFunction_Render' );
 19+ # Set a function hook associating the "example" magic word with our function
 20+ $wgParser->setFunctionHook( 'todo', 'wfTodoParserFunction_Render' );
2121
2222 return true;
2323 }
@@ -71,18 +71,18 @@
7272 }
7373
7474 function getValidProjects() {
75 - global $wgOut;
 75+ global $wgOut;
7676
77 - $ProjPageTitle = Title::newFromText ('TodoTasksValidProjects', NS_MEDIAWIKI) ;
78 - if ($ProjPageTitle == NULL) {
79 - $wgOut->addWikiText(wfMsgTL('tasklistnoprojects'));
80 - return;
81 - }
82 - return Revision::newFromTitle($ProjPageTitle)->getText();
 77+ $validProjects = wfMsgForContentNoTrans( 'todoTasksValidProjects' );
 78+ if ( $validProjects == '' ) {
 79+ $wgOut->addWikiText( wfMsg( 'tasklistnoprojects' ) );
 80+ return;
 81+ }
 82+ return $validProjects;
8383 }
8484
8585 function validateProject($projlist, $proj) {
86 -
 86+
8787 $validprojects = preg_split('/\s*\*\s*/', $projlist, -1, PREG_SPLIT_NO_EMPTY);
8888 foreach ($validprojects as $vp) {
8989 if (preg_match("/^$proj$/i", $vp))
@@ -221,8 +221,8 @@
222222 (todo) # template may be a TODO
223223 | # or
224224 (action item) # template may be an ACTION ITEM
225 - )
226 - \s* # the template name may have trailing spaces
 225+ )
 226+ \s* # the template name may have trailing spaces
227227 \| # the pipe to indicate template parameter #1 (task description)
228228 ( # capture the template parameter in $4; this string is comprized of
229229 [^|]*? # a possible sequence of non pipe characters
@@ -311,7 +311,7 @@
312312 list ($firstname, $lastname) = preg_split('/ /', $fullname);
313313
314314 $wgOut->addWikiText(sprintf(wfMsgTL('tasklistbyname'), $fullname));
315 - $wgOut->addWikiText("<dpl> uses=Template:Todo\n notuses=Template:Status Legend\n include={Todo}.dpl\n
 315+ $wgOut->addWikiText("<dpl> uses=Template:Todo\n notuses=Template:Status Legend\n include={Todo}.dpl\n
316316 includematch=/${fullname}/i\n </dpl>");
317317 }
318318 }
@@ -319,65 +319,75 @@
320320
321321 class TaskListByProject extends SpecialPage
322322 {
323 - function TaskListByProject() {
324 - SpecialPage::SpecialPage("TaskListByProject");
325 - self::loadMessages();
326 - return true;
327 - }
 323+ public function __construct() {
 324+ parent::__construct( 'TaskListByProject' );
 325+ SpecialPage::SpecialPage("TaskListByProject");
 326+ self::loadMessages();
 327+ return true;
 328+ }
328329
329330 function loadMessages() {
330331 TaskListLoadMessages();
331332 return true;
332333 }
333334
334 - function execute($proj) {
335 - global $wgRequest, $wgOut;
 335+ function execute($proj) {
 336+ global $wgRequest, $wgOut, $wgUseProjects;
336337
337 - $this->setHeaders();
338 - $wgOut->setPagetitle(wfMsgTL('tasklistbyproject'));
 338+ $this->setHeaders();
339339
340 - $project = '';
 340+ if ( !$wgUseProjects ) {
 341+ $wgOut->showErrorPage( 'tasklistbyproject', 'tasklistnowguseprojects' );
 342+ return;
 343+ }
341344
342 - if (isset($proj)) {
343 - $proj = str_replace('+', ' ', $proj);
344 - $validProjects = getValidProjects();
345 - $project = validateProject($validProjects, $proj);
346 - if ($project == wfMsgTL('tasklistunknownproject')) {
347 - $wgOut->addWikiText(sprintf(wfMsgTL('tasklistbyprojectbad'), $proj));
348 - self::ValidProjectsForm();
349 - return;
350 - }
351 - }
 345+ $wgOut->setPagetitle(wfMsgTL('tasklistbyproject'));
352346
353 - self::ValidProjectsForm();
 347+ $project = '';
354348
355 - if ($project == '')
356 - $project = $wgRequest->getVal('project');
357 - if ($project) {
358 - $wgOut->addWikiText("----");
359 - $wgOut->addWikiText(sprintf(wfMsgTL('tasklistbyprojname'), $project));
360 - $dpl = "<dpl>\n uses=Template:Todo \n notuses=Template:Status Legend \n include={Todo}.dpl \n";
361 - $dpl .= 'includematch=/project\s*=\s*([^\x2c]*\x2c)*\s*' . $project . '\s*(\x2c[^\x2c]*\s*)*$/i';
362 - $dpl .= "\n </dpl>";
363 - $wgOut->addWikiText($dpl);
364 - }
365 - }
 349+ if (isset($proj)) {
 350+ $proj = str_replace('+', ' ', $proj);
 351+ $validProjects = getValidProjects();
 352+ $project = validateProject($validProjects, $proj);
 353+ if ($project == wfMsgTL('tasklistunknownproject')) {
 354+ $wgOut->addWikiText(sprintf(wfMsgTL('tasklistbyprojectbad'), $proj));
 355+ self::ValidProjectsForm();
 356+ return;
 357+ }
 358+ }
366359
367 - function ValidProjectsForm() {
368 - global $wgOut;
 360+ self::ValidProjectsForm();
369361
370 - $titleObj = SpecialPage::getTitleFor( "TaskListByProject" );
371 - $kiaction = $titleObj->getLocalUrl();
372 - $wgOut->addHTML("<FORM ACTION=\"{$kiaction}\" METHOD=GET><LABEL FOR=project>" .
373 - wfMsgTL('tasklistchooseproj') . "</LABEL>");
374 - $wgOut->addHTML("<select name=project>");
 362+ if ($project == '')
 363+ $project = $wgRequest->getVal('project');
 364+ if ($project) {
 365+ $wgOut->addWikiText("----");
 366+ $wgOut->addWikiText(sprintf(wfMsgTL('tasklistbyprojname'), $project));
 367+ $dpl = "<dpl>\n uses=Template:Todo \n notuses=Template:Status Legend \n include={Todo}.dpl \n";
 368+ $dpl .= 'includematch=/project\s*=\s*([^\x2c]*\x2c)*\s*' . $project . '\s*(\x2c[^\x2c]*\s*)*$/i';
 369+ $dpl .= "\n </dpl>";
 370+ $wgOut->addWikiText($dpl);
 371+ }
 372+ }
375373
376 - $validprojects = preg_split('/\s*\*\s*/', getValidProjects(), -1, PREG_SPLIT_NO_EMPTY);
377 - foreach ($validprojects as $vp)
378 - $wgOut->addHTML("<option value=\"$vp\">$vp</option>");
 374+ function ValidProjectsForm() {
 375+ global $wgOut;
379376
380 - $wgOut->addHTML("</select><INPUT TYPE=submit VALUE='" . wfMsgTL('tasklistprojdisp') . "'></FORM>");
381 - }
 377+ $titleObj = SpecialPage::getTitleFor( "TaskListByProject" );
 378+ $kiaction = $titleObj->getLocalUrl();
 379+
 380+ $validprojects = preg_split('/\s*\*\s*/', getValidProjects(), -1, PREG_SPLIT_NO_EMPTY);
 381+
 382+ if( $validprojects ) {
 383+ $wgOut->addHTML("<FORM ACTION=\"{$kiaction}\" METHOD=GET><LABEL FOR=project>" .
 384+ wfMsgTL('tasklistchooseproj') . "</LABEL>");
 385+ $wgOut->addHTML("<select name=project>");
 386+
 387+ foreach ($validprojects as $vp) {
 388+ $wgOut->addHTML("<option value=\"$vp\">$vp</option>");
 389+ }
 390+
 391+ $wgOut->addHTML("</select><INPUT TYPE=submit VALUE='" . wfMsgTL('tasklistprojdisp') . "'></FORM>");
 392+ }
 393+ }
382394 }
383 -
384 -?>
Index: trunk/extensions/TodoTasks/SpecialTaskList.i18n.php
@@ -23,6 +23,7 @@
2424 'tasklistchooseproj' => 'Select project:',
2525 'tasklistprojdisp' => 'Display',
2626 'tasklistbyname' => '== Todo list for %s ==',
 27+ 'tasklistnowguseprojects' => 'You have set $wgUseProjects to "false" and cannot use this page.',
2728 'tasklistnoprojects' => "Error: It looks like you enabled '''\$wgUseProjects''', but did not create [[MediaWiki:TodoTasksValidProjects]]. See [http://www.mediawiki.org/wiki/Extension:Todo_Tasks#Step_8 Installation Instructions] for more details.",
2829 'tasklistemailbody' => ",
2930
@@ -31,6 +32,7 @@
3233 To see your complete Task List go to %s.
3334
3435 Your friendly %s notification system",
 36+ 'todoTasksValidProjects' => '', # Do not translate this message.
3537 );
3638
3739 /** Message documentation (Message documentation)

Status & tagging log