Index: trunk/extensions/Todo/TodoForm.php |
— | — | @@ -10,8 +10,8 @@ |
11 | 11 | $tododetail = wfMsg( 'todo-form-details' ); |
12 | 12 | $todoemail = wfMsg( 'todo-form-email' ); |
13 | 13 | $todosubmit = wfMsg( 'todo-form-submit' ); |
14 | | - $wgOut->addHTML( " |
15 | | -<style type=\"text/css\"> |
| 14 | +?> |
| 15 | +<style type="text/css"> |
16 | 16 | .mwTodoNewForm { |
17 | 17 | border: solid 1px #ccc; |
18 | 18 | background-color: #eee; |
— | — | @@ -22,38 +22,36 @@ |
23 | 23 | .mwTodoTitle { |
24 | 24 | font-weight: bold; |
25 | 25 | } |
26 | | -</style>" ); |
27 | | -?> |
| 26 | +</style> |
| 27 | + |
28 | 28 | <script type="text/javascript" src="<?php $this->text( 'script' ) ?>"></script> |
29 | 29 | |
30 | | -<form action="<?php $this->text( 'action' ) ?>" method="post"> |
| 30 | +<form action="<?php $this->text( 'action' ); ?>" method="post"> |
31 | 31 | <input type="hidden" name="wpNewItem" value="1" /> |
| 32 | + <div class="mwTodoNewForm"> |
32 | 33 | <p> |
33 | | -<?php |
34 | | -$wgOut->addHTML( " |
35 | | - <div class=\"mwTodoNewForm\"> |
36 | | - <label for=\"wpSummary\">{$todosummary}</label> |
| 34 | + <label for="wpSummary"><?php echo $todosummary; ?></label> |
37 | 35 | <br /> |
38 | | - <input id=\"wpSummary\" name=\"wpSummary\" size=\"40\" /> |
| 36 | + <input id="wpSummary" name="wpSummary" size="40" /> |
39 | 37 | </p> |
40 | 38 | |
41 | 39 | <p> |
42 | | - <label for=\"wpComment\">{$tododetail}</label> |
| 40 | + <label for="wpComment"><?php echo $tododetail ?></label> |
43 | 41 | <br /> |
44 | | - <textarea id=\"wpComment\" name=\"wpComment\" cols=\"40\" rows=\"6\" wrap=\"virtual\"></textarea> |
| 42 | + <textarea id="wpComment" name="wpComment" cols="40" rows="6" wrap="virtual"></textarea> |
45 | 43 | </p> |
46 | 44 | |
47 | 45 | <p> |
48 | | - <label for=\"wpEmail\">{$todoemail}</label> |
| 46 | + <label for="wpEmail"><?php echo $todoemail ?></label> |
49 | 47 | <br /> |
50 | | - <input id=\"wpEmail\" name=\"wpEmail\" size=\"30\" /> |
| 48 | + <input id="wpEmail" name="wpEmail" size="30" /> |
51 | 49 | </p> |
52 | 50 | |
53 | 51 | <p> |
54 | | - <input type=\"submit\" value=\"{$todosubmit}\" /> |
| 52 | + <input type="submit" value="<?php echo $todosubmit; ?>" /> |
55 | 53 | </p> |
56 | 54 | </div> |
57 | | -</form>" |
58 | | - ); |
| 55 | +</form> |
| 56 | +<?php |
59 | 57 | } |
60 | 58 | } |
Index: trunk/extensions/Todo/Todo.alias.php |
— | — | @@ -0,0 +1,15 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Aliases for special pages of Todo extension. |
| 5 | + * |
| 6 | + * @file |
| 7 | + */ |
| 8 | + |
| 9 | +$specialPageAliases = array(); |
| 10 | + |
| 11 | +/** |
| 12 | + * English |
| 13 | + */ |
| 14 | +$specialPageAliases['en'] = array( |
| 15 | + 'Todo' => array( 'Todo' ), |
| 16 | +); |
\ No newline at end of file |
Property changes on: trunk/extensions/Todo/Todo.alias.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 17 | + native |
Index: trunk/extensions/Todo/Todo.i18n.php |
— | — | @@ -35,6 +35,7 @@ |
36 | 36 | 'todo-list-change' => 'Change', |
37 | 37 | 'todo-list-cancel' => 'Cancel', |
38 | 38 | 'todo-new-item' => 'New item', |
| 39 | + 'todo-not-updated' => 'Could not update database record', |
39 | 40 | 'todo-issue-summary' => 'Issue summary:', |
40 | 41 | 'todo-form-details' => 'Details:', |
41 | 42 | 'todo-form-email' => 'To receive notification by e-mail when the item is closed, provide your address:', |
Index: trunk/extensions/Todo/Todo.php |
— | — | @@ -25,11 +25,11 @@ |
26 | 26 | 'descriptionmsg' => 'todo-desc', |
27 | 27 | ); |
28 | 28 | |
29 | | -$wgExtensionFunctions[] = 'todoSetup'; |
30 | 29 | $wgHooks['SkinTemplateTabs'][] = 'todoAddTab'; |
31 | 30 | |
32 | 31 | $dir = dirname( __FILE__ ) . '/'; |
33 | 32 | $wgExtensionMessagesFiles['todoAddTab'] = $dir . 'Todo.i18n.php'; |
| 33 | +$wgExtensionMessagesFiles['todoAddTabSp'] = $dir . 'Todo.alias.php'; |
34 | 34 | |
35 | 35 | // Creates a group of users who can have todo lists |
36 | 36 | $wgGroupPermissions['todo']['todo'] = true; |
— | — | @@ -41,11 +41,7 @@ |
42 | 42 | $wgAvailableRights[] = 'todo'; |
43 | 43 | $wgAvailableRights[] = 'todosubmit'; |
44 | 44 | |
45 | | -// FIXME: use $wgSpecialPages and delay message loading |
46 | | -function todoSetup() { |
47 | | - wfLoadExtensionMessages( 'todoAddTab' ); |
48 | | - SpecialPage::addPage( new SpecialPage( 'Todo' ) ); |
49 | | -} |
| 45 | +$wgSpecialPages['Todo'] = 'SpecialTodo'; |
50 | 46 | |
51 | 47 | // FIXME: use class file(s) to delay loading |
52 | 48 | /** |
— | — | @@ -55,9 +51,8 @@ |
56 | 52 | * @return bool true to continue running hooks, false to abort operation |
57 | 53 | */ |
58 | 54 | function todoAddTab( $skin, &$actions ) { |
59 | | - global $wgTitle; |
60 | | - if ( $wgTitle->getNamespace() == NS_USER || $wgTitle->getNamespace() == NS_USER_TALK ) { |
61 | | - $title = SpecialPage::getTitleFor( 'Todo', $wgTitle->getText() ); |
| 55 | + if ( $skin->getTitle()->getNamespace() == NS_USER || $skin->getTitle()->getNamespace() == NS_USER_TALK ) { |
| 56 | + $title = SpecialPage::getTitleFor( 'Todo', $skin->getTitle()->getText() ); |
62 | 57 | $actions['todo'] = array( |
63 | 58 | 'text' => wfMsg( 'todo-tab' ), |
64 | 59 | 'href' => $title->getLocalUrl() ); |
— | — | @@ -65,66 +60,63 @@ |
66 | 61 | return true; |
67 | 62 | } |
68 | 63 | |
69 | | -/** |
70 | | - * Entry-point function for Special:Todo |
71 | | - * @param mixed $par Will contain username to view on |
72 | | - */ |
73 | | -function wfSpecialTodo( $par = null ) { |
74 | | - if ( is_null( $par ) || $par == '' ) { |
75 | | - global $wgUser; |
76 | | - $user = $wgUser; |
77 | | - } else { |
78 | | - $user = User::newFromName( $par ); |
| 64 | +class SpecialTodo extends SpecialPage { |
| 65 | + function __construct() { |
| 66 | + parent::__construct( 'Todo' ); |
79 | 67 | } |
80 | | - if ( is_null( $user ) || !$user->isAllowed( 'todo' ) ) { |
81 | | - global $wgOut; |
82 | | - $wgOut->fatalError( wfMsgHtml( 'todo-user-invalide' ) ); |
83 | | - } else { |
84 | | - global $wgRequest; |
85 | | - $todo = new TodoForm( $user ); |
86 | | - if ( $wgRequest->wasPosted() ) { |
87 | | - $todo->submit( $wgRequest ); |
| 68 | + |
| 69 | + public function execute( $par ) { |
| 70 | + global $wgOut, $wgUser, $wgRequest; |
| 71 | + if ( is_null( $par ) || $par === '' ) { |
| 72 | + $user = $wgUser; |
88 | 73 | } else { |
89 | | - $todo->show(); |
| 74 | + $user = User::newFromName( $par ); |
90 | 75 | } |
91 | | - } |
92 | | -} |
93 | 76 | |
94 | | -class TodoForm { |
95 | | - function __construct( $user ) { |
| 77 | + $this->setHeaders(); |
| 78 | + $this->outputHeader(); |
| 79 | + |
| 80 | + if ( is_null( $user ) || !$user->isAllowed( 'todo' ) ) { |
| 81 | + return $wgOut->addWikiMsg( 'todo-user-invalide' ); |
| 82 | + } |
| 83 | + |
96 | 84 | $this->target = $user; |
97 | | - $this->self = SpecialPage::getTitleFor( 'Todo', $user->getName() ); |
| 85 | + $this->self = $this->getTitle( $user->getName() ); |
| 86 | + if ( $wgRequest->wasPosted() ) { |
| 87 | + $this->submit( $wgRequest ); |
| 88 | + } else { |
| 89 | + $this->show(); |
| 90 | + } |
98 | 91 | } |
99 | 92 | |
100 | 93 | function submit( $request ) { |
101 | 94 | if ( $request->getVal( 'wpNewItem' ) ) { |
102 | | - $this->submitNew( $request ); |
| 95 | + $result = $this->submitNew( $request ); |
103 | 96 | } elseif ( $request->getVal( 'wpUpdateField' ) ) { |
104 | | - $this->submitUpdate( $request ); |
| 97 | + $result = $this->submitUpdate( $request ); |
105 | 98 | } |
106 | 99 | $this->showError( $result ); |
107 | 100 | $this->show(); |
108 | 101 | } |
109 | 102 | |
110 | 103 | function submitNew( $request ) { |
111 | | - $result = TodoItem::add( |
| 104 | + return TodoItem::add( |
112 | 105 | $this->target, |
113 | 106 | $request->getText( 'wpSummary' ), |
114 | 107 | $request->getText( 'wpComment' ), |
115 | 108 | $request->getVal( 'wpEmail' ) ); |
116 | | - return $result; |
117 | 109 | } |
118 | 110 | |
119 | 111 | function submitUpdate( $request ) { |
120 | 112 | $id = $request->getInt( 'wpItem' ); |
121 | 113 | $item = TodoItem::loadFromId( $id ); |
122 | 114 | if ( is_null( $item ) ) { |
123 | | - return new WikiError( wfMsgHtml( 'todo-invalid-item' ) ); |
| 115 | + return Status::newFatal( 'todo-invalid-item' ); |
124 | 116 | } |
125 | 117 | |
126 | 118 | global $wgUser; |
127 | 119 | if ( $item->owner != $wgUser->getId() ) { |
128 | | - return new WikiError( wfMsgHtml( 'todo-update-else-item' ) ); |
| 120 | + return Status::newFatal( 'todo-update-else-item' ); |
129 | 121 | } |
130 | 122 | |
131 | 123 | switch( $request->getVal( 'wpUpdateField' ) ) { |
— | — | @@ -138,7 +130,7 @@ |
139 | 131 | return $item->setTitle( $request->getText( 'wpTitle' ) ); |
140 | 132 | break; |
141 | 133 | default: |
142 | | - return new WikiError( wfMsgHtml( 'todo-unrecognize-type' ) ); |
| 134 | + return Status::newFatal( 'todo-unrecognize-type' ); |
143 | 135 | } |
144 | 136 | } |
145 | 137 | |
— | — | @@ -149,7 +141,7 @@ |
150 | 142 | |
151 | 143 | $wgOut->addWikiText( "== " . wfMsg( 'todo-new-item' ) . " ==\n" ); |
152 | 144 | |
153 | | - require_once ( 'TodoForm.php' ); |
| 145 | + require_once( 'TodoForm.php' ); |
154 | 146 | $form = new TodoTemplate(); |
155 | 147 | $form->set( 'action', $this->self->getLocalUrl( 'action=submit' ) ); |
156 | 148 | $form->set( 'script', "$wgScriptPath/extensions/Todo/todo.js" ); |
— | — | @@ -164,10 +156,9 @@ |
165 | 157 | |
166 | 158 | function showError( $result ) { |
167 | 159 | global $wgOut; |
168 | | - if ( WikiError::isError( $result ) ) { |
169 | | - $wgOut->addHTML( '<p class="error">' . |
170 | | - htmlspecialcahrs( $result->getMessage() ) . |
171 | | - "</p>\n" ); |
| 160 | + if ( !$result->isOK() ) { |
| 161 | + $wgOut->addWikiText( "<p class=\"error\">\n" . |
| 162 | + $result->getWikiText() . "\n</p>\n" ); |
172 | 163 | } |
173 | 164 | } |
174 | 165 | |
— | — | @@ -186,7 +177,7 @@ |
187 | 178 | $result = $dbr->select( 'todolist', '*', array( |
188 | 179 | 'todo_owner' => $this->owner, |
189 | 180 | 'todo_status' => 'open' ), |
190 | | - 'TodoList::TodoList', |
| 181 | + __METHOD__, |
191 | 182 | array( 'ORDER BY' => 'todo_owner,todo_status,todo_queue,todo_timestamp DESC' ) ); |
192 | 183 | |
193 | 184 | $this->items = array(); |
— | — | @@ -274,7 +265,7 @@ |
275 | 266 | $row = $dbr->selectRow( 'todolist', |
276 | 267 | '*', |
277 | 268 | array( 'todo_id' => intval( $id ) ), |
278 | | - 'TodoForm::loadFromId' ); |
| 269 | + __METHOD__ ); |
279 | 270 | if ( $row ) { |
280 | 271 | return new TodoItem( $row ); |
281 | 272 | } else { |
— | — | @@ -289,7 +280,7 @@ |
290 | 281 | * @param string $email |
291 | 282 | * @static |
292 | 283 | */ |
293 | | - function add( $owner, $summary, $comment, $email ) { |
| 284 | + static function add( $owner, $summary, $comment, $email ) { |
294 | 285 | $dbw = wfGetDB( DB_MASTER ); |
295 | 286 | $dbw->insert( 'todolist', |
296 | 287 | array( |
— | — | @@ -300,8 +291,8 @@ |
301 | 292 | 'todo_title' => $summary, |
302 | 293 | 'todo_comment' => $comment, |
303 | 294 | 'todo_email' => $email ), |
304 | | - 'TodoItem::add' ); |
305 | | - return true; |
| 295 | + __METHOD__ ); |
| 296 | + return Status::newGood(); |
306 | 297 | } |
307 | 298 | |
308 | 299 | |
— | — | @@ -429,8 +420,8 @@ |
430 | 421 | } |
431 | 422 | |
432 | 423 | /** |
433 | | - * @param string $comment |
434 | | - * @param bool $sendMail false to supppress sending of email to submitter |
| 424 | + * @param $comment String |
| 425 | + * @param $sendMail Boolean: false to supppress sending of email to submitter |
435 | 426 | */ |
436 | 427 | function close( $comment, $sendMail ) { |
437 | 428 | $this->status = 'closed'; |
— | — | @@ -441,20 +432,19 @@ |
442 | 433 | } |
443 | 434 | |
444 | 435 | /** |
445 | | - * @param string $closeComment |
446 | | - * @return mixed true on success, WikiError on failure |
| 436 | + * @param $closeComment String |
447 | 437 | */ |
448 | 438 | function sendConfirmationMail( $closeComment ) { |
449 | 439 | global $wgContLang; |
450 | 440 | |
451 | 441 | $owner = User::newFromId( $this->owner ); |
452 | 442 | if ( is_null( $owner ) ) { |
453 | | - return new WikiError( wfMsgHtml( 'todo-invalid-owner' ) ); |
| 443 | + return; |
454 | 444 | } |
455 | 445 | |
456 | 446 | $sender = new MailAddress( $owner ); |
457 | 447 | $recipient = new MailAddress( $this->email ); |
458 | | - return UserMailer::send( $recipient, $sender, |
| 448 | + UserMailer::send( $recipient, $sender, |
459 | 449 | wfMsgForContent( 'todo-mail-subject', $owner->getName() ), |
460 | 450 | wordwrap( wfMsgForContent( 'todo-mail-body', |
461 | 451 | $owner->getName(), |
— | — | @@ -469,9 +459,14 @@ |
470 | 460 | */ |
471 | 461 | function updateRecord( $changes ) { |
472 | 462 | $dbw = wfGetDB( DB_MASTER ); |
473 | | - return $dbw->update( 'todolist', |
| 463 | + $ret = $dbw->update( 'todolist', |
474 | 464 | $changes, |
475 | 465 | array( 'todo_id' => $this->id ), |
476 | | - 'TodoItem::updateRecord' ); |
| 466 | + __METHOD__ ); |
| 467 | + if ( $ret ) { |
| 468 | + return Status::newGood(); |
| 469 | + } else { |
| 470 | + return Status::newFatal( 'todo-not-updated' ); |
| 471 | + } |
477 | 472 | } |
478 | 473 | } |