Genderize Special:Preferences
[lhc/web/wiklou.git] / includes / EditPage.php
index 00eb76f..292d2b7 100644 (file)
@@ -480,6 +480,7 @@ class EditPage {
                        throw new PermissionsError( $action, $permErrors );
                }
 
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->setPageTitle( wfMessage( 'viewsource-title', $this->getContextTitle()->getPrefixedText() ) );
                $wgOut->addBacklinkSubtitle( $this->getContextTitle() );
                $wgOut->addWikiText( $wgOut->formatPermissionsErrorMessage( $permErrors, 'edit' ) );
@@ -1063,6 +1064,7 @@ class EditPage {
                $title = Title::newFromText( $preload );
                # Check for existence to avoid getting MediaWiki:Noarticletext
                if ( $title === null || !$title->exists() || !$title->userCan( 'read', $wgUser ) ) {
+                       //TODO: somehow show a warning to the user!
                        return $handler->makeEmptyContent();
                }
 
@@ -1071,6 +1073,7 @@ class EditPage {
                        $title = $page->getRedirectTarget();
                        # Same as before
                        if ( $title === null || !$title->exists() || !$title->userCan( 'read', $wgUser ) ) {
+                               //TODO: somehow show a warning to the user!
                                return $handler->makeEmptyContent();
                        }
                        $page = WikiPage::factory( $title );
@@ -1080,9 +1083,25 @@ class EditPage {
                $content = $page->getContent( Revision::RAW );
 
                if ( !$content ) {
+                       //TODO: somehow show a warning to the user!
                        return $handler->makeEmptyContent();
                }
 
+               if ( $content->getModel() !== $handler->getModelID() ) {
+                       $converted = $content->convert( $handler->getModelID() );
+
+                       if ( !$converted ) {
+                               //TODO: somehow show a warning to the user!
+                               wfDebug( "Attempt to preload incompatible content: "
+                                               . "can't convert " . $content->getModel()
+                                               . " to " . $handler->getModelID() );
+
+                               return $handler->makeEmptyContent();
+                       }
+
+                       $content = $converted;
+               }
+
                return $content->preloadTransform( $title, $parserOptions );
        }
 
@@ -1398,8 +1417,8 @@ class EditPage {
                                        // passed.
                                        if ( $this->summary === '' ) {
                                                $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle );
-                                               $this->summary = wfMessage( 'newsectionsummary', $cleanSectionTitle )
-                                                       ->inContentLanguage()->text() ;
+                                               $this->summary = wfMessage( 'newsectionsummary' )
+                                                       ->rawParams( $cleanSectionTitle )->inContentLanguage()->text();
                                        }
                                } elseif ( $this->summary !== '' ) {
                                        // Insert the section title above the content.
@@ -1410,8 +1429,8 @@ class EditPage {
 
                                        // Create a link to the new section from the edit summary.
                                        $cleanSummary = $wgParser->stripSectionName( $this->summary );
-                                       $this->summary = wfMessage( 'newsectionsummary', $cleanSummary )
-                                               ->inContentLanguage()->text();
+                                       $this->summary = wfMessage( 'newsectionsummary' )
+                                               ->rawParams( $cleanSummary )->inContentLanguage()->text();
                                }
                        }
 
@@ -1473,16 +1492,14 @@ class EditPage {
                                $this->isConflict = true;
                                $content = $textbox_content; // do not try to merge here!
                        } elseif ( $this->isConflict ) {
-                               $contentObj = $content;
                                # Attempt merge
-                               if ( $this->mergeChangesInto( $content ) ) {
+                               if ( $this->mergeChangesIntoContent( $content ) ) {
                                        // Successful merge! Maybe we should tell the user the good news?
                                        $this->isConflict = false;
-                                       $content = $this->toEditContent( $content );
                                        wfDebug( __METHOD__ . ": Suppressing edit conflict, successful merge.\n" );
                                } else {
                                        $this->section = '';
-                                       $this->textbox1 = ContentHandler::getContentText( $contentObj );
+                                       $this->textbox1 = ContentHandler::getContentText( $content );
                                        wfDebug( __METHOD__ . ": Keeping edit conflict, failed merge.\n" );
                                }
                        }
@@ -1555,16 +1572,16 @@ class EditPage {
                                        // passed.
                                        if ( $this->summary === '' ) {
                                                $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle );
-                                               $this->summary = wfMessage( 'newsectionsummary', $cleanSectionTitle )
-                                                       ->inContentLanguage()->text();
+                                               $this->summary = wfMessage( 'newsectionsummary' )
+                                                       ->rawParams( $cleanSectionTitle )->inContentLanguage()->text();
                                        }
                                } elseif ( $this->summary !== '' ) {
                                        $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->summary );
                                        # This is a new section, so create a link to the new section
                                        # in the revision summary.
                                        $cleanSummary = $wgParser->stripSectionName( $this->summary );
-                                       $this->summary = wfMessage( 'newsectionsummary', $cleanSummary )
-                                               ->inContentLanguage()->text();
+                                       $this->summary = wfMessage( 'newsectionsummary' )
+                                               ->rawParams( $cleanSummary )->inContentLanguage()->text();
                                }
                        } elseif ( $this->section != '' ) {
                                # Try to get a section anchor from the section source, redirect to edited section if header found
@@ -1666,37 +1683,15 @@ class EditPage {
        function mergeChangesInto( &$editText ){
                ContentHandler::deprecated( __METHOD__, "1.21" );
 
-               wfProfileIn( __METHOD__ );
+               $editContent = $this->toEditContent( $editText );
 
-               $db = wfGetDB( DB_MASTER );
+               $ok = $this->mergeChangesIntoContent( $editContent );
 
-               // This is the revision the editor started from
-               $baseRevision = $this->getBaseRevision();
-               if ( is_null( $baseRevision ) ) {
-                       wfProfileOut( __METHOD__ );
-                       return false;
-               }
-               $baseText = $baseRevision->getText();
-
-               // The current state, we want to merge updates into it
-               $currentRevision = Revision::loadFromTitle( $db, $this->mTitle );
-               if ( is_null( $currentRevision ) ) {
-                       wfProfileOut( __METHOD__ );
-                       return false;
-               }
-               $currentText = $currentRevision->getText();
-
-               $result = '';
-               $editText = $this->toEditText( $editText );
-
-               if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
-                       $editText = $result;
-                       wfProfileOut( __METHOD__ );
+               if ( $ok ) {
+                       $editText = $this->toEditText( $editContent );
                        return true;
-               } else {
-                       wfProfileOut( __METHOD__ );
-                       return false;
                }
+               return false;
        }
 
        /**
@@ -1945,7 +1940,7 @@ class EditPage {
         * an exception will be raised. Set $this->allowNonTextContent to true to allow editing of non-textual
         * content.
         *
-        * @param Content|null|false|string $content
+        * @param Content|null|bool|string $content
         * @return String the editable text form of the content.
         *
         * @throws MWException if $content is not an instance of TextContent and $this->allowNonTextContent is not true.
@@ -2200,30 +2195,8 @@ class EditPage {
                        $wgOut->addWikiMsg( 'talkpagetext' );
                }
 
-               # Optional notices on a per-namespace and per-page basis
-               $editnotice_ns = 'editnotice-' . $this->mTitle->getNamespace();
-               $editnotice_ns_message = wfMessage( $editnotice_ns );
-               if ( $editnotice_ns_message->exists() ) {
-                       $wgOut->addWikiText( $editnotice_ns_message->plain() );
-               }
-               if ( MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) {
-                       $parts = explode( '/', $this->mTitle->getDBkey() );
-                       $editnotice_base = $editnotice_ns;
-                       while ( count( $parts ) > 0 ) {
-                               $editnotice_base .= '-' . array_shift( $parts );
-                               $editnotice_base_msg = wfMessage( $editnotice_base );
-                               if ( $editnotice_base_msg->exists() ) {
-                                       $wgOut->addWikiText( $editnotice_base_msg->plain() );
-                               }
-                       }
-               } 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 );
-                       if ( $editnoticeMsg->exists() ) {
-                               $wgOut->addWikiText( $editnoticeMsg->plain() );
-                       }
-               }
+               // Add edit notices
+               $wgOut->addHTML( implode( "\n", $this->mTitle->getEditNotices() ) );
 
                if ( $this->isConflict ) {
                        $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1\n</div>", 'explainconflict' );
@@ -2651,7 +2624,7 @@ HTML
                                $oldContent = null;
                        }
                } else {
-                       $oldContent = $this->getOriginalContent();
+                       $oldContent = $this->getCurrentContent();
                }
 
                $textboxContent = $this->toEditContent( $this->textbox1 );
@@ -2786,7 +2759,9 @@ HTML
                        wfMessage( 'newwindow' )->parse();
                $wgOut->addHTML( "      <span class='cancelLink'>{$cancel}</span>\n" );
                $wgOut->addHTML( "      <span class='editHelp'>{$edithelp}</span>\n" );
-               $wgOut->addHTML( "</div><!-- editButtons -->\n</div><!-- editOptions -->\n" );
+               $wgOut->addHTML( "</div><!-- editButtons -->\n" );
+               wfRunHooks( 'EditPage::showStandardInputs:options', array( $this, $wgOut, &$tabindex ) );
+               $wgOut->addHTML( "</div><!-- editOptions -->\n" );
        }
 
        /**
@@ -2936,6 +2911,12 @@ HTML
                try {
                        $content = $this->toEditContent( $this->textbox1 );
 
+                       $previewHTML = '';
+                       if ( !wfRunHooks( 'AlternateEditPreview', array( $this, &$content, &$previewHTML, &$this->mParserOutput ) ) ) {
+                               wfProfileOut( __METHOD__ );
+                               return $previewHTML;
+                       }
+
                        if ( $this->mTriedSave && !$this->mTokenOk ) {
                                if ( $this->mTokenOkExceptSuffix ) {
                                        $note = wfMessage( 'token_suffix_mismatch' )->plain() ;