3 * A content object represents page content, e.g. the text to show on a page.
4 * Content objects have no knowledge about how they relate to wiki pages.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
26 * @author Daniel Kinzler
33 * @return string A string representing the content in a way useful for
34 * building a full text search index. If no useful representation exists,
35 * this method returns an empty string.
37 * @todo: test that this actually works
38 * @todo: make sure this also works with LuceneSearch / WikiSearch
40 public function getTextForSearchIndex();
45 * @return string The wikitext to include when another page includes this
46 * content, or false if the content is not includable in a wikitext page.
48 * @TODO: allow native handling, bypassing wikitext representation, like
49 * for includable special pages.
50 * @TODO: allow transclusion into other content models than Wikitext!
51 * @TODO: used in WikiPage and MessageCache to get message text. Not so
52 * nice. What should we use instead?!
54 public function getWikitextForTransclusion();
57 * Returns a textual representation of the content suitable for use in edit
58 * summaries and log messages.
62 * @param $maxLength int Maximum length of the summary text
63 * @return string The summary text
65 public function getTextForSummary( $maxLength = 250 );
68 * Returns native representation of the data. Interpretation depends on
69 * the data model used, as given by getDataModel().
73 * @return mixed The native representation of the content. Could be a
74 * string, a nested array structure, an object, a binary blob...
77 * @NOTE: Caller must be aware of content model!
79 public function getNativeData();
82 * Returns the content's nominal size in bogo-bytes.
86 public function getSize();
89 * Returns the ID of the content model used by this Content object.
90 * Corresponds to the CONTENT_MODEL_XXX constants.
94 * @return String The model id
96 public function getModel();
99 * Convenience method that returns the ContentHandler singleton for handling
100 * the content model that this Content object uses.
102 * Shorthand for ContentHandler::getForContent( $this )
106 * @return ContentHandler
108 public function getContentHandler();
111 * Convenience method that returns the default serialization format for the
112 * content model that this Content object uses.
114 * Shorthand for $this->getContentHandler()->getDefaultFormat()
120 public function getDefaultFormat();
123 * Convenience method that returns the list of serialization formats
124 * supported for the content model that this Content object uses.
126 * Shorthand for $this->getContentHandler()->getSupportedFormats()
130 * @return Array of supported serialization formats
132 public function getSupportedFormats();
135 * Returns true if $format is a supported serialization format for this
136 * Content object, false if it isn't.
138 * Note that this should always return true if $format is null, because null
139 * stands for the default serialization.
141 * Shorthand for $this->getContentHandler()->isSupportedFormat( $format )
145 * @param $format string The format to check
146 * @return bool Whether the format is supported
148 public function isSupportedFormat( $format );
151 * Convenience method for serializing this Content object.
153 * Shorthand for $this->getContentHandler()->serializeContent( $this, $format )
157 * @param $format null|string The desired serialization format (or null for
158 * the default format).
159 * @return string Serialized form of this Content object
161 public function serialize( $format = null );
164 * Returns true if this Content object represents empty content.
168 * @return bool Whether this Content object is empty
170 public function isEmpty();
173 * Returns whether the content is valid. This is intended for local validity
174 * checks, not considering global consistency.
176 * Content needs to be valid before it can be saved.
178 * This default implementation always returns true.
184 public function isValid();
187 * Returns true if this Content objects is conceptually equivalent to the
188 * given Content object.
192 * - Will return false if $that is null.
193 * - Will return true if $that === $this.
194 * - Will return false if $that->getModel() != $this->getModel().
195 * - Will return false if $that->getNativeData() is not equal to $this->getNativeData(),
196 * where the meaning of "equal" depends on the actual data model.
198 * Implementations should be careful to make equals() transitive and reflexive:
200 * - $a->equals( $b ) <=> $b->equals( $a )
201 * - $a->equals( $b ) && $b->equals( $c ) ==> $a->equals( $c )
205 * @param $that Content The Content object to compare to
206 * @return bool True if this Content object is equal to $that, false otherwise.
208 public function equals( Content
$that = null );
211 * Return a copy of this Content object. The following must be true for the
214 * if $copy = $original->copy()
216 * - get_class($original) === get_class($copy)
217 * - $original->getModel() === $copy->getModel()
218 * - $original->equals( $copy )
220 * If and only if the Content object is immutable, the copy() method can and
221 * should return $this. That is, $copy === $original may be true, but only
222 * for immutable content objects.
226 * @return Content. A copy of this object
228 public function copy( );
231 * Returns true if this content is countable as a "real" wiki page, provided
232 * that it's also in a countable location (e.g. a current revision in the
237 * @param $hasLinks Bool: If it is known whether this content contains
238 * links, provide this information here, to avoid redundant parsing to
242 public function isCountable( $hasLinks = null );
246 * Parse the Content object and generate a ParserOutput from the result.
247 * $result->getText() can be used to obtain the generated HTML. If no HTML
248 * is needed, $generateHtml can be set to false; in that case,
249 * $result->getText() may return null.
251 * @param $title Title The page title to use as a context for rendering
252 * @param $revId null|int The revision being rendered (optional)
253 * @param $options null|ParserOptions Any parser options
254 * @param $generateHtml Boolean Whether to generate HTML (default: true). If false,
255 * the result of calling getText() on the ParserOutput object returned by
256 * this method is undefined.
260 * @return ParserOutput
262 public function getParserOutput( Title
$title,
264 ParserOptions
$options = null, $generateHtml = true );
265 # TODO: make RenderOutput and RenderOptions base classes
268 * Returns a list of DataUpdate objects for recording information about this
269 * Content in some secondary data store. If the optional second argument,
270 * $old, is given, the updates may model only the changes that need to be
271 * made to replace information about the old content with information about
274 * This default implementation calls
275 * $this->getParserOutput( $content, $title, null, null, false ),
276 * and then calls getSecondaryDataUpdates( $title, $recursive ) on the
277 * resulting ParserOutput object.
279 * Subclasses may implement this to determine the necessary updates more
280 * efficiently, or make use of information about the old content.
282 * @param $title Title The context for determining the necessary updates
283 * @param $old Content|null An optional Content object representing the
284 * previous content, i.e. the content being replaced by this Content
286 * @param $recursive boolean Whether to include recursive updates (default:
288 * @param $parserOutput ParserOutput|null Optional ParserOutput object.
289 * Provide if you have one handy, to avoid re-parsing of the content.
291 * @return Array. A list of DataUpdate objects for putting information
292 * about this content object somewhere.
296 public function getSecondaryDataUpdates( Title
$title,
298 $recursive = true, ParserOutput
$parserOutput = null
302 * Construct the redirect destination from this content and return an
303 * array of Titles, or null if this content doesn't represent a redirect.
304 * The last element in the array is the final destination after all redirects
305 * have been resolved (up to $wgMaxRedirects times).
309 * @return Array of Titles, with the destination last
311 public function getRedirectChain();
314 * Construct the redirect destination from this content and return a Title,
315 * or null if this content doesn't represent a redirect.
316 * This will only return the immediate redirect target, useful for
317 * the redirect table and other checks that don't need full recursion.
321 * @return Title: The corresponding Title
323 public function getRedirectTarget();
326 * Construct the redirect destination from this content and return the
327 * Title, or null if this content doesn't represent a redirect.
329 * This will recurse down $wgMaxRedirects times or until a non-redirect
330 * target is hit in order to provide (hopefully) the Title of the final
331 * destination instead of another redirect.
333 * There is usually no need to override the default behaviour, subclasses that
334 * want to implement redirects should override getRedirectTarget().
340 public function getUltimateRedirectTarget();
343 * Returns whether this Content represents a redirect.
344 * Shorthand for getRedirectTarget() !== null.
350 public function isRedirect();
353 * If this Content object is a redirect, this method updates the redirect target.
354 * Otherwise, it does nothing.
358 * @param Title $target the new redirect target
360 * @return Content a new Content object with the updated redirect (or $this if this Content object isn't a redirect)
362 public function updateRedirect( Title
$target );
365 * Returns the section with the given ID.
369 * @param $sectionId string The section's ID, given as a numeric string.
370 * The ID "0" retrieves the section before the first heading, "1" the
371 * text between the first heading (included) and the second heading
373 * @return Content|Boolean|null The section, or false if no such section
374 * exist, or null if sections are not supported.
376 public function getSection( $sectionId );
379 * Replaces a section of the content and returns a Content object with the
384 * @param $section Empty/null/false or a section number (0, 1, 2, T1, T2...), or "new"
385 * @param $with Content: new content of the section
386 * @param $sectionTitle String: new section's subject, only if $section is 'new'
387 * @return string Complete article text, or null if error
389 public function replaceSection( $section, Content
$with, $sectionTitle = '' );
392 * Returns a Content object with pre-save transformations applied (or this
393 * object if no transformations apply).
397 * @param $title Title
399 * @param $popts null|ParserOptions
402 public function preSaveTransform( Title
$title, User
$user, ParserOptions
$popts );
405 * Returns a new WikitextContent object with the given section heading
406 * prepended, if supported. The default implementation just returns this
407 * Content object unmodified, ignoring the section header.
411 * @param $header string
414 public function addSectionHeader( $header );
417 * Returns a Content object with preload transformations applied (or this
418 * object if no transformations apply).
422 * @param $title Title
423 * @param $popts null|ParserOptions
426 public function preloadTransform( Title
$title, ParserOptions
$popts );
429 * Prepare Content for saving. Called before Content is saved by WikiPage::doEditContent() and in
432 * This may be used to check the content's consistency with global state. This function should
433 * NOT write any information to the database.
435 * Note that this method will usually be called inside the same transaction bracket that will be used
436 * to save the new revision.
438 * Note that this method is called before any update to the page table is performed. This means that
439 * $page may not yet know a page ID.
443 * @param WikiPage $page The page to be saved.
444 * @param int $flags bitfield for use with EDIT_XXX constants, see WikiPage::doEditContent()
445 * @param int $baseRevId the ID of the current revision
448 * @return Status A status object indicating whether the content was successfully prepared for saving.
449 * If the returned status indicates an error, a rollback will be performed and the
450 * transaction aborted.
452 * @see see WikiPage::doEditContent()
454 public function prepareSave( WikiPage
$page, $flags, $baseRevId, User
$user );
457 * Returns a list of updates to perform when this content is deleted.
458 * The necessary updates may be taken from the Content object, or depend on
459 * the current state of the database.
463 * @param $page \WikiPage the deleted page
464 * @param $parserOutput null|\ParserOutput optional parser output object
465 * for efficient access to meta-information about the content object.
466 * Provide if you have one handy.
468 * @return array A list of DataUpdate instances that will clean up the
469 * database after deletion.
471 public function getDeletionUpdates( WikiPage
$page,
472 ParserOutput
$parserOutput = null );
475 * Returns true if this Content object matches the given magic word.
479 * @param MagicWord $word the magic word to match
481 * @return bool whether this Content object matches the given magic word.
483 public function matchMagicWord( MagicWord
$word );
485 # TODO: ImagePage and CategoryPage interfere with per-content action handlers
486 # TODO: nice&sane integration of GeSHi syntax highlighting
487 # [11:59] <vvv> Hooks are ugly; make CodeHighlighter interface and a
488 # config to set the class which handles syntax highlighting
489 # [12:00] <vvv> And default it to a DummyHighlighter