Add/update function level parameter documentation
[lhc/web/wiklou.git] / includes / EditPage.php
index 052a783..5979ed4 100644 (file)
@@ -36,11 +36,6 @@ class EditPage {
         */
        const AS_HOOK_ERROR                = 210;
 
-       /**
-        * Status: The filter function set in $wgFilterCallback returned true (= block it)
-        */
-       const AS_FILTERING                 = 211;
-
        /**
         * Status: A hook function returned an error
         */
@@ -144,6 +139,11 @@ class EditPage {
         */
        const AS_IMAGE_REDIRECT_LOGGED     = 234;
 
+       /**
+        * HTML id and name for the beginning of the edit form.
+        */
+       const EDITFORM_ID                  = 'editform';
+
        /**
         * @var Article
         */
@@ -819,7 +819,7 @@ class EditPage {
 
                                                        # If we just undid one rev, use an autosummary
                                                        $firstrev = $oldrev->getNext();
-                                                       if ( $firstrev->getId() == $undo ) {
+                                                       if ( $firstrev && $firstrev->getId() == $undo ) {
                                                                $undoSummary = wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
                                                                if ( $this->summary === '' ) {
                                                                        $this->summary = $undoSummary;
@@ -985,7 +985,6 @@ class EditPage {
                                return true;
 
                        case self::AS_HOOK_ERROR:
-                       case self::AS_FILTERING:
                                return false;
 
                        case self::AS_SUCCESS_NEW_ARTICLE:
@@ -1057,8 +1056,7 @@ class EditPage {
         * AS_CONTENT_TOO_BIG and AS_BLOCKED_PAGE_FOR_USER. All that stuff needs to be cleaned up some time.
         */
        function internalAttemptSave( &$result, $bot = false ) {
-               global $wgFilterCallback, $wgUser, $wgRequest, $wgParser;
-               global $wgMaxArticleSize;
+               global $wgUser, $wgRequest, $wgParser, $wgMaxArticleSize;
 
                $status = Status::newGood();
 
@@ -1104,13 +1102,6 @@ class EditPage {
                        wfProfileOut( __METHOD__ );
                        return $status;
                }
-               if ( $wgFilterCallback && is_callable( $wgFilterCallback ) && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section, $this->hookError, $this->summary ) ) {
-                       # Error messages or other handling should be performed by the filter function
-                       $status->setResult( false, self::AS_FILTERING );
-                       wfProfileOut( __METHOD__ . '-checks' );
-                       wfProfileOut( __METHOD__ );
-                       return $status;
-               }
                if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1, $this->section, &$this->hookError, $this->summary ) ) ) {
                        # Error messages etc. could be handled within the hook...
                        $status->fatal( 'hookaborted' );
@@ -1188,9 +1179,10 @@ class EditPage {
 
                wfProfileOut( __METHOD__ . '-checks' );
 
-               # If article is new, insert it.
-               $aid = $this->mTitle->getArticleID( Title::GAID_FOR_UPDATE );
-               $new = ( $aid == 0 );
+               // Use SELECT FOR UPDATE here to avoid transaction collision in
+               // WikiPage::updateRevisionOn() and ending in the self::AS_END case.
+               $this->mArticle->loadPageData( 'forupdate' );
+               $new = !$this->mArticle->exists();
 
                if ( $new ) {
                        // Late check for create permission, just in case *PARANOIA*
@@ -1259,10 +1251,7 @@ class EditPage {
                } else {
 
                        # Article exists. Check for edit conflict.
-
-                       $this->mArticle->clear(); # Force reload of dates, etc.
                        $timestamp = $this->mArticle->getTimestamp();
-
                        wfDebug( "timestamp: {$timestamp}, edittime: {$this->edittime}\n" );
 
                        if ( $timestamp != $this->edittime ) {
@@ -1603,21 +1592,21 @@ class EditPage {
                # Enabled article-related sidebar, toplinks, etc.
                $wgOut->setArticleRelated( true );
 
+               $contextTitle = $this->getContextTitle();
                if ( $this->isConflict ) {
-                       $wgOut->setPageTitle( wfMessage( 'editconflict', $this->getContextTitle()->getPrefixedText() ) );
-               } elseif ( $this->section != '' ) {
+                       $msg = 'editconflict';
+               } elseif ( $contextTitle->exists() && $this->section != '' ) {
                        $msg = $this->section == 'new' ? 'editingcomment' : 'editingsection';
-                       $wgOut->setPageTitle( wfMessage( $msg, $this->getContextTitle()->getPrefixedText() ) );
                } else {
-                       # Use the title defined by DISPLAYTITLE magic word when present
-                       if ( isset( $this->mParserOutput )
-                        && ( $dt = $this->mParserOutput->getDisplayTitle() ) !== false ) {
-                               $title = $dt;
-                       } else {
-                               $title = $this->getContextTitle()->getPrefixedText();
-                       }
-                       $wgOut->setPageTitle( wfMessage( 'editing', $title ) );
+                       $msg = $contextTitle->exists() || ( $contextTitle->getNamespace() == NS_MEDIAWIKI && $contextTitle->getDefaultMessageText() !== false ) ?
+                               'editing' : 'creating';
+               }
+               # Use the title defined by DISPLAYTITLE magic word when present
+               $displayTitle = isset( $this->mParserOutput ) ? $this->mParserOutput->getDisplayTitle() : false;
+               if ( $displayTitle === false ) {
+                       $displayTitle = $contextTitle->getPrefixedText();
                }
+               $wgOut->setPageTitle( wfMessage( $msg, $displayTitle ) );
        }
 
        /**
@@ -1769,7 +1758,7 @@ class EditPage {
                        }
                }
 
-               $wgOut->addHTML( Html::openElement( 'form', array( 'id' => 'editform', 'name' => 'editform',
+               $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' ) ) );
 
@@ -1801,6 +1790,11 @@ class EditPage {
                        );
                }
 
+               # When the summary is hidden, also hide them on preview/show changes
+               if( $this->nosummary ) {
+                       $wgOut->addHTML( Html::hidden( 'nosummary', true ) );
+               }
+
                # If a blank edit summary was previously provided, and the appropriate
                # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
                # user being bounced back more than once in the event that a summary
@@ -1908,7 +1902,7 @@ class EditPage {
 
                # Optional notices on a per-namespace and per-page basis
                $editnotice_ns = 'editnotice-' . $this->mTitle->getNamespace();
-               $editnotice_ns_message = wfMessage( $editnotice_ns )->inContentLanguage();
+               $editnotice_ns_message = wfMessage( $editnotice_ns );
                if ( $editnotice_ns_message->exists() ) {
                        $wgOut->addWikiText( $editnotice_ns_message->plain() );
                }
@@ -1917,7 +1911,7 @@ class EditPage {
                        $editnotice_base = $editnotice_ns;
                        while ( count( $parts ) > 0 ) {
                                $editnotice_base .= '-' . array_shift( $parts );
-                               $editnotice_base_msg = wfMessage( $editnotice_base )->inContentLanguage();
+                               $editnotice_base_msg = wfMessage( $editnotice_base );
                                if ( $editnotice_base_msg->exists() ) {
                                        $wgOut->addWikiText( $editnotice_base_msg->plain() );
                                }
@@ -1925,7 +1919,7 @@ class EditPage {
                } else {
                        # Even if there are no subpages in namespace, we still don't want / in MW ns.
                        $editnoticeText = $editnotice_ns . '-' . str_replace( '/', '-', $this->mTitle->getDBkey() );
-                       $editnoticeMsg = wfMessage( $editnoticeText )->inContentLanguage();
+                       $editnoticeMsg = wfMessage( $editnoticeText );
                        if ( $editnoticeMsg->exists() ) {
                                $wgOut->addWikiText( $editnoticeMsg->plain() );
                        }
@@ -2330,7 +2324,16 @@ HTML
        function showDiff() {
                global $wgUser, $wgContLang, $wgParser, $wgOut;
 
-               $oldtext = $this->mArticle->getRawText();
+               $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';
+                       }
+               } else {
+                       $oldtext = $this->mArticle->getRawText();
+               }
                $newtext = $this->mArticle->replaceSection(
                        $this->section, $this->textbox1, $this->summary, $this->edittime );
 
@@ -2340,7 +2343,7 @@ HTML
                $newtext = $wgParser->preSaveTransform( $newtext, $this->mTitle, $wgUser, $popts );
 
                if ( $oldtext !== false  || $newtext != '' ) {
-                       $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) );
+                       $oldtitle = wfMsgExt( $oldtitlemsg, array( 'parseinline' ) );
                        $newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) );
 
                        $de = new DifferenceEngine( $this->mArticle->getContext() );
@@ -2536,7 +2539,7 @@ HTML
         * @return string
         */
        function getPreviewText() {
-               global $wgOut, $wgUser, $wgParser, $wgRawHtml;
+               global $wgOut, $wgUser, $wgParser, $wgRawHtml, $wgLang;
 
                wfProfileIn( __METHOD__ );
 
@@ -2564,7 +2567,8 @@ HTML
                } elseif ( $this->incompleteForm ) {
                        $note = wfMsg( 'edit_form_incomplete' );
                } else {
-                       $note = wfMsg( 'previewnote' );
+                       $note = wfMsg( 'previewnote' ) .
+                               ' [[#' . self::EDITFORM_ID . '|' . $wgLang->getArrow() . ' ' . wfMsg( 'continue-editing' ) . ']]';
                }
 
                $parserOptions = ParserOptions::newFromUser( $wgUser );
@@ -2574,9 +2578,7 @@ HTML
                $parserOptions->setIsSectionPreview( !is_null( $this->section ) && $this->section !== '' );
 
                # don't parse non-wikitext pages, show message about preview
-               # 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?
-
-               if ( $this->isCssJsSubpage || !$this->mTitle->isWikitextPage() ) {
+               if ( $this->mTitle->isCssJsSubpage() || !$this->mTitle->isWikitextPage() ) {
                        if ( $this->mTitle->isCssJsSubpage() ) {
                                $level = 'user';
                        } elseif ( $this->mTitle->isCssOrJsPage() ) {
@@ -2587,20 +2589,23 @@ HTML
 
                        # 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-code mw-css";
+                                       $class .= " mw-css";
                                } elseif ( preg_match( "/\\.js$/", $this->mTitle->getText() ) ) {
                                        $previewtext = "<div id='mw-{$level}jspreview'>\n" . wfMsg( "{$level}jspreview" ) . "\n</div>";
-                                       $class = "mw-code mw-js";
+                                       $class .= " mw-js";
                                } else {
                                        throw new MWException( 'A CSS/JS (sub)page but which is not css nor js!' );
                                }
+                               $parserOutput = $wgParser->parse( $previewtext, $this->mTitle, $parserOptions );
+                               $previewHTML = $parserOutput->getText();
+                       } else {
+                               $previewHTML = '';
                        }
 
-                       $parserOutput = $wgParser->parse( $previewtext, $this->mTitle, $parserOptions );
-                       $previewHTML = $parserOutput->mText;
                        $previewHTML .= "<pre class=\"$class\" dir=\"ltr\">\n" . htmlspecialchars( $this->textbox1 ) . "\n</pre>\n";
                } else {
                        $toparse = $this->textbox1;