r114447 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114446‎ | r114447 | r114448 >
Date:15:18, 23 March 2012
Author:daniel
Status:deferred
Tags:
Comment:
EditPage to use Content objects
Modified paths:
  • /branches/Wikidata/phase3/includes/Content.php (modified) (history)
  • /branches/Wikidata/phase3/includes/ContentHandler.php (modified) (history)
  • /branches/Wikidata/phase3/includes/EditPage.php (modified) (history)
  • /branches/Wikidata/phase3/includes/WikiPage.php (modified) (history)
  • /branches/Wikidata/phase3/includes/diff/DifferenceEngine.php (modified) (history)

Diff [purge]

Index: branches/Wikidata/phase3/includes/diff/DifferenceEngine.php
@@ -67,7 +67,7 @@
6868 * @param $refreshCache boolean If set, refreshes the diff cache
6969 * @param $unhide boolean If set, allow viewing deleted revs
7070 */
71 - function __construct( $context = null, $old = 0, $new = 0, $rcid = 0,
 71+ function __construct( $context = null, $old = 0, $new = 0, $rcid = 0, # FIXME: use Contenthandler::getDifferenceEngine everywhere!
7272 $refreshCache = false, $unhide = false )
7373 {
7474 if ( $context instanceof IContextSource ) {
@@ -925,14 +925,35 @@
926926
927927 /**
928928 * Use specified text instead of loading from the database
 929+ * @deprecated since 1.20
929930 */
930 - function setText( $oldText, $newText ) { #FIXME: deprecate, use Content objects instead!
 931+ function setText( $oldText, $newText ) {
 932+ wfDeprecated( __METHOD__, "1.20" );
 933+ $this->setText_internal( $oldText, $newText );
 934+ }
 935+
 936+ /**
 937+ * @private
 938+ * Use specified text instead of loading from the database
 939+ */
 940+ private function setText_internal( $oldText, $newText ) {
931941 $this->mOldtext = $oldText;
932942 $this->mNewtext = $newText;
933943 $this->mTextLoaded = 2;
934944 $this->mRevisionsLoaded = true;
935945 }
936946
 947+ /**
 948+ * Use specified text instead of loading from the database
 949+ * @since 1.20
 950+ */
 951+ function setContent( Content $oldContent, Content $newContent, $format = null ) { #FIXME: use this!
 952+ $oldText = $oldContent->serialize( $format );
 953+ $newText = $newContent->serialize( $format );
 954+
 955+ return $this->setText_internal( $oldText, $newText );
 956+ }
 957+
937958 /**
938959 * Set the language in which the diff text is written
939960 * (Defaults to page content language).
Index: branches/Wikidata/phase3/includes/Content.php
@@ -167,6 +167,17 @@
168168 }
169169
170170 /**
 171+ * Returns a new WikitextContent object with the given section heading prepended, if supported.
 172+ * The default implementation just returns this Content object unmodified, ignoring the section header.
 173+ *
 174+ * @param $header String
 175+ * @return Content
 176+ */
 177+ public function addSectionHeader( $header ) {
 178+ return $this;
 179+ }
 180+
 181+ /**
171182 * Returns a Content object with preload transformations applied (or this object if no transformations apply).
172183 *
173184 * @param Title $title
@@ -389,6 +400,18 @@
390401 }
391402
392403 /**
 404+ * Returns a new WikitextContent object with the given section heading prepended.
 405+ *
 406+ * @param $header String
 407+ * @return Content
 408+ */
 409+ public function addSectionHeader( $header ) {
 410+ $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->sectiontitle ) . "\n\n" . $this->getNativeData();
 411+
 412+ return new WikitextContent( $text );
 413+ }
 414+
 415+ /**
393416 * Returns a Content object with pre-save transformations applied (or this object if no transformations apply).
394417 *
395418 * @param Title $title
Index: branches/Wikidata/phase3/includes/ContentHandler.php
@@ -209,12 +209,19 @@
210210 }
211211
212212 /**
213 - public function updatePage( $title, $obj ) {
214 - }
215 - **/
216 -
217 - public function getDiffEngine( Article $article ) { #FIXME: change interface of diff engine? or accept content objects here=?
218 - $de = new DifferenceEngine( $article->getContext() );
 213+ * Factory
 214+ * @param $context IContextSource context to use, anything else will be ignored
 215+ * @param $old Integer old ID we want to show and diff with.
 216+ * @param $new String either 'prev' or 'next'.
 217+ * @param $rcid Integer ??? FIXME (default 0)
 218+ * @param $refreshCache boolean If set, refreshes the diff cache
 219+ * @param $unhide boolean If set, allow viewing deleted revs
 220+ */
 221+ public function getDifferenceEngine( IContextSource $context, $old = 0, $new = 0, $rcid = 0, #FIMXE: use everywhere!
 222+ $refreshCache = false, $unhide = false ) {
 223+
 224+ $de = new DifferenceEngine( $context, $old, $new, $rcid, $refreshCache, $unhide );
 225+
219226 return $de;
220227 }
221228
Index: branches/Wikidata/phase3/includes/EditPage.php
@@ -920,7 +920,7 @@
921921 */
922922 private function getCurrentContent() {
923923 $rev = $this->mArticle->getRevision();
924 - $content = $rev->getContentObject( Revision::RAW );
 924+ $content = $rev->getContent( Revision::RAW );
925925
926926 if ( $content === false || $content === null ) {
927927 if ( !$this->content_model ) $this->content_model = $this->getTitle()->getContentModelName();
@@ -1309,10 +1309,9 @@
13101310
13111311 $result['sectionanchor'] = '';
13121312 if ( $this->section == 'new' ) {
1313 - .........FIXME...............
13141313 if ( $this->sectiontitle !== '' ) {
13151314 // Insert the section title above the content.
1316 - $T_E_X_T = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->sectiontitle ) . "\n\n" . $T_E_X_T;
 1315+ $content = $content->addSectionHeader( $this->sectiontitle );
13171316
13181317 // Jump to the new section
13191318 $result['sectionanchor'] = $wgParser->guessLegacySectionNameFromWikiText( $this->sectiontitle );
@@ -1326,7 +1325,7 @@
13271326 }
13281327 } elseif ( $this->summary !== '' ) {
13291328 // Insert the section title above the content.
1330 - $T_E_X_T = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->summary ) . "\n\n" . $T_E_X_T;
 1329+ $content = $content->addSectionHeader( $this->sectiontitle );
13311330
13321331 // Jump to the new section
13331332 $result['sectionanchor'] = $wgParser->guessLegacySectionNameFromWikiText( $this->summary );
@@ -1376,27 +1375,34 @@
13771376 } else {
13781377 $sectionTitle = $this->summary;
13791378 }
1380 -
 1379+
 1380+ $textbox_content = ContentHandler::makeContent( $this->textbox1, $this->getTitle(), $this->content_model, $this->content_format );
 1381+ $content = false;
 1382+
13811383 if ( $this->isConflict ) {
13821384 wfDebug( __METHOD__ . ": conflict! getting section '$this->section' for time '$this->edittime' (article time '{$timestamp}')\n" );
1383 - $T_E_X_T = $this->mArticle->replaceSection( $this->section, $this->textbox1, $sectionTitle, $this->edittime ); #FIXME: use Content object throughout, make edit form aware of content model and serialization format
 1385+
 1386+ $content = $this->mArticle->replaceSectionContent( $this->section, $textbox_content, $sectionTitle, $this->edittime );
13841387 } else {
13851388 wfDebug( __METHOD__ . ": getting section '$this->section'\n" );
1386 - $T_E_X_T = $this->mArticle->replaceSection( $this->section, $this->textbox1, $sectionTitle ); #FIXME: use Content object throughout, make edit form aware of content model and serialization format
 1389+
 1390+ $content = $this->mArticle->replaceSectionContent( $this->section, $textbox_content, $sectionTitle );
13871391 }
1388 - if ( is_null( $T_E_X_T ) ) {
 1392+
 1393+ if ( is_null( $content ) ) {
13891394 wfDebug( __METHOD__ . ": activating conflict; section replace failed.\n" );
13901395 $this->isConflict = true;
1391 - $T_E_X_T = $this->textbox1; // do not try to merge here! #FIXME: unserialize Content
 1396+ $content = $textbox_content; // do not try to merge here!
13921397 } elseif ( $this->isConflict ) {
13931398 # Attempt merge
1394 - if ( $this->mergeChangesInto( $T_E_X_T ) ) { #FIXME: passe/receive Content object
 1399+ if ( $this->mergeChangesIntoContent( $textbox_content ) ) {
13951400 // Successful merge! Maybe we should tell the user the good news?
 1401+ $content = $textbox_content;
13961402 $this->isConflict = false;
13971403 wfDebug( __METHOD__ . ": Suppressing edit conflict, successful merge.\n" );
13981404 } else {
13991405 $this->section = '';
1400 - $this->textbox1 = $T_E_X_T;
 1406+ #$this->textbox1 = $text; #redundant, nothing to do here?
14011407 wfDebug( __METHOD__ . ": Keeping edit conflict, failed merge.\n" );
14021408 }
14031409 }
@@ -1408,7 +1414,8 @@
14091415 }
14101416
14111417 // Run post-section-merge edit filter
1412 - if ( !wfRunHooks( 'EditFilterMerged', array( $this, $T_E_X_T, &$this->hookError, $this->summary ) ) ) {
 1418+ if ( !wfRunHooks( 'EditFilterMerged', array( $this, $content->serialize( $this->content_format ), &$this->hookError, $this->summary ) )
 1419+ || !wfRunHooks( 'EditFilterMergedContent', array( $this, $content, &$this->hookError, $this->summary ) ) ) { #FIXME: document new hook
14131420 # Error messages etc. could be handled within the hook...
14141421 $status->fatal( 'hookaborted' );
14151422 $status->value = self::AS_HOOK_ERROR;
@@ -1424,8 +1431,8 @@
14251432
14261433 # Handle the user preference to force summaries here, but not for null edits
14271434 if ( $this->section != 'new' && !$this->allowBlankSummary
1428 - && $this->getOriginalContent()... != $T_E_X_T
1429 - && !Title::newFromRedirect( $T_E_X_T ) ) # check if it's not a redirect
 1435+ && !$content->equals( $this->getOriginalContent() )
 1436+ && !$content->isRedirect() ) # check if it's not a redirect
14301437 {
14311438 if ( md5( $this->summary ) == $this->autoSumm ) {
14321439 $this->missingSummary = true;
@@ -1493,14 +1500,14 @@
14941501 // merged the section into full text. Clear the section field
14951502 // so that later submission of conflict forms won't try to
14961503 // replace that into a duplicated mess.
1497 - $this->textbox1 = $T_E_X_T;
 1504+ $this->textbox1 = $content->serialize( $this->content_format );
14981505 $this->section = '';
14991506
15001507 $status->value = self::AS_SUCCESS_UPDATE;
15011508 }
15021509
15031510 // Check for length errors again now that the section is merged in
1504 - $this->kblength = (int)( strlen( $T_E_X_T ) / 1024 );
 1511+ $this->kblength = (int)( strlen( $content->serialize( $this->content_format ) ) / 1024 );
15051512 if ( $this->kblength > $wgMaxArticleSize ) {
15061513 $this->tooBig = true;
15071514 $status->setResult( false, self::AS_MAX_ARTICLE_SIZE_EXCEEDED );
@@ -1513,10 +1520,10 @@
15141521 ( ( $this->minoredit && !$this->isNew ) ? EDIT_MINOR : 0 ) |
15151522 ( $bot ? EDIT_FORCE_BOT : 0 );
15161523
1517 - $doEditStatus = $this->mArticle->doEdit( $T_E_X_T, $this->summary, $flags ); # FIXME: use WikiPage::doEditContent()
 1524+ $doEditStatus = $this->mArticle->doEditContent( $content, $this->summary, $flags );
15181525
15191526 if ( $doEditStatus->isOK() ) {
1520 - $result['redirect'] = Title::newFromRedirect( $T_E_X_T ) !== null;
 1527+ $result['redirect'] = $content->isRedirect();
15211528 $this->commitWatch();
15221529 wfProfileOut( __METHOD__ );
15231530 return $status;
@@ -1581,8 +1588,34 @@
15821589 * @parma $editText string
15831590 *
15841591 * @return bool
 1592+ * @deprecated since 1.20
15851593 */
1586 - function mergeChangesInto( &$editText ){
 1594+ function mergeChangesInto( &$editText ){
 1595+ wfDebug( __METHOD__, "1.20" );
 1596+
 1597+ $handler = ContentHandler::getForModelName( $this->content_model );
 1598+ $editContent = $handler->unserialize( $editText, $this->content_format );
 1599+
 1600+ $ok = $this->mergeChangesIntoContent( $editContent );
 1601+
 1602+ if ( $ok ) {
 1603+ $editText = $editContent->serialize( $this->content_format ); #XXX: really serialize?!
 1604+ return true;
 1605+ } else {
 1606+ return false;
 1607+ }
 1608+ }
 1609+
 1610+ /**
 1611+ * @private
 1612+ * @todo document
 1613+ *
 1614+ * @parma $editText string
 1615+ *
 1616+ * @return bool
 1617+ * @since since 1.20
 1618+ */
 1619+ private function mergeChangesIntoContent( &$editContent ){
15871620 wfProfileIn( __METHOD__ );
15881621
15891622 $db = wfGetDB( DB_MASTER );
@@ -1604,11 +1637,11 @@
16051638 $currentContent = $currentRevision->getContent();
16061639
16071640 $handler = ContentHandler::getForModelName( $baseContent->getModelName() );
1608 - $editContent = $handler->unserialize( $editText, $this->content_format ); #FIXME: supply serialization fomrat from edit form!
16091641
16101642 $result = $handler->merge3( $baseContent, $editContent, $currentContent );
 1643+
16111644 if ( $result ) {
1612 - $editText = ContentHandler::getContentText($result, $this->content_format ); #FIXME: supply serialization fomrat from edit form!
 1645+ $editContent = $result;
16131646 wfProfileOut( __METHOD__ );
16141647 return true;
16151648 } else {
@@ -2421,8 +2454,9 @@
24222455 $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) );
24232456 $newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) );
24242457
2425 - $de = new DifferenceEngine( $this->mArticle->getContext() );
2426 - $de->setText( $oldContent, $newContent ); #FIXME: content-based diff!
 2458+ $de = $oldContent->getContentHandler()->getDifferenceEngine( $this->mArticle->getContext() );
 2459+ $de->setContent( $oldContent, $newContent );
 2460+
24272461 $difftext = $de->getDiff( $oldtitle, $newtitle );
24282462 $de->showDiffStyle();
24292463 } else {
@@ -2512,8 +2546,12 @@
25132547 if ( wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
25142548 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
25152549
2516 - $de = new DifferenceEngine( $this->mArticle->getContext() );
2517 - $de->setText( $this->textbox2, $this->textbox1 );
 2550+ $content1 = ContentHandler::makeContent( $this->textbox1, $this->getTitle(), $this->content_model, $this->content_format );
 2551+ $content2 = ContentHandler::makeContent( $this->textbox2, $this->getTitle(), $this->content_model, $this->content_format );
 2552+
 2553+ $handler = ContentHandler::getForModelName( $this->content_model );
 2554+ $de = $handler->getDifferenceEngine( $this->mArticle->getContext() );
 2555+ $de->setContent( $content2, $content1 );
25182556 $de->showDiff( wfMsgExt( 'yourtext', 'parseinline' ), wfMsg( 'storedversion' ) );
25192557
25202558 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
@@ -3140,10 +3178,13 @@
31413179 $wgOut->addHTML( '</div>' );
31423180
31433181 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
3144 - $de = new DifferenceEngine( $this->mArticle->getContext() ); #FIXME: get from content handler!
31453182
3146 - $de->setText( $this->getCurrentText(), $this->textbox2 ); #FIXME: make Content based
 3183+ $handler = ContentHandler::getForTitle( $this->getTitle() );
 3184+ $de = $handler->getDifferenceEngine( $this->mArticle->getContext() );
31473185
 3186+ $content2 = ContentHandler::makeContent( $this->textbox2, $this->getTitle(), $this->content_model, $this->content_format );
 3187+ $de->setContent( $this->getCurrentContent(), $content2 );
 3188+
31483189 $de->showDiff( wfMsg( "storedversion" ), wfMsgExt( 'yourtext', 'parseinline' ) );
31493190
31503191 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
Index: branches/Wikidata/phase3/includes/WikiPage.php
@@ -1142,7 +1142,7 @@
11431143 return ContentHandler::getContentText( $newContent ); #XXX: unclear what will happen for non-wikitext!
11441144 }
11451145
1146 - public function replaceSectionContent( $section, $sectionContent, $sectionTitle = '', $edittime = null ) {
 1146+ public function replaceSectionContent( $section, Content $sectionContent, $sectionTitle = '', $edittime = null ) {
11471147 wfProfileIn( __METHOD__ );
11481148
11491149 if ( strval( $section ) == '' ) {

Status & tagging log