From: Tim Starling Date: Wed, 13 Jun 2012 07:11:43 +0000 (+1000) Subject: Clean up comments and whitespace X-Git-Tag: 1.31.0-rc.0~22097^2^2~99 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=c2bb00a76485c6841b8ef34c50d57e05b5644ac7;p=lhc%2Fweb%2Fwiklou.git Clean up comments and whitespace * Break most comment lines at 80 columns * Break code lines at 100 columns or less * Fix capitalisation in comments * Fix several instances of reversed name and type in @param, Doxygen cares * Replaced @param with @return in several places * Use a Doxygen format list in doc comments where appropriate * Reduced comment duplication in subclasses, for maintainability * General copyediting of comments * Fixed a couple of other minor code style issues Change-Id: I3a6f9a6870a9b859c1bd4251202acba607fbf2b7 --- diff --git a/includes/Content.php b/includes/Content.php index caea845519..7d211c189f 100644 --- a/includes/Content.php +++ b/includes/Content.php @@ -1,7 +1,7 @@ getContentHandler()->getDefaultFormat() * @@ -95,30 +100,30 @@ interface Content { public function getDefaultFormat(); /** - * Convenience method that returns the list of serialization formats supported - * for the content model model this Content object uses. + * Convenience method that returns the list of serialization formats + * supported for the content model that this Content object uses. * * Shorthand for $this->getContentHandler()->getSupportedFormats() * * @since WD.1 * - * @return array of supported serialization formats + * @return Array of supported serialization formats */ public function getSupportedFormats(); /** - * Returns true if $format is a supported serialization format for this Content object, - * false if it isn't. + * Returns true if $format is a supported serialization format for this + * Content object, false if it isn't. * - * Note that this should always return true if $format is null, because null stands for the - * default serialization. + * Note that this should always return true if $format is null, because null + * stands for the default serialization. * * Shorthand for $this->getContentHandler()->isSupportedFormat( $format ) * * @since WD.1 * - * @param String $format the format to check - * @return bool whether the format is supported + * @param $format string The format to check + * @return bool Whether the format is supported */ public function isSupportedFormat( $format ); @@ -129,8 +134,9 @@ interface Content { * * @since WD.1 * - * @param null|String $format the desired serialization format (or null for the default format). - * @return String serialized form of this Content object + * @param $format null|string The desired serialization format (or null for + * the default format). + * @return string Serialized form of this Content object */ public function serialize( $format = null ); @@ -139,12 +145,14 @@ interface Content { * * @since WD.1 * - * @return bool whether this Content object is empty + * @return bool Whether this Content object is empty */ public function isEmpty(); /** - * Returns whether the content is valid. This is intended for local validity checks, not considering global consistency. + * Returns whether the content is valid. This is intended for local validity + * checks, not considering global consistency. + * * Content needs to be valid before it can be saved. * * This default implementation always returns true. @@ -156,38 +164,42 @@ interface Content { public function isValid(); /** - * Returns true if this Content objects is conceptually equivalent to the given Content object. + * Returns true if this Content objects is conceptually equivalent to the + * given Content object. + * * Contract: * - * * 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->getNativeData() is not equal to $this->getNativeData(), + * - 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->getNativeData() is not equal to $this->getNativeData(), * where the meaning of "equal" depends on the actual data model. * * Implementations should be careful to make equals() transitive and reflexive: * - * * $a->equals( $b ) <=> $b->equals( $a ) - * * $a->equals( $b ) && $b->equals( $c ) ==> $a->equals( $c ) + * - $a->equals( $b ) <=> $b->equals( $a ) + * - $a->equals( $b ) && $b->equals( $c ) ==> $a->equals( $c ) * * @since WD.1 * - * @param Content $that the Content object to compare to - * @return bool true if this Content object is equal to $that, false otherwise. + * @param $that Content The Content object to compare to + * @return bool True if this Content object is equal to $that, false otherwise. */ public function equals( Content $that = null ); /** - * Return a copy of this Content object. The following must be true for the object returned + * Return a copy of this Content object. The following must be true for the + * object returned: + * * if $copy = $original->copy() * - * * get_class($original) === get_class($copy) - * * $original->getModel() === $copy->getModel() - * * $original->equals( $copy ) + * - get_class($original) === get_class($copy) + * - $original->getModel() === $copy->getModel() + * - $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 for immutable content - * objects. + * 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 + * for immutable content objects. * * @since WD.1 * @@ -197,12 +209,14 @@ interface Content { /** * Returns true if this content is countable as a "real" wiki page, provided - * that it's also in a countable location (e.g. a current revision in the main namespace). + * that it's also in a countable location (e.g. a current revision in the + * main namespace). * * @since WD.1 * - * @param $hasLinks Bool: if it is known whether this content contains links, provide this information here, - * to avoid redundant parsing to find out. + * @param $hasLinks Bool: If it is known whether this content contains + * links, provide this information here, to avoid redundant parsing to + * find out. * @return boolean */ public function isCountable( $hasLinks = null ) ; @@ -214,18 +228,19 @@ interface Content { * @note: subclasses should NOT override this to provide custom rendering. * Override ContentHandler::getParserOutput() instead! * - * @param Title $title - * @param null $revId - * @param null|ParserOptions $options - * @param Boolean $generateHtml whether to generate Html (default: true). If false, - * the result of calling getText() on the ParserOutput object returned by - * this method is undefined. + * @param $title Title + * @param $revId null + * @param $options null|ParserOptions + * @param $generateHtml Boolean Whether to generate HTML (default: true). + * If false, the result of calling getText() on the ParserOutput object + * returned by this method is undefined. * * @since WD.1 * * @return ParserOutput */ - public function getParserOutput( Title $title, $revId = null, ParserOptions $options = null, $generateHtml = true ); + public function getParserOutput( Title $title, $revId = null, ParserOptions $options = null, + $generateHtml = true ); /** * Construct the redirect destination from this content and return an @@ -254,9 +269,14 @@ interface Content { /** * Construct the redirect destination from this content and return the * Title, or null if this content doesn't represent a redirect. - * This will recurse down $wgMaxRedirects times or until a non-redirect target is hit - * in order to provide (hopefully) the Title of the final destination instead of another redirect. * + * This will recurse down $wgMaxRedirects times or until a non-redirect + * target is hit in order to provide (hopefully) the Title of the final + * destination instead of another redirect. + * + * There is usually no need to override the default behaviour, subclasses that + * want to implement redirects should override getRedirectTarget(). + * * @since WD.1 * * @return Title @@ -274,22 +294,26 @@ interface Content { public function isRedirect(); /** - * Returns the section with the given id. + * Returns the section with the given ID. * * @since WD.1 * - * @param String $sectionId the section's id, given as a numeric string. The id "0" retrieves the section before - * the first heading, "1" the text between the first heading (included) and the second heading (excluded), etc. - * @return Content|Boolean|null the section, or false if no such section exist, or null if sections are not supported + * @param $sectionId string The section's ID, given as a numeric string. + * The ID "0" retrieves the section before the first heading, "1" the + * text between the first heading (included) and the second heading + * (excluded), etc. + * @return Content|Boolean|null The section, or false if no such section + * exist, or null if sections are not supported. */ public function getSection( $sectionId ); /** - * Replaces a section of the content and returns a Content object with the section replaced. + * Replaces a section of the content and returns a Content object with the + * section replaced. * * @since WD.1 * - * @param $section empty/null/false or a section number (0, 1, 2, T1, T2...), or "new" + * @param $section Empty/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 @@ -297,35 +321,38 @@ interface Content { public function replaceSection( $section, Content $with, $sectionTitle = '' ); /** - * Returns a Content object with pre-save transformations applied (or this object if no transformations apply). + * Returns a Content object with pre-save transformations applied (or this + * object if no transformations apply). * * @since WD.1 * - * @param Title $title - * @param User $user - * @param null|ParserOptions $popts + * @param $title Title + * @param $user User + * @param $popts null|ParserOptions * @return Content */ public function preSaveTransform( Title $title, User $user, ParserOptions $popts ); /** - * Returns a new WikitextContent object with the given section heading prepended, if supported. - * The default implementation just returns this Content object unmodified, ignoring the section header. + * Returns a new WikitextContent object with the given section heading + * prepended, if supported. The default implementation just returns this + * Content object unmodified, ignoring the section header. * * @since WD.1 * - * @param $header String + * @param $header string * @return Content */ public function addSectionHeader( $header ); /** - * Returns a Content object with preload transformations applied (or this object if no transformations apply). + * Returns a Content object with preload transformations applied (or this + * object if no transformations apply). * * @since WD.1 * - * @param Title $title - * @param null|ParserOptions $popts + * @param $title Title + * @param $popts null|ParserOptions * @return Content */ public function preloadTransform( Title $title, ParserOptions $popts ); @@ -334,7 +361,8 @@ interface Content { # TODO: make sure we cover lucene search / wikisearch. # TODO: make sure ReplaceTemplates still works # FUTURE: nice&sane integration of GeSHi syntax highlighting - # [11:59] Hooks are ugly; make CodeHighlighter interface and a config to set the class which handles syntax highlighting + # [11:59] Hooks are ugly; make CodeHighlighter interface and a + # config to set the class which handles syntax highlighting # [12:00] And default it to a DummyHighlighter # TODO: make sure we cover the external editor interface (does anyone actually use that?!) @@ -348,7 +376,8 @@ interface Content { # FUTURE: MultipartMultipart < WikipageContent (Main + Links + X) # FUTURE: LinksContent < LanguageLinksContent, CategoriesContent -// @TODO: add support for ar_content_format, ar_content_model, rev_content_format, rev_content_model to API + // @TODO: add support for ar_content_format, ar_content_model, + // rev_content_format, rev_content_model to API } @@ -364,24 +393,19 @@ abstract class AbstractContent implements Content { * Name of the content model this Content object represents. * Use with CONTENT_MODEL_XXX constants * - * @var String $model_id + * @var string $model_id */ protected $model_id; /** - * @param int $model_id + * @param $model_id int */ public function __construct( $model_id = null ) { $this->model_id = $model_id; } /** - * Returns the id of the content model used by this content objects. - * Corresponds to the CONTENT_MODEL_XXX constants. - * - * @since WD.1 - * - * @return int the model id + * @see Content::getModel() */ public function getModel() { return $this->model_id; @@ -391,7 +415,7 @@ abstract class AbstractContent implements Content { * Throws an MWException if $model_id is not the id of the content model * supported by this Content object. * - * @param int $model_id the model to check + * @param $model_id int the model to check * * @throws MWException */ @@ -400,65 +424,35 @@ abstract class AbstractContent implements Content { $model_name = ContentHandler::getContentModelName( $model_id ); $own_model_name = ContentHandler::getContentModelName( $this->model_id ); - throw new MWException( "Bad content model: expected {$this->model_id} ($own_model_name) but got found $model_id ($model_name)." ); + throw new MWException( "Bad content model: " . + "expected {$this->model_id} ($own_model_name) " . + "but got $model_id ($model_name)." ); } } /** - * Convenience method that returns the ContentHandler singleton for handling the content - * model this Content object uses. - * - * Shorthand for ContentHandler::getForContent( $this ) - * - * @since WD.1 - * - * @return ContentHandler + * @see Content::getContentHandler() */ public function getContentHandler() { return ContentHandler::getForContent( $this ); } /** - * Convenience method that returns the default serialization format for the content model - * model this Content object uses. - * - * Shorthand for $this->getContentHandler()->getDefaultFormat() - * - * @since WD.1 - * - * @return ContentHandler + * @see Content::getDefaultFormat() */ public function getDefaultFormat() { return $this->getContentHandler()->getDefaultFormat(); } /** - * Convenience method that returns the list of serialization formats supported - * for the content model model this Content object uses. - * - * Shorthand for $this->getContentHandler()->getSupportedFormats() - * - * @since WD.1 - * - * @return array of supported serialization formats + * @see Content::getSupportedFormats() */ public function getSupportedFormats() { return $this->getContentHandler()->getSupportedFormats(); } /** - * Returns true if $format is a supported serialization format for this Content object, - * false if it isn't. - * - * Note that this will always return true if $format is null, because null stands for the - * default serialization. - * - * Shorthand for $this->getContentHandler()->isSupportedFormat( $format ) - * - * @since WD.1 - * - * @param String $format the format to check - * @return bool whether the format is supported + * @see Content::isSupportedFormat() */ public function isSupportedFormat( $format ) { if ( !$format ) { @@ -469,77 +463,45 @@ abstract class AbstractContent implements Content { } /** - * Throws an MWException if $this->isSupportedFormat( $format ) doesn't return true. + * Throws an MWException if $this->isSupportedFormat( $format ) doesn't + * return true. * * @param $format * @throws MWException */ protected function checkFormat( $format ) { if ( !$this->isSupportedFormat( $format ) ) { - throw new MWException( "Format $format is not supported for content model " . $this->getModel() ); + throw new MWException( "Format $format is not supported for content model " . + $this->getModel() ); } } /** - * Convenience method for serializing this Content object. - * - * Shorthand for $this->getContentHandler()->serializeContent( $this, $format ) - * - * @since WD.1 - * - * @param null|String $format the desired serialization format (or null for the default format). - * @return String serialized form of this Content object + * @see Content::serialize */ public function serialize( $format = null ) { return $this->getContentHandler()->serializeContent( $this, $format ); } /** - * Returns true if this Content object represents empty content. - * - * @since WD.1 - * - * @return bool whether this Content object is empty + * @see Content::isEmpty() */ public function isEmpty() { return $this->getSize() == 0; } /** - * Returns if the content is valid. This is intended for local validity checks, not considering global consistency. - * It needs to be valid before it can be saved. - * - * This default implementation always returns true. - * - * @since WD.1 - * - * @return boolean + * @see Content::isValid() */ public function isValid() { return true; } /** - * Returns true if this Content objects is conceptually equivalent to the given Content object. - * - * Will returns false if $that is null. - * Will return true if $that === $this. - * Will return false if $that->getModelName() != $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. - * - * Implementations should be careful to make equals() transitive and reflexive: - * - * * $a->equals( $b ) <=> $b->equals( $a ) - * * $a->equals( $b ) && $b->equals( $c ) ==> $a->equals( $c ) - * - * @since WD.1 - * - * @param Content $that the Content object to compare to - * @return bool true if this Content object is euqual to $that, false otherwise. + * @see Content::equals() */ public function equals( Content $that = null ) { - if ( is_null( $that ) ){ + if ( is_null( $that ) ) { return false; } @@ -555,40 +517,17 @@ abstract class AbstractContent implements Content { } /** - * Convenience method, shorthand for - * $this->getContentHandler()->getParserOutput( $this, $title, $revId, $options, $generateHtml ) - * - * @note: subclasses should NOT override this to provide custom rendering. - * Override ContentHandler::getParserOutput() instead! - * - * @param Title $title - * @param null $revId - * @param null|ParserOptions $options - * @param Boolean $generateHtml whether to generate Html (default: true). If false, - * the result of calling getText() on the ParserOutput object returned by - * this method is undefined. - * - * @since WD.1 - * - * @return ParserOutput + * @see Content::getParserOutput() */ - public function getParserOutput( Title $title, $revId = null, ParserOptions $options = null, $generateHtml = true ) { - return $this->getContentHandler()->getParserOutput( $this, $title, $revId, $options, $generateHtml ); + public function getParserOutput( Title $title, $revId = null, ParserOptions $options = null, + $generateHtml = true ) + { + return $this->getContentHandler()->getParserOutput( + $this, $title, $revId, $options, $generateHtml ); } /** - * Construct the redirect destination from this content and return an - * array of Titles, or null if this content doesn't represent a redirect. - * The last element in the array is the final destination after all redirects - * have been resolved (up to $wgMaxRedirects times). - * - * There is usually no need to override the default behaviour, subclasses that - * want to implement redirects should override getRedirectTarget(). - * - * @since WD.1 - * - * @return Array of Titles, with the destination last - * @note: migrated here from Title::newFromRedirectArray + * @see Content::getRedirectChain() */ public function getRedirectChain() { global $wgMaxRedirects; @@ -608,7 +547,8 @@ abstract class AbstractContent implements Content { } // Redirects to some special pages are not permitted if ( $newtitle instanceOf Title && $newtitle->isValidRedirectTarget() ) { - // the new title passes the checks, so make that our current title so that further recursion can be checked + // The new title passes the checks, so make that our current + // title so that further recursion can be checked $title = $newtitle; $titles[] = $newtitle; } else { @@ -619,35 +559,14 @@ abstract class AbstractContent implements Content { } /** - * Construct the redirect destination from this content and return a Title, - * or null if this content doesn't represent a redirect. - * - * This shall only return the immediate redirect target, useful for - * the redirect table and other checks that don't need full recursion. - * - * This implementation always returns null, subclasses should implement it - * according to their data model. - * - * @since WD.1 - * - * @return Title: The corresponding Title + * @see Content::getRedirectTarget() */ public function getRedirectTarget() { return null; } /** - * Construct the redirect destination from this content and return the - * Title, or null if this content doesn't represent a redirect. - * This will recurse down $wgMaxRedirects times or until a non-redirect target is hit - * in order to provide (hopefully) the Title of the final destination instead of another redirect. - * - * There is usually no need to override the default behaviour, subclasses that - * want to implement redirects should override getRedirectTarget(). - * - * @since WD.1 - * - * @return Title + * @see Content::getUltimateRedirectTarget() * @note: migrated here from Title::newFromRedirectRecurse */ public function getUltimateRedirectTarget() { @@ -665,69 +584,35 @@ abstract class AbstractContent implements Content { } /** - * Returns the section with the given id. - * - * The default implementation returns null. - * - * @since WD.1 - * - * @param String $sectionId the section's id, given as a numeric string. The id "0" retrieves the section before - * the first heading, "1" the text between the first heading (included) and the second heading (excluded), etc. - * @return Content|Boolean|null the section, or false if no such section exist, or null if sections are not supported + * @see Content::getSection() */ public function getSection( $sectionId ) { return null; } /** - * Replaces a section of the content and returns a Content object with the section replaced. - * - * @since WD.1 - * - * @param $section empty/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 + * @see Content::replaceSection() */ public function replaceSection( $section, Content $with, $sectionTitle = '' ) { return null; } /** - * Returns a Content object with pre-save transformations applied (or this object if no transformations apply). - * - * @since WD.1 - * - * @param Title $title - * @param User $user - * @param null|ParserOptions $popts - * @return Content + * @see Content::preSaveTransform() */ public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) { return $this; } /** - * Returns a new WikitextContent object with the given section heading prepended, if supported. - * The default implementation just returns this Content object unmodified, ignoring the section header. - * - * @since WD.1 - * - * @param $header String - * @return Content + * @see Content::addSectionHeader() */ public function addSectionHeader( $header ) { return $this; } /** - * Returns a Content object with preload transformations applied (or this object if no transformations apply). - * - * @since WD.1 - * - * @param Title $title - * @param null|ParserOptions $popts - * @return Content + * @see Content::preloadTransform() */ public function preloadTransform( Title $title, ParserOptions $popts ) { return $this; @@ -750,7 +635,7 @@ abstract class TextContent extends AbstractContent { } public function copy() { - return $this; #NOTE: this is ok since TextContent are immutable. + return $this; # NOTE: this is ok since TextContent are immutable. } public function getTextForSummary( $maxlength = 250 ) { @@ -768,7 +653,7 @@ abstract class TextContent extends AbstractContent { /** * returns the text's size in bytes. * - * @return int the size + * @return int The size */ public function getSize( ) { $text = $this->getNativeData( ); @@ -776,12 +661,13 @@ abstract class TextContent extends AbstractContent { } /** - * Returns true if this content is not a redirect, and $wgArticleCountMethod is "any". + * Returns true if this content is not a redirect, and $wgArticleCountMethod + * is "any". * - * @param $hasLinks Bool: if it is known whether this content contains links, provide this information here, - * to avoid redundant parsing to find out. + * @param $hasLinks Bool: if it is known whether this content contains links, + * provide this information here, to avoid redundant parsing to find out. * - * @return bool true if the content is countable + * @return bool True if the content is countable */ public function isCountable( $hasLinks = null ) { global $wgArticleCountMethod; @@ -800,7 +686,7 @@ abstract class TextContent extends AbstractContent { /** * Returns the text represented by this Content object, as a string. * - * @return String the raw text + * @param the raw text */ public function getNativeData( ) { $text = $this->mText; @@ -810,7 +696,7 @@ abstract class TextContent extends AbstractContent { /** * Returns the text represented by this Content object, as a string. * - * @return String the raw text + * @param the raw text */ public function getTextForSearchIndex( ) { return $this->getNativeData(); @@ -819,7 +705,7 @@ abstract class TextContent extends AbstractContent { /** * Returns the text represented by this Content object, as a string. * - * @return String the raw text + * @param the raw text */ public function getWikitextForTransclusion( ) { return $this->getNativeData(); @@ -830,18 +716,19 @@ abstract class TextContent extends AbstractContent { * * @since WD.diff * - * @param Content $that the other content object to compare this content object to - * @param Language $lang the language object to use for text segmentation. If not given, $wgContentLang is used. + * @param $that Content the other content object to compare this content object to + * @param $lang Language the language object to use for text segmentation. + * If not given, $wgContentLang is used. * - * @return DiffResult a diff representing the changes that would have to be made to this content object - * to make it equal to $that. + * @return DiffResult a diff representing the changes that would have to be + * made to this content object to make it equal to $that. */ public function diff( Content $that, Language $lang = null ) { global $wgContLang; $this->checkModelID( $that->getModel() ); - #@todo: could implement this in DifferenceEngine and just delegate here? + # @todo: could implement this in DifferenceEngine and just delegate here? if ( !$lang ) $lang = $wgContLang; @@ -865,16 +752,11 @@ abstract class TextContent extends AbstractContent { class WikitextContent extends TextContent { public function __construct( $text ) { - parent::__construct($text, CONTENT_MODEL_WIKITEXT); + parent::__construct( $text, CONTENT_MODEL_WIKITEXT ); } /** - * Returns the section with the given id. - * - * @param String $section - * - * @internal param String $sectionId the section's id - * @return Content|false|null the section, or false if no such section exist, or null if sections are not supported + * @see Content::getSection() */ public function getSection( $section ) { global $wgParser; @@ -886,14 +768,7 @@ class WikitextContent extends TextContent { } /** - * Replaces a section in the wikitext - * - * @param $section empty/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' - * - * @throws MWException - * @return Content Complete article content, or null if error + * @see Content::replaceSection() */ public function replaceSection( $section, Content $with, $sectionTitle = '' ) { wfProfileIn( __METHOD__ ); @@ -905,18 +780,23 @@ class WikitextContent extends TextContent { $myModelName = ContentHandler::getContentModelName( $myModelId ); $sectionModelName = ContentHandler::getContentModelName( $sectionModelId ); - throw new MWException( "Incompatible content model for section: document uses $myModelId ($myModelName), " - . "section uses $sectionModelId ($sectionModelName)." ); + throw new MWException( "Incompatible content model for section: " . + "document uses $myModelId ($myModelName), " . + "section uses $sectionModelId ($sectionModelName)." ); } $oldtext = $this->getNativeData(); $text = $with->getNativeData(); if ( $section === '' ) { - return $with; #XXX: copy first? + return $with; # XXX: copy first? } if ( $section == 'new' ) { # Inserting a new section - $subject = $sectionTitle ? wfMsgForContent( 'newsectionheaderdefaultlevel', $sectionTitle ) . "\n\n" : ''; + if ( $sectionTitle ) { + $subject = wfMsgForContent( 'newsectionheaderdefaultlevel', $sectionTitle ) . "\n\n"; + } else { + $subject = ''; + } if ( wfRunHooks( 'PlaceNewSection', array( $this, $oldtext, $subject, &$text ) ) ) { $text = strlen( trim( $oldtext ) ) > 0 ? "{$oldtext}\n\n{$subject}{$text}" @@ -936,23 +816,26 @@ class WikitextContent extends TextContent { } /** - * Returns a new WikitextContent object with the given section heading prepended. + * Returns a new WikitextContent object with the given section heading + * prepended. * - * @param $header String + * @param $header string * @return Content */ public function addSectionHeader( $header ) { - $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $header ) . "\n\n" . $this->getNativeData(); + $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $header ) . "\n\n" . + $this->getNativeData(); return new WikitextContent( $text ); } /** - * Returns a Content object with pre-save transformations applied using Parser::preSaveTransform(). + * Returns a Content object with pre-save transformations applied using + * Parser::preSaveTransform(). * - * @param Title $title - * @param User $user - * @param ParserOptions $popts + * @param $title Title + * @param $user User + * @param $popts ParserOptions * @return Content */ public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) { @@ -965,10 +848,11 @@ class WikitextContent extends TextContent { } /** - * Returns a Content object with preload transformations applied (or this object if no transformations apply). + * Returns a Content object with preload transformations applied (or this + * object if no transformations apply). * - * @param Title $title - * @param ParserOptions $popts + * @param $title Title + * @param $popts ParserOptions * @return Content */ public function preloadTransform( Title $title, ParserOptions $popts ) { @@ -993,7 +877,7 @@ class WikitextContent extends TextContent { public function getRedirectTarget() { global $wgMaxRedirects; if ( $wgMaxRedirects < 1 ) { - //redirects are disabled, so quit early + // redirects are disabled, so quit early return null; } $redir = MagicWord::get( 'redirect' ); @@ -1022,16 +906,17 @@ 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. + * 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 links, provide this information here, - * to avoid redundant parsing to find out. - * @param null|\Title $title + * @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 * * @internal param \IContextSource $context context for parsing if necessary * - * @return bool true if the content is countable + * @return bool True if the content is countable */ public function isCountable( $hasLinks = null, Title $title = null ) { global $wgArticleCountMethod; @@ -1068,8 +953,9 @@ class WikitextContent extends TextContent { public function getTextForSummary( $maxlength = 250 ) { $truncatedtext = parent::getTextForSummary( $maxlength ); - #clean up unfinished links - #XXX: make this optional? wasn't there in autosummary, but required for deletion summary. + # clean up unfinished links + # XXX: make this optional? wasn't there in autosummary, but required for + # deletion summary. $truncatedtext = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $truncatedtext ); return $truncatedtext; @@ -1082,7 +968,9 @@ class WikitextContent extends TextContent { */ class MessageContent extends TextContent { public function __construct( $msg_key, $params = null, $options = null ) { - parent::__construct(null, CONTENT_MODEL_WIKITEXT); #XXX: messages may be wikitext, html or plain text! and maybe even something else entirely. + # XXX: messages may be wikitext, html or plain text! and maybe even + # something else entirely. + parent::__construct( null, CONTENT_MODEL_WIKITEXT ); $this->mMessageKey = $msg_key; @@ -1099,23 +987,25 @@ class MessageContent extends TextContent { } /** - * Returns the message as rendered HTML, using the options supplied to the constructor plus "parse". - * @return String the message text, parsed + * Returns the message as rendered HTML, using the options supplied to the + * constructor plus "parse". + * @param the message text, parsed */ public function getHtml( ) { - $opt = array_merge( $this->mOptions, array('parse') ); + $opt = array_merge( $this->mOptions, array( 'parse' ) ); return wfMsgExt( $this->mMessageKey, $this->mParameters, $opt ); } /** - * Returns the message as raw text, using the options supplied to the constructor minus "parse" and "parseinline". + * Returns the message as raw text, using the options supplied to the + * constructor minus "parse" and "parseinline". * - * @return String the message text, unparsed. + * @param the message text, unparsed. */ public function getNativeData( ) { - $opt = array_diff( $this->mOptions, array('parse', 'parseinline') ); + $opt = array_diff( $this->mOptions, array( 'parse', 'parseinline' ) ); return wfMsgExt( $this->mMessageKey, $this->mParameters, $opt ); } @@ -1127,11 +1017,12 @@ class MessageContent extends TextContent { */ class JavaScriptContent extends TextContent { public function __construct( $text ) { - parent::__construct($text, CONTENT_MODEL_JAVASCRIPT); + parent::__construct( $text, CONTENT_MODEL_JAVASCRIPT ); } /** - * Returns a Content object with pre-save transformations applied using Parser::preSaveTransform(). + * Returns a Content object with pre-save transformations applied using + * Parser::preSaveTransform(). * * @param Title $title * @param User $user @@ -1141,6 +1032,7 @@ class JavaScriptContent extends TextContent { public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) { global $wgParser; // @todo: make pre-save transformation optional for script pages + // See bug #32858 $text = $this->getNativeData(); $pst = $wgParser->preSaveTransform( $text, $title, $user, $popts ); @@ -1155,15 +1047,16 @@ class JavaScriptContent extends TextContent { */ class CssContent extends TextContent { public function __construct( $text ) { - parent::__construct($text, CONTENT_MODEL_CSS); + parent::__construct( $text, CONTENT_MODEL_CSS ); } /** - * Returns a Content object with pre-save transformations applied using Parser::preSaveTransform(). + * Returns a Content object with pre-save transformations applied using + * Parser::preSaveTransform(). * - * @param Title $title - * @param User $user - * @param ParserOptions $popts + * @param $title Title + * @param $user User + * @param $popts ParserOptions * @return Content */ public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) { diff --git a/includes/ContentHandler.php b/includes/ContentHandler.php index ce7d08349d..486de365c6 100644 --- a/includes/ContentHandler.php +++ b/includes/ContentHandler.php @@ -8,46 +8,54 @@ class MWContentSerializationException extends MWException { } /** - * A content handler knows how do deal with a specific type of content on a wiki page. - * Content is stored in the database in a serialized form (using a serialization format aka mime type) - * and is be unserialized into it's native PHP representation (the content model), which is wrapped in - * an instance of the appropriate subclass of Content. + * A content handler knows how do deal with a specific type of content on a wiki + * page. Content is stored in the database in a serialized form (using a + * serialization format a.k.a. MIME type) and is unserialized into its native + * PHP representation (the content model), which is wrapped in an instance of + * the appropriate subclass of Content. * - * ContentHandler instances are stateless singletons that serve, among other things, as a factory for - * Content objects. Generally, there is one subclass of ContentHandler and one subclass of Content - * for every type of content model. + * ContentHandler instances are stateless singletons that serve, among other + * things, as a factory for Content objects. Generally, there is one subclass + * of ContentHandler and one subclass of Content for every type of content model. * - * Some content types have a flat model, that is, their native representation is the - * same as their serialized form. Examples would be JavaScript and CSS code. As of now, - * this also applies to wikitext (mediawiki's default content type), but wikitext - * content may be represented by a DOM or AST structure in the future. + * Some content types have a flat model, that is, their native representation + * is the same as their serialized form. Examples would be JavaScript and CSS + * code. As of now, this also applies to wikitext (MediaWiki's default content + * type), but wikitext content may be represented by a DOM or AST structure in + * the future. * * @since 1.WD */ abstract class ContentHandler { /** - * Convenience function for getting flat text from a Content object. This should only - * be used in the context of backwards compatibility with code that is not yet able - * to handle Content objects! + * Convenience function for getting flat text from a Content object. This + * should only be used in the context of backwards compatibility with code + * that is not yet able to handle Content objects! * * If $content is null, this method returns the empty string. * - * If $content is an instance of TextContent, this method returns the flat text as returned by $content->getNativeData(). + * If $content is an instance of TextContent, this method returns the flat + * text as returned by $content->getNativeData(). * - * If $content is not a TextContent object, the behavior of this method depends on the global $wgContentHandlerTextFallback: - * * If $wgContentHandlerTextFallback is 'fail' and $content is not a TextContent object, an MWException is thrown. - * * If $wgContentHandlerTextFallback is 'serialize' and $content is not a TextContent object, $content->serialize() - * is called to get a string form of the content. - * * If $wgContentHandlerTextFallback is 'ignore' and $content is not a TextContent object, this method returns null. - * * otherwise, the behaviour is undefined. + * If $content is not a TextContent object, the behavior of this method + * depends on the global $wgContentHandlerTextFallback: + * - If $wgContentHandlerTextFallback is 'fail' and $content is not a + * TextContent object, an MWException is thrown. + * - If $wgContentHandlerTextFallback is 'serialize' and $content is not a + * TextContent object, $content->serialize() is called to get a string + * form of the content. + * - If $wgContentHandlerTextFallback is 'ignore' and $content is not a + * TextContent object, this method returns null. + * - otherwise, the behaviour is undefined. * * @since WD.1 * * @static - * @param Content|null $content + * @param $content Content|null * @return null|string the textual form of $content, if available - * @throws MWException if $content is not an instance of TextContent and $wgContentHandlerTextFallback was set to 'fail'. + * @throws MWException if $content is not an instance of TextContent and + * $wgContentHandlerTextFallback was set to 'fail'. */ public static function getContentText( Content $content = null ) { global $wgContentHandlerTextFallback; @@ -61,7 +69,10 @@ abstract class ContentHandler { } if ( $wgContentHandlerTextFallback == 'fail' ) { - throw new MWException( "Attempt to get text from Content with model " . $content->getModel() ); + throw new MWException( + "Attempt to get text from Content with model " . + $content->getModel() + ); } if ( $wgContentHandlerTextFallback == 'serialize' ) { @@ -72,26 +83,34 @@ abstract class ContentHandler { } /** - * Convenience function for creating a Content object from a given textual representation. + * Convenience function for creating a Content object from a given textual + * representation. * - * $text will be deserialized into a Content object of the model specified by $modelId (or, - * if that is not given, $title->getContentModel()) using the given format. + * $text will be deserialized into a Content object of the model specified + * by $modelId (or, if that is not given, $title->getContentModel()) using + * the given format. * * @since WD.1 * * @static * - * @param string $text the textual representation, will be unserialized to create the Content object - * @param null|Title $title the title of the page this text belongs to. Required if $modelId is not provided. - * @param null|String $modelId the model to deserialize to. If not provided, $title->getContentModel() is used. - * @param null|String $format the format to use for deserialization. If not given, the model's default format is used. + * @param $text string the textual representation, will be + * unserialized to create the Content object + * @param $title null|Title the title of the page this text belongs to. + * Required if $modelId is not provided. + * @param $modelId null|string the model to deserialize to. If not provided, + * $title->getContentModel() is used. + * @param $format null|string the format to use for deserialization. If not + * given, the model's default format is used. * * @return Content a Content object representing $text * - * @throw MWException if $model or $format is not supported or if $text can not be unserialized using $format. + * @throw MWException if $model or $format is not supported or if $text can + * not be unserialized using $format. */ - public static function makeContent( $text, Title $title = null, $modelId = null, $format = null ) { - + public static function makeContent( $text, Title $title = null, + $modelId = null, $format = null ) + { if ( is_null( $modelId ) ) { if ( is_null( $title ) ) { throw new MWException( "Must provide a Title object or a content model ID." ); @@ -105,18 +124,26 @@ abstract class ContentHandler { } /** - * Returns the name of the default content model to be used for the page with the given title. + * Returns the name of the default content model to be used for the page + * with the given title. * * Note: There should rarely be need to call this method directly. - * To determine the actual content model for a given page, use Title::getContentModel(). - * - * Which model is to be used per default for the page is determined based on several factors: - * * The global setting $wgNamespaceContentModels specifies a content model per namespace. - * * The hook DefaultModelFor may be used to override the page's default model. - * * Pages in NS_MEDIAWIKI and NS_USER default to the CSS or JavaScript model if they end in .js or .css, respectively. - * * Pages in NS_MEDIAWIKI default to the wikitext model otherwise. - * * The hook TitleIsCssOrJsPage may be used to force a page to use the CSS or JavaScript model if they end in .js or .css, respectively. - * * The hook TitleIsWikitextPage may be used to force a page to use the wikitext model. + * To determine the actual content model for a given page, use + * Title::getContentModel(). + * + * Which model is to be used by default for the page is determined based + * on several factors: + * - The global setting $wgNamespaceContentModels specifies a content model + * per namespace. + * - The hook DefaultModelFor may be used to override the page's default + * model. + * - Pages in NS_MEDIAWIKI and NS_USER default to the CSS or JavaScript + * model if they end in .js or .css, respectively. + * - Pages in NS_MEDIAWIKI default to the wikitext model otherwise. + * - The hook TitleIsCssOrJsPage may be used to force a page to use the CSS + * or JavaScript model if they end in .js or .css, respectively. + * - The hook TitleIsWikitextPage may be used to force a page to use the + * wikitext model. * * If none of the above applies, the wikitext model is used. * @@ -125,14 +152,14 @@ abstract class ContentHandler { * @since WD.1 * * @static - * @param Title $title + * @param $title Title * @return null|string default model name for the page given by $title */ public static function getDefaultModelFor( Title $title ) { global $wgNamespaceContentModels; // NOTE: this method must not rely on $title->getContentModel() directly or indirectly, - // because it is used to initialized the mContentModel member. + // because it is used to initialize the mContentModel member. $ns = $title->getNamespace(); @@ -144,7 +171,7 @@ abstract class ContentHandler { $model = $wgNamespaceContentModels[ $ns ]; } - // hook can determin default model + // Hook can determine default model if ( !wfRunHooks( 'ContentHandlerDefaultModelFor', array( $title, &$model ) ) ) { if ( !is_null( $model ) ) { return $model; @@ -157,20 +184,22 @@ abstract class ContentHandler { $ext = $m[1]; } - // hook can force js/css + // Hook can force JS/CSS wfRunHooks( 'TitleIsCssOrJsPage', array( $title, &$isCssOrJsPage ) ); // Is this a .css subpage of a user page? - $isJsCssSubpage = NS_USER == $ns && !$isCssOrJsPage && preg_match( "/\\/.*\\.(js|css)$/", $title->getText(), $m ); + $isJsCssSubpage = NS_USER == $ns + && !$isCssOrJsPage + && preg_match( "/\\/.*\\.(js|css)$/", $title->getText(), $m ); if ( $isJsCssSubpage ) { $ext = $m[1]; } - // is this wikitext, according to $wgNamespaceContentModels or the DefaultModelFor hook? + // Is this wikitext, according to $wgNamespaceContentModels or the DefaultModelFor hook? $isWikitext = is_null( $model ) || $model == CONTENT_MODEL_WIKITEXT; $isWikitext = $isWikitext && !$isCssOrJsPage && !$isJsCssSubpage; - // hook can override $isWikitext + // Hook can override $isWikitext wfRunHooks( 'TitleIsWikitextPage', array( $title, &$isWikitext ) ); if ( !$isWikitext ) { @@ -184,18 +213,18 @@ abstract class ContentHandler { } } - // we established that is must be wikitext + // We established that it must be wikitext return CONTENT_MODEL_WIKITEXT; } /** - * returns the appropriate ContentHandler singleton for the given title + * Returns the appropriate ContentHandler singleton for the given title. * * @since WD.1 * * @static - * @param Title $title + * @param $title Title * @return ContentHandler */ public static function getForTitle( Title $title ) { @@ -204,12 +233,13 @@ abstract class ContentHandler { } /** - * returns the appropriate ContentHandler singleton for the given Content object + * Returns the appropriate ContentHandler singleton for the given Content + * object. * * @since WD.1 * * @static - * @param Content $content + * @param $content Content * @return ContentHandler */ public static function getForContent( Content $content ) { @@ -218,24 +248,29 @@ abstract class ContentHandler { } /** - * returns the ContentHandler singleton for the given model id. Use the CONTENT_MODEL_XXX constants to - * identify the desired content model. + * Returns the ContentHandler singleton for the given model ID. Use the + * CONTENT_MODEL_XXX constants to identify the desired content model. * - * ContentHandler singletons are take from the global $wgContentHandlers array. Keys in that array are - * model names, the values are either ContentHandler singleton objects, or strings specifying the appropriate + * ContentHandler singletons are taken from the global $wgContentHandlers + * array. Keys in that array are model names, the values are either + * ContentHandler singleton objects, or strings specifying the appropriate * subclass of ContentHandler. * - * If a class name in encountered when looking up the singleton for a given model name, the class is - * instantiated and the class name is replaced by te resulting singleton in $wgContentHandlers. + * If a class name is encountered when looking up the singleton for a given + * model name, the class is instantiated and the class name is replaced by + * the resulting singleton in $wgContentHandlers. * - * If no ContentHandler is defined for the desired $modelId, the ContentHandler may be provided by the - * a ContentHandlerForModelID hook. if no ContentHandler can be determined, an MWException is raised. + * If no ContentHandler is defined for the desired $modelId, the + * ContentHandler may be provided by the ContentHandlerForModelID hook. + * If no ContentHandler can be determined, an MWException is raised. * * @since WD.1 * * @static - * @param $modelId int the id of the content model for which to get a handler. Use CONTENT_MODEL_XXX constants. - * @return ContentHandler the ContentHandler singleton for handling the model given by $modelId + * @param $modelId int The ID of the content model for which to get a + * handler. Use CONTENT_MODEL_XXX constants. + * @return ContentHandler The ContentHandler singleton for handling the + * model given by $modelId * @throws MWException if no handler is known for $modelId. */ public static function getForModelID( $modelId ) { @@ -249,7 +284,8 @@ abstract class ContentHandler { if ( $handler ) { // NOTE: may be a string or an object, either is fine! $wgContentHandlers[$modelId] = $handler; } else { - throw new MWException( "No handler for model #$modelId registered in \$wgContentHandlers" ); + throw new MWException( "No handler for model #$modelId registered " . + "in \$wgContentHandlers" ); } } @@ -262,16 +298,16 @@ abstract class ContentHandler { } /** - * Returns the appropriate mime type for a given content format, - * or null if no mime type is known for this format. + * Returns the appropriate MIME type for a given content format, + * or null if no MIME type is known for this format. * - * Mime types can be registered in the global array $wgContentFormatMimeTypes. + * MIME types can be registered in the global array $wgContentFormatMimeTypes. * * @static - * @param int $id the content format id, as given by a CONTENT_FORMAT_XXX constant - * or returned by Revision::getContentFormat(). + * @param $id int The content format id, as given by a CONTENT_FORMAT_XXX + * constant or returned by Revision::getContentFormat(). * - * @return String|null the content format's mime type. + * @return string|null The content format's MIME type. */ public static function getContentFormatMimeType( $id ) { global $wgContentFormatMimeTypes; @@ -284,15 +320,15 @@ abstract class ContentHandler { } /** - * Returns the content format if for a given mime type, - * or null if no format id if known for this mime type. + * Returns the content format if for a given MIME type, + * or null if no format ID if known for this MIME type. * * Mime types can be registered in the global array $wgContentFormatMimeTypes. * * @static - * @param String $mime the mime type + * @param $mime string the MIME type * - * @return int|null the format id, as defined by a CONTENT_FORMAT_XXX constant + * @return int|null The format ID, as defined by a CONTENT_FORMAT_XXX constant */ public static function getContentFormatID( $mime ) { global $wgContentFormatMimeTypes; @@ -312,16 +348,16 @@ abstract class ContentHandler { /** * Returns the localized name for a given content model, - * or null of no mime type is known. + * or null if no MIME type is known. * * Model names are localized using system messages. Message keys * have the form content-model-$id. * * @static - * @param int $id the content model id, as given by a CONTENT_MODEL_XXX constant - * or returned by Revision::getContentModel(). + * @param $id int The content model ID, as given by a CONTENT_MODEL_XXX + * constant or returned by Revision::getContentModel(). * - * @return String|null the content format's mime type. + * @return string|null The content format's MIME type. */ public static function getContentModelName( $id ) { $key = "content-model-$id"; @@ -330,17 +366,19 @@ abstract class ContentHandler { else return wfMsg( $key ); } - // ---------------------------------------------------------------------------------------------------------- + // ------------------------------------------------------------------------ protected $mModelID; protected $mSupportedFormats; /** - * Constructor, initializing the ContentHandler instance with it's model id and a list of supported formats. - * Values for the parameters are typically provided as literals by subclasses' constructors. + * Constructor, initializing the ContentHandler instance with its model ID + * and a list of supported formats. Values for the parameters are typically + * provided as literals by subclass's constructors. * - * @param int $modelId (use CONTENT_MODEL_XXX constants). - * @param array $formats list for supported serialization formats (typically as MIME types) + * @param $modelId int (use CONTENT_MODEL_XXX constants). + * @param $formats array List for supported serialization formats + * (typically as MIME types) */ public function __construct( $modelId, $formats ) { $this->mModelID = $modelId; @@ -349,14 +387,14 @@ abstract class ContentHandler { /** - * Serializes Content object of the type supported by this ContentHandler. + * Serializes a Content object of the type supported by this ContentHandler. * * @since WD.1 * * @abstract - * @param Content $content the Content object to serialize - * @param null $format the desired serialization format - * @return String serialized form of the content + * @param $content Content The Content object to serialize + * @param $format null The desired serialization format + * @return string Serialized form of the content */ public abstract function serializeContent( Content $content, $format = null ); @@ -366,14 +404,15 @@ abstract class ContentHandler { * @since WD.1 * * @abstract - * @param $blob String serialized form of the content - * @param null $format the format used for serialization + * @param $blob string serialized form of the content + * @param $format null the format used for serialization * @return Content the Content object created by deserializing $blob */ public abstract function unserializeContent( $blob, $format = null ); /** - * Creates an empty Content object of the type supported by this ContentHandler. + * Creates an empty Content object of the type supported by this + * ContentHandler. * * @since WD.1 * @@ -382,24 +421,24 @@ abstract class ContentHandler { public abstract function makeEmptyContent(); /** - * Returns the model id that identifies the content model this ContentHandler can handle. - * Use with the CONTENT_MODEL_XXX constants. + * Returns the model id that identifies the content model this + * ContentHandler can handle. Use with the CONTENT_MODEL_XXX constants. * * @since WD.1 * - * @return int the model id + * @return int The model ID */ public function getModelID() { return $this->mModelID; } /** - * Throws an MWException if $model_id is not the id of the content model + * Throws an MWException if $model_id is not the ID of the content model * supported by this ContentHandler. * * @since WD.1 * - * @param int $model_id the model to check + * @param $model_id int The model to check * * @throws MWException */ @@ -408,13 +447,16 @@ abstract class ContentHandler { $model_name = ContentHandler::getContentModelName( $model_id ); $own_model_name = ContentHandler::getContentModelName( $this->mModelID ); - throw new MWException( "Bad content model: expected {$this->mModelID} ($own_model_name) but got found $model_id ($model_name)." ); + throw new MWException( "Bad content model: " . + "expected {$this->mModelID} ($own_model_name) " . + "but got $model_id ($model_name)." ); } } /** - * Returns a list of serialization formats supported by the serializeContent() and unserializeContent() methods of - * this ContentHandler. + * Returns a list of serialization formats supported by the + * serializeContent() and unserializeContent() methods of this + * ContentHandler. * * @since WD.1 * @@ -425,29 +467,30 @@ abstract class ContentHandler { } /** - * The format used for serialization/deserialization per default by this ContentHandler. + * The format used for serialization/deserialization by default by this + * ContentHandler. * - * This default implementation will return the first element of the array of formats - * that was passed to the constructor. + * This default implementation will return the first element of the array + * of formats that was passed to the constructor. * * @since WD.1 * - * @return String the name of the default serialization format as a MIME type + * @return string the name of the default serialization format as a MIME type */ public function getDefaultFormat() { return $this->mSupportedFormats[0]; } /** - * Returns true if $format is a serialization format supported by this ContentHandler, - * and false otherwise. + * Returns true if $format is a serialization format supported by this + * ContentHandler, and false otherwise. * - * Note that if $format is null, this method always returns true, because null - * means "use the default format". + * Note that if $format is null, this method always returns true, because + * null means "use the default format". * * @since WD.1 * - * @param String $format the serialization format to check + * @param $format string the serialization format to check * @return bool */ public function isSupportedFormat( $format ) { @@ -460,22 +503,26 @@ abstract class ContentHandler { } /** - * Throws an MWException if isSupportedFormat( $format ) is not true. Convenient - * for checking whether a format provided as a parameter is actually supported. + * Throws an MWException if isSupportedFormat( $format ) is not true. + * Convenient for checking whether a format provided as a parameter is + * actually supported. * - * @param String $format the serialization format to check + * @param $format string the serialization format to check * * @throws MWException */ protected function checkFormat( $format ) { if ( !$this->isSupportedFormat( $format ) ) { - throw new MWException( "Format $format is not supported for content model " . $this->getModelID() ); + throw new MWException( + "Format $format is not supported for content model " + . $this->getModelID() + ); } } /** - * Returns if the content is consistent with the database, that is if saving it to the database would not violate any - * global constraints. + * Returns true if the content is consistent with the database, that is if + * saving it to the database would not violate any global constraints. * * Content needs to be valid using this method before it can be saved. * @@ -483,7 +530,7 @@ abstract class ContentHandler { * * @since WD.1 * - * @param \Content $content + * @param $content \Content * * @return boolean */ @@ -506,22 +553,25 @@ abstract class ContentHandler { } /** - * Factory creating an appropriate DifferenceEngine for this content model. + * Factory for creating an appropriate DifferenceEngine for this content model. * * @since WD.1 * - * @param $context IContextSource context to use, anything else will be ignored - * @param $old Integer old ID we want to show and diff with. - * @param int|String $new String either 'prev' or 'next'. - * @param $rcid Integer ??? FIXME (default 0) - * @param $refreshCache boolean If set, refreshes the diff cache - * @param $unhide boolean If set, allow viewing deleted revs + * @param $context IContextSource context to use, anything else will be + * ignored + * @param $old Integer Old ID we want to show and diff with. + * @param $new int|string String either 'prev' or 'next'. + * @param $rcid Integer ??? FIXME (default 0) + * @param $refreshCache boolean If set, refreshes the diff cache + * @param $unhide boolean If set, allow viewing deleted revs * * @return DifferenceEngine */ - public function createDifferenceEngine( IContextSource $context, $old = 0, $new = 0, $rcid = 0, #FIMXE: use everywhere! - $refreshCache = false, $unhide = false ) { - + public function createDifferenceEngine( IContextSource $context, + $old = 0, $new = 0, + $rcid = 0, # FIXME: use everywhere! + $refreshCache = false, $unhide = false + ) { $this->checkModelID( $context->getTitle()->getContentModel() ); $diffEngineClass = $this->getDiffEngineClass(); @@ -541,16 +591,17 @@ abstract class ContentHandler { } /** - * attempts to merge differences between three versions. - * Returns a new Content object for a clean merge and false for failure or a conflict. + * Attempts to merge differences between three versions. + * Returns a new Content object for a clean merge and false for failure or + * a conflict. * * This default implementation always returns false. * * @since WD.1 * - * @param Content|String $oldContent String - * @param Content|String $myContent String - * @param Content|String $yourContent String + * @param $oldContent Content|string String + * @param $myContent Content|string String + * @param $yourContent Content|string String * * @return Content|Bool */ @@ -565,7 +616,7 @@ abstract class ContentHandler { * * @param $oldContent Content|null: the previous text of the page. * @param $newContent Content|null: The submitted text of the page. - * @param $flags Int bit mask: a bit mask of flags submitted for the edit. + * @param $flags int Bit mask: a bit mask of flags submitted for the edit. * * @return string An appropriate auto-summary, or an empty string. */ @@ -584,19 +635,24 @@ abstract class ContentHandler { $ot = !is_null( $oldContent ) ? $oldContent->getRedirectTarget() : null; $rt = !is_null( $newContent ) ? $newContent->getRedirectTarget() : null; - if ( is_object( $rt ) && ( !is_object( $ot ) || !$rt->equals( $ot ) || $ot->getFragment() != $rt->getFragment() ) ) { - - $truncatedtext = $newContent->getTextForSummary( - 250 - - strlen( wfMsgForContent( 'autoredircomment' ) ) - - strlen( $rt->getFullText() ) ); - - return wfMsgForContent( 'autoredircomment', $rt->getFullText(), $truncatedtext ); + if ( is_object( $rt ) ) { + if ( !is_object( $ot ) + || !$rt->equals( $ot ) + || $ot->getFragment() != $rt->getFragment() ) + { + $truncatedtext = $newContent->getTextForSummary( + 250 + - strlen( wfMsgForContent( 'autoredircomment' ) ) + - strlen( $rt->getFullText() ) ); + + return wfMsgForContent( 'autoredircomment', $rt->getFullText(), $truncatedtext ); + } } // New page auto-summaries if ( $flags & EDIT_NEW && $newContent->getSize() > 0 ) { - // If they're making a new article, give its text, truncated, in the summary. + // If they're making a new article, give its text, truncated, in + // the summary. $truncatedtext = $newContent->getTextForSummary( 200 - strlen( wfMsgForContent( 'autosumm-new' ) ) ); @@ -607,7 +663,10 @@ abstract class ContentHandler { // Blanking auto-summaries if ( !empty( $oldContent ) && $oldContent->getSize() > 0 && $newContent->getSize() == 0 ) { return wfMsgForContent( 'autosumm-blank' ); - } elseif ( !empty( $oldContent ) && $oldContent->getSize() > 10 * $newContent->getSize() && $newContent->getSize() < 500 ) { + } elseif ( !empty( $oldContent ) + && $oldContent->getSize() > 10 * $newContent->getSize() + && $newContent->getSize() < 500 ) + { // Removing more than 90% of the article $truncatedtext = $newContent->getTextForSummary( @@ -616,8 +675,8 @@ abstract class ContentHandler { return wfMsgForContent( 'autosumm-replace', $truncatedtext ); } - // If we reach this point, there's no applicable auto-summary for our case, so our - // auto-summary is empty. + // If we reach this point, there's no applicable auto-summary for our + // case, so our auto-summary is empty. return ''; } @@ -629,10 +688,12 @@ abstract class ContentHandler { * * @param $title Title: the page's title * @param &$hasHistory Boolean: whether the page has a history - * @return mixed String containing deletion reason or empty string, or boolean false - * if no revision occurred + * @return mixed String containing deletion reason or empty string, or + * boolean false if no revision occurred * - * @XXX &$hasHistory is extremely ugly, it's here because WikiPage::getAutoDeleteReason() and Article::getReason() have it / want it. + * @XXX &$hasHistory is extremely ugly, it's here because + * WikiPage::getAutoDeleteReason() and Article::getReason() + * have it / want it. */ public function getAutoDeleteReason( Title $title, &$hasHistory ) { $dbw = wfGetDB( DB_MASTER ); @@ -651,7 +712,8 @@ abstract class ContentHandler { $this->checkModelID( $content->getModel() ); // If the page is blank, use the text from the previous revision, - // which can only be blank if there's a move/import/protect dummy revision involved + // which can only be blank if there's a move/import/protect dummy + // revision involved if ( $content->getSize() == 0 ) { $prev = $rev->getPrevious(); @@ -664,7 +726,10 @@ abstract class ContentHandler { // Find out if there was only one contributor // Only scan the last 20 revisions $res = $dbw->select( 'revision', 'rev_user_text', - array( 'rev_page' => $title->getArticleID(), $dbw->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ), + array( + 'rev_page' => $title->getArticleID(), + $dbw->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' + ), __METHOD__, array( 'LIMIT' => 20 ) ); @@ -718,15 +783,16 @@ abstract class ContentHandler { } /** - * Parse the Content object and generate a ParserObject from the result. $result->getText() can - * be used to obtain the generated HTML. If no HTML is needed, $generateHtml can be set to false; - * in that case, $result->getText() may return null. - * - * @param Content $content the content to render - * @param Title $title the page title to use as a context for rendering - * @param null|int $revId the revision being rendered (optional) - * @param null|ParserOptions $options any parser options - * @param Boolean $generateHtml whether to generate Html (default: true). If false, + * Parse the Content object and generate a ParserOutput from the result. + * $result->getText() can be used to obtain the generated HTML. If no HTML + * is needed, $generateHtml can be set to false; in that case, + * $result->getText() may return null. + * + * @param $content Content the content to render + * @param $title Title The page title to use as a context for rendering + * @param $revId null|int The revision being rendered (optional) + * @param $options null|ParserOptions Any parser options + * @param $generateHtml Boolean Whether to generate HTML (default: true). If false, * the result of calling getText() on the ParserOutput object returned by * this method is undefined. * @@ -734,35 +800,45 @@ abstract class ContentHandler { * * @return ParserOutput */ - public abstract function getParserOutput( Content $content, Title $title, $revId = null, ParserOptions $options = null, $generateHtml = true ); - #TODO: make RenderOutput and RenderOptions base classes + public abstract function getParserOutput( Content $content, Title $title, + $revId = null, + ParserOptions $options = null, $generateHtml = true ); + # TODO: make RenderOutput and RenderOptions base classes /** - * Returns a list of DataUpdate objects for recording information about this Content in some secondary - * data store. If the optional second argument, $old, is given, the updates may model only the changes that - * need to be made to replace information about the old content with information about the new content. - * - * This default implementation calls $this->getParserOutput( $content, $title, null, null, false ), and then - * calls getSecondaryDataUpdates( $title, $recursive ) on the resulting ParserOutput object. - * - * Subclasses may implement this to determine the necessary updates more efficiently, or make use of information - * about the old content. - * - * @param Content $content the content for determining the necessary updates - * @param Title $title the context for determining the necessary updates - * @param Content|null $old an optional Content object representing the previous content, i.e. the content being - * replaced by this Content object. - * @param boolean $recursive whether to include recursive updates (default: false). - * @param ParserOutput|null $parserOutput optional ParserOutput object. Provide if you have one handy, to avoid re-parsing - * of the content. - * - * @return Array. A list of DataUpdate objects for putting information about this content object somewhere. + * Returns a list of DataUpdate objects for recording information about this + * Content in some secondary data store. If the optional second argument, + * $old, is given, the updates may model only the changes that need to be + * made to replace information about the old content with information about + * the new content. + * + * This default implementation calls + * $this->getParserOutput( $content, $title, null, null, false ), + * and then calls getSecondaryDataUpdates( $title, $recursive ) on the + * resulting ParserOutput object. + * + * Subclasses may implement this to determine the necessary updates more + * efficiently, or make use of information about the old content. + * + * @param $content Content The content for determining the necessary updates + * @param $title Title The context for determining the necessary updates + * @param $old Content|null An optional Content object representing the + * previous content, i.e. the content being replaced by this Content + * object. + * @param $recursive boolean Whether to include recursive updates (default: + * false). + * @param $parserOutput ParserOutput|null Optional ParserOutput object. + * Provide if you have one handy, to avoid re-parsing of the content. + * + * @return Array. A list of DataUpdate objects for putting information + * about this content object somewhere. * * @since WD.1 */ - public function getSecondaryDataUpdates( Content $content, Title $title, Content $old = null, - $recursive = true, ParserOutput $parserOutput = null ) { - + public function getSecondaryDataUpdates( Content $content, Title $title, + Content $old = null, + $recursive = true, ParserOutput $parserOutput = null + ) { if ( !$parserOutput ) { $parserOutput = $this->getParserOutput( $content, $title, null, null, false ); } @@ -774,15 +850,15 @@ abstract class ContentHandler { /** * Get the Content object that needs to be saved in order to undo all revisions * between $undo and $undoafter. Revisions must belong to the same page, - * must exist and must not be deleted + * must exist and must not be deleted. * * @since WD.1 * - * @param $current Revision the current text - * @param $undo Revision the revision to undo + * @param $current Revision The current text + * @param $undo Revision The revision to undo * @param $undoafter Revision Must be an earlier revision than $undo * - * @return mixed string on success, false on failure + * @return mixed String on success, false on failure */ public function getUndoContent( Revision $current, Revision $undo, Revision $undoafter ) { $cur_content = $current->getContent(); @@ -809,8 +885,8 @@ abstract class ContentHandler { } /** - * Returns true for content models that support caching using the ParserCache mechanism. - * See WikiPage::isParserCacheUser(). + * Returns true for content models that support caching using the + * ParserCache mechanism. See WikiPage::isParserCacheUser(). * * @since WD.1 * @@ -821,28 +897,33 @@ abstract class ContentHandler { } /** - * Returns a lost of updates to perform when the given content is deleted. - * The necessary updates may be taken from the Content object, or depend on the current state of the database. + * Returns a list of updates to perform when the given content is deleted. + * The necessary updates may be taken from the Content object, or depend on + * the current state of the database. * * @since WD.1 * - * @param \Content $content the Content object for deletion - * @param \Title $title the title of the deleted page - * @param null|\ParserOutput $parserOutput optional parser output object for efficient access to meta-information - * about the content object. Provide if you have one handy. + * @param $content \Content the Content object for deletion + * @param $title \Title the title of 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. * - * @return array a list of DataUpdate instances that will clean up the database ofter deletion. + * @return array A list of DataUpdate instances that will clean up the + * database after deletion. */ - public function getDeletionUpdates( Content $content, Title $title, ParserOutput $parserOutput = null ) { + public function getDeletionUpdates( Content $content, Title $title, + ParserOutput $parserOutput = null ) + { return array( new LinksDeletionUpdate( $title ), ); } /** - * Returns true iff this content model supports sections. + * Returns true if this content model supports sections. * - * This default implementation returns false, + * This default implementation returns false. * * @return boolean whether sections are supported. */ @@ -863,8 +944,8 @@ abstract class TextContentHandler extends ContentHandler { /** * Returns the content's text as-is. * - * @param Content $content - * @param String|null $format + * @param $content Content + * @param $format string|null * @return mixed */ public function serializeContent( Content $content, $format = null ) { @@ -873,16 +954,17 @@ abstract class TextContentHandler extends ContentHandler { } /** - * attempts to merge differences between three versions. - * Returns a new Content object for a clean merge and false for failure or a conflict. + * Attempts to merge differences between three versions. Returns a new + * Content object for a clean merge and false for failure or a conflict. * - * All three Content objects passed as parameters must have the same content model. + * All three Content objects passed as parameters must have the same + * content model. * * This text-based implementation uses wfMerge(). * - * @param \Content|String $oldContent String - * @param \Content|String $myContent String - * @param \Content|String $yourContent String + * @param $oldContent \Content|string String + * @param $myContent \Content|string String + * @param $yourContent \Content|string String * * @return Content|Bool */ @@ -912,39 +994,47 @@ abstract class TextContentHandler extends ContentHandler { } /** - * Returns a generic ParserOutput object, wrapping the HTML returned by getHtml(). + * Returns a generic ParserOutput object, wrapping the HTML returned by + * getHtml(). * - * @param Content $content the content to render - * @param Title $title context title for parsing - * @param int|null $revId revision id (the parser wants that for some reason) - * @param ParserOptions|null $options parser options - * @param bool $generateHtml whether or not to generate HTML + * @param $content Content The content to render + * @param $title Title Context title for parsing + * @param $revId int|null Revision ID (for {{REVISIONID}}) + * @param $options ParserOptions|null Parser options + * @param $generateHtml bool Whether or not to generate HTML * * @return ParserOutput representing the HTML form of the text */ - public function getParserOutput( Content $content, Title $title, $revId = null, ParserOptions $options = null, $generateHtml = true ) { + public function getParserOutput( Content $content, Title $title, + $revId = null, + ParserOptions $options = null, $generateHtml = true + ) { $this->checkModelID( $content->getModel() ); - # generic implementation, relying on $this->getHtml() + # Generic implementation, relying on $this->getHtml() - if ( $generateHtml ) $html = $this->getHtml( $content ); - else $html = ''; + if ( $generateHtml ) { + $html = $this->getHtml( $content ); + } else { + $html = ''; + } $po = new ParserOutput( $html ); return $po; } /** - * Generates an HTML version of the content, for display. - * Used by getParserOutput() to construct a ParserOutput object. + * Generates an HTML version of the content, for display. Used by + * getParserOutput() to construct a ParserOutput object. * - * This default implementation just calls getHighlightHtml(). Content models that - * have another mapping to HTML (as is the case for markup languages like wikitext) - * should override this method to generate the appropriate html. + * This default implementation just calls getHighlightHtml(). Content + * models that have another mapping to HTML (as is the case for markup + * languages like wikitext) should override this method to generate the + * appropriate HTML. * - * @param Content $content the content to render + * @param $content Content The content to render * - * @return String an HTML representation of the content + * @return string An HTML representation of the content */ protected function getHtml( Content $content ) { $this->checkModelID( $content->getModel() ); @@ -954,16 +1044,16 @@ abstract class TextContentHandler extends ContentHandler { /** * Generates a syntax-highlighted version the content, as HTML. - * Used by the default implementation if getHtml(). + * Used by the default implementation of getHtml(). * - * @param Content $content the content to render + * @param $content Content the content to render * - * @return String an HTML representation of the content's markup + * @return string an HTML representation of the content's markup */ protected function getHighlightHtml( Content $content ) { $this->checkModelID( $content->getModel() ); - #TODO: make Highlighter interface, use here highlighter, if available + # TODO: make Highlighter interface, use highlighter here, if available return htmlspecialchars( $content->getNativeData() ); } @@ -990,20 +1080,24 @@ class WikitextContentHandler extends TextContentHandler { } /** - * Returns a ParserOutput object resulting from parsing the content's text using $wgParser. + * Returns a ParserOutput object resulting from parsing the content's text + * using $wgParser. * * @since WD.1 * - * @param Content $content the content to render - * @param \Title $title - * @param null $revId - * @param null|ParserOptions $options - * @param bool $generateHtml + * @param $content Content the content to render + * @param $title \Title + * @param $revId null + * @param $options null|ParserOptions + * @param $generateHtml bool * * @internal param \IContextSource|null $context * @return ParserOutput representing the HTML form of the text */ - public function getParserOutput( Content $content, Title $title, $revId = null, ParserOptions $options = null, $generateHtml = true ) { + public function getParserOutput( Content $content, Title $title, + $revId = null, + ParserOptions $options = null, $generateHtml = true + ) { global $wgParser; $this->checkModelID( $content->getModel() ); @@ -1017,7 +1111,10 @@ class WikitextContentHandler extends TextContentHandler { } protected function getHtml( Content $content ) { - throw new MWException( "getHtml() not implemented for wikitext. Use getParserOutput()->getText()." ); + throw new MWException( + "getHtml() not implemented for wikitext. " + . "Use getParserOutput()->getText()." + ); } /** @@ -1030,7 +1127,7 @@ class WikitextContentHandler extends TextContentHandler { } } -#XXX: make ScriptContentHandler base class, do highlighting stuff there? +# XXX: make ScriptContentHandler base class, do highlighting stuff there? /** * @since WD.1