Merge "(bug 46463) Mark edit preview as in page view language"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 8 Aug 2013 07:16:04 +0000 (07:16 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 8 Aug 2013 07:16:04 +0000 (07:16 +0000)
1  2 
includes/EditPage.php

diff --combined includes/EditPage.php
@@@ -100,7 -100,7 +100,7 @@@ class EditPage 
  
        /**
         * Status: user tried to create this page, but is not allowed to do that
 -       * ( Title->usercan('create') == false )
 +       * ( Title->userCan('create') == false )
         */
        const AS_NO_CREATE_PERMISSION = 223;
  
                        // The edit page was reached via a red link.
                        // Redirect to the article page and let them click the edit tab if
                        // they really want a permission error.
 -                      $wgOut->redirect( $this->mTitle->getFullUrl() );
 +                      $wgOut->redirect( $this->mTitle->getFullURL() );
                        return;
                }
  
                $wgOut->addHTML( Html::rawElement( 'div', array( 'class' => 'templatesUsed' ),
                        Linker::formatTemplates( $this->getTemplates() ) ) );
  
 +              $wgOut->addModules( 'mediawiki.action.edit.collapsibleFooter' );
 +
                if ( $this->mTitle->exists() ) {
                        $wgOut->returnToMain( null, $this->mTitle );
                }
                        // The edit page was reached via a red link.
                        // Redirect to the article page and let them click the edit tab if
                        // they really want a permission error.
 -                      $wgOut->redirect( $this->mTitle->getFullUrl() );
 +                      $wgOut->redirect( $this->mTitle->getFullURL() );
                } else {
                        $wgOut->readOnlyPage( $source, $protected, $reasons, $action );
                }
                $this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );
  
                if ( $this->section !== null && $this->section !== '' && !$this->isSectionEditSupported() ) {
 +                      wfProfileOut( __METHOD__ );
                        throw new ErrorPageError( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
                }
  
                                $orig = $this->getOriginalContent();
                                $content = $orig ? $orig->getSection( $this->section ) : null;
  
 -                              if ( !$content ) $content = $def_content;
 +                              if ( !$content ) {
 +                                      $content = $def_content;
 +                              }
                        } else {
                                $undoafter = $wgRequest->getInt( 'undoafter' );
                                $undo = $wgRequest->getInt( 'undo' );
                                                        # If we just undid one rev, use an autosummary
                                                        $firstrev = $oldrev->getNext();
                                                        if ( $firstrev && $firstrev->getId() == $undo ) {
 -                                                              $undoSummary = wfMessage( 'undo-summary', $undo, $undorev->getUserText() )->inContentLanguage()->text();
 +                                                              $userText = $undorev->getUserText();
 +                                                              if ( $userText === '' ) {
 +                                                                      $undoSummary = wfMessage(
 +                                                                              'undo-summary-username-hidden',
 +                                                                              $undo
 +                                                                      )->inContentLanguage()->text();
 +                                                              } else {
 +                                                                      $undoSummary = wfMessage(
 +                                                                              'undo-summary',
 +                                                                              $undo,
 +                                                                              $userText
 +                                                                      )->inContentLanguage()->text();
 +                                                              }
                                                                if ( $this->summary === '' ) {
                                                                        $this->summary = $undoSummary;
                                                                } else {
                }
                $revision = $this->mArticle->getRevisionFetched();
                if ( $revision === null ) {
 -                      if ( !$this->contentModel ) $this->contentModel = $this->getTitle()->getContentModel();
 +                      if ( !$this->contentModel ) {
 +                              $this->contentModel = $this->getTitle()->getContentModel();
 +                      }
                        $handler = ContentHandler::getForModelID( $this->contentModel );
  
                        return $handler->makeEmptyContent();
                $content = $rev ? $rev->getContent( Revision::RAW ) : null;
  
                if ( $content === false || $content === null ) {
 -                      if ( !$this->contentModel ) $this->contentModel = $this->getTitle()->getContentModel();
 +                      if ( !$this->contentModel ) {
 +                              $this->contentModel = $this->getTitle()->getContentModel();
 +                      }
                        $handler = ContentHandler::getForModelID( $this->contentModel );
  
                        return $handler->makeEmptyContent();
         * marked HttpOnly. The JavaScript code converts the cookie to a wgPostEdit config
         * variable.
         *
 -       * Since WebResponse::setcookie does not allow forcing HttpOnly for a single
 -       * cookie, we have to use PHP's setcookie() directly.
 -       *
         * We use a path of '/' since wgCookiePath is not exposed to JS
         *
         * If the variable were set on the server, it would be cached, which is unwanted
         * since the post-edit state should only apply to the load right after the save.
         */
        protected function setPostEditCookie() {
 -              global $wgCookiePrefix, $wgCookieDomain;
                $revisionId = $this->mArticle->getLatest();
                $postEditKey = self::POST_EDIT_COOKIE_KEY_PREFIX . $revisionId;
  
 -              setcookie( $wgCookiePrefix . $postEditKey, '1', time() + self::POST_EDIT_COOKIE_DURATION, '/', $wgCookieDomain );
 +              $response = RequestContext::getMain()->getRequest()->response();
 +              $response->setcookie( $postEditKey, '1', time() + self::POST_EDIT_COOKIE_DURATION, array(
 +                      'path' => '/',
 +                      'httpOnly' => false,
 +              ) );
        }
  
        /**
  
                        case self::AS_SUCCESS_NEW_ARTICLE:
                                $query = $resultDetails['redirect'] ? 'redirect=no' : '';
 -                              $anchor = isset ( $resultDetails['sectionanchor'] ) ? $resultDetails['sectionanchor'] : '';
 +                              $anchor = isset( $resultDetails['sectionanchor'] ) ? $resultDetails['sectionanchor'] : '';
                                $wgOut->redirect( $this->mTitle->getFullURL( $query ) . $anchor );
                                return false;
  
  
                # Check for spam
                $match = self::matchSummarySpamRegex( $this->summary );
 +              if ( $match === false && $this->section == 'new' ) {
 +                      if ( $this->sectiontitle !== '' ) {
 +                              $match = self::matchSpamRegex( $this->sectiontitle );
 +                      } else {
 +                              $match = self::matchSpamRegex( $this->summary );
 +                      }
 +              }
                if ( $match === false ) {
                        $match = self::matchSpamRegex( $this->textbox1 );
                }
                                return $status;
                        }
  
 -                      # Don't save a new article if it's blank.
 -                      if ( $this->textbox1 == '' ) {
 +                      // Don't save a new page if it's blank or if it's a MediaWiki:
 +                      // message with content equivalent to default (allow empty pages
 +                      // in this case to disable messages, see bug 50124)
 +                      $defaultMessageText = $this->mTitle->getDefaultMessageText();
 +                      if( $this->mTitle->getNamespace() === NS_MEDIAWIKI && $defaultMessageText !== false ) {
 +                              $defaultText = $defaultMessageText;
 +                      } else {
 +                              $defaultText = '';
 +                      }
 +
 +                      if ( $this->textbox1 === $defaultText ) {
                                $status->setResult( false, self::AS_BLANK_ARTICLE );
                                wfProfileOut( __METHOD__ );
                                return $status;
        protected function updateWatchlist() {
                global $wgUser;
  
 -              if ( $wgUser->isLoggedIn() && $this->watchthis != $wgUser->isWatched( $this->mTitle ) ) {
 +              if ( $wgUser->isLoggedIn()
 +                      && $this->watchthis != $wgUser->isWatched( $this->mTitle, WatchedItem::IGNORE_USER_RIGHTS )
 +              ) {
                        $fname = __METHOD__;
                        $title = $this->mTitle;
                        $watch = $this->watchthis;
                        $dbw = wfGetDB( DB_MASTER );
                        $dbw->onTransactionIdle( function() use ( $dbw, $title, $watch, $wgUser, $fname ) {
                                $dbw->begin( $fname );
 -                              if ( $watch ) {
 -                                      WatchAction::doWatch( $title, $wgUser );
 -                              } else {
 -                                      WatchAction::doUnwatch( $title, $wgUser );
 -                              }
 +                              WatchAction::doWatchOrUnwatch( $watch, $title, $wgUser );
                                $dbw->commit( $fname );
                        } );
                }
                if ( $wgUser->getOption( 'uselivepreview', false ) ) {
                        $wgOut->addModules( 'mediawiki.action.edit.preview' );
                }
 +
 +              if ( $wgUser->getOption( 'useeditwarning', false ) ) {
 +                      $wgOut->addModules( 'mediawiki.action.edit.editWarning' );
 +              }
 +
                // Bug #19334: textarea jumps when editing articles in IE8
                $wgOut->addStyle( 'common/IE80Fixes.css', 'screen', 'IE 8' );
  
                if ( $namespace == NS_MEDIAWIKI ) {
                        # Show a warning if editing an interface message
                        $wgOut->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1\n</div>", 'editinginterface' );
 -              } else if( $namespace == NS_FILE ) {
 +              } elseif ( $namespace == NS_FILE ) {
                        # Show a hint to shared repo
                        $file = wfFindFile( $this->mTitle );
 -                      if( $file && !$file->isLocal() ) {
 +                      if ( $file && !$file->isLocal() ) {
                                $descUrl = $file->getDescriptionUrl();
                                # there must be a description url to show a hint to shared repo
 -                              if( $descUrl ) {
 -                                      if( !$this->mTitle->exists() ) {
 -                                              $wgOut->wrapWikiMsg( "<div class=\"mw-sharedupload-desc-create\">\n$1\n</div>", array (
 +                              if ( $descUrl ) {
 +                                      if ( !$this->mTitle->exists() ) {
 +                                              $wgOut->wrapWikiMsg( "<div class=\"mw-sharedupload-desc-create\">\n$1\n</div>", array(
                                                                        'sharedupload-desc-create', $file->getRepo()->getDisplayName(), $descUrl
                                                ) );
                                        } else {
                        }
                }
  
 -              //@todo: add EditForm plugin interface and use it here!
 +              // @todo add EditForm plugin interface and use it here!
                //       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() ),
                }
  
                # When the summary is hidden, also hide them on preview/show changes
 -              if( $this->nosummary ) {
 +              if ( $this->nosummary ) {
                        $wgOut->addHTML( Html::hidden( 'nosummary', true ) );
                }
  
                $wgOut->addHTML( Html::rawElement( 'div', array( 'class' => 'hiddencats' ),
                        Linker::formatHiddenCategories( $this->mArticle->getHiddenCategories() ) ) );
  
 +              $wgOut->addModules( 'mediawiki.action.edit.collapsibleFooter' );
 +
                if ( $this->isConflict ) {
                        try {
                                $this->showConflict();
                }
  
                // Add edit notices
 -              $wgOut->addHTML( implode( "\n", $this->mTitle->getEditNotices() ) );
 +              $wgOut->addHTML( implode( "\n", $this->mTitle->getEditNotices( $this->oldid ) ) );
  
                if ( $this->isConflict ) {
                        $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1\n</div>", 'explainconflict' );
@@@ -2668,7 -2626,7 +2668,7 @@@ HTM
  
                $attribs = $customAttribs + array(
                        'accesskey' => ',',
 -                      'id'   => $name,
 +                      'id' => $name,
                        'cols' => $wgUser->getIntOption( 'cols' ),
                        'rows' => $wgUser->getIntOption( 'rows' ),
                        'style' => '' // avoid php notices when appending preferences (appending allows customAttribs['style'] to still work
  
                $oldtitlemsg = 'currentrev';
                # if message does not exist, show diff against the preloaded default
 -              if( $this->mTitle->getNamespace() == NS_MEDIAWIKI && !$this->mTitle->exists() ) {
 +              if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI && !$this->mTitle->exists() ) {
                        $oldtext = $this->mTitle->getDefaultMessageText();
 -                      if( $oldtext !== false ) {
 +                      if ( $oldtext !== false ) {
                                $oldtitlemsg = 'defaultmessagetext';
                                $oldContent = $this->toEditContent( $oldtext );
                        } else {
  
                        # don't parse non-wikitext pages, show message about preview
                        if ( $this->mTitle->isCssJsSubpage() || $this->mTitle->isCssOrJsPage() ) {
 -                              if( $this->mTitle->isCssJsSubpage() ) {
 +                              if ( $this->mTitle->isCssJsSubpage() ) {
                                        $level = 'user';
 -                              } elseif( $this->mTitle->isCssOrJsPage() ) {
 +                              } elseif ( $this->mTitle->isCssOrJsPage() ) {
                                        $level = 'site';
                                } else {
                                        $level = false;
  
                                # Used messages to make sure grep find them:
                                # Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview
 -                              if( $level && $format ) {
 +                              if ( $level && $format ) {
                                        $note = "<div id='mw-{$level}{$format}preview'>" . wfMessage( "{$level}{$format}preview" )->text() . "</div>";
                                }
                        }
                        '<h2 id="mw-previewheader">' . wfMessage( 'preview' )->escaped() . "</h2>" .
                        $wgOut->parse( $note, true, /* interface */true ) . $conflict . "</div>\n";
  
-               $pageLang = $this->mTitle->getPageLanguage();
-               $attribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
-                       'class' => 'mw-content-' . $pageLang->getDir() );
+               $pageViewLang = $this->mTitle->getPageViewLanguage();
+               $attribs = array( 'lang' => $pageViewLang->getHtmlCode(), 'dir' => $pageViewLang->getDir(),
+                       'class' => 'mw-content-' . $pageViewLang->getDir() );
                $previewHTML = Html::rawElement( 'div', $attribs, $previewHTML );
  
                wfProfileOut( __METHOD__ );
                        $minorLabel = wfMessage( 'minoredit' )->parse();
                        if ( $wgUser->isAllowed( 'minoredit' ) ) {
                                $attribs = array(
 -                                      'tabindex'  => ++$tabindex,
 +                                      'tabindex' => ++$tabindex,
                                        'accesskey' => wfMessage( 'accesskey-minoredit' )->text(),
 -                                      'id'        => 'wpMinoredit',
 +                                      'id' => 'wpMinoredit',
                                );
                                $checkboxes['minor'] =
                                        Xml::check( 'wpMinoredit', $checked['minor'], $attribs ) .
                $checkboxes['watch'] = '';
                if ( $wgUser->isLoggedIn() ) {
                        $attribs = array(
 -                              'tabindex'  => ++$tabindex,
 +                              'tabindex' => ++$tabindex,
                                'accesskey' => wfMessage( 'accesskey-watch' )->text(),
 -                              'id'        => 'wpWatchthis',
 +                              'id' => 'wpWatchthis',
                        );
                        $checkboxes['watch'] =
                                Xml::check( 'wpWatchthis', $checked['watch'], $attribs ) .
                $buttons = array();
  
                $temp = array(
 -                      'id'        => 'wpSave',
 -                      'name'      => 'wpSave',
 -                      'type'      => 'submit',
 -                      'tabindex'  => ++$tabindex,
 -                      'value'     => wfMessage( 'savearticle' )->text(),
 +                      'id' => 'wpSave',
 +                      'name' => 'wpSave',
 +                      'type' => 'submit',
 +                      'tabindex' => ++$tabindex,
 +                      'value' => wfMessage( 'savearticle' )->text(),
                        'accesskey' => wfMessage( 'accesskey-save' )->text(),
 -                      'title'     => wfMessage( 'tooltip-save' )->text() . ' [' . wfMessage( 'accesskey-save' )->text() . ']',
 +                      'title' => wfMessage( 'tooltip-save' )->text() . ' [' . wfMessage( 'accesskey-save' )->text() . ']',
                );
                $buttons['save'] = Xml::element( 'input', $temp, '' );
  
                ++$tabindex; // use the same for preview and live preview
                $temp = array(
 -                      'id'        => 'wpPreview',
 -                      'name'      => 'wpPreview',
 -                      'type'      => 'submit',
 -                      'tabindex'  => $tabindex,
 -                      'value'     => wfMessage( 'showpreview' )->text(),
 +                      'id' => 'wpPreview',
 +                      'name' => 'wpPreview',
 +                      'type' => 'submit',
 +                      'tabindex' => $tabindex,
 +                      'value' => wfMessage( 'showpreview' )->text(),
                        'accesskey' => wfMessage( 'accesskey-preview' )->text(),
 -                      'title'     => wfMessage( 'tooltip-preview' )->text() . ' [' . wfMessage( 'accesskey-preview' )->text() . ']',
 +                      'title' => wfMessage( 'tooltip-preview' )->text() . ' [' . wfMessage( 'accesskey-preview' )->text() . ']',
                );
                $buttons['preview'] = Xml::element( 'input', $temp, '' );
                $buttons['live'] = '';
  
                $temp = array(
 -                      'id'        => 'wpDiff',
 -                      'name'      => 'wpDiff',
 -                      'type'      => 'submit',
 -                      'tabindex'  => ++$tabindex,
 -                      'value'     => wfMessage( 'showdiff' )->text(),
 +                      'id' => 'wpDiff',
 +                      'name' => 'wpDiff',
 +                      'type' => 'submit',
 +                      'tabindex' => ++$tabindex,
 +                      'value' => wfMessage( 'showdiff' )->text(),
                        'accesskey' => wfMessage( 'accesskey-diff' )->text(),
 -                      'title'     => wfMessage( 'tooltip-diff' )->text() . ' [' . wfMessage( 'accesskey-diff' )->text() . ']',
 +                      'title' => wfMessage( 'tooltip-diff' )->text() . ' [' . wfMessage( 'accesskey-diff' )->text() . ']',
                );
                $buttons['diff'] = Xml::element( 'input', $temp, '' );
  
                global $wgOut, $wgLang;
                $this->textbox2 = $this->textbox1;
  
 -              if( is_array( $match ) ) {
 +              if ( is_array( $match ) ) {
                        $match = $wgLang->listToText( $match );
                }
                $wgOut->prepareErrorPage( wfMessage( 'spamprotectiontitle' ) );