Merge "(bug 46463) Mark edit preview as in page view language"
[lhc/web/wiklou.git] / includes / EditPage.php
index 519591c..17a1946 100644 (file)
@@ -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;
 
@@ -487,7 +487,7 @@ class EditPage {
                        // 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;
                }
 
@@ -521,6 +521,8 @@ class EditPage {
                $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 );
                }
@@ -540,7 +542,7 @@ class EditPage {
                        // 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 );
                }
@@ -621,6 +623,7 @@ class EditPage {
                $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' );
                }
 
@@ -897,7 +900,9 @@ class EditPage {
                                $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' );
@@ -932,7 +937,19 @@ class EditPage {
                                                        # 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 {
@@ -985,7 +1002,9 @@ class EditPage {
                }
                $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();
@@ -1007,7 +1026,9 @@ class EditPage {
                $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();
@@ -1157,20 +1178,20 @@ class EditPage {
         * 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,
+               ) );
        }
 
        /**
@@ -1213,7 +1234,7 @@ class EditPage {
 
                        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;
 
@@ -1381,6 +1402,13 @@ class EditPage {
 
                # 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 );
                }
@@ -1488,8 +1516,17 @@ class EditPage {
                                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;
@@ -1736,7 +1773,9 @@ class EditPage {
        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;
@@ -1745,11 +1784,7 @@ class EditPage {
                        $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 );
                        } );
                }
@@ -1889,6 +1924,11 @@ class EditPage {
                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' );
 
@@ -1928,15 +1968,15 @@ class EditPage {
                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 {
@@ -2126,7 +2166,7 @@ class EditPage {
                        }
                }
 
-               //@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() ),
@@ -2161,7 +2201,7 @@ class EditPage {
                }
 
                # When the summary is hidden, also hide them on preview/show changes
-               if( $this->nosummary ) {
+               if ( $this->nosummary ) {
                        $wgOut->addHTML( Html::hidden( 'nosummary', true ) );
                }
 
@@ -2239,6 +2279,8 @@ class EditPage {
                $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();
@@ -2282,7 +2324,7 @@ class EditPage {
                }
 
                // 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' );
@@ -2626,7 +2668,7 @@ HTML
 
                $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
@@ -2702,9 +2744,9 @@ HTML
 
                $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 {
@@ -3028,9 +3070,9 @@ HTML
 
                        # 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;
@@ -3046,7 +3088,7 @@ HTML
 
                                # 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>";
                                }
                        }
@@ -3314,9 +3356,9 @@ HTML
                        $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 ) .
@@ -3330,9 +3372,9 @@ HTML
                $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 ) .
@@ -3356,37 +3398,37 @@ HTML
                $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, '' );
 
@@ -3506,7 +3548,7 @@ HTML
                global $wgOut, $wgLang;
                $this->textbox2 = $this->textbox1;
 
-               if( is_array( $match ) ) {
+               if ( is_array( $match ) ) {
                        $match = $wgLang->listToText( $match );
                }
                $wgOut->prepareErrorPage( wfMessage( 'spamprotectiontitle' ) );