Merge "Delete autoload.ide.php"
[lhc/web/wiklou.git] / includes / content / WikitextContent.php
index bc20aa0..a7021b1 100644 (file)
@@ -25,6 +25,8 @@
  * @author Daniel Kinzler
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Content object for wiki text pages.
  *
 class WikitextContent extends TextContent {
        private $redirectTargetAndText = null;
 
+       /**
+        * @var bool Tracks if the parser set the user-signature flag when creating this content, which
+        *   would make it expire faster in ApiStashEdit.
+        */
+       private $hadSignature = false;
+
        public function __construct( $text ) {
                parent::__construct( $text, CONTENT_MODEL_WIKITEXT );
        }
@@ -138,7 +146,17 @@ class WikitextContent extends TextContent {
                $text = $this->getNativeData();
                $pst = $wgParser->preSaveTransform( $text, $title, $user, $popts );
 
-               return ( $text === $pst ) ? $this : new static( $pst );
+               if ( $text === $pst ) {
+                       return $this;
+               }
+
+               $ret = new static( $pst );
+
+               if ( $wgParser->getOutput()->getFlag( 'user-signature' ) ) {
+                       $ret->hadSignature = true;
+               }
+
+               return $ret;
        }
 
        /**
@@ -182,7 +200,7 @@ class WikitextContent extends TextContent {
                        return $this->redirectTargetAndText;
                }
 
-               $redir = MagicWord::get( 'redirect' );
+               $redir = MediaWikiServices::getInstance()->getMagicWordFactory()->get( 'redirect' );
                $text = ltrim( $this->getNativeData() );
                if ( $redir->matchStartAndRemove( $text ) ) {
                        // Extract the first link and see if it's usable
@@ -270,28 +288,22 @@ class WikitextContent extends TextContent {
                        return false;
                }
 
-               switch ( $wgArticleCountMethod ) {
-                       case 'any':
-                               return true;
-                       case 'comma':
-                               $text = $this->getNativeData();
-                               return strpos( $text, ',' ) !== false;
-                       case 'link':
-                               if ( $hasLinks === null ) { # not known, find out
-                                       if ( !$title ) {
-                                               $context = RequestContext::getMain();
-                                               $title = $context->getTitle();
-                                       }
-
-                                       $po = $this->getParserOutput( $title, null, null, false );
-                                       $links = $po->getLinks();
-                                       $hasLinks = !empty( $links );
+               if ( $wgArticleCountMethod === 'link' ) {
+                       if ( $hasLinks === null ) { # not known, find out
+                               if ( !$title ) {
+                                       $context = RequestContext::getMain();
+                                       $title = $context->getTitle();
                                }
 
-                               return $hasLinks;
+                               $po = $this->getParserOutput( $title, null, null, false );
+                               $links = $po->getLinks();
+                               $hasLinks = !empty( $links );
+                       }
+
+                       return $hasLinks;
                }
 
-               return false;
+               return true;
        }
 
        /**
@@ -341,6 +353,11 @@ class WikitextContent extends TextContent {
                                $output->addModuleStyles( 'mediawiki.action.view.redirectPage' );
                        }
                }
+
+               // Pass along user-signature flag
+               if ( $this->hadSignature ) {
+                       $output->setFlag( 'user-signature' );
+               }
        }
 
        /**