Index: trunk/phase3/includes/specials/SpecialRevisionMove.php |
— | — | @@ -20,7 +20,7 @@ |
21 | 21 | /** |
22 | 22 | * Special page allowing users with the appropriate permissions to |
23 | 23 | * move revisions of a page to a new target (either an existing page or not) |
24 | | - * |
| 24 | + * |
25 | 25 | * The user selects revisions in the page history (HistoryPage.php), |
26 | 26 | * clicks on the submit button and gets this special page. |
27 | 27 | * A form is shown (showForm()) where the user has to enter a target page |
— | — | @@ -29,10 +29,10 @@ |
30 | 30 | * If the target doesn't exist, a new page gets created. rev_page of the |
31 | 31 | * selected revisions is updated, after that it is determined whether page_latest |
32 | 32 | * of the target page and the source page require an update. |
33 | | - * |
| 33 | + * |
34 | 34 | * **** NOTE: This feature is EXPERIMENTAL. **** |
35 | 35 | * **** Do not use on any productive system. **** |
36 | | - * |
| 36 | + * |
37 | 37 | * @file |
38 | 38 | * @ingroup SpecialPage |
39 | 39 | */ |
— | — | @@ -45,7 +45,6 @@ |
46 | 46 | */ |
47 | 47 | |
48 | 48 | class SpecialRevisionMove extends UnlistedSpecialPage { |
49 | | - |
50 | 49 | # common objects |
51 | 50 | var $mOldTitle; # Title object. |
52 | 51 | var $mNewTitle; # Title object. Desired new title |
— | — | @@ -66,7 +65,7 @@ |
67 | 66 | |
68 | 67 | /** |
69 | 68 | * @param $par subpage part, standard special page parameter, is ignored here |
70 | | - * |
| 69 | + * |
71 | 70 | * Mostly initializes variables and calls either showForm() or submit() |
72 | 71 | */ |
73 | 72 | public function execute( $par ) { |
— | — | @@ -78,6 +77,7 @@ |
79 | 78 | $this->mIsAllowedRevisionMove = $wgUser->isAllowed( 'revisionmove' ); |
80 | 79 | $this->user = $wgUser; |
81 | 80 | $this->skin = $wgUser->getSkin(); |
| 81 | + |
82 | 82 | if ( !$this->request instanceof WebRequest ) { |
83 | 83 | $this->request = $GLOBALS['wgRequest']; |
84 | 84 | } |
— | — | @@ -125,7 +125,6 @@ |
126 | 126 | } else { |
127 | 127 | $this->showForm(); |
128 | 128 | } |
129 | | - |
130 | 129 | } |
131 | 130 | |
132 | 131 | /** |
— | — | @@ -147,14 +146,14 @@ |
148 | 147 | } |
149 | 148 | |
150 | 149 | $out = Xml::openElement( 'form', array( 'method' => 'post', |
151 | | - 'action' => $this->getTitle()->getLocalUrl( array( 'action' => 'submit' ) ), |
| 150 | + 'action' => $this->getTitle()->getLocalUrl( array( 'action' => 'submit' ) ), |
152 | 151 | 'id' => 'mw-revmove-form' ) ) . |
153 | 152 | Xml::fieldset( wfMsg( 'revmove-legend' ) ) . |
154 | 153 | Xml::hidden( 'wpEditToken', $wgUser->editToken() ) . |
155 | 154 | Xml::hidden( 'oldTitle', $this->mOldTitle->getPrefixedText() ) . |
156 | 155 | '<div>' . Xml::inputLabel( wfMsg( 'revmove-reasonfield' ), 'wpReason', 'revmove-reasonfield', 60 ) . '</div>' . |
157 | 156 | Xml::inputLabel( wfMsg( 'revmove-titlefield' ), 'newTitle', 'revmove-titlefield', 20, $this->mOldTitle->getPrefixedText() ) . |
158 | | - Xml::hidden( 'ids', implode( ',', $this->mIds ) ) . |
| 157 | + Xml::hidden( 'ids', implode( ',', $this->mIds ) ) . |
159 | 158 | Xml::submitButton( wfMsg( 'revmove-submit' ), |
160 | 159 | array( 'name' => 'wpSubmit' ) ) . |
161 | 160 | Xml::closeElement( 'fieldset' ) . "\n" . |
— | — | @@ -185,18 +184,19 @@ |
186 | 185 | } |
187 | 186 | |
188 | 187 | # No valid revisions specified (e.g. only revs belonging to another page) |
189 | | - if( $numRevisions == 0 ) { |
| 188 | + if ( $numRevisions == 0 ) { |
190 | 189 | $wgOut->showErrorPage( 'revmove-norevisions-title', 'revmove-norevisions' ); |
191 | 190 | return false; |
192 | 191 | } |
193 | | - |
| 192 | + |
194 | 193 | $wgOut->addHTML( "</ul>" ); |
| 194 | + |
195 | 195 | return true; |
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
199 | 199 | * Submit the posted changes (in $this->request). |
200 | | - * |
| 200 | + * |
201 | 201 | * This function does some checks and then calls moveRevisions(), which does the real work |
202 | 202 | */ |
203 | 203 | public function submit() { |
— | — | @@ -208,8 +208,9 @@ |
209 | 209 | $wgOut->showPermissionsErrorPage( $permErrors, 'revisionmove' ); |
210 | 210 | return false; |
211 | 211 | } |
| 212 | + |
212 | 213 | # Confirm Token |
213 | | - if( !$wgUser->matchEditToken( $this->request->getVal( 'wpEditToken' ) ) ) { |
| 214 | + if ( !$wgUser->matchEditToken( $this->request->getVal( 'wpEditToken' ) ) ) { |
214 | 215 | $wgOut->showErrorPage( 'sessionfailure-title', 'sessionfailure' ); |
215 | 216 | return false; |
216 | 217 | } |
— | — | @@ -256,7 +257,7 @@ |
257 | 258 | # Update revision table |
258 | 259 | $dbw->update( 'revision', |
259 | 260 | array( 'rev_page' => $this->mNewTitle->getArticleID() ), |
260 | | - array( |
| 261 | + array( |
261 | 262 | 'rev_id IN (' . $idstring . ')', |
262 | 263 | 'rev_page' => $this->mOldTitle->getArticleID(), |
263 | 264 | ), |
— | — | @@ -266,7 +267,7 @@ |
267 | 268 | |
268 | 269 | # Check if we need to update page_latest |
269 | 270 | # Get the latest version of the revisions we are moving |
270 | | - $timestampNewPage = $this->queryLatestTimestamp( |
| 271 | + $timestampNewPage = $this->queryLatestTimestamp( |
271 | 272 | $dbw, |
272 | 273 | $this->mNewTitle->getArticleID(), |
273 | 274 | array( 'rev_id IN (' . $idstring . ')' ) |
— | — | @@ -278,17 +279,17 @@ |
279 | 280 | $currentNewPageRev = Revision::newFromId( $this->mNewTitle->getLatestRevID() ); |
280 | 281 | if ( $this->createArticle || $timestampNewPage > $currentNewPageRev->getTimestamp() ) { |
281 | 282 | # we have to set page_latest to $timestampNewPage's revid |
282 | | - $this->updatePageLatest( |
283 | | - $dbw, |
| 283 | + $this->updatePageLatest( |
| 284 | + $dbw, |
284 | 285 | $this->mNewTitle, |
285 | 286 | $newArticle, |
286 | | - $timestampNewPage, |
| 287 | + $timestampNewPage, |
287 | 288 | array( 'rev_id IN (' . $idstring . ')' ) |
288 | 289 | ); |
289 | 290 | } |
290 | 291 | |
291 | 292 | # Update the old page's page_latest field |
292 | | - $timestampOldPage = $this->queryLatestTimestamp( |
| 293 | + $timestampOldPage = $this->queryLatestTimestamp( |
293 | 294 | $dbw, |
294 | 295 | $this->mOldTitle->getArticleID() |
295 | 296 | ); |
— | — | @@ -307,8 +308,8 @@ |
308 | 309 | # page_latest has to be updated |
309 | 310 | $currentOldPageRev = Revision::newFromId( $this->mOldTitle->getLatestRevID() ); |
310 | 311 | if ( $timestampOldPage < $currentOldPageRev->getTimestamp() ) { |
311 | | - $this->updatePageLatest( |
312 | | - $dbw, |
| 312 | + $this->updatePageLatest( |
| 313 | + $dbw, |
313 | 314 | $this->mOldTitle, |
314 | 315 | $oldArticle, |
315 | 316 | $timestampOldPage |
— | — | @@ -336,12 +337,12 @@ |
337 | 338 | * @param &$dbw Database object (Master) |
338 | 339 | * @param $articleId Integer page_id |
339 | 340 | * @param $conds array database conditions |
340 | | - * |
| 341 | + * |
341 | 342 | * @return String timestamp |
342 | 343 | */ |
343 | 344 | protected function queryLatestTimestamp( &$dbw, $articleId, $conds = array() ) { |
344 | | - $timestampNewRow = $dbw->selectRow( |
345 | | - 'revision', |
| 345 | + $timestampNewRow = $dbw->selectRow( |
| 346 | + 'revision', |
346 | 347 | 'max(rev_timestamp) as maxtime', |
347 | 348 | array_merge( array( 'rev_page' => $articleId ), $conds ), |
348 | 349 | __METHOD__ |
— | — | @@ -352,19 +353,19 @@ |
353 | 354 | /** |
354 | 355 | * Updates page_latest and similar database fields (see Article::updateRevisionOn). |
355 | 356 | * Called two times, for the new and the old page |
356 | | - * |
| 357 | + * |
357 | 358 | * @param &$dbw Database object (Master) |
358 | 359 | * @param $articleTitle Title object of the page |
359 | 360 | * @param $articleObj Article object of the page |
360 | 361 | * @param $timestamp to search for (use queryLatestTimestamp to get the latest) |
361 | 362 | * @param $conds array database conditions |
362 | | - * |
| 363 | + * |
363 | 364 | * @return boolean indicating success |
364 | 365 | */ |
365 | 366 | protected function updatePageLatest( &$dbw, $articleTitle, &$articleObj, $timestamp, $conds = array() ) { |
366 | 367 | # Query to find out the rev_id |
367 | | - $revisionRow = $dbw->selectRow( |
368 | | - 'revision', |
| 368 | + $revisionRow = $dbw->selectRow( |
| 369 | + 'revision', |
369 | 370 | 'rev_id', |
370 | 371 | array_merge( array( |
371 | 372 | 'rev_timestamp' => $timestamp, |
— | — | @@ -372,6 +373,7 @@ |
373 | 374 | ), $conds ), |
374 | 375 | __METHOD__ |
375 | 376 | ); |
| 377 | + |
376 | 378 | # Update page_latest |
377 | 379 | $latestRev = Revision::newFromId( $revisionRow->rev_id ); |
378 | 380 | return $articleObj->updateRevisionOn( $dbw, $latestRev, $articleTitle->getLatestRevID(), null, /* set new page flag */ true ); |
— | — | @@ -385,19 +387,19 @@ |
386 | 388 | $this->mNewTitle->getPrefixedText(), |
387 | 389 | $modifiedRevsNum |
388 | 390 | ); |
| 391 | + |
389 | 392 | $log = new LogPage( 'move' ); |
390 | 393 | $log->addEntry( 'move_rev', $this->mOldTitle, $this->mReason, $paramArray, $this->user ); |
391 | | - |
392 | 394 | } |
393 | 395 | |
394 | 396 | protected function showSuccess( $modifiedRevsNum ) { |
395 | 397 | global $wgOut; |
396 | 398 | |
397 | 399 | if ( $this->createArticle ) { |
398 | | - $wgOut->addWikiMsg( 'revmove-success-created', $modifiedRevsNum, |
| 400 | + $wgOut->addWikiMsg( 'revmove-success-created', $modifiedRevsNum, |
399 | 401 | $this->mOldTitle->getPrefixedText(), $this->mNewTitle->getPrefixedText() ); |
400 | 402 | } else { |
401 | | - $wgOut->addWikiMsg( 'revmove-success-existing', $modifiedRevsNum, |
| 403 | + $wgOut->addWikiMsg( 'revmove-success-existing', $modifiedRevsNum, |
402 | 404 | $this->mOldTitle->getPrefixedText(), $this->mNewTitle->getPrefixedText() ); |
403 | 405 | } |
404 | 406 | } |