Index: branches/Wikidata/phase3/includes/ContentHandler.php |
— | — | @@ -304,84 +304,91 @@ |
305 | 305 | public function getAutoDeleteReason( Title $title, &$hasHistory ) { |
306 | 306 | global $wgContLang; |
307 | 307 | |
308 | | - $dbw = wfGetDB( DB_MASTER ); |
| 308 | + try { |
| 309 | + $dbw = wfGetDB( DB_MASTER ); |
309 | 310 | |
310 | | - // Get the last revision |
311 | | - $rev = Revision::newFromTitle( $title ); |
| 311 | + // Get the last revision |
| 312 | + $rev = Revision::newFromTitle( $title ); |
312 | 313 | |
313 | | - if ( is_null( $rev ) ) { |
314 | | - return false; |
315 | | - } |
| 314 | + if ( is_null( $rev ) ) { |
| 315 | + return false; |
| 316 | + } |
316 | 317 | |
317 | | - // Get the article's contents |
318 | | - $content = $rev->getContent(); |
319 | | - $blank = false; |
| 318 | + // Get the article's contents |
| 319 | + $content = $rev->getContent(); |
| 320 | + $blank = false; |
320 | 321 | |
321 | | - // If the page is blank, use the text from the previous revision, |
322 | | - // which can only be blank if there's a move/import/protect dummy revision involved |
323 | | - if ( $content->getSize() == 0 ) { |
324 | | - $prev = $rev->getPrevious(); |
| 322 | + // If the page is blank, use the text from the previous revision, |
| 323 | + // which can only be blank if there's a move/import/protect dummy revision involved |
| 324 | + if ( $content->getSize() == 0 ) { |
| 325 | + $prev = $rev->getPrevious(); |
325 | 326 | |
326 | | - if ( $prev ) { |
327 | | - $content = $rev->getContent(); |
328 | | - $blank = true; |
| 327 | + if ( $prev ) { |
| 328 | + $content = $rev->getContent(); |
| 329 | + $blank = true; |
| 330 | + } |
329 | 331 | } |
330 | | - } |
331 | 332 | |
332 | | - // Find out if there was only one contributor |
333 | | - // Only scan the last 20 revisions |
334 | | - $res = $dbw->select( 'revision', 'rev_user_text', |
335 | | - array( 'rev_page' => $title->getArticleID(), $dbw->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ), |
336 | | - __METHOD__, |
337 | | - array( 'LIMIT' => 20 ) |
338 | | - ); |
| 333 | + // Find out if there was only one contributor |
| 334 | + // Only scan the last 20 revisions |
| 335 | + $res = $dbw->select( 'revision', 'rev_user_text', |
| 336 | + array( 'rev_page' => $title->getArticleID(), $dbw->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ), |
| 337 | + __METHOD__, |
| 338 | + array( 'LIMIT' => 20 ) |
| 339 | + ); |
339 | 340 | |
340 | | - if ( $res === false ) { |
341 | | - // This page has no revisions, which is very weird |
342 | | - return false; |
343 | | - } |
| 341 | + if ( $res === false ) { |
| 342 | + // This page has no revisions, which is very weird |
| 343 | + return false; |
| 344 | + } |
344 | 345 | |
345 | | - $hasHistory = ( $res->numRows() > 1 ); |
346 | | - $row = $dbw->fetchObject( $res ); |
| 346 | + $hasHistory = ( $res->numRows() > 1 ); |
| 347 | + $row = $dbw->fetchObject( $res ); |
347 | 348 | |
348 | | - if ( $row ) { // $row is false if the only contributor is hidden |
349 | | - $onlyAuthor = $row->rev_user_text; |
350 | | - // Try to find a second contributor |
351 | | - foreach ( $res as $row ) { |
352 | | - if ( $row->rev_user_text != $onlyAuthor ) { // Bug 22999 |
353 | | - $onlyAuthor = false; |
354 | | - break; |
| 349 | + if ( $row ) { // $row is false if the only contributor is hidden |
| 350 | + $onlyAuthor = $row->rev_user_text; |
| 351 | + // Try to find a second contributor |
| 352 | + foreach ( $res as $row ) { |
| 353 | + if ( $row->rev_user_text != $onlyAuthor ) { // Bug 22999 |
| 354 | + $onlyAuthor = false; |
| 355 | + break; |
| 356 | + } |
355 | 357 | } |
| 358 | + } else { |
| 359 | + $onlyAuthor = false; |
356 | 360 | } |
357 | | - } else { |
358 | | - $onlyAuthor = false; |
359 | | - } |
360 | 361 | |
361 | | - // Generate the summary with a '$1' placeholder |
362 | | - if ( $blank ) { |
363 | | - // The current revision is blank and the one before is also |
364 | | - // blank. It's just not our lucky day |
365 | | - $reason = wfMsgForContent( 'exbeforeblank', '$1' ); |
366 | | - } else { |
367 | | - if ( $onlyAuthor ) { |
368 | | - $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor ); |
| 362 | + // Generate the summary with a '$1' placeholder |
| 363 | + if ( $blank ) { |
| 364 | + // The current revision is blank and the one before is also |
| 365 | + // blank. It's just not our lucky day |
| 366 | + $reason = wfMsgForContent( 'exbeforeblank', '$1' ); |
369 | 367 | } else { |
370 | | - $reason = wfMsgForContent( 'excontent', '$1' ); |
| 368 | + if ( $onlyAuthor ) { |
| 369 | + $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor ); |
| 370 | + } else { |
| 371 | + $reason = wfMsgForContent( 'excontent', '$1' ); |
| 372 | + } |
371 | 373 | } |
372 | | - } |
373 | 374 | |
374 | | - if ( $reason == '-' ) { |
375 | | - // Allow these UI messages to be blanked out cleanly |
376 | | - return ''; |
377 | | - } |
| 375 | + if ( $reason == '-' ) { |
| 376 | + // Allow these UI messages to be blanked out cleanly |
| 377 | + return ''; |
| 378 | + } |
378 | 379 | |
379 | | - // Max content length = max comment length - length of the comment (excl. $1) |
380 | | - $text = $content->getTextForSummary( 255 - ( strlen( $reason ) - 2 ) ); |
| 380 | + // Max content length = max comment length - length of the comment (excl. $1) |
| 381 | + $text = $content->getTextForSummary( 255 - ( strlen( $reason ) - 2 ) ); |
381 | 382 | |
382 | | - // Now replace the '$1' placeholder |
383 | | - $reason = str_replace( '$1', $text, $reason ); |
| 383 | + // Now replace the '$1' placeholder |
| 384 | + $reason = str_replace( '$1', $text, $reason ); |
384 | 385 | |
385 | | - return $reason; |
| 386 | + return $reason; |
| 387 | + } catch (MWException $e) { |
| 388 | + # if a page is horribly broken, we still want to be able to delete it. so be lenient about errors here. |
| 389 | + wfDebug("Error while building auto delete summary: $e"); |
| 390 | + } |
| 391 | + |
| 392 | + return ''; |
386 | 393 | } |
387 | 394 | |
388 | 395 | /** |
Index: branches/Wikidata/phase3/includes/EditPage.php |
— | — | @@ -706,6 +706,9 @@ |
707 | 707 | $this->content_model = $request->getText( 'model', $content_handler->getModelName() ); #may be overridden by revision |
708 | 708 | $this->content_format = $request->getText( 'format', $content_handler->getDefaultFormat() ); #may be overridden by revision |
709 | 709 | |
| 710 | + #TODO: check if the desired model is allowed in this namespace, and if a transition from the page's current model to the new model is allowed |
| 711 | + #TODO: check if the desired content model supports the given content format! |
| 712 | + |
710 | 713 | $this->live = $request->getCheck( 'live' ); |
711 | 714 | $this->editintro = $request->getText( 'editintro', |
712 | 715 | // Custom edit intro for new sections |
— | — | @@ -920,7 +923,7 @@ |
921 | 924 | */ |
922 | 925 | private function getCurrentContent() { |
923 | 926 | $rev = $this->mArticle->getRevision(); |
924 | | - $content = $rev->getContent( Revision::RAW ); |
| 927 | + $content = $rev ? $rev->getContent( Revision::RAW ) : null; |
925 | 928 | |
926 | 929 | if ( $content === false || $content === null ) { |
927 | 930 | if ( !$this->content_model ) $this->content_model = $this->getTitle()->getContentModelName(); |
— | — | @@ -1520,7 +1523,7 @@ |
1521 | 1524 | ( ( $this->minoredit && !$this->isNew ) ? EDIT_MINOR : 0 ) | |
1522 | 1525 | ( $bot ? EDIT_FORCE_BOT : 0 ); |
1523 | 1526 | |
1524 | | - $doEditStatus = $this->mArticle->doEditContent( $content, $this->summary, $flags ); |
| 1527 | + $doEditStatus = $this->mArticle->doEditContent( $content, $this->summary, $flags, false, null, $this->content_format ); |
1525 | 1528 | |
1526 | 1529 | if ( $doEditStatus->isOK() ) { |
1527 | 1530 | $result['redirect'] = $content->isRedirect(); |
— | — | @@ -1918,6 +1921,9 @@ |
1919 | 1922 | |
1920 | 1923 | $wgOut->addHTML( Html::hidden( 'oldid', $this->oldid ) ); |
1921 | 1924 | |
| 1925 | + $wgOut->addHTML( Html::hidden( 'format', $this->content_format ) ); |
| 1926 | + $wgOut->addHTML( Html::hidden( 'model', $this->content_model ) ); |
| 1927 | + |
1922 | 1928 | if ( $this->section == 'new' ) { |
1923 | 1929 | $this->showSummaryInput( true, $this->summary ); |
1924 | 1930 | $wgOut->addHTML( $this->getSummaryPreview( true, $this->summary ) ); |
— | — | @@ -1948,6 +1954,9 @@ |
1949 | 1955 | |
1950 | 1956 | $wgOut->addWikiText( $this->getCopywarn() ); |
1951 | 1957 | |
| 1958 | + $wgOut->addHTML( Html::element( 'p', null, "model: " . $this->content_model ) ); #FIXME: content handler debug stuff, DELETE! |
| 1959 | + $wgOut->addHTML( Html::element( 'p', null, "format: " . $this->content_format ) ); #FIXME: content handler debug stuff, DELETE! |
| 1960 | + |
1952 | 1961 | $wgOut->addHTML( $this->editFormTextAfterWarn ); |
1953 | 1962 | |
1954 | 1963 | $this->showStandardInputs(); |
— | — | @@ -2692,8 +2701,7 @@ |
2693 | 2702 | # don't parse non-wikitext pages, show message about preview |
2694 | 2703 | # XXX: stupid php bug won't let us use $this->getContextTitle()->isCssJsSubpage() here -- This note has been there since r3530. Sure the bug was fixed time ago? |
2695 | 2704 | |
2696 | | - #FIXME: get appropriate content handler! |
2697 | | - if ( $this->isCssJsSubpage || !$this->mTitle->isWikitextPage() ) { |
| 2705 | + if ( $this->isCssJsSubpage || $this->mTitle->isCssOrJsPage() ) { #TODO: kill all special case handling for CSS/JS content! |
2698 | 2706 | if( $this->mTitle->isCssJsSubpage() ) { |
2699 | 2707 | $level = 'user'; |
2700 | 2708 | } elseif( $this->mTitle->isCssOrJsPage() ) { |
— | — | @@ -2715,30 +2723,39 @@ |
2716 | 2724 | } else { |
2717 | 2725 | throw new MWException( 'A CSS/JS (sub)page but which is not css nor js!' ); |
2718 | 2726 | } |
2719 | | - } |
| 2727 | + } #FIXME: else $previewtext is undefined! |
2720 | 2728 | |
2721 | 2729 | $parserOutput = $wgParser->parse( $previewtext, $this->mTitle, $parserOptions ); |
2722 | 2730 | $previewHTML = $parserOutput->mText; |
2723 | | - $previewHTML .= "<pre class=\"$class\" dir=\"ltr\">\n" . htmlspecialchars( $this->textbox1 ) . "\n</pre>\n"; |
| 2731 | + $previewHTML .= "<pre class=\"$class\" dir=\"ltr\">\n" . htmlspecialchars( $this->textbox1 ) . "\n</pre>\n"; #FIXME: use content object! |
2724 | 2732 | } else { |
2725 | 2733 | $rt = Title::newFromRedirectArray( $this->textbox1 ); |
2726 | 2734 | if ( $rt ) { |
2727 | 2735 | $previewHTML = $this->mArticle->viewRedirect( $rt, false ); |
2728 | 2736 | } else { |
2729 | | - $toparse = $this->textbox1; |
| 2737 | + $content = ContentHandler::makeContent( $this->textbox1, $this->getTitle(), $this->content_model, $this->content_format ); |
2730 | 2738 | |
2731 | 2739 | # If we're adding a comment, we need to show the |
2732 | 2740 | # summary as the headline |
2733 | 2741 | if ( $this->section == "new" && $this->summary != "" ) { |
2734 | | - $toparse = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->summary ) . "\n\n" . $toparse; |
| 2742 | + $content = $content->addSectionHeader( $this->summary ); |
2735 | 2743 | } |
2736 | 2744 | |
| 2745 | + $toparse_orig = $content->serialize( $this->content_format ); |
| 2746 | + $toparse = $toparse_orig; |
2737 | 2747 | wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) ); |
2738 | 2748 | |
| 2749 | + if ( $toparse !== $toparse_orig ) { |
| 2750 | + #hook changed the text, create new Content object |
| 2751 | + $content = ContentHandler::makeContent( $toparse, $this->getTitle(), $this->content_model, $this->content_format ); |
| 2752 | + } |
| 2753 | + |
| 2754 | + wfRunHooks( 'EditPageGetPreviewContent', array( $this, &$content ) ); # FIXME: document new hook |
| 2755 | + |
2739 | 2756 | $parserOptions->enableLimitReport(); |
2740 | 2757 | |
2741 | | - $toparse = $wgParser->preSaveTransform( $toparse, $this->mTitle, $wgUser, $parserOptions ); |
2742 | | - $parserOutput = $wgParser->parse( $toparse, $this->mTitle, $parserOptions ); |
| 2758 | + $content = $content->preSaveTransform( $this->mTitle, $wgUser, $parserOptions ); |
| 2759 | + $parserOutput = $content->getParserOutput( $this->mTitle, null, $parserOptions ); |
2743 | 2760 | |
2744 | 2761 | $previewHTML = $parserOutput->getText(); |
2745 | 2762 | $this->mParserOutput = $parserOutput; |
Index: branches/Wikidata/phase3/includes/Revision.php |
— | — | @@ -479,14 +479,8 @@ |
480 | 480 | $this->mSha1 = isset( $row['sha1'] ) ? strval( $row['sha1'] ) : null; |
481 | 481 | |
482 | 482 | $this->mContentModelName = isset( $row['content_model'] ) ? strval( $row['content_model'] ) : null; |
483 | | - $this->mContentFormat = isset( $row['content_format'] ) ? strval( $row['content_format'] ) : null; |
| 483 | + $this->mContentFormat = isset( $row['content_format'] ) ? strval( $row['content_format'] ) : null; |
484 | 484 | |
485 | | - if( !isset( $row->rev_content_format ) || is_null( $row->rev_content_format ) ) { |
486 | | - $this->mContentFormat = null; # determine on demand if needed |
487 | | - } else { |
488 | | - $this->mContentFormat = $row->rev_content_format; |
489 | | - } |
490 | | - |
491 | 485 | // Enforce spacing trimming on supplied text |
492 | 486 | $this->mComment = isset( $row['comment'] ) ? trim( strval( $row['comment'] ) ) : null; |
493 | 487 | $this->mText = isset( $row['text'] ) ? rtrim( strval( $row['text'] ) ) : null; |
— | — | @@ -843,7 +837,7 @@ |
844 | 838 | $this->mText = $this->loadText(); |
845 | 839 | } |
846 | 840 | |
847 | | - $this->mContent = $handler->unserialize( $this->mText, $title, $format ); |
| 841 | + $this->mContent = is_null( $this->mText ) ? null : $handler->unserialize( $this->mText, $format ); |
848 | 842 | } |
849 | 843 | |
850 | 844 | return $this->mContent; |
— | — | @@ -1104,29 +1098,30 @@ |
1105 | 1099 | $rev_id = isset( $this->mId ) |
1106 | 1100 | ? $this->mId |
1107 | 1101 | : $dbw->nextSequenceValue( 'revision_rev_id_seq' ); |
1108 | | - $dbw->insert( 'revision', |
1109 | | - array( |
1110 | | - 'rev_id' => $rev_id, |
1111 | | - 'rev_page' => $this->mPage, |
1112 | | - 'rev_text_id' => $this->mTextId, |
1113 | | - 'rev_comment' => $this->mComment, |
1114 | | - 'rev_minor_edit' => $this->mMinorEdit ? 1 : 0, |
1115 | | - 'rev_user' => $this->mUser, |
1116 | | - 'rev_user_text' => $this->mUserText, |
1117 | | - 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp ), |
1118 | | - 'rev_deleted' => $this->mDeleted, |
1119 | | - 'rev_len' => $this->mSize, |
1120 | | - 'rev_parent_id' => is_null( $this->mParentId ) |
1121 | | - ? $this->getPreviousRevisionId( $dbw ) |
1122 | | - : $this->mParentId, |
1123 | | - 'rev_sha1' => is_null( $this->mSha1 ) |
1124 | | - ? Revision::base36Sha1( $this->mText ) |
1125 | | - : $this->mSha1, |
1126 | | - 'rev_content_model' => $this->getContentModelName(), |
1127 | | - 'rev_content_format' => $this->getContentFormat(), |
1128 | | - ), __METHOD__ |
1129 | | - ); |
1130 | 1102 | |
| 1103 | + $row = array( |
| 1104 | + 'rev_id' => $rev_id, |
| 1105 | + 'rev_page' => $this->mPage, |
| 1106 | + 'rev_text_id' => $this->mTextId, |
| 1107 | + 'rev_comment' => $this->mComment, |
| 1108 | + 'rev_minor_edit' => $this->mMinorEdit ? 1 : 0, |
| 1109 | + 'rev_user' => $this->mUser, |
| 1110 | + 'rev_user_text' => $this->mUserText, |
| 1111 | + 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp ), |
| 1112 | + 'rev_deleted' => $this->mDeleted, |
| 1113 | + 'rev_len' => $this->mSize, |
| 1114 | + 'rev_parent_id' => is_null( $this->mParentId ) |
| 1115 | + ? $this->getPreviousRevisionId( $dbw ) |
| 1116 | + : $this->mParentId, |
| 1117 | + 'rev_sha1' => is_null( $this->mSha1 ) |
| 1118 | + ? Revision::base36Sha1( $this->mText ) |
| 1119 | + : $this->mSha1, |
| 1120 | + 'rev_content_model' => $this->getContentModelName(), |
| 1121 | + 'rev_content_format' => $this->getContentFormat(), |
| 1122 | + ); |
| 1123 | + |
| 1124 | + $dbw->insert( 'revision', $row, __METHOD__ ); |
| 1125 | + |
1131 | 1126 | $this->mId = !is_null( $rev_id ) ? $rev_id : $dbw->insertId(); |
1132 | 1127 | |
1133 | 1128 | wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) ); |
Index: branches/Wikidata/phase3/includes/WikiPage.php |
— | — | @@ -1397,7 +1397,9 @@ |
1398 | 1398 | 'parent_id' => $oldid, |
1399 | 1399 | 'user' => $user->getId(), |
1400 | 1400 | 'user_text' => $user->getName(), |
1401 | | - 'timestamp' => $now |
| 1401 | + 'timestamp' => $now, |
| 1402 | + 'content_model' => $content->getModelName(), |
| 1403 | + 'content_format' => $serialisation_format, |
1402 | 1404 | ) ); |
1403 | 1405 | |
1404 | 1406 | $changed = !$content->equals( $old_content ); |
— | — | @@ -1502,7 +1504,9 @@ |
1503 | 1505 | 'len' => $newsize, |
1504 | 1506 | 'user' => $user->getId(), |
1505 | 1507 | 'user_text' => $user->getName(), |
1506 | | - 'timestamp' => $now |
| 1508 | + 'timestamp' => $now, |
| 1509 | + 'content_model' => $content->getModelName(), |
| 1510 | + 'content_format' => $serialisation_format, |
1507 | 1511 | ) ); |
1508 | 1512 | $revisionId = $revision->insertOn( $dbw ); |
1509 | 1513 | |