Index: trunk/phase3/tests/phpunit/includes/ArticleTest.php |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | |
9 | 9 | /** creates a title object and its article object */ |
10 | 10 | function setUp() { |
11 | | - $this->title = Title::makeTitle( NS_MAIN, 'somePage' ); |
| 11 | + $this->title = Title::makeTitle( NS_MAIN, 'SomePage' ); |
12 | 12 | $this->article = new Article( $this->title ); |
13 | 13 | |
14 | 14 | } |
Index: trunk/phase3/includes/Article.php |
— | — | @@ -1267,101 +1267,6 @@ |
1268 | 1268 | } |
1269 | 1269 | |
1270 | 1270 | /** |
1271 | | - * Auto-generates a deletion reason |
1272 | | - * |
1273 | | - * @param &$hasHistory Boolean: whether the page has a history |
1274 | | - * @return mixed String containing deletion reason or empty string, or boolean false |
1275 | | - * if no revision occurred |
1276 | | - */ |
1277 | | - public function generateReason( &$hasHistory ) { |
1278 | | - global $wgContLang; |
1279 | | - |
1280 | | - $dbw = wfGetDB( DB_MASTER ); |
1281 | | - // Get the last revision |
1282 | | - $rev = Revision::newFromTitle( $this->getTitle() ); |
1283 | | - |
1284 | | - if ( is_null( $rev ) ) { |
1285 | | - return false; |
1286 | | - } |
1287 | | - |
1288 | | - // Get the article's contents |
1289 | | - $contents = $rev->getText(); |
1290 | | - $blank = false; |
1291 | | - |
1292 | | - // If the page is blank, use the text from the previous revision, |
1293 | | - // which can only be blank if there's a move/import/protect dummy revision involved |
1294 | | - if ( $contents == '' ) { |
1295 | | - $prev = $rev->getPrevious(); |
1296 | | - |
1297 | | - if ( $prev ) { |
1298 | | - $contents = $prev->getText(); |
1299 | | - $blank = true; |
1300 | | - } |
1301 | | - } |
1302 | | - |
1303 | | - // Find out if there was only one contributor |
1304 | | - // Only scan the last 20 revisions |
1305 | | - $res = $dbw->select( 'revision', 'rev_user_text', |
1306 | | - array( 'rev_page' => $this->mPage->getID(), $dbw->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ), |
1307 | | - __METHOD__, |
1308 | | - array( 'LIMIT' => 20 ) |
1309 | | - ); |
1310 | | - |
1311 | | - if ( $res === false ) { |
1312 | | - // This page has no revisions, which is very weird |
1313 | | - return false; |
1314 | | - } |
1315 | | - |
1316 | | - $hasHistory = ( $res->numRows() > 1 ); |
1317 | | - $row = $dbw->fetchObject( $res ); |
1318 | | - |
1319 | | - if ( $row ) { // $row is false if the only contributor is hidden |
1320 | | - $onlyAuthor = $row->rev_user_text; |
1321 | | - // Try to find a second contributor |
1322 | | - foreach ( $res as $row ) { |
1323 | | - if ( $row->rev_user_text != $onlyAuthor ) { // Bug 22999 |
1324 | | - $onlyAuthor = false; |
1325 | | - break; |
1326 | | - } |
1327 | | - } |
1328 | | - } else { |
1329 | | - $onlyAuthor = false; |
1330 | | - } |
1331 | | - |
1332 | | - // Generate the summary with a '$1' placeholder |
1333 | | - if ( $blank ) { |
1334 | | - // The current revision is blank and the one before is also |
1335 | | - // blank. It's just not our lucky day |
1336 | | - $reason = wfMsgForContent( 'exbeforeblank', '$1' ); |
1337 | | - } else { |
1338 | | - if ( $onlyAuthor ) { |
1339 | | - $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor ); |
1340 | | - } else { |
1341 | | - $reason = wfMsgForContent( 'excontent', '$1' ); |
1342 | | - } |
1343 | | - } |
1344 | | - |
1345 | | - if ( $reason == '-' ) { |
1346 | | - // Allow these UI messages to be blanked out cleanly |
1347 | | - return ''; |
1348 | | - } |
1349 | | - |
1350 | | - // Replace newlines with spaces to prevent uglyness |
1351 | | - $contents = preg_replace( "/[\n\r]/", ' ', $contents ); |
1352 | | - // Calculate the maximum amount of chars to get |
1353 | | - // Max content length = max comment length - length of the comment (excl. $1) |
1354 | | - $maxLength = 255 - ( strlen( $reason ) - 2 ); |
1355 | | - $contents = $wgContLang->truncate( $contents, $maxLength ); |
1356 | | - // Remove possible unfinished links |
1357 | | - $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents ); |
1358 | | - // Now replace the '$1' placeholder |
1359 | | - $reason = str_replace( '$1', $contents, $reason ); |
1360 | | - |
1361 | | - return $reason; |
1362 | | - } |
1363 | | - |
1364 | | - |
1365 | | - /** |
1366 | 1271 | * UI entry point for page deletion |
1367 | 1272 | */ |
1368 | 1273 | public function delete() { |
— | — | @@ -2042,6 +1947,10 @@ |
2043 | 1948 | return $this->mPage->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser ); |
2044 | 1949 | } |
2045 | 1950 | |
| 1951 | + public function generateReason( &$hasHistory ) { |
| 1952 | + return $this->mPage->getAutoDeleteReason( $hasHistory ); |
| 1953 | + } |
| 1954 | + |
2046 | 1955 | // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** // |
2047 | 1956 | public static function selectFields() { |
2048 | 1957 | return WikiPage::selectFields(); |
Index: trunk/phase3/includes/WikiPage.php |
— | — | @@ -574,7 +574,7 @@ |
575 | 575 | * @return string MW timestamp of last article revision |
576 | 576 | */ |
577 | 577 | public function getTimestamp() { |
578 | | - // Check if the field has been filled by ParserCache::get() |
| 578 | + // Check if the field has been filled by WikiPage::setTimestamp() |
579 | 579 | if ( !$this->mTimestamp ) { |
580 | 580 | $this->loadLastEdit(); |
581 | 581 | } |
— | — | @@ -1094,7 +1094,7 @@ |
1095 | 1095 | |
1096 | 1096 | # Provide autosummaries if one is not provided and autosummaries are enabled. |
1097 | 1097 | if ( $wgUseAutomaticEditSummaries && $flags & EDIT_AUTOSUMMARY && $summary == '' ) { |
1098 | | - $summary = $this->getAutosummary( $oldtext, $text, $flags ); |
| 1098 | + $summary = self::getAutosummary( $oldtext, $text, $flags ); |
1099 | 1099 | } |
1100 | 1100 | |
1101 | 1101 | $editInfo = $this->prepareTextForEdit( $text, null, $user ); |
— | — | @@ -2465,6 +2465,100 @@ |
2466 | 2466 | } |
2467 | 2467 | |
2468 | 2468 | /** |
| 2469 | + * Auto-generates a deletion reason |
| 2470 | + * |
| 2471 | + * @param &$hasHistory Boolean: whether the page has a history |
| 2472 | + * @return mixed String containing deletion reason or empty string, or boolean false |
| 2473 | + * if no revision occurred |
| 2474 | + */ |
| 2475 | + public function getAutoDeleteReason( &$hasHistory ) { |
| 2476 | + global $wgContLang; |
| 2477 | + |
| 2478 | + $dbw = wfGetDB( DB_MASTER ); |
| 2479 | + // Get the last revision |
| 2480 | + $rev = Revision::newFromTitle( $this->getTitle() ); |
| 2481 | + |
| 2482 | + if ( is_null( $rev ) ) { |
| 2483 | + return false; |
| 2484 | + } |
| 2485 | + |
| 2486 | + // Get the article's contents |
| 2487 | + $contents = $rev->getText(); |
| 2488 | + $blank = false; |
| 2489 | + |
| 2490 | + // If the page is blank, use the text from the previous revision, |
| 2491 | + // which can only be blank if there's a move/import/protect dummy revision involved |
| 2492 | + if ( $contents == '' ) { |
| 2493 | + $prev = $rev->getPrevious(); |
| 2494 | + |
| 2495 | + if ( $prev ) { |
| 2496 | + $contents = $prev->getText(); |
| 2497 | + $blank = true; |
| 2498 | + } |
| 2499 | + } |
| 2500 | + |
| 2501 | + // Find out if there was only one contributor |
| 2502 | + // Only scan the last 20 revisions |
| 2503 | + $res = $dbw->select( 'revision', 'rev_user_text', |
| 2504 | + array( 'rev_page' => $this->getID(), $dbw->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ), |
| 2505 | + __METHOD__, |
| 2506 | + array( 'LIMIT' => 20 ) |
| 2507 | + ); |
| 2508 | + |
| 2509 | + if ( $res === false ) { |
| 2510 | + // This page has no revisions, which is very weird |
| 2511 | + return false; |
| 2512 | + } |
| 2513 | + |
| 2514 | + $hasHistory = ( $res->numRows() > 1 ); |
| 2515 | + $row = $dbw->fetchObject( $res ); |
| 2516 | + |
| 2517 | + if ( $row ) { // $row is false if the only contributor is hidden |
| 2518 | + $onlyAuthor = $row->rev_user_text; |
| 2519 | + // Try to find a second contributor |
| 2520 | + foreach ( $res as $row ) { |
| 2521 | + if ( $row->rev_user_text != $onlyAuthor ) { // Bug 22999 |
| 2522 | + $onlyAuthor = false; |
| 2523 | + break; |
| 2524 | + } |
| 2525 | + } |
| 2526 | + } else { |
| 2527 | + $onlyAuthor = false; |
| 2528 | + } |
| 2529 | + |
| 2530 | + // Generate the summary with a '$1' placeholder |
| 2531 | + if ( $blank ) { |
| 2532 | + // The current revision is blank and the one before is also |
| 2533 | + // blank. It's just not our lucky day |
| 2534 | + $reason = wfMsgForContent( 'exbeforeblank', '$1' ); |
| 2535 | + } else { |
| 2536 | + if ( $onlyAuthor ) { |
| 2537 | + $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor ); |
| 2538 | + } else { |
| 2539 | + $reason = wfMsgForContent( 'excontent', '$1' ); |
| 2540 | + } |
| 2541 | + } |
| 2542 | + |
| 2543 | + if ( $reason == '-' ) { |
| 2544 | + // Allow these UI messages to be blanked out cleanly |
| 2545 | + return ''; |
| 2546 | + } |
| 2547 | + |
| 2548 | + // Replace newlines with spaces to prevent uglyness |
| 2549 | + $contents = preg_replace( "/[\n\r]/", ' ', $contents ); |
| 2550 | + // Calculate the maximum amount of chars to get |
| 2551 | + // Max content length = max comment length - length of the comment (excl. $1) |
| 2552 | + $maxLength = 255 - ( strlen( $reason ) - 2 ); |
| 2553 | + $contents = $wgContLang->truncate( $contents, $maxLength ); |
| 2554 | + // Remove possible unfinished links |
| 2555 | + $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents ); |
| 2556 | + // Now replace the '$1' placeholder |
| 2557 | + $reason = str_replace( '$1', $contents, $reason ); |
| 2558 | + |
| 2559 | + return $reason; |
| 2560 | + } |
| 2561 | + |
| 2562 | + /** |
2469 | 2563 | * Get parser options suitable for rendering the primary article wikitext |
2470 | 2564 | * @param $canonical boolean Determines that the generated options must not depend on user preferences (see bug 14404) |
2471 | 2565 | * @return mixed ParserOptions object or boolean false |
Index: trunk/extensions/Checkpoint/Checkpoint.php |
— | — | @@ -45,7 +45,7 @@ |
46 | 46 | // blank summary, so let's get an automatic one if |
47 | 47 | // applicable (the appending bit prevents autosummaries |
48 | 48 | // from appearing otherwise). |
49 | | - $oldtext = $article->fetchContent(); |
| 49 | + $oldtext = $article->getRawText(); // current revision |
50 | 50 | $summary = $article->getAutosummary( $oldtext, $text, $flags ); |
51 | 51 | } |
52 | 52 | $summary .= wfMsg( 'word-separator' ) . wfMsg( 'checkpoint-notice' ); |