From: daniel Date: Tue, 29 May 2012 15:01:13 +0000 (+0200) Subject: merged master X-Git-Tag: 1.31.0-rc.0~22097^2^2~151 X-Git-Url: http://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=250da851d1ab6d01a7c53a6e947b699e54b4b470 merged master --- 250da851d1ab6d01a7c53a6e947b699e54b4b470 diff --cc includes/Article.php index 5bfc7712e8,ded8c497f2..c7d350acaf --- a/includes/Article.php +++ b/includes/Article.php @@@ -37,15 -56,23 +56,30 @@@ class Article extends Page */ public $mParserOptions; + /** - * Content of the revision we are working on ++ * Text of the revision we are working on + * @var string $mContent + */ - var $mContent; // !< + var $mContent; // !< #BC cruft + + /** ++ * Content of the revision we are working on + * @var Content + * @since 1.WD + */ - var $mContentObject; ++ var $mContentObject; // !< + /** + * Is the content ($mContent) already loaded? + * @var bool $mContentLoaded + */ var $mContentLoaded = false; // !< + + /** + * The oldid of the article that is to be shown, 0 for the + * current revision + * @var int|null $mOldId + */ var $mOldId; // !< /** diff --cc includes/EditPage.php index 5273c54d09,9e337fde31..cc09d7ffaa --- a/includes/EditPage.php +++ b/includes/EditPage.php @@@ -1443,118 -1388,81 +1466,127 @@@ class EditPage wfProfileOut( __METHOD__ ); return $status; } - if ( $this->sectiontitle !== '' ) { - $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->sectiontitle ); - // If no edit summary was specified, create one automatically from the section - // title and have it link to the new section. Otherwise, respect the summary as - // passed. - if ( $this->summary === '' ) { - $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle ); - $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSectionTitle ); + + $content = ContentHandler::makeContent( $this->textbox1, $this->getTitle(), $this->content_model, $this->content_format ); + + # Handle the user preference to force summaries here, but not for null edits + if ( $this->section != 'new' && !$this->allowBlankSummary + && !$content->equals( $this->getOriginalContent() ) + && !$content->isRedirect() ) # check if it's not a redirect + { + if ( md5( $this->summary ) == $this->autoSumm ) { + $this->missingSummary = true; + $status->fatal( 'missingsummary' ); + $status->value = self::AS_SUMMARY_NEEDED; + wfProfileOut( __METHOD__ ); + return $status; } - } elseif ( $this->summary !== '' ) { - $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->summary ); - # This is a new section, so create a link to the new section - # in the revision summary. - $cleanSummary = $wgParser->stripSectionName( $this->summary ); - $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSummary ); } - } elseif ( $this->section != '' ) { - # Try to get a section anchor from the section source, redirect to edited section if header found - # XXX: might be better to integrate this into Article::replaceSection - # for duplicate heading checking and maybe parsing - $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches ); - # we can't deal with anchors, includes, html etc in the header for now, - # headline would need to be parsed to improve this - if ( $hasmatch && strlen( $matches[2] ) > 0 ) { - $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $matches[2] ); + + # And a similar thing for new sections + if ( $this->section == 'new' && !$this->allowBlankSummary ) { + if ( trim( $this->summary ) == '' ) { + $this->missingSummary = true; + $status->fatal( 'missingsummary' ); // or 'missingcommentheader' if $section == 'new'. Blegh + $status->value = self::AS_SUMMARY_NEEDED; + wfProfileOut( __METHOD__ ); + return $status; + } } - } - $result['sectionanchor'] = $sectionanchor; - wfProfileOut( __METHOD__ . '-sectionanchor' ); - // Save errors may fall down to the edit form, but we've now - // merged the section into full text. Clear the section field - // so that later submission of conflict forms won't try to - // replace that into a duplicated mess. - $this->textbox1 = $text; - $this->section = ''; + # All's well + wfProfileIn( __METHOD__ . '-sectionanchor' ); + $sectionanchor = ''; + if ( $this->section == 'new' ) { + if ( $this->textbox1 == '' ) { + $this->missingComment = true; + $status->fatal( 'missingcommenttext' ); + $status->value = self::AS_TEXTBOX_EMPTY; + wfProfileOut( __METHOD__ . '-sectionanchor' ); + wfProfileOut( __METHOD__ ); + return $status; + } + if ( $this->sectiontitle !== '' ) { + $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->sectiontitle ); + // If no edit summary was specified, create one automatically from the section + // title and have it link to the new section. Otherwise, respect the summary as + // passed. + if ( $this->summary === '' ) { + $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle ); + $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSectionTitle ); + } + } elseif ( $this->summary !== '' ) { + $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->summary ); + # This is a new section, so create a link to the new section + # in the revision summary. + $cleanSummary = $wgParser->stripSectionName( $this->summary ); + $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSummary ); + } + } elseif ( $this->section != '' ) { + # Try to get a section anchor from the section source, redirect to edited section if header found + # XXX: might be better to integrate this into Article::replaceSection + # for duplicate heading checking and maybe parsing + $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches ); + # we can't deal with anchors, includes, html etc in the header for now, + # headline would need to be parsed to improve this + if ( $hasmatch && strlen( $matches[2] ) > 0 ) { + $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $matches[2] ); + } + } + $result['sectionanchor'] = $sectionanchor; + wfProfileOut( __METHOD__ . '-sectionanchor' ); - $status->value = self::AS_SUCCESS_UPDATE; - } + // Save errors may fall down to the edit form, but we've now + // merged the section into full text. Clear the section field + // so that later submission of conflict forms won't try to + // replace that into a duplicated mess. + $this->textbox1 = $content->serialize( $this->content_format ); + $this->section = ''; - // Check for length errors again now that the section is merged in - $this->kblength = (int)( strlen( $text ) / 1024 ); - if ( $this->kblength > $wgMaxArticleSize ) { - $this->tooBig = true; - $status->setResult( false, self::AS_MAX_ARTICLE_SIZE_EXCEEDED ); - wfProfileOut( __METHOD__ ); - return $status; - } + $status->value = self::AS_SUCCESS_UPDATE; + } + + // Check for length errors again now that the section is merged in + $this->kblength = (int)( strlen( $content->serialize( $this->content_format ) ) / 1024 ); + if ( $this->kblength > $wgMaxArticleSize ) { + $this->tooBig = true; + $status->setResult( false, self::AS_MAX_ARTICLE_SIZE_EXCEEDED ); + wfProfileOut( __METHOD__ ); + return $status; + } - $flags = EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY | - ( $new ? EDIT_NEW : EDIT_UPDATE ) | - ( ( $this->minoredit && !$this->isNew ) ? EDIT_MINOR : 0 ) | - ( $bot ? EDIT_FORCE_BOT : 0 ); + $flags = EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY | + ( $new ? EDIT_NEW : EDIT_UPDATE ) | + ( ( $this->minoredit && !$this->isNew ) ? EDIT_MINOR : 0 ) | + ( $bot ? EDIT_FORCE_BOT : 0 ); - $doEditStatus = $this->mArticle->doEdit( $text, $this->summary, $flags ); + $doEditStatus = $this->mArticle->doEditContent( $content, $this->summary, $flags, false, null, $this->content_format ); - if ( $doEditStatus->isOK() ) { - $result['redirect'] = Title::newFromRedirect( $text ) !== null; - $this->commitWatch(); - wfProfileOut( __METHOD__ ); - return $status; - } else { - // Failure from doEdit() - // Show the edit conflict page for certain recognized errors from doEdit(), - // but don't show it for errors from extension hooks - $errors = $doEditStatus->getErrorsArray(); - if ( in_array( $errors[0][0], array( 'edit-gone-missing', 'edit-conflict', - 'edit-already-exists' ) ) ) - { - $this->isConflict = true; - // Destroys data doEdit() put in $status->value but who cares - $doEditStatus->value = self::AS_END; + if ( $doEditStatus->isOK() ) { + $result['redirect'] = $content->isRedirect(); + $this->commitWatch(); + wfProfileOut( __METHOD__ ); + return $status; + } else { - $this->isConflict = true; - $doEditStatus->value = self::AS_END; // Destroys data doEdit() put in $status->value but who cares ++ // Failure from doEdit() ++ // Show the edit conflict page for certain recognized errors from doEdit(), ++ // but don't show it for errors from extension hooks ++ $errors = $doEditStatus->getErrorsArray(); ++ if ( in_array( $errors[0][0], array( 'edit-gone-missing', 'edit-conflict', ++ 'edit-already-exists' ) ) ) ++ { ++ $this->isConflict = true; ++ // Destroys data doEdit() put in $status->value but who cares ++ $doEditStatus->value = self::AS_END; ++ } + wfProfileOut( __METHOD__ ); + return $doEditStatus; } + } catch (MWContentSerializationException $ex) { + $status->fatal( 'content-failed-to-parse', $this->content_model, $this->content_format, $ex->getMessage() ); + $status->value = self::AS_PARSE_ERROR; wfProfileOut( __METHOD__ ); - return $doEditStatus; + return $status; } } diff --cc includes/Revision.php index 53b792e509,98b8a0de94..5fd1f5a719 --- a/includes/Revision.php +++ b/includes/Revision.php @@@ -1294,20 -1116,12 +1294,21 @@@ class Revision * @return Revision|null on error */ public static function newNullRevision( $dbw, $pageId, $summary, $minor ) { + global $wgContentHandlerUseDB; + wfProfileIn( __METHOD__ ); - $fields = array( 'page_latest', 'rev_text_id', 'rev_len', 'rev_sha1' ); ++ $fields = array( 'page_latest', 'page_namespace', 'page_title', ++ 'rev_text_id', 'rev_len', 'rev_sha1' ); + + if ( $wgContentHandlerUseDB ) { + $fields[] = 'rev_content_model'; + $fields[] = 'rev_content_format'; + } + $current = $dbw->selectRow( array( 'page', 'revision' ), - array( 'page_latest', 'page_namespace', 'page_title', - 'rev_text_id', 'rev_len', 'rev_sha1' ), + $fields, array( 'page_id' => $pageId, 'page_latest=rev_id', @@@ -1322,15 -1136,9 +1323,16 @@@ 'text_id' => $current->rev_text_id, 'parent_id' => $current->page_latest, 'len' => $current->rev_len, - 'sha1' => $current->rev_sha1, + 'sha1' => $current->rev_sha1 - ) ); + ); + + if ( $wgContentHandlerUseDB ) { + $row[ 'content_model' ] = $current->rev_content_model; + $row[ 'content_format' ] = $current->rev_content_format; + } + + $revision = new Revision( $row ); + $revision->setTitle( Title::makeTitle( $current->page_namespace, $current->page_title ) ); } else { $revision = null; } diff --cc tests/phpunit/includes/WikiPageTest.php index cdf6fcda83,c8606cc745..e2d3605af7 --- a/tests/phpunit/includes/WikiPageTest.php +++ b/tests/phpunit/includes/WikiPageTest.php @@@ -29,11 -28,10 +29,12 @@@ class WikiPageTest extends MediaWikiLan 'templatelinks', 'iwlinks' ) ); } - + public function setUp() { + parent::setUp(); $this->pages_to_delete = array(); + + LinkCache::singleton()->clear(); # avoid cached redirect status, etc } public function tearDown() { @@@ -48,12 -46,9 +49,13 @@@ // fail silently } } + parent::tearDown(); } + /** + * @param Title $title + * @return WikiPage + */ protected function newPage( $title ) { if ( is_string( $title ) ) $title = Title::newFromText( $title );