Merge "Added --all option and other features to purgeList.php"
[lhc/web/wiklou.git] / includes / EditPage.php
index 0e6eafb..4e3ea49 100644 (file)
@@ -546,8 +546,8 @@ class EditPage {
                        // Standard preference behaviour
                        return true;
                } elseif ( !$this->mTitle->exists() &&
-                 isset( $wgPreviewOnOpenNamespaces[$this->mTitle->getNamespace()] ) &&
-                 $wgPreviewOnOpenNamespaces[$this->mTitle->getNamespace()] )
+                       isset( $wgPreviewOnOpenNamespaces[$this->mTitle->getNamespace()] ) &&
+                       $wgPreviewOnOpenNamespaces[$this->mTitle->getNamespace()] )
                {
                        // Categories are special
                        return true;
@@ -577,13 +577,15 @@ class EditPage {
        }
 
        /**
-        * Does this EditPage class support section editing?
-        * This is used by EditPage subclasses to indicate their ui cannot handle section edits
+        * Returns whether section editing is supported for the current page.
+        * Subclasses may override this to replace the default behavior, which is
+        * to check ContentHandler::supportsSections.
         *
-        * @return bool
+        * @return bool true if this edit page supports sections, false otherwise.
         */
        protected function isSectionEditSupported() {
-               return true;
+               $contentHandler = ContentHandler::getForTitle( $this->mTitle );
+               return $contentHandler->supportsSections();
        }
 
        /**
@@ -597,6 +599,11 @@ class EditPage {
 
                # Section edit can come from either the form or a link
                $this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );
+
+               if ( $this->section !== null && $this->section !== '' && !$this->isSectionEditSupported() ) {
+                       throw new ErrorPageError( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
+               }
+
                $this->isNew = !$this->mTitle->exists() || $this->section == 'new';
 
                if ( $request->wasPosted() ) {
@@ -617,8 +624,11 @@ class EditPage {
                                wfProfileOut( get_class( $this ) . "::importContentFormData" );
                        }
 
+                       # Trim spaces on user supplied text
+                       $summary = trim( $request->getText( 'wpSummary' ) );
+
                        # Truncate for whole multibyte characters
-                       $this->summary = $wgContLang->truncate( $request->getText( 'wpSummary' ), 255 );
+                       $this->summary = $wgContLang->truncate( $summary, 255 );
 
                        # If the summary consists of a heading, e.g. '==Foobar==', extract the title from the
                        # header syntax, e.g. 'Foobar'. This is mainly an issue when we are using wpSummary for
@@ -1152,7 +1162,7 @@ class EditPage {
                                return false;
 
                        case self::AS_PARSE_ERROR:
-                               $wgOut->addWikiText( '<div class="error">' . $status->getWikiText() . '</div>');
+                               $wgOut->addWikiText( '<div class="error">' . $status->getWikiText() . '</div>' );
                                return true;
 
                        case self::AS_SUCCESS_NEW_ARTICLE:
@@ -1283,7 +1293,7 @@ class EditPage {
 
                $status = Status::newGood();
 
-               wfProfileIn( __METHOD__  );
+               wfProfileIn( __METHOD__ );
                wfProfileIn( __METHOD__ . '-checks' );
 
                if ( !wfRunHooks( 'EditPage::attemptSave', array( $this ) ) ) {
@@ -1291,7 +1301,7 @@ class EditPage {
                        $status->fatal( 'hookaborted' );
                        $status->value = self::AS_HOOK_ERROR;
                        wfProfileOut( __METHOD__ . '-checks' );
-                       wfProfileOut( __METHOD__  );
+                       wfProfileOut( __METHOD__ );
                        return $status;
                }
 
@@ -1301,6 +1311,7 @@ class EditPage {
                } catch ( MWContentSerializationException $ex ) {
                        $status->fatal( 'content-failed-to-parse', $this->contentModel, $this->contentFormat, $ex->getMessage() );
                        $status->value = self::AS_PARSE_ERROR;
+                       wfProfileOut( __METHOD__ . '-checks' );
                        wfProfileOut( __METHOD__ );
                        return $status;
                }
@@ -1313,7 +1324,7 @@ class EditPage {
                                $status->setResult( false, $code );
 
                                wfProfileOut( __METHOD__ . '-checks' );
-                               wfProfileOut( __METHOD__  );
+                               wfProfileOut( __METHOD__ );
 
                                return $status;
                }
@@ -1497,7 +1508,7 @@ class EditPage {
                                                $this->isConflict = false;
                                                wfDebug( __METHOD__ . ": conflict suppressed; new section\n" );
                                        }
-                               } elseif ( $this->section == '' && Revision::userWasLastToEdit( DB_MASTER,  $this->mTitle->getArticleID(),
+                               } elseif ( $this->section == '' && Revision::userWasLastToEdit( DB_MASTER, $this->mTitle->getArticleID(),
                                                        $wgUser->getId(), $this->edittime ) ) {
                                        # Suppress edit conflict with self, except for section edits where merging is required.
                                        wfDebug( __METHOD__ . ": Suppressing edit conflict, same user.\n" );
@@ -1649,12 +1660,7 @@ class EditPage {
                        $doEditStatus = $this->mArticle->doEditContent( $content, $this->summary, $flags,
                                                                                                                        false, null, $this->contentFormat );
 
-               if ( $doEditStatus->isOK() ) {
-                               $result['redirect'] = $content->isRedirect();
-                       $this->updateWatchlist();
-                       wfProfileOut( __METHOD__ );
-                       return $status;
-               } else {
+               if ( !$doEditStatus->isOK() ) {
                        // Failure from doEdit()
                        // Show the edit conflict page for certain recognized errors from doEdit(),
                        // but don't show it for errors from extension hooks
@@ -1669,6 +1675,11 @@ class EditPage {
                        wfProfileOut( __METHOD__ );
                        return $doEditStatus;
                }
+
+               $result['redirect'] = $content->isRedirect();
+               $this->updateWatchlist();
+               wfProfileOut( __METHOD__ );
+               return $status;
        }
 
        /**
@@ -1704,7 +1715,7 @@ class EditPage {
         * @return bool
         * @deprecated since 1.21, use mergeChangesIntoContent() instead
         */
-       function mergeChangesInto( &$editText ){
+       function mergeChangesInto( &$editText ) {
                ContentHandler::deprecated( __METHOD__, "1.21" );
 
                $editContent = $this->toEditContent( $editText );
@@ -1729,7 +1740,7 @@ class EditPage {
         *
         * @return bool
         */
-       private function mergeChangesIntoContent( &$editContent ){
+       private function mergeChangesIntoContent( &$editContent ) {
                wfProfileIn( __METHOD__ );
 
                $db = wfGetDB( DB_MASTER );
@@ -1760,10 +1771,10 @@ class EditPage {
                        $editContent = $result;
                        wfProfileOut( __METHOD__ );
                        return true;
-               } else {
-                       wfProfileOut( __METHOD__ );
-                       return false;
                }
+
+               wfProfileOut( __METHOD__ );
+               return false;
        }
 
        /**
@@ -2186,7 +2197,7 @@ class EditPage {
                        } catch ( MWContentSerializationException $ex ) {
                                // this can't really happen, but be nice if it does.
                                $msg = wfMessage( 'content-failed-to-parse', $this->contentModel, $this->contentFormat, $ex->getMessage() );
-                               $wgOut->addWikiText( '<div class="error">' . $msg->text() . '</div>');
+                               $wgOut->addWikiText( '<div class="error">' . $msg->text() . '</div>' );
                        }
                }
 
@@ -2605,7 +2616,7 @@ HTML
                                $this->showDiff();
                        } catch ( MWContentSerializationException $ex ) {
                                $msg = wfMessage( 'content-failed-to-parse', $this->contentModel, $this->contentFormat, $ex->getMessage() );
-                               $wgOut->addWikiText( '<div class="error">' . $msg->text() . '</div>');
+                               $wgOut->addWikiText( '<div class="error">' . $msg->text() . '</div>' );
                        }
                }
        }
@@ -2877,21 +2888,24 @@ HTML
                $dbr = wfGetDB( DB_SLAVE );
                $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' ),
-                       array( 'log_namespace' => $this->mTitle->getNamespace(),
-                                  'log_title' => $this->mTitle->getDBkey(),
-                                  'log_type' => 'delete',
-                                  'log_action' => 'delete',
-                                  'user_id=log_user' ),
+                       array(
+                               'log_type',
+                               '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'
+                       ),
                        __METHOD__,
                        array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' )
                );
@@ -2946,13 +2960,13 @@ HTML
 
                        if ( $this->mTriedSave && !$this->mTokenOk ) {
                                if ( $this->mTokenOkExceptSuffix ) {
-                                       $note = wfMessage( 'token_suffix_mismatch' )->plain() ;
+                                       $note = wfMessage( 'token_suffix_mismatch' )->plain();
 
                                } else {
-                                       $note = wfMessage( 'session_fail_preview' )->plain() ;
+                                       $note = wfMessage( 'session_fail_preview' )->plain();
                                }
                        } elseif ( $this->incompleteForm ) {
-                               $note = wfMessage( 'edit_form_incomplete' )->plain() ;
+                               $note = wfMessage( 'edit_form_incomplete' )->plain();
                        } else {
                                $note = wfMessage( 'previewnote' )->plain() .
                                        ' [[#' . self::EDITFORM_ID . '|' . $wgLang->getArrow() . ' ' . wfMessage( 'continue-editing' )->text() . ']]';
@@ -2961,7 +2975,7 @@ HTML
                        $parserOptions = $this->mArticle->makeParserOptions( $this->mArticle->getContext() );
                        $parserOptions->setEditSection( false );
                        $parserOptions->setIsPreview( true );
-                       $parserOptions->setIsSectionPreview( !is_null($this->section) && $this->section !== '' );
+                       $parserOptions->setIsSectionPreview( !is_null( $this->section ) && $this->section !== '' );
 
                        # don't parse non-wikitext pages, show message about preview
                        if ( $this->mTitle->isCssJsSubpage() || $this->mTitle->isCssOrJsPage() ) {
@@ -2984,7 +2998,7 @@ HTML
                                # Used messages to make sure grep find them:
                                # Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview
                                if( $level && $format ) {
-                                       $note = "<div id='mw-{$level}{$format}preview'>" . wfMessage( "{$level}{$format}preview" )->text()  . "</div>";
+                                       $note = "<div id='mw-{$level}{$format}preview'>" . wfMessage( "{$level}{$format}preview" )->text() . "</div>";
                                }
                        }
 
@@ -3020,7 +3034,7 @@ HTML
                                }
                        }
                } catch ( MWContentSerializationException $ex ) {
-                       $m = wfMessage('content-failed-to-parse', $this->contentModel, $this->contentFormat, $ex->getMessage() );
+                       $m = wfMessage( 'content-failed-to-parse', $this->contentModel, $this->contentFormat, $ex->getMessage() );
                        $note .= "\n\n" . $m->parse();
                        $previewHTML = '';
                }
@@ -3443,7 +3457,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' ) );