Improve documentation of content handler stuff
[lhc/web/wiklou.git] / includes / content / Content.php
index a972e67..75ac5f2 100644 (file)
@@ -3,7 +3,33 @@
  * 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
+ */
+
+/**
+ * Base interface for content objects.
+ *
+ * @ingroup Content
  */
 interface Content {
 
@@ -17,21 +43,21 @@ interface Content {
         * @todo: test that this actually works
         * @todo: make sure this also works with LuceneSearch / WikiSearch
         */
-       public function getTextForSearchIndex( );
+       public function getTextForSearchIndex();
 
        /**
         * @since 1.21
         *
-        * @return string The wikitext to include when another page includes this
+        * @return string|false The wikitext to include when another page includes this
         * content, or false if the content is not includable in a wikitext page.
         *
-        * @TODO: allow native handling, bypassing wikitext representation, like
+        * @todo allow native handling, bypassing wikitext representation, like
         *    for includable special pages.
-        * @TODO: allow transclusion into other content models than Wikitext!
-        * @TODO: used in WikiPage and MessageCache to get message text. Not so
+        * @todo allow transclusion into other content models than Wikitext!
+        * @todo used in WikiPage and MessageCache to get message text. Not so
         *    nice. What should we use instead?!
         */
-       public function getWikitextForTransclusion( );
+       public function getWikitextForTransclusion();
 
        /**
         * Returns a textual representation of the content suitable for use in edit
@@ -39,10 +65,10 @@ interface Content {
         *
         * @since 1.21
         *
-        * @param $maxlength int Maximum length of the summary text
-        * @return   The summary text
+        * @param $maxLength int Maximum length of the summary text
+        * @return string The summary text
         */
-       public function getTextForSummary( $maxlength = 250 );
+       public function getTextForSummary( $maxLength = 250 );
 
        /**
         * Returns native representation of the data. Interpretation depends on
@@ -54,16 +80,16 @@ interface Content {
         *    string, a nested array structure, an object, a binary blob...
         *    anything, really.
         *
-        * @NOTE: review all calls carefully, caller must be aware of content model!
+        * @note Caller must be aware of content model!
         */
-       public function getNativeData( );
+       public function getNativeData();
 
        /**
         * Returns the content's nominal size in bogo-bytes.
         *
         * @return int
         */
-       public function getSize( );
+       public function getSize();
 
        /**
         * Returns the ID of the content model used by this Content object.
@@ -171,7 +197,7 @@ interface Content {
         *
         * - Will return false if $that is null.
         * - Will return true if $that === $this.
-        * - Will return false if $that->getModelName() != $this->getModel().
+        * - Will return false if $that->getModel() != $this->getModel().
         * - Will return false if $that->getNativeData() is not equal to $this->getNativeData(),
         *   where the meaning of "equal" depends on the actual data model.
         *
@@ -198,7 +224,7 @@ interface Content {
         * - $original->equals( $copy )
         *
         * If and only if the Content object is immutable, the copy() method can and
-        * should return $this. That is,  $copy === $original may be true, but only
+        * should return $this. That is, $copy === $original may be true, but only
         * for immutable content objects.
         *
         * @since 1.21
@@ -219,8 +245,7 @@ interface Content {
         *    find out.
         * @return boolean
         */
-       public function isCountable( $hasLinks = null ) ;
-
+       public function isCountable( $hasLinks = null );
 
        /**
         * Parse the Content object and generate a ParserOutput from the result.
@@ -242,7 +267,7 @@ interface Content {
        public function getParserOutput( Title $title,
                $revId = null,
                ParserOptions $options = null, $generateHtml = true );
-       # TODO: make RenderOutput and RenderOptions base classes
+       // TODO: make RenderOutput and RenderOptions base classes
 
        /**
         * Returns a list of DataUpdate objects for recording information about this
@@ -312,7 +337,7 @@ interface Content {
         *
         * There is usually no need to override the default behaviour, subclasses that
         * want to implement redirects should override getRedirectTarget().
-        * 
+        *
         * @since 1.21
         *
         * @return Title
@@ -361,7 +386,7 @@ interface Content {
         *
         * @since 1.21
         *
-        * @param $section Empty/null/false or a section number (0, 1, 2, T1, T2...), or "new"
+        * @param $section null/false or a section number (0, 1, 2, T1, T2...), or "new"
         * @param $with Content: new content of the section
         * @param $sectionTitle String: new section's subject, only if $section is 'new'
         * @return string Complete article text, or null if error
@@ -376,10 +401,10 @@ interface Content {
         *
         * @param $title Title
         * @param $user User
-        * @param $popts null|ParserOptions
+        * @param $parserOptions null|ParserOptions
         * @return Content
         */
-       public function preSaveTransform( Title $title, User $user, ParserOptions $popts );
+       public function preSaveTransform( Title $title, User $user, ParserOptions $parserOptions );
 
        /**
         * Returns a new WikitextContent object with the given section heading
@@ -400,10 +425,10 @@ interface Content {
         * @since 1.21
         *
         * @param $title Title
-        * @param $popts null|ParserOptions
+        * @param $parserOptions null|ParserOptions
         * @return Content
         */
-       public function preloadTransform( Title $title, ParserOptions $popts );
+       public function preloadTransform( Title $title, ParserOptions $parserOptions );
 
        /**
         * Prepare Content for saving. Called before Content is saved by WikiPage::doEditContent() and in
@@ -418,6 +443,8 @@ interface Content {
         * Note that this method is called before any update to the page table is performed. This means that
         * $page may not yet know a page ID.
         *
+        * @since 1.21
+        *
         * @param WikiPage $page The page to be saved.
         * @param int      $flags bitfield for use with EDIT_XXX constants, see WikiPage::doEditContent()
         * @param int      $baseRevId the ID of the current revision
@@ -438,8 +465,8 @@ interface 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.
         *
@@ -452,17 +479,30 @@ interface Content {
        /**
         * Returns true if this Content object matches the given magic word.
         *
+        * @since 1.21
+        *
         * @param MagicWord $word the magic word to match
         *
         * @return bool whether this Content object matches the given magic word.
         */
        public function matchMagicWord( MagicWord $word );
 
-       # TODO: ImagePage and CategoryPage interfere with per-content action handlers
-       # TODO: make sure WikiSearch extension still works
-       # TODO: make sure ReplaceTemplates extension still works
-       # TODO: nice&sane integration of GeSHi syntax highlighting
-       #   [11:59] <vvv> Hooks are ugly; make CodeHighlighter interface and a 
-       #   config to set the class which handles syntax highlighting
-       #   [12:00] <vvv> And default it to a DummyHighlighter
-}
\ No newline at end of file
+       /**
+        * Converts this content object into another content object with the given content model,
+        * if that is possible.
+        *
+        * @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 = '' );
+
+               // TODO: ImagePage and CategoryPage interfere with per-content action handlers
+       // TODO: nice&sane integration of GeSHi syntax highlighting
+       //   [11:59] <vvv> Hooks are ugly; make CodeHighlighter interface and a
+       //   config to set the class which handles syntax highlighting
+       //   [12:00] <vvv> And default it to a DummyHighlighter
+}