Merge "Remove static method from interface"
[lhc/web/wiklou.git] / includes / content / WikitextContent.php
index 5de09b6..dabb855 100644 (file)
@@ -1,6 +1,26 @@
 <?php
 /**
- * @since WD.1
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since 1.21
+ *
+ * @file
+ * @ingroup Content
+ *
+ * @author Daniel Kinzler
  */
 class WikitextContent extends TextContent {
 
@@ -17,7 +37,11 @@ class WikitextContent extends TextContent {
                $text = $this->getNativeData();
                $sect = $wgParser->getSection( $text, $section, false );
 
-               return  new WikitextContent( $sect );
+               if ( $sect === false ) {
+                       return false;
+               } else {
+                       return new WikitextContent( $sect );
+               }
        }
 
        /**
@@ -39,6 +63,7 @@ class WikitextContent extends TextContent {
                $text = $with->getNativeData();
 
                if ( $section === '' ) {
+                       wfProfileOut( __METHOD__ );
                        return $with; # XXX: copy first?
                } if ( $section == 'new' ) {
                        # Inserting a new section
@@ -71,7 +96,7 @@ class WikitextContent extends TextContent {
         */
        public function addSectionHeader( $header ) {
                $text = wfMessage( 'newsectionheaderdefaultlevel' )
-                               ->inContentLanguage()->params( $header )->text();
+                       ->rawParams( $header )->inContentLanguage()->text();
                $text .= "\n\n";
                $text .= $this->getNativeData();
 
@@ -92,8 +117,9 @@ class WikitextContent extends TextContent {
 
                $text = $this->getNativeData();
                $pst = $wgParser->preSaveTransform( $text, $title, $user, $popts );
+               rtrim( $pst );
 
-               return new WikitextContent( $pst );
+               return ( $text === $pst ) ? $this : new WikitextContent( $pst );
        }
 
        /**
@@ -160,7 +186,7 @@ class WikitextContent extends TextContent {
         * 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.
         *
-        * @since WD.1
+        * @since 1.21
         *
         * @param Title $target
         *
@@ -187,8 +213,8 @@ class WikitextContent extends TextContent {
         *
         * @param $hasLinks Bool  if it is known whether this content contains
         *    links, provide this information here, to avoid redundant parsing to
-        *    find out.
-        * @param $title null|\Title
+        *    find out (default: null).
+        * @param $title Title: (default: null)
         *
         * @internal param \IContextSource $context context for parsing if necessary
         *
@@ -241,13 +267,12 @@ class WikitextContent extends TextContent {
         * Returns a ParserOutput object resulting from parsing the content's text
         * using $wgParser.
         *
-        * @since    WD.1
+        * @since    1.21
         *
-        * @param $content Content the content to render
-        * @param $title \Title
-        * @param $revId null
-        * @param $options null|ParserOptions
-        * @param $generateHtml bool
+        * @param $title Title
+        * @param $revId int Revision to pass to the parser (default: null)
+        * @param $options ParserOptions (default: null)
+        * @param $generateHtml bool (default: false)
         *
         * @internal param \IContextSource|null $context
         * @return ParserOutput representing the HTML form of the text
@@ -286,4 +311,4 @@ class WikitextContent extends TextContent {
        public function matchMagicWord( MagicWord $word ) {
                return $word->match( $this->getNativeData() );
        }
-}
\ No newline at end of file
+}