Merge "Remove static method from interface"
[lhc/web/wiklou.git] / includes / content / AbstractContent.php
index 488c4be..386f55a 100644 (file)
@@ -3,7 +3,27 @@
  * A content object represents page content, e.g. the text to show on a page.
  * Content objects have no knowledge about how they relate to Wiki pages.
  *
+ * 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
  */
 abstract class AbstractContent implements Content {
 
@@ -361,8 +381,8 @@ abstract class AbstractContent implements Content {
         *
         * @since 1.21
         *
-        * @param $page \WikiPage the deleted page
-        * @param $parserOutput null|\ParserOutput optional parser output object
+        * @param $page WikiPage the deleted page
+        * @param $parserOutput null|ParserOutput optional parser output object
         *    for efficient access to meta-information about the content object.
         *    Provide if you have one handy.
         *
@@ -391,4 +411,30 @@ abstract class AbstractContent implements Content {
        public function matchMagicWord( MagicWord $word ) {
                return false;
        }
-}
\ No newline at end of file
+
+       /**
+        * @see Content::convert()
+        *
+        * This base implementation calls the hook ConvertContent to enable custom conversions.
+        * Subclasses may override this to implement conversion for "their" content model.
+        *
+        * @param String  $toModel the desired content model, use the CONTENT_MODEL_XXX flags.
+        * @param String  $lossy flag, set to "lossy" to allow lossy conversion. If lossy conversion is
+        * not allowed, full round-trip conversion is expected to work without losing information.
+        *
+        * @return Content|bool A content object with the content model $toModel, or false if
+        * that conversion is not supported.
+        */
+       public function convert( $toModel, $lossy = '' ) {
+               if ( $this->getModel() === $toModel ) {
+                       //nothing to do, shorten out.
+                       return $this;
+               }
+
+               $lossy = ( $lossy === 'lossy' ); // string flag, convert to boolean for convenience
+               $result = false;
+
+               wfRunHooks( 'ConvertContent', array( $this, $toModel, $lossy, &$result ) );
+               return $result;
+       }
+}