Merge "jquery.suggestions: Hide the suggestions list asynchronously"
[lhc/web/wiklou.git] / includes / content / WikitextContent.php
index f495c56..ccea916 100644 (file)
  * @ingroup Content
  */
 class WikitextContent extends TextContent {
+
        public function __construct( $text ) {
                parent::__construct( $text, CONTENT_MODEL_WIKITEXT );
        }
 
        /**
+        * @param string $section
+        *
+        * @return Content|bool|null
+        *
         * @see Content::getSection()
         */
        public function getSection( $section ) {
@@ -52,6 +57,13 @@ class WikitextContent extends TextContent {
        }
 
        /**
+        * @param string $section
+        * @param Content $with
+        * @param string $sectionTitle
+        *
+        * @throws MWException
+        * @return Content
+        *
         * @see Content::replaceSection()
         */
        public function replaceSection( $section, Content $with, $sectionTitle = '' ) {
@@ -103,7 +115,8 @@ class WikitextContent extends TextContent {
         * Returns a new WikitextContent object with the given section heading
         * prepended.
         *
-        * @param $header string
+        * @param string $header
+        *
         * @return Content
         */
        public function addSectionHeader( $header ) {
@@ -119,9 +132,10 @@ class WikitextContent extends TextContent {
         * Returns a Content object with pre-save transformations applied using
         * Parser::preSaveTransform().
         *
-        * @param $title Title
-        * @param $user User
-        * @param $popts ParserOptions
+        * @param Title $title
+        * @param User $user
+        * @param ParserOptions $popts
+        *
         * @return Content
         */
        public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
@@ -138,15 +152,17 @@ class WikitextContent extends TextContent {
         * Returns a Content object with preload transformations applied (or this
         * object if no transformations apply).
         *
-        * @param $title Title
-        * @param $popts ParserOptions
+        * @param Title $title
+        * @param ParserOptions $popts
+        * @param array $params
+        *
         * @return Content
         */
-       public function preloadTransform( Title $title, ParserOptions $popts ) {
+       public function preloadTransform( Title $title, ParserOptions $popts, $params = array() ) {
                global $wgParser;
 
                $text = $this->getNativeData();
-               $plt = $wgParser->getPreloadText( $text, $title, $popts );
+               $plt = $wgParser->getPreloadText( $text, $title, $popts, $params );
 
                return new WikitextContent( $plt );
        }
@@ -157,7 +173,8 @@ class WikitextContent extends TextContent {
         * @note: migrated here from Title::newFromRedirectInternal()
         *
         * @since 1.23
-        * @return array 2 elements: Title|null and string
+        *
+        * @return array List of two elements: Title|null and string.
         */
        protected function getRedirectTargetAndText() {
                global $wgMaxRedirects;
@@ -195,10 +212,9 @@ class WikitextContent extends TextContent {
        /**
         * Implement redirect extraction for wikitext.
         *
-        * @return null|Title
+        * @return Title|null
         *
         * @see Content::getRedirectTarget
-        * @see AbstractContent::getRedirectTarget
         */
        public function getRedirectTarget() {
                list( $title, ) = $this->getRedirectTargetAndText();
@@ -207,8 +223,6 @@ class WikitextContent extends TextContent {
        }
 
        /**
-        * @see Content::updateRedirect()
-        *
         * This implementation replaces the first link on the page with the given new target
         * if this Content object is a redirect. Otherwise, this method returns $this.
         *
@@ -216,8 +230,9 @@ class WikitextContent extends TextContent {
         *
         * @param Title $target
         *
-        * @return Content a new Content object with the updated redirect (or $this
-        *   if this Content object isn't a redirect)
+        * @return Content
+        *
+        * @see Content::updateRedirect()
         */
        public function updateRedirect( Title $target ) {
                if ( !$this->isRedirect() ) {
@@ -238,14 +253,12 @@ class WikitextContent extends TextContent {
         * Returns true if this content is not a redirect, and this content's text
         * is countable according to the criteria defined by $wgArticleCountMethod.
         *
-        * @param bool $hasLinks if it is known whether this content contains
+        * @param bool $hasLinks If it is known whether this content contains
         *    links, provide this information here, to avoid redundant parsing to
         *    find out (default: null).
-        * @param $title Title: (default: null)
-        *
-        * @internal param \IContextSource $context context for parsing if necessary
+        * @param Title $title Optional title, defaults to the title from the current main request.
         *
-        * @return bool True if the content is countable
+        * @return bool
         */
        public function isCountable( $hasLinks = null, Title $title = null ) {
                global $wgArticleCountMethod;
@@ -279,6 +292,10 @@ class WikitextContent extends TextContent {
                return false;
        }
 
+       /**
+        * @param int $maxlength
+        * @return string
+        */
        public function getTextForSummary( $maxlength = 250 ) {
                $truncatedtext = parent::getTextForSummary( $maxlength );
 
@@ -294,46 +311,38 @@ class WikitextContent extends TextContent {
         * Returns a ParserOutput object resulting from parsing the content's text
         * using $wgParser.
         *
-        * @since    1.21
-        *
-        * @param $title Title
+        * @param Title $title
         * @param int $revId Revision to pass to the parser (default: null)
-        * @param $options ParserOptions (default: null)
-        * @param bool $generateHtml (default: false)
-        *
-        * @internal param \IContextSource|null $context
-        * @return ParserOutput representing the HTML form of the text
+        * @param ParserOptions $options (default: null)
+        * @param bool $generateHtml (default: true)
+        * @param &$output ParserOutput representing the HTML form of the text,
+        *           may be manipulated or replaced.
         */
-       public function getParserOutput( Title $title,
-               $revId = null,
-               ParserOptions $options = null, $generateHtml = true
+       protected function fillParserOutput( Title $title, $revId,
+                       ParserOptions $options, $generateHtml, ParserOutput &$output
        ) {
                global $wgParser;
 
-               if ( !$options ) {
-                       //NOTE: use canonical options per default to produce cacheable output
-                       $options = $this->getContentHandler()->makeParserOptions( 'canonical' );
-               }
-
                list( $redir, $text ) = $this->getRedirectTargetAndText();
-               $po = $wgParser->parse( $text, $title, $options, true, true, $revId );
+               $output = $wgParser->parse( $text, $title, $options, true, true, $revId );
 
                // Add redirect indicator at the top
                if ( $redir ) {
                        // Make sure to include the redirect link in pagelinks
-                       $po->addLink( $redir );
+                       $output->addLink( $redir );
                        if ( $generateHtml ) {
                                $chain = $this->getRedirectChain();
-                               $po->setText(
+                               $output->setText(
                                        Article::getRedirectHeaderHtml( $title->getPageLanguage(), $chain, false ) .
-                                       $po->getText()
+                                       $output->getText()
                                );
                        }
                }
-
-               return $po;
        }
 
+       /**
+        * @throws MWException
+        */
        protected function getHtml() {
                throw new MWException(
                        "getHtml() not implemented for wikitext. "
@@ -342,15 +351,16 @@ class WikitextContent extends TextContent {
        }
 
        /**
-        * @see  Content::matchMagicWord()
-        *
         * This implementation calls $word->match() on the this TextContent object's text.
         *
         * @param MagicWord $word
         *
-        * @return bool whether this Content object matches the given magic word.
+        * @return bool
+        *
+        * @see Content::matchMagicWord()
         */
        public function matchMagicWord( MagicWord $word ) {
                return $word->match( $this->getNativeData() );
        }
+
 }