(bug 28978) jquery.autoEllipsis cache doesn't take position into account, leads to...
[lhc/web/wiklou.git] / includes / EditPage.php
index a79e272..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;
@@ -366,7 +374,7 @@ 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' );
@@ -408,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 )
@@ -523,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' ) ) {
@@ -969,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;
                        }
 
@@ -980,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" );
 
@@ -1052,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 ) {
@@ -1063,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__ );
@@ -1074,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' );
@@ -1122,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 );
@@ -1147,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();
                }
@@ -1231,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;
@@ -1262,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;
@@ -1329,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
 );
@@ -1349,9 +1355,12 @@ HTML
 
                        // 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' )
                                ) .
@@ -1380,6 +1389,8 @@ HTML
                }
 
                $wgOut->addHTML( $this->editFormTextBeforeContent );
+               
+               $wgOut->addHTML( $toolbar );
 
                if ( $this->isConflict ) {
                        // In an edit conflict bypass the overrideable content form method
@@ -2116,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;
@@ -2225,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
@@ -2401,11 +2404,10 @@ 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>";
@@ -2431,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' ) );
@@ -2652,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;
@@ -2689,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