(bug 28978) jquery.autoEllipsis cache doesn't take position into account, leads to...
[lhc/web/wiklou.git] / includes / EditPage.php
index bab93b0..d8fcdd7 100644 (file)
@@ -42,7 +42,14 @@ class EditPage {
        const AS_IMAGE_REDIRECT_ANON       = 233;
        const AS_IMAGE_REDIRECT_LOGGED     = 234;
 
+       /**
+        * @var Article
+        */
        var $mArticle;
+
+       /**
+        * @var Title
+        */
        var $mTitle;
        private $mContextTitle = null;
        var $action;
@@ -50,6 +57,7 @@ class EditPage {
        var $isCssJsSubpage = false;
        var $isCssSubpage = false;
        var $isJsSubpage = false;
+       var $isNew = false; // new page or new section
        var $deletedSinceEdit;
        var $formtype;
        var $firsttime;
@@ -57,6 +65,7 @@ class EditPage {
        var $mTokenOk = false;
        var $mTokenOkExceptSuffix = false;
        var $mTriedSave = false;
+       var $incompleteForm = false;
        var $tooBig = false;
        var $kblength = false;
        var $missingComment = false;
@@ -365,11 +374,13 @@ class EditPage {
                        $this->preview = true;
                }
 
-               $wgOut->addModules( array( 'mediawiki.legacy.edit', 'mediawiki.action.edit' ) );
+               $wgOut->addModules( array( 'mediawiki.action.edit' ) );
 
                if ( $wgUser->getOption( 'uselivepreview', false ) ) {
                        $wgOut->addModules( 'mediawiki.legacy.preview' );
                }
+               // Bug #19334: textarea jumps when editing articles in IE8
+               $wgOut->addStyle( 'common/IE80Fixes.css', 'screen', 'IE 8' );
 
                $permErrors = $this->getEditPermissionErrors();
                if ( $permErrors ) {
@@ -405,10 +416,11 @@ class EditPage {
 
                $this->isConflict = false;
                // css / js subpages of user pages get a special treatment
-               $this->isCssJsSubpage      = $this->mTitle->isCssJsSubpage();
-               $this->isCssSubpage        = $this->mTitle->isCssSubpage();
-               $this->isJsSubpage         = $this->mTitle->isJsSubpage();
+               $this->isCssJsSubpage       = $this->mTitle->isCssJsSubpage();
+               $this->isCssSubpage         = $this->mTitle->isCssSubpage();
+               $this->isJsSubpage          = $this->mTitle->isJsSubpage();
                $this->isWrongCaseCssJsPage = $this->isWrongCaseCssJsPage();
+               $this->isNew                = !$this->mTitle->exists() || $this->section == 'new';
 
                # Show applicable editing introductions
                if ( $this->formtype == 'initial' || $this->firsttime )
@@ -520,7 +532,7 @@ class EditPage {
                } elseif ( $wgRequest->getVal( 'preview' ) == 'no' ) {
                        // Explicit override from request
                        return false;
-               } elseif ( $this->section == 'new' ) {
+               } elseif ( $this->section == 'new' ) { 
                        // Nothing *to* preview for new sections
                        return false;
                } elseif ( ( $wgRequest->getVal( 'preload' ) !== null || $this->mTitle->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
@@ -599,7 +611,17 @@ class EditPage {
 
                        $this->scrolltop = $request->getIntOrNull( 'wpScrolltop' );
 
-                       if ( is_null( $this->edittime ) ) {
+                       if ($this->textbox1 === '' && $request->getVal( 'wpTextbox1' ) === null) {
+                               // wpTextbox1 field is missing, possibly due to being "too big"
+                               // according to some filter rules such as Suhosin's setting for
+                               // suhosin.request.max_value_length (d'oh)
+                               $this->incompleteForm = true;
+                       } else {
+                               // edittime should be one of our last fields; if it's missing,
+                               // the submission probably broke somewhere in the middle.
+                               $this->incompleteForm = is_null( $this->edittime );
+                       }
+                       if ( $this->incompleteForm ) {
                                # If the form is incomplete, force to preview.
                                wfDebug( __METHOD__ . ": Form data appears to be incomplete\n" );
                                wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
@@ -956,7 +978,7 @@ class EditPage {
                        }
 
                        $text = $this->textbox1;
-                       if ( $this->section == 'new' && $this->summary != '' ) {
+                       if ( $this->section == 'new' && $this->summary != '' ) { 
                                $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->summary ) . "\n\n" . $text;
                        }
 
@@ -967,7 +989,6 @@ class EditPage {
                        # Article exists. Check for edit conflict.
 
                        $this->mArticle->clear(); # Force reload of dates, etc.
-                       $this->mArticle->forUpdate( true ); # Lock the article
 
                        wfDebug( "timestamp: {$this->mArticle->getTimestamp()}, edittime: {$this->edittime}\n" );
 
@@ -1039,7 +1060,7 @@ class EditPage {
                        }
 
                        # Handle the user preference to force summaries here, but not for null edits
-                       if ( $this->section != 'new' && !$this->allowBlankSummary && 0 != strcmp( $oldtext, $text )
+                       if ( $this->section != 'new' && !$this->allowBlankSummary && 0 != strcmp( $oldtext, $text ) 
                                && !Title::newFromRedirect( $text ) ) # check if it's not a redirect
                        {
                                if ( md5( $this->summary ) == $this->autoSumm ) {
@@ -1050,7 +1071,7 @@ class EditPage {
                        }
 
                        # And a similar thing for new sections
-                       if ( $this->section == 'new' && !$this->allowBlankSummary ) {
+                       if ( $this->section == 'new' && !$this->allowBlankSummary ) { 
                                if ( trim( $this->summary ) == '' ) {
                                        $this->missingSummary = true;
                                        wfProfileOut( __METHOD__ );
@@ -1061,7 +1082,7 @@ class EditPage {
                        # All's well
                        wfProfileIn( __METHOD__ . '-sectionanchor' );
                        $sectionanchor = '';
-                       if ( $this->section == 'new' ) {
+                       if ( $this->section == 'new' ) { 
                                if ( $this->textbox1 == '' ) {
                                        $this->missingComment = true;
                                        wfProfileOut( __METHOD__ . '-sectionanchor' );
@@ -1109,7 +1130,7 @@ class EditPage {
 
                $flags = EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
                        ( $new ? EDIT_NEW : EDIT_UPDATE ) |
-                       ( $this->minoredit ? EDIT_MINOR : 0 ) |
+                       ( ( $this->minoredit && !$this->isNew ) ? EDIT_MINOR : 0 ) |
                        ( $bot ? EDIT_FORCE_BOT : 0 );
 
                $status = $this->mArticle->doEdit( $text, $this->summary, $flags );
@@ -1134,9 +1155,9 @@ class EditPage {
                        $dbw = wfGetDB( DB_MASTER );
                        $dbw->begin();
                        if ( $this->watchthis ) {
-                               $this->mArticle->doWatch();
+                               Action::factory( 'watch', $this->mArticle )->execute();
                        } else {
-                               $this->mArticle->doUnwatch();
+                               Action::factory( 'unwatch', $this->mArticle )->execute();
                        }
                        $dbw->commit();
                }
@@ -1218,7 +1239,7 @@ class EditPage {
                        # Already watched
                        $this->watchthis = true;
                }
-               if ( $wgUser->getOption( 'minordefault' ) ) $this->minoredit = true;
+               if ( $wgUser->getOption( 'minordefault' ) && !$this->isNew ) $this->minoredit = true;
                if ( $this->textbox1 === false ) return false;
                wfProxyCheck();
                return true;
@@ -1249,9 +1270,8 @@ class EditPage {
 
        /**
         * Send the edit form and related headers to $wgOut
-        * @param $formCallback Optional callable that takes an OutputPage
-        *                      parameter; will be called during form output
-        *                      near the top, for captchas and the like.
+        * @param $formCallback Callback that takes an OutputPage parameter; will be called
+        *     during form output near the top, for captchas and the like.
         */
        function showEditForm( $formCallback = null ) {
                global $wgOut, $wgUser;
@@ -1316,7 +1336,6 @@ class EditPage {
                        // @todo move this to a cleaner conditional instead of blanking a variable
                }
                $wgOut->addHTML( <<<HTML
-{$toolbar}
 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
 HTML
 );
@@ -1333,12 +1352,15 @@ HTML
                if ( $this->wasDeletedSinceLastEdit() && 'save' == $this->formtype ) {
                        $username = $this->lastDelete->user_name;
                        $comment = $this->lastDelete->log_comment;
-       
+
                        // It is better to not parse the comment at all than to have templates expanded in the middle
                        // TODO: can the checkLabel be moved outside of the div so that wrapWikiMsg could be used?
+                       $key = $comment === ''
+                               ? 'confirmrecreate-noreason'
+                               : 'confirmrecreate';
                        $wgOut->addHTML(
                                '<div class="mw-confirm-recreate">' .
-                               wfMsgExt( 'confirmrecreate', 'parseinline', $username, "<nowiki>$comment</nowiki>" ) .
+                               wfMsgExt( $key, 'parseinline', $username, "<nowiki>$comment</nowiki>" ) .
                                Xml::checkLabel( wfMsg( 'recreate' ), 'wpRecreate', 'wpRecreate', false,
                                        array( 'title' => $sk->titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' )
                                ) .
@@ -1367,6 +1389,8 @@ HTML
                }
 
                $wgOut->addHTML( $this->editFormTextBeforeContent );
+               
+               $wgOut->addHTML( $toolbar );
 
                if ( $this->isConflict ) {
                        // In an edit conflict bypass the overrideable content form method
@@ -1825,7 +1849,8 @@ HTML
                // Allow for site and per-namespace customization of contribution/copyright notice.
                wfRunHooks( 'EditPageCopyrightWarning', array( $this->mTitle, &$copywarnMsg ) );
 
-               return "<div id=\"editpage-copywarn\">\n" . call_user_func_array("wfMsgNoTrans", $copywarnMsg) . "\n</div>";
+               return "<div id=\"editpage-copywarn\">\n" .
+                       call_user_func_array("wfMsgNoTrans", $copywarnMsg) . "\n</div>";
        }
 
        protected function showStandardInputs( &$tabindex = 2 ) {
@@ -1878,20 +1903,20 @@ HTML
                $data = $dbr->selectRow(
                        array( 'logging', 'user' ),
                        array( 'log_type',
-                              'log_action',
-                              'log_timestamp',
-                              'log_user',
-                              'log_namespace',
-                              'log_title',
-                              'log_comment',
-                              'log_params',
-                              'log_deleted',
-                              'user_name' ),
+                                  'log_action',
+                                  'log_timestamp',
+                                  'log_user',
+                                  'log_namespace',
+                                  'log_title',
+                                  'log_comment',
+                                  'log_params',
+                                  'log_deleted',
+                                  'user_name' ),
                        array( 'log_namespace' => $this->mTitle->getNamespace(),
-                              'log_title' => $this->mTitle->getDBkey(),
-                              'log_type' => 'delete',
-                              'log_action' => 'delete',
-                              'user_id=log_user' ),
+                                  'log_title' => $this->mTitle->getDBkey(),
+                                  'log_type' => 'delete',
+                                  'log_action' => 'delete',
+                                  'user_id=log_user' ),
                        __METHOD__,
                        array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' )
                );
@@ -1920,6 +1945,8 @@ HTML
                        } else {
                                $note = wfMsg( 'session_fail_preview' );
                        }
+               } else if ( $this->incompleteForm ) {
+                       $note = wfMsg( 'edit_form_incomplete' );
                } else {
                        $note = wfMsg( 'previewnote' );
                }
@@ -2100,7 +2127,7 @@ HTML
         * Produce the stock "your edit contains spam" page
         *
         * @param $match Text which triggered one or more filters
-        * @deprecated Use method spamPageWithContent() instead
+        * @deprecated since 1.17 Use method spamPageWithContent() instead
         */
        static function spamPage( $match = false ) {
                global $wgOut, $wgTitle;
@@ -2209,14 +2236,6 @@ HTML
                return true;
        }
 
-       /**
-        * @deprecated use $wgParser->stripSectionName()
-        */
-       function pseudoParseSectionAnchor( $text ) {
-               global $wgParser;
-               return $wgParser->stripSectionName( $text );
-       }
-
        /**
         * Format an anchor fragment as it would appear for a given section name
         * @param $text String
@@ -2242,16 +2261,19 @@ HTML
                $imagesAvailable = $wgEnableUploads || count( $wgForeignFileRepos );
 
                /**
-
-                * toolarray an array of arrays which each include the filename of
-                * the button image (without path), the opening tag, the closing tag,
-                * and optionally a sample text that is inserted between the two when no
-                * selection is highlighted.
-                * The tip text is shown when the user moves the mouse over the button.
+                * $toolarray is an array of arrays each of which includes the
+                * filename of the button image (without path), the opening
+                * tag, the closing tag, optionally a sample text that is
+                * inserted between the two when no selection is highlighted
+                * and an option to select which switches the automatic
+                * selection of inserted text (default is true, see
+                * mw-editbutton-image).  The tip text is shown when the user
+                * moves the mouse over the button.
                 *
-                * Already here are accesskeys (key), which are not used yet until someone
-                * can figure out a way to make them work in IE. However, we should make
-                * sure these keys are not defined on the edit page.
+                * Also here: accesskeys (key), which are not used yet until
+                * someone can figure out a way to make them work in
+                * IE. However, we should make sure these keys are not defined
+                * on the edit page.
                 */
                $toolarray = array(
                        array(
@@ -2306,7 +2328,8 @@ HTML
                                'close'  => ']]',
                                'sample' => wfMsg( 'image_sample' ),
                                'tip'    => wfMsg( 'image_tip' ),
-                               'key'    => 'D'
+                               'key'    => 'D',
+                               'select' => true
                        ) : false,
                        $imagesAvailable ? array(
                                'image'  => $wgLang->getImageFile( 'button-media' ),
@@ -2362,6 +2385,10 @@ HTML
                                continue;
                        }
 
+                       if( !isset( $tool['select'] ) ) {
+                         $tool['select'] = true;
+                       }
+
                        $params = array(
                                $image = $wgStylePath . '/common/images/' . $tool['image'],
                                // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
@@ -2377,13 +2404,12 @@ HTML
 
                        $paramList = implode( ',',
                                array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
-                       $script .= "addButton($paramList);\n";
+                       $script .= "mw.toolbar.addButton($paramList);\n";
                }
-               
                $wgOut->addScript( Html::inlineScript(
-                       "if ( window.mediaWiki ) { jQuery(function(){{$script}}); }"
+                       "if ( window.mediaWiki ) {{$script}}"
                ) );
-               
+
                $toolbar .= "\n</div>";
 
                wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) );
@@ -2407,19 +2433,22 @@ HTML
 
                $checkboxes = array();
 
-               $checkboxes['minor'] = '';
-               $minorLabel = wfMsgExt( 'minoredit', array( 'parseinline' ) );
-               if ( $wgUser->isAllowed( 'minoredit' ) ) {
-                       $attribs = array(
-                               'tabindex'  => ++$tabindex,
-                               'accesskey' => wfMsg( 'accesskey-minoredit' ),
-                               'id'        => 'wpMinoredit',
-                       );
-                       $checkboxes['minor'] =
-                               Xml::check( 'wpMinoredit', $checked['minor'], $attribs ) .
-                               "&#160;<label for='wpMinoredit' id='mw-editpage-minoredit'" .
-                               Xml::expandAttributes( array( 'title' => $skin->titleAttrib( 'minoredit', 'withaccess' ) ) ) .
-                               ">{$minorLabel}</label>";
+               // don't show the minor edit checkbox if it's a new page or section
+               if ( !$this->isNew ) {
+                       $checkboxes['minor'] = '';
+                       $minorLabel = wfMsgExt( 'minoredit', array( 'parseinline' ) );
+                       if ( $wgUser->isAllowed( 'minoredit' ) ) {
+                               $attribs = array(
+                                       'tabindex'  => ++$tabindex,
+                                       'accesskey' => wfMsg( 'accesskey-minoredit' ),
+                                       'id'        => 'wpMinoredit',
+                               );
+                               $checkboxes['minor'] =
+                                       Xml::check( 'wpMinoredit', $checked['minor'], $attribs ) .
+                                       "&#160;<label for='wpMinoredit' id='mw-editpage-minoredit'" .
+                                       Xml::expandAttributes( array( 'title' => $skin->titleAttrib( 'minoredit', 'withaccess' ) ) ) .
+                                       ">{$minorLabel}</label>";
+                       }
                }
 
                $watchLabel = wfMsgExt( 'watchthis', array( 'parseinline' ) );
@@ -2628,7 +2657,7 @@ HTML
                $result = "";
                $working = 0;
                for( $i = 0; $i < strlen( $invalue ); $i++ ) {
-                       $bytevalue = ord( $invalue{$i} );
+                       $bytevalue = ord( $invalue[$i] );
                        if ( $bytevalue <= 0x7F ) { //0xxx xxxx
                                $result .= chr( $bytevalue );
                                $bytesleft = 0;
@@ -2665,13 +2694,13 @@ HTML
        function unmakesafe( $invalue ) {
                $result = "";
                for( $i = 0; $i < strlen( $invalue ); $i++ ) {
-                       if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+3} != '0' ) ) {
+                       if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue[$i+3] != '0' ) ) {
                                $i += 3;
                                $hexstring = "";
                                do {
-                                       $hexstring .= $invalue{$i};
+                                       $hexstring .= $invalue[$i];
                                        $i++;
-                               } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
+                               } while( ctype_xdigit( $invalue[$i] ) && ( $i < strlen( $invalue ) ) );
 
                                // Do some sanity checks. These aren't needed for reversability,
                                // but should help keep the breakage down if the editor
@@ -2715,7 +2744,7 @@ HTML
                switch ( $value ) {
                        case self::AS_HOOK_ERROR_EXPECTED:
                        case self::AS_CONTENT_TOO_BIG:
-                       case self::AS_ARTICLE_WAS_DELETED:
+                       case self::AS_ARTICLE_WAS_DELETED:
                        case self::AS_CONFLICT_DETECTED:
                        case self::AS_SUMMARY_NEEDED:
                        case self::AS_TEXTBOX_EMPTY:
@@ -2765,22 +2794,22 @@ HTML
                                $this->userNotLoggedInPage();
                                return false;
 
-                       case self::AS_READ_ONLY_PAGE_LOGGED:
-                       case self::AS_READ_ONLY_PAGE:
-                               $wgOut->readOnlyPage();
-                               return false;
+                       case self::AS_READ_ONLY_PAGE_LOGGED:
+                       case self::AS_READ_ONLY_PAGE:
+                               $wgOut->readOnlyPage();
+                               return false;
 
-                       case self::AS_RATE_LIMITED:
-                               $wgOut->rateLimited();
-                               return false;
+                       case self::AS_RATE_LIMITED:
+                               $wgOut->rateLimited();
+                               return false;
 
-                       case self::AS_NO_CREATE_PERMISSION:
-                               $this->noCreatePermission();
-                               return;
+                       case self::AS_NO_CREATE_PERMISSION:
+                               $this->noCreatePermission();
+                               return;
 
                        case self::AS_BLANK_ARTICLE:
-                               $wgOut->redirect( $this->getContextTitle()->getFullURL() );
-                               return false;
+                               $wgOut->redirect( $this->getContextTitle()->getFullURL() );
+                               return false;
 
                        case self::AS_IMAGE_REDIRECT_LOGGED:
                                $wgOut->permissionRequired( 'upload' );