From: daniel Date: Wed, 25 Apr 2012 17:49:09 +0000 (+0200) Subject: merged from master X-Git-Tag: 1.31.0-rc.0~22097^2^2~198 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=a990fd78ffa34b3a6834398e7efc80ac05fbf1ed;p=lhc%2Fweb%2Fwiklou.git merged from master --- a990fd78ffa34b3a6834398e7efc80ac05fbf1ed diff --cc .gitreview index 7e1473a6a9,0ec44b8359..46f67145ad --- a/.gitreview +++ b/.gitreview @@@ -2,4 -2,5 +2,5 @@@ host=gerrit.wikimedia.org port=29418 project=mediawiki/core.git - defaultbranch=Wikidata + defaultbranch=master -defaultrebase=0 ++defaultrebase=0 diff --cc includes/AutoLoader.php index 03553c48ef,60cbbaafb8..77f69e3940 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@@ -261,19 -259,8 +261,20 @@@ $wgAutoloadLocalClasses = array 'ZhClient' => 'includes/ZhClient.php', 'ZipDirectoryReader' => 'includes/ZipDirectoryReader.php', + # content handler + 'Content' => 'includes/Content.php', + 'ContentHandler' => 'includes/ContentHandler.php', + 'CssContent' => 'includes/Content.php', + 'CssContentHandler' => 'includes/ContentHandler.php', + 'JavaScriptContent' => 'includes/Content.php', + 'JavaScriptContentHandler' => 'includes/ContentHandler.php', + 'MessageContent' => 'includes/Content.php', + 'TextContent' => 'includes/Content.php', + 'WikitextContent' => 'includes/Content.php', + 'WikitextContentHandler' => 'includes/ContentHandler.php', + # includes/actions + 'CachedAction' => 'includes/actions/CachedAction.php', 'CreditsAction' => 'includes/actions/CreditsAction.php', 'DeleteAction' => 'includes/actions/DeleteAction.php', 'EditAction' => 'includes/actions/EditAction.php', diff --cc includes/EditPage.php index c943e96ebd,92bca9ef58..e8a91e3e5d --- a/includes/EditPage.php +++ b/includes/EditPage.php @@@ -144,11 -144,11 +144,16 @@@ class EditPage */ const AS_IMAGE_REDIRECT_LOGGED = 234; + /** + * Status: can't parse content + */ + const AS_PARSE_ERROR = 240; + + /** + * HTML id and name for the beginning of the edit form. + */ + const EDITFORM_ID = 'editform'; + /** * @var Article */ @@@ -1902,8 -1774,7 +1907,8 @@@ } } + #FIXME: add EditForm plugin interface and use it here! #FIXME: search for textarea1 and textares2, and allow EditForm to override all uses. - $wgOut->addHTML( Html::openElement( 'form', array( 'id' => 'editform', 'name' => 'editform', + $wgOut->addHTML( Html::openElement( 'form', array( 'id' => self::EDITFORM_ID, 'name' => self::EDITFORM_ID, 'method' => 'post', 'action' => $this->getActionURL( $this->getContextTitle() ), 'enctype' => 'multipart/form-data' ) ) ); @@@ -2474,37 -2340,30 +2479,49 @@@ HTM function showDiff() { global $wgUser, $wgContLang, $wgParser, $wgOut; - $oldContent = $this->getOriginalContent(); + $oldtitlemsg = 'currentrev'; + # if message does not exist, show diff against the preloaded default + if( $this->mTitle->getNamespace() == NS_MEDIAWIKI && !$this->mTitle->exists() ) { + $oldtext = $this->mTitle->getDefaultMessageText(); + if( $oldtext !== false ) { + $oldtitlemsg = 'defaultmessagetext'; ++ $oldContent = ContentHandler::makeContent( $oldtext, $this->mTitle ); ++ } else { ++ $oldContent = null; + } + } else { - $oldtext = $this->mArticle->getRawText(); ++ $oldContent = $this->getOriginalContent(); ++ } + + $textboxContent = ContentHandler::makeContent( $this->textbox1, $this->getTitle(), + $this->content_model, $this->content_format ); #XXX: handle parse errors ? + + $newContent = $this->mArticle->replaceSectionContent( + $this->section, $textboxContent, + $this->summary, $this->edittime ); + + # hanlde legacy text-based hook + $newtext_orig = $newContent->serialize( $this->content_format ); + $newtext = $newtext_orig; #clone + wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) ); + + if ( $newtext != $newtext_orig ) { + #if the hook changed the text, create a new Content object accordingly. + $newContent = ContentHandler::makeContent( $newtext, $this->getTitle(), $newContent->getModelName() ); #XXX: handle parse errors ? } - $newtext = $this->mArticle->replaceSection( - $this->section, $this->textbox1, $this->summary, $this->edittime ); - wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) ); + wfRunHooks( 'EditPageGetDiffContent', array( $this, &$newContent ) ); #FIXME: document new hook $popts = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang ); - $newtext = $wgParser->preSaveTransform( $newtext, $this->mTitle, $wgUser, $popts ); + $newContent = $newContent->preSaveTransform( $this->mTitle, $wgUser, $popts ); - if ( $oldtext !== false || $newtext != '' ) { + if ( ( $oldContent && !$oldContent->isEmpty() ) || ( $newContent && !$newContent->isEmpty() ) ) { - $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) ); + $oldtitle = wfMsgExt( $oldtitlemsg, array( 'parseinline' ) ); $newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) ); - $de = $oldContent->getContentHandler()->getDifferenceEngine( $this->mArticle->getContext() ); - $de = new DifferenceEngine( $this->mArticle->getContext() ); - $de->setText( $oldtext, $newtext ); ++ $de = $oldContent->getContentHandler()->createDifferenceEngine( $this->mArticle->getContext() ); + $de->setContent( $oldContent, $newContent ); + $difftext = $de->getDiff( $oldtitle, $newtitle ); $de->showDiffStyle(); } else { @@@ -2719,97 -2574,85 +2736,102 @@@ return $parsedNote; } - if ( $this->mTriedSave && !$this->mTokenOk ) { - if ( $this->mTokenOkExceptSuffix ) { - $note = wfMsg( 'token_suffix_mismatch' ); - } else { - $note = wfMsg( 'session_fail_preview' ); - } - } elseif ( $this->incompleteForm ) { - $note = wfMsg( 'edit_form_incomplete' ); - } else { - $note = wfMsg( 'previewnote' ) . - ' [[#' . self::EDITFORM_ID . '|' . $wgLang->getArrow() . ' ' . wfMsg( 'continue-editing' ) . ']]'; - } - - $parserOptions = ParserOptions::newFromUser( $wgUser ); - $parserOptions->setEditSection( false ); - $parserOptions->setTidy( true ); - $parserOptions->setIsPreview( true ); - $parserOptions->setIsSectionPreview( !is_null( $this->section ) && $this->section !== '' ); - - # don't parse non-wikitext pages, show message about preview - if ( $this->mTitle->isCssJsSubpage() || !$this->mTitle->isWikitextPage() ) { - if ( $this->mTitle->isCssJsSubpage() ) { - $level = 'user'; - } elseif ( $this->mTitle->isCssOrJsPage() ) { - $level = 'site'; - } else { - $level = false; - } ++ $note = ''; ++ + try { - $content = ContentHandler::makeContent( $this->textbox1, $this->getTitle(), $this->content_model, $this->content_format ); ++ $content = ContentHandler::makeContent( $this->textbox1, $this->getTitle(), $this->content_model, $this->content_format ); - if ( $this->mTriedSave && !$this->mTokenOk ) { - if ( $this->mTokenOkExceptSuffix ) { - $note = wfMsg( 'token_suffix_mismatch' ); - } else { - $note = wfMsg( 'session_fail_preview' ); - } - } elseif ( $this->incompleteForm ) { - $note = wfMsg( 'edit_form_incomplete' ); - } elseif ( $this->isCssJsSubpage || $this->mTitle->isCssOrJsPage() ) { - # if this is a CSS or JS page used in the UI, show a special notice - # 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? - # Used messages to make sure grep find them: - # Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview - $class = 'mw-code'; - if ( $level ) { - if ( preg_match( "/\\.css$/", $this->mTitle->getText() ) ) { - $previewtext = "
\n" . wfMsg( "{$level}csspreview" ) . "\n
"; - $class .= " mw-css"; - } elseif ( preg_match( "/\\.js$/", $this->mTitle->getText() ) ) { - $previewtext = "
\n" . wfMsg( "{$level}jspreview" ) . "\n
"; - $class .= " mw-js"; ++ if ( $this->mTriedSave && !$this->mTokenOk ) { ++ if ( $this->mTokenOkExceptSuffix ) { ++ $note = wfMsg( 'token_suffix_mismatch' ); + } else { - throw new MWException( 'A CSS/JS (sub)page but which is not css nor js!' ); ++ $note = wfMsg( 'session_fail_preview' ); + } - $parserOutput = $wgParser->parse( $previewtext, $this->mTitle, $parserOptions ); - $previewHTML = $parserOutput->getText(); ++ } elseif ( $this->incompleteForm ) { ++ $note = wfMsg( 'edit_form_incomplete' ); + } else { - $previewHTML = ''; - } - - $previewHTML .= "
\n" . htmlspecialchars( $this->textbox1 ) . "\n
\n"; - } else { - $toparse = $this->textbox1; - - # If we're adding a comment, we need to show the - # summary as the headline - if ( $this->section == "new" && $this->summary != "" ) { - $toparse = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->summary ) . "\n\n" . $toparse; - } - - wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) ); - - $parserOptions->enableLimitReport(); - - $toparse = $wgParser->preSaveTransform( $toparse, $this->mTitle, $wgUser, $parserOptions ); - $parserOutput = $wgParser->parse( $toparse, $this->mTitle, $parserOptions ); - - $rt = Title::newFromRedirectArray( $this->textbox1 ); - if ( $rt ) { - $previewHTML = $this->mArticle->viewRedirect( $rt, false ); - } else { - $previewHTML = $parserOutput->getText(); - } - - $this->mParserOutput = $parserOutput; - $wgOut->addParserOutputNoText( $parserOutput ); - - if ( count( $parserOutput->getWarnings() ) ) { - $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() ); - } - } ++ $note = wfMsg( 'previewnote' ) . ++ ' [[#' . self::EDITFORM_ID . '|' . $wgLang->getArrow() . ' ' . wfMsg( 'continue-editing' ) . ']]'; ++ } ++ ++ $parserOptions = ParserOptions::newFromUser( $wgUser ); ++ $parserOptions->setEditSection( false ); ++ $parserOptions->setTidy( true ); ++ $parserOptions->setIsPreview( true ); ++ $parserOptions->setIsSectionPreview( !is_null($this->section) && $this->section !== '' ); + ++ if ( $this->mTitle->isCssJsSubpage() || $this->mTitle->isCssOrJsPage() ) { ++ # don't parse non-wikitext pages, show message about preview + if( $this->mTitle->isCssJsSubpage() ) { + $level = 'user'; + } elseif( $this->mTitle->isCssOrJsPage() ) { + $level = 'site'; + } else { + $level = false; + } + + if ( $content->getModelName() == CONTENT_MODEL_CSS ) { + $format = 'css'; + } elseif ( $content->getModelName() == CONTENT_MODEL_JAVASCRIPT ) { + $format = 'js'; + } else { + $format = false; + } + + # Used messages to make sure grep find them: + # Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview + if( $level && $format ) { + $note = "
" . wfMsg( "{$level}{$format}preview" ) . "
"; + } else { + $note = wfMsg( 'previewnote' ); + } + } else { + $note = wfMsg( 'previewnote' ); + } + - $parserOptions = ParserOptions::newFromUser( $wgUser ); - $parserOptions->setEditSection( false ); - $parserOptions->setTidy( true ); - $parserOptions->setIsPreview( true ); - $parserOptions->setIsSectionPreview( !is_null($this->section) && $this->section !== '' ); - + $rt = $content->getRedirectChain(); + + if ( $rt ) { + $previewHTML = $this->mArticle->viewRedirect( $rt, false ); + } else { + + # If we're adding a comment, we need to show the + # summary as the headline + if ( $this->section == "new" && $this->summary != "" ) { + $content = $content->addSectionHeader( $this->summary ); + } + + $toparse_orig = $content->serialize( $this->content_format ); + $toparse = $toparse_orig; + wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) ); + + if ( $toparse !== $toparse_orig ) { + #hook changed the text, create new Content object + $content = ContentHandler::makeContent( $toparse, $this->getTitle(), $this->content_model, $this->content_format ); + } + + wfRunHooks( 'EditPageGetPreviewContent', array( $this, &$content ) ); # FIXME: document new hook + + $parserOptions->enableLimitReport(); + + #XXX: For CSS/JS pages, we should have called the ShowRawCssJs hook here. But it's now deprecated, so never mind + $content = $content->preSaveTransform( $this->mTitle, $wgUser, $parserOptions ); + + // TODO: might be a saner way to get a meaningfull context here? + $parserOutput = $content->getParserOutput( $this->getArticle()->getContext(), null, $parserOptions ); + + $previewHTML = $parserOutput->getText(); + $this->mParserOutput = $parserOutput; + $wgOut->addParserOutputNoText( $parserOutput ); + + if ( count( $parserOutput->getWarnings() ) ) { + $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() ); + } + } + } catch (MWContentSerializationException $ex) { + $note .= "\n\n" . wfMsg('content-failed-to-parse', $this->content_model, $this->content_format, $ex->getMessage() ); + $previewHTML = ''; + } if ( $this->isConflict ) { $conflict = '

' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "

\n"; diff --cc maintenance/refreshLinks.php index 4372502522,a7c7ec4ab9..20a80431c9 --- a/maintenance/refreshLinks.php +++ b/maintenance/refreshLinks.php @@@ -219,14 -219,8 +219,14 @@@ class RefreshLinks extends Maintenance $dbw->begin( __METHOD__ ); - $options = new ParserOptions; + $options = ParserOptions::newFromUserAndLang( new User, $wgContLang ); $parserOutput = $wgParser->parse( $revision->getText(), $title, $options, true, true, $revision->getId() ); + + $updates = $parserOutput->getSecondaryDataUpdates( $title, false ); + SecondaryDataUpdate::runUpdates( $updates ); + + $dbw->commit(); + // TODO: We don't know what happens here. $update = new LinksUpdate( $title, $parserOutput, false ); $update->doUpdate(); $dbw->commit( __METHOD__ );