merged from master
authordaniel <daniel.kinzler@wikimedia.de>
Wed, 25 Apr 2012 17:49:09 +0000 (19:49 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Wed, 25 Apr 2012 17:49:09 +0000 (19:49 +0200)
1  2 
.gitreview
includes/AutoLoader.php
includes/DefaultSettings.php
includes/EditPage.php
includes/Title.php
includes/api/ApiDelete.php
includes/api/ApiMain.php
languages/messages/MessagesEn.php
maintenance/refreshLinks.php

diff --cc .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
@@@ -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',
Simple merge
@@@ -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
         */
                        }
                }
  
-               $wgOut->addHTML( Html::openElement( 'form', array( 'id' => 'editform', 'name' => 'editform',
 +              #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' => self::EDITFORM_ID, 'name' => self::EDITFORM_ID,
                        'method' => 'post', 'action' => $this->getActionURL( $this->getContextTitle() ),
                        'enctype' => 'multipart/form-data' ) ) );
  
        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 {
                        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 = "<div id='mw-{$level}csspreview'>\n" . wfMsg( "{$level}csspreview" ) . "\n</div>";
 -                                      $class .= " mw-css";
 -                              } elseif ( preg_match( "/\\.js$/", $this->mTitle->getText() ) ) {
 -                                      $previewtext = "<div id='mw-{$level}jspreview'>\n" . wfMsg( "{$level}jspreview" ) . "\n</div>";
 -                                      $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 .= "<pre class=\"$class\" dir=\"ltr\">\n" . htmlspecialchars( $this->textbox1 ) . "\n</pre>\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 = "<div id='mw-{$level}{$format}preview'>" . wfMsg( "{$level}{$format}preview" ) . "</div>";
 +                } 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 = '<h2 id="mw-previewconflict">' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
Simple merge
Simple merge
Simple merge
Simple merge
@@@ -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__ );