KSS: Make section headings links
[lhc/web/wiklou.git] / includes / EditPage.php
index a5994e7..b0da562 100644 (file)
@@ -156,6 +156,12 @@ class EditPage {
         */
        const AS_SELF_REDIRECT = 236;
 
+       /**
+        * Status: an error relating to change tagging. Look at the message key for
+        * more details
+        */
+       const AS_CHANGE_TAG_ERROR = 237;
+
        /**
         * Status: can't parse content
         */
@@ -351,6 +357,9 @@ class EditPage {
        /** @var null|string */
        public $contentFormat = null;
 
+       /** @var null|array */
+       public $changeTags = null;
+
        # Placeholders for text injection by hooks (must be HTML)
        # extensions should take care to _append_ to the present value
 
@@ -371,12 +380,14 @@ class EditPage {
 
        public $suppressIntro = false;
 
-       /** @var bool Set to true to allow editing of non-text content types. */
-       public $allowNonTextContent = false;
-
        /** @var bool */
        protected $edit;
 
+       /**
+        * @var bool Set in ApiEditPage, based on ContentHandler::allowsDirectApiEditing
+        */
+       private $enableApiEditOverride = false;
+
        /**
         * @param Article $article
         */
@@ -438,8 +449,18 @@ class EditPage {
         * @throws MWException If $modelId has no known handler
         */
        public function isSupportedContentModel( $modelId ) {
-               return $this->allowNonTextContent ||
-                       ContentHandler::getForModelID( $modelId ) instanceof TextContentHandler;
+               return $this->enableApiEditOverride === true ||
+                       ContentHandler::getForModelID( $modelId )->supportsDirectEditing();
+       }
+
+       /**
+        * Allow editing of content that supports API direct editing, but not general
+        * direct editing. Set to false by default.
+        *
+        * @param bool $enableOverride
+        */
+       public function setApiEditOverride( $enableOverride ) {
+               $this->enableApiEditOverride = $enableOverride;
        }
 
        function submit() {
@@ -844,6 +865,14 @@ class EditPage {
 
                        $this->allowBlankArticle = $request->getBool( 'wpIgnoreBlankArticle' );
                        $this->allowSelfRedirect = $request->getBool( 'wpIgnoreSelfRedirect' );
+
+                       $changeTags = $request->getVal( 'wpChangeTags' );
+                       if ( is_null( $changeTags ) || $changeTags === '' ) {
+                               $this->changeTags = array();
+                       } else {
+                               $this->changeTags = array_filter( array_map( 'trim', explode( ',',
+                                       $changeTags ) ) );
+                       }
                } else {
                        # Not a posted form? Start with nothing.
                        wfDebug( __METHOD__ . ": Not a posted form.\n" );
@@ -1642,6 +1671,15 @@ class EditPage {
                        return $status;
                }
 
+               if ( $this->changeTags ) {
+                       $changeTagsStatus = ChangeTags::canAddTagsAccompanyingChange(
+                               $this->changeTags, $wgUser );
+                       if ( !$changeTagsStatus->isOK() ) {
+                               $changeTagsStatus->value = self::AS_CHANGE_TAG_ERROR;
+                               return $changeTagsStatus;
+                       }
+               }
+
                if ( wfReadOnly() ) {
                        $status->fatal( 'readonlytext' );
                        $status->value = self::AS_READ_ONLY_PAGE;
@@ -1915,7 +1953,18 @@ class EditPage {
                        $wgUser->pingLimiter( 'linkpurge' );
                }
                $result['redirect'] = $content->isRedirect();
+
                $this->updateWatchlist();
+
+               if ( $this->changeTags && isset( $doEditStatus->value['revision'] ) ) {
+                       // If a revision was created, apply any change tags that were requested
+                       ChangeTags::addTags(
+                               $this->changeTags,
+                               isset( $doEditStatus->value['rc'] ) ? $doEditStatus->value['rc']->mAttribs['rc_id'] : null,
+                               $doEditStatus->value['revision']->getId()
+                       );
+               }
+
                return $status;
        }
 
@@ -2670,19 +2719,21 @@ class EditPage {
                                                array( 'userinvalidcssjstitle', $this->mTitle->getSkinFromCssJsSubpage() )
                                        );
                                }
-                               if ( $this->formtype !== 'preview' ) {
-                                       if ( $this->isCssSubpage && $wgAllowUserCss ) {
-                                               $wgOut->wrapWikiMsg(
-                                                       "<div id='mw-usercssyoucanpreview'>\n$1\n</div>",
-                                                       array( 'usercssyoucanpreview' )
-                                               );
-                                       }
+                               if ( $this->getTitle()->isSubpageOf( $wgUser->getUserPage() ) ) {
+                                       if ( $this->formtype !== 'preview' ) {
+                                               if ( $this->isCssSubpage && $wgAllowUserCss ) {
+                                                       $wgOut->wrapWikiMsg(
+                                                               "<div id='mw-usercssyoucanpreview'>\n$1\n</div>",
+                                                               array( 'usercssyoucanpreview' )
+                                                       );
+                                               }
 
-                                       if ( $this->isJsSubpage && $wgAllowUserJs ) {
-                                               $wgOut->wrapWikiMsg(
-                                                       "<div id='mw-userjsyoucanpreview'>\n$1\n</div>",
-                                                       array( 'userjsyoucanpreview' )
-                                               );
+                                               if ( $this->isJsSubpage && $wgAllowUserJs ) {
+                                                       $wgOut->wrapWikiMsg(
+                                                               "<div id='mw-userjsyoucanpreview'>\n$1\n</div>",
+                                                               array( 'userjsyoucanpreview' )
+                                                       );
+                                               }
                                        }
                                }
                        }
@@ -3698,7 +3749,7 @@ HTML
                }
 
                $script .= '});';
-               $wgOut->addScript( Html::inlineScript( ResourceLoader::makeLoaderConditionalScript( $script ) ) );
+               $wgOut->addScript( ResourceLoader::makeInlineScript( $script ) );
 
                $toolbar = '<div id="toolbar"></div>';