Index: trunk/extensions/ChangeAuthor/ChangeAuthor.body.php |
— | — | @@ -30,7 +30,7 @@ |
31 | 31 | /** |
32 | 32 | * Constructor |
33 | 33 | */ |
34 | | - public function __construct(){ |
| 34 | + public function __construct() { |
35 | 35 | global $wgUser; |
36 | 36 | wfLoadExtensionMessages( 'ChangeAuthor' ); |
37 | 37 | parent::__construct( 'ChangeAuthor'/* class */, 'changeauthor'/* restriction */ ); |
— | — | @@ -43,43 +43,45 @@ |
44 | 44 | * |
45 | 45 | * @param $par Mixed: parameter passed to the page or null |
46 | 46 | */ |
47 | | - public function execute( $par ){ |
| 47 | + public function execute( $par ) { |
48 | 48 | global $wgRequest, $wgOut, $wgContLang, $wgUser; |
| 49 | + |
49 | 50 | $this->setHeaders(); |
50 | 51 | |
51 | 52 | // Check permissions |
52 | | - if( !$this->userCanExecute( $wgUser ) ){ |
| 53 | + if( !$this->userCanExecute( $wgUser ) ) { |
53 | 54 | $this->displayRestrictionError(); |
54 | 55 | return; |
55 | 56 | } |
56 | 57 | |
57 | 58 | $wgOut->setPageTitle( wfMsg( 'changeauthor-title' ) ); |
58 | 59 | |
59 | | - if( !is_null( $par ) ){ |
| 60 | + if( !is_null( $par ) ) { |
60 | 61 | $obj = $this->parseTitleOrRevID( $par ); |
61 | | - if( $obj instanceof Title ){ |
62 | | - if( $obj->exists() ) |
| 62 | + if( $obj instanceof Title ) { |
| 63 | + if( $obj->exists() ) { |
63 | 64 | $wgOut->addHTML( $this->buildRevisionList( $obj ) ); |
64 | | - else |
| 65 | + } else { |
65 | 66 | $wgOut->addHTML( $this->buildInitialForm( wfMsg( 'changeauthor-nosuchtitle', $obj->getPrefixedText() ) ) ); |
| 67 | + } |
66 | 68 | return; |
67 | | - } else if( $obj instanceof Revision ){ |
| 69 | + } elseif( $obj instanceof Revision ) { |
68 | 70 | $wgOut->addHTML( $this->buildOneRevForm( $obj ) ); |
69 | 71 | return; |
70 | 72 | } |
71 | 73 | } |
72 | 74 | |
73 | 75 | $action = $wgRequest->getVal( 'action' ); |
74 | | - if( $wgRequest->wasPosted() && $action == 'change' ){ |
| 76 | + if( $wgRequest->wasPosted() && $action == 'change' ) { |
75 | 77 | $arr = $this->parseChangeRequest(); |
76 | | - if( !is_array( $arr ) ){ |
| 78 | + if( !is_array( $arr ) ) { |
77 | 79 | $targetPage = $wgRequest->getVal( 'targetpage' ); |
78 | | - if( !is_null( $targetPage ) ){ |
| 80 | + if( !is_null( $targetPage ) ) { |
79 | 81 | $wgOut->addHTML( $this->buildRevisionList( Title::newFromURL( $targetPage ), $arr ) ); |
80 | 82 | return; |
81 | 83 | } |
82 | 84 | $targetRev = $wgRequest->getVal( 'targetrev' ); |
83 | | - if( !is_null( $targetRev ) ){ |
| 85 | + if( !is_null( $targetRev ) ) { |
84 | 86 | $wgOut->addHTML( $this->buildOneRevForm( Revision::newFromId( $targetRev ), $arr ) ); |
85 | 87 | return; |
86 | 88 | } |
— | — | @@ -90,14 +92,15 @@ |
91 | 93 | } |
92 | 94 | return; |
93 | 95 | } |
94 | | - if( $wgRequest->wasPosted() && $action == 'list' ){ |
| 96 | + if( $wgRequest->wasPosted() && $action == 'list' ) { |
95 | 97 | $obj = $this->parseTitleOrRevID( $wgRequest->getVal( 'pagename-revid' ) ); |
96 | | - if( $obj instanceof Title ){ |
97 | | - if( $obj->exists() ) |
| 98 | + if( $obj instanceof Title ) { |
| 99 | + if( $obj->exists() ) { |
98 | 100 | $wgOut->addHTML( $this->buildRevisionList( $obj ) ); |
99 | | - else |
| 101 | + } else { |
100 | 102 | $wgOut->addHTML( $this->buildInitialForm( wfMsg( 'changeauthor-nosuchtitle', $obj->getPrefixedText() ) ) ); |
101 | | - } else if( $obj instanceof Revision ){ |
| 103 | + } |
| 104 | + } elseif( $obj instanceof Revision ) { |
102 | 105 | $wgOut->addHTML( $this->buildOneRevForm( $obj ) ); |
103 | 106 | } |
104 | 107 | return; |
— | — | @@ -110,12 +113,14 @@ |
111 | 114 | * @param $str Mixed: revision ID or an article name |
112 | 115 | * @return Title or Revision object, or NULL |
113 | 116 | */ |
114 | | - private function parseTitleOrRevID( $str ){ |
| 117 | + private function parseTitleOrRevID( $str ) { |
115 | 118 | $retval = false; |
116 | | - if( is_numeric( $str ) ) |
| 119 | + if( is_numeric( $str ) ) { |
117 | 120 | $retval = Revision::newFromID( $str ); |
118 | | - if( !$retval ) |
| 121 | + } |
| 122 | + if( !$retval ) { |
119 | 123 | $retval = Title::newFromURL( $str ); |
| 124 | + } |
120 | 125 | return $retval; |
121 | 126 | } |
122 | 127 | |
— | — | @@ -124,7 +129,7 @@ |
125 | 130 | * @param $errMsg String: Error message |
126 | 131 | * @return HTML |
127 | 132 | */ |
128 | | - private function buildInitialForm( $errMsg = '' ){ |
| 133 | + private function buildInitialForm( $errMsg = '' ) { |
129 | 134 | global $wgScript; |
130 | 135 | $retval = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $wgScript ) ); |
131 | 136 | $retval .= Xml::hidden( 'title', $this->selfTitle->getPrefixedDBkey() ); |
— | — | @@ -134,7 +139,7 @@ |
135 | 140 | $retval .= Xml::inputLabel( wfMsg( 'changeauthor-pagename-or-revid' ), |
136 | 141 | 'pagename-revid', 'pagename-revid' ); |
137 | 142 | $retval .= Xml::submitButton( wfMsg( 'changeauthor-pagenameform-go' ) ); |
138 | | - if( $errMsg != '' ){ |
| 143 | + if( $errMsg != '' ) { |
139 | 144 | $retval .= Xml::openElement( 'p' ) . Xml::openElement( 'b' ); |
140 | 145 | $retval .= Xml::element( 'font', array( 'color' => 'red' ), $errMsg ); |
141 | 146 | $retval .= Xml::closeElement( 'b' ) . Xml::closeElement( 'p' ); |
— | — | @@ -154,43 +159,48 @@ |
155 | 160 | * @param $isLast Boolean: set to true if $rev is the last revision |
156 | 161 | * @return HTML |
157 | 162 | */ |
158 | | - private function buildRevisionLine( $rev, $title, $isFirst = false, $isLast = false ){ |
| 163 | + private function buildRevisionLine( $rev, $title, $isFirst = false, $isLast = false ) { |
159 | 164 | // Build curlink |
160 | | - if( $isFirst ) |
| 165 | + if( $isFirst ) { |
161 | 166 | $curLink = wfMsgExt( 'cur', 'escape' ); |
162 | | - else |
| 167 | + } else { |
163 | 168 | $curLink = $this->skin->makeKnownLinkObj( $title, |
164 | 169 | wfMsgExt( 'cur', 'escape' ), |
165 | 170 | "oldid={$rev->getId()}&diff=cur" ); |
| 171 | + } |
166 | 172 | |
167 | | - if( $isLast ) |
| 173 | + if( $isLast ) { |
168 | 174 | $lastLink = wfMsgExt( 'last', 'escape' ); |
169 | | - else |
| 175 | + } else { |
170 | 176 | $lastLink = $this->skin->makeKnownLinkObj( $title, |
171 | 177 | wfMsgExt( 'last', 'escape' ), |
172 | 178 | "oldid=prev&diff={$rev->getId()}" ); |
| 179 | + } |
173 | 180 | |
174 | 181 | // Build oldid link |
175 | 182 | global $wgLang; |
176 | 183 | $date = $wgLang->timeanddate( wfTimestamp( TS_MW, $rev->getTimestamp() ), true ); |
177 | | - if( $rev->userCan( Revision::DELETED_TEXT ) ) |
| 184 | + if( $rev->userCan( Revision::DELETED_TEXT ) ) { |
178 | 185 | $link = $this->skin->makeKnownLinkObj( $title, $date, "oldid={$rev->getId()}" ); |
179 | | - else |
| 186 | + } else { |
180 | 187 | $link = $date; |
| 188 | + } |
181 | 189 | |
182 | 190 | // Build user textbox |
183 | 191 | global $wgRequest; |
184 | 192 | $userBox = Xml::input( "user-new-{$rev->getId()}", 50, $wgRequest->getVal( "user-{$rev->getId()}", $rev->getUserText() ) ); |
185 | 193 | $userText = Xml::hidden( "user-old-{$rev->getId()}", $rev->getUserText() ) . $rev->getUserText(); |
186 | 194 | |
187 | | - if( !is_null( $size = $rev->getSize() ) ){ |
188 | | - if( $size == 0 ) |
| 195 | + if( !is_null( $size = $rev->getSize() ) ) { |
| 196 | + if( $size == 0 ) { |
189 | 197 | $stxt = wfMsgHtml( 'historyempty' ); |
190 | | - else |
| 198 | + } else { |
191 | 199 | $stxt = wfMsgHtml( 'historysize', $wgLang->formatNum( $size ) ); |
192 | | - } else |
| 200 | + } |
| 201 | + } else { |
193 | 202 | $stxt = ''; // Stop PHP from whining about unset variables |
194 | | - $comment = $this->skin->commentBlock( $rev->getComment(), $title ); |
| 203 | + } |
| 204 | + $comment = $this->skin->commentBlock( $rev->getComment(), $title ); |
195 | 205 | |
196 | 206 | // Now put it all together |
197 | 207 | return "<li>($curLink) ($lastLink) $link . . $userBox ($userText) $stxt $comment</li>\n"; |
— | — | @@ -202,7 +212,7 @@ |
203 | 213 | * @param $errMsg String: error message |
204 | 214 | * @return HTML |
205 | 215 | */ |
206 | | - private function buildRevisionList( $title, $errMsg = '' ){ |
| 216 | + private function buildRevisionList( $title, $errMsg = '' ) { |
207 | 217 | global $wgScript; |
208 | 218 | $dbr = wfGetDB( DB_SLAVE ); |
209 | 219 | $res = $dbr->select( |
— | — | @@ -213,23 +223,28 @@ |
214 | 224 | array( 'ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => 50 ) |
215 | 225 | ); |
216 | 226 | $revs = array(); |
217 | | - while( ( $r = $dbr->fetchObject($res ) ) ) |
| 227 | + while( ( $r = $dbr->fetchObject( $res ) ) ) { |
218 | 228 | $revs[] = new Revision( $r ); |
219 | | - if( empty( $revs ) ) |
| 229 | + } |
| 230 | + if( empty( $revs ) ) { |
220 | 231 | // That's *very* weird |
221 | 232 | return wfMsg( 'changeauthor-weirderror' ); |
| 233 | + } |
222 | 234 | |
223 | | - $retval = Xml::openElement('form', array( 'method' => 'post', 'action' => $wgScript ) ); |
| 235 | + $retval = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $wgScript ) ); |
224 | 236 | $retval .= Xml::hidden( 'title', $this->selfTitle->getPrefixedDBkey() ); |
225 | 237 | $retval .= Xml::hidden( 'action', 'change' ); |
226 | 238 | $retval .= Xml::hidden( 'targetpage', $title->getPrefixedDBkey() ); |
227 | 239 | $retval .= Xml::openElement( 'fieldset' ); |
228 | | - $retval .= Xml::element( 'p', array(), wfMsg('changeauthor-explanation-multi')); |
| 240 | + $retval .= Xml::element( 'p', array(), wfMsg( 'changeauthor-explanation-multi' ) ); |
229 | 241 | $retval .= Xml::inputLabel( wfMsg( 'changeauthor-comment'), 'comment', 'comment', 50); |
230 | 242 | $retval .= Xml::submitButton( |
231 | | - wfMsgExt( 'changeauthor-changeauthors-multi', array( 'parsemag', 'escape' ), |
232 | | - count( $revs ) ) ); |
233 | | - if( $errMsg != '' ){ |
| 243 | + wfMsgExt( 'changeauthor-changeauthors-multi', |
| 244 | + array( 'parsemag', 'escape' ), |
| 245 | + count( $revs ) |
| 246 | + ) |
| 247 | + ); |
| 248 | + if( $errMsg != '' ) { |
234 | 249 | $retval .= Xml::openElement( 'p' ) . Xml::openElement( 'b' ); |
235 | 250 | $retval .= Xml::element( 'font', array( 'color' => 'red' ), $errMsg ); |
236 | 251 | $retval .= Xml::closeElement( 'b' ) . Xml::closeElement( 'p' ); |
— | — | @@ -237,12 +252,13 @@ |
238 | 253 | $retval .= Xml::element( 'h2', array(), $title->getPrefixedText() ); |
239 | 254 | $retval .= Xml::openElement( 'ul' ); |
240 | 255 | $count = count( $revs ); |
241 | | - foreach( $revs as $i => $rev ) |
242 | | - $retval .= $this->buildRevisionLine( $rev, $title, ($i == 0), ($i == $count - 1) ); |
| 256 | + foreach( $revs as $i => $rev ) { |
| 257 | + $retval .= $this->buildRevisionLine( $rev, $title, ( $i == 0 ), ( $i == $count - 1 ) ); |
| 258 | + } |
243 | 259 | $retval .= Xml::closeElement( 'ul' ); |
244 | 260 | $retval .= Xml::closeElement( 'fieldset' ); |
245 | 261 | $retval .= Xml::closeElement( 'form' ); |
246 | | - return $retval; |
| 262 | + return $retval; |
247 | 263 | } |
248 | 264 | |
249 | 265 | /** |
— | — | @@ -251,7 +267,7 @@ |
252 | 268 | * @param $errMsg String: error message |
253 | 269 | * @return HTML |
254 | 270 | */ |
255 | | - private function buildOneRevForm( $rev, $errMsg = '' ){ |
| 271 | + private function buildOneRevForm( $rev, $errMsg = '' ) { |
256 | 272 | global $wgScript; |
257 | 273 | $retval = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $wgScript ) ); |
258 | 274 | $retval .= Xml::hidden( 'title', $this->selfTitle->getPrefixedDBkey() ); |
— | — | @@ -261,7 +277,7 @@ |
262 | 278 | $retval .= Xml::element( 'p', array(), wfMsg( 'changeauthor-explanation-single' ) ); |
263 | 279 | $retval .= Xml::inputLabel( wfMsg( 'changeauthor-comment' ), 'comment', 'comment' ); |
264 | 280 | $retval .= Xml::submitButton( wfMsg( 'changeauthor-changeauthors-single' ) ); |
265 | | - if( $errMsg != '' ){ |
| 281 | + if( $errMsg != '' ) { |
266 | 282 | $retval .= Xml::openElement( 'p' ) . Xml::openElement( 'b' ); |
267 | 283 | $retval .= Xml::element( 'font', array( 'color' => 'red' ), $errMsg ); |
268 | 284 | $retval .= Xml::closeElement( 'b' ) . Xml::closeElement( 'p' ); |
— | — | @@ -279,27 +295,33 @@ |
280 | 296 | * Extracts an array needed by changeRevAuthors() from $wgRequest |
281 | 297 | * @return array |
282 | 298 | */ |
283 | | - private function parseChangeRequest(){ |
| 299 | + private function parseChangeRequest() { |
284 | 300 | global $wgRequest; |
285 | 301 | $vals = $wgRequest->getValues(); |
286 | 302 | $retval = array(); |
287 | | - foreach( $vals as $name => $val ){ |
288 | | - if( substr( $name, 0, 9 ) != 'user-new-' ) |
| 303 | + foreach( $vals as $name => $val ) { |
| 304 | + if( substr( $name, 0, 9 ) != 'user-new-' ) { |
289 | 305 | continue; |
| 306 | + } |
290 | 307 | $revid = substr( $name, 9 ); |
291 | | - if( !is_numeric( $revid ) ) |
| 308 | + if( !is_numeric( $revid ) ) { |
292 | 309 | continue; |
| 310 | + } |
293 | 311 | |
294 | 312 | $new = User::newFromName( $val, false ); |
295 | | - if( !$new ) // Can this even happen? |
| 313 | + if( !$new ) { // Can this even happen? |
296 | 314 | return wfMsg( 'changeauthor-invalid-username', $val ); |
297 | | - if( $new->getId() == 0 && $val != 'MediaWiki default' && !User::isIP( $new->getName() ) ) |
| 315 | + } |
| 316 | + if( $new->getId() == 0 && $val != 'MediaWiki default' && !User::isIP( $new->getName() ) ) { |
298 | 317 | return wfMsg( 'changeauthor-nosuchuser', $val ); |
| 318 | + } |
299 | 319 | $old = User::newFromName( $wgRequest->getVal( "user-old-$revid" ), false ); |
300 | | - if( !$old->getName() ) |
| 320 | + if( !$old->getName() ) { |
301 | 321 | return wfMsg( 'changeauthor-invalidform' ); |
302 | | - if( $old->getName() != $new->getName() ) |
| 322 | + } |
| 323 | + if( $old->getName() != $new->getName() ) { |
303 | 324 | $retval[$revid] = array( $old, $new ); |
| 325 | + } |
304 | 326 | } |
305 | 327 | return $retval; |
306 | 328 | } |
— | — | @@ -309,13 +331,14 @@ |
310 | 332 | * @param $authors Array: key=revid value=array(User from, User to) |
311 | 333 | * @param $comment Mixed: log comment |
312 | 334 | */ |
313 | | - private function changeRevAuthors( $authors, $comment ){ |
| 335 | + private function changeRevAuthors( $authors, $comment ) { |
314 | 336 | $dbw = wfGetDB( DB_MASTER ); |
315 | 337 | $dbw->begin(); |
316 | 338 | $editcounts = array(); // Array to keep track of EC mutations; key=userid, value=mutation |
317 | 339 | $log = new LogPage( 'changeauth' ); |
318 | | - foreach( $authors as $id => $users ){ |
319 | | - $dbw->update( 'revision', |
| 340 | + foreach( $authors as $id => $users ) { |
| 341 | + $dbw->update( |
| 342 | + 'revision', |
320 | 343 | /* SET */array( |
321 | 344 | 'rev_user' => $users[1]->getId(), |
322 | 345 | 'rev_user_text' => $users[1]->getName() |
— | — | @@ -324,22 +347,33 @@ |
325 | 348 | __METHOD__ |
326 | 349 | ); |
327 | 350 | $rev = Revision::newFromId( $id ); |
328 | | - $log->addEntry( 'changeauth', $rev->getTitle(), $comment, array( |
329 | | - wfMsg( 'changeauthor-rev', $id ), $users[0]->getName(), $users[1]->getName() ) ); |
| 351 | + $log->addEntry( |
| 352 | + 'changeauth', |
| 353 | + $rev->getTitle(), |
| 354 | + $comment, |
| 355 | + array( |
| 356 | + wfMsg( 'changeauthor-rev', $id ), |
| 357 | + $users[0]->getName(), |
| 358 | + $users[1]->getName() |
| 359 | + ) |
| 360 | + ); |
330 | 361 | $editcounts[$users[1]->getId()]++; |
331 | 362 | $editcounts[$users[0]->getId()]--; |
332 | 363 | } |
333 | | - foreach( $editcounts as $userid => $mutation ){ |
334 | | - if( $mutation == 0 || $userid == 0 ) |
| 364 | + foreach( $editcounts as $userid => $mutation ) { |
| 365 | + if( $mutation == 0 || $userid == 0 ) { |
335 | 366 | continue; |
336 | | - if( $mutation > 0 ) |
| 367 | + } |
| 368 | + if( $mutation > 0 ) { |
337 | 369 | $mutation = "+$mutation"; |
338 | | - $dbw->update( 'user', |
| 370 | + } |
| 371 | + $dbw->update( |
| 372 | + 'user', |
339 | 373 | array( "user_editcount=user_editcount$mutation" ), |
340 | 374 | array( 'user_id' => $userid ), |
341 | 375 | __METHOD__ |
342 | 376 | ); |
343 | | - if( $dbw->affectedRows() == 0 ){ |
| 377 | + if( $dbw->affectedRows() == 0 ) { |
344 | 378 | // Let's have mercy on those who don't have a proper DB server |
345 | 379 | // (but not enough to spare their master) |
346 | 380 | $count = $dbw->selectField( |
— | — | @@ -348,7 +382,8 @@ |
349 | 383 | array( 'rev_user' => $userid ), |
350 | 384 | __METHOD__ |
351 | 385 | ); |
352 | | - $dbw->update( 'user', |
| 386 | + $dbw->update( |
| 387 | + 'user', |
353 | 388 | array( 'user_editcount' => $count ), |
354 | 389 | array( 'user_id' => $userid ), |
355 | 390 | __METHOD__ |