MediaWiki  REL1_24
ApiFormatBase Class Reference

This is the abstract base class for API formatters. More...

Inheritance diagram for ApiFormatBase:
Collaboration diagram for ApiFormatBase:

List of all members.

Public Member Functions

 __construct (ApiMain $main, $format)
 If $format ends with 'fm', pretty-print the output in HTML.
 canPrintErrors ()
 Whether this formatter can handle printing API errors.
 closePrinter ()
 Finish printing.
 disable ()
 Disable the formatter completely.
 getBuffer ()
 Get the contents of the buffer.
 getDescription ()
 Returns the description string for this module.
 getExamples ()
 Returns usage examples for this module.
 getFormat ()
 Get the internal format name.
 getHelpUrls ()
 getIsHtml ()
 Returns true when the HTML pretty-printer should be used.
 getMimeType ()
 Overriding class returns the MIME type that should be sent to the client.
 getNeedsRawData ()
 Whether this formatter needs raw data such as _element tags.
 getWantsHelp ()
 Whether this formatter can format the help message in a nice way.
 initPrinter ($isHelpScreen)
 Initialize the printer function and prepare the output headers, etc.
 isDisabled ()
 printText ($text)
 The main format printing function.
 setBufferResult ($value)
 Set the flag to buffer the result instead of printing it.
 setHelp ($help=true)
 Sets whether the pretty-printer should format *bold*.
 setUnescapeAmps ($b)
 Specify whether or not sequences like " should be unescaped to " .

Public Attributes

 $mBuffer
 $mCleared
 $mDisabled = false
 $mFormat
 $mHelp
 $mUnescapeAmps

Protected Member Functions

 formatHTML ($text)
 Pretty-print various elements in HTML format, such as xml tags and URLs.
 markDeprecated ()
 To avoid code duplication with the deprecation of dbg, dump, txt, wddx, and yaml, this method is added to do the necessary work.

Private Attributes

 $mBufferResult = false
 $mIsHtml

Detailed Description

This is the abstract base class for API formatters.

Definition at line 32 of file ApiFormatBase.php.


Constructor & Destructor Documentation

ApiFormatBase::__construct ( ApiMain main,
format 
)

If $format ends with 'fm', pretty-print the output in HTML.

Parameters:
ApiMain$main
string$formatFormat name

Reimplemented in ApiFormatXmlRsd, and ApiFormatJson.

Definition at line 41 of file ApiFormatBase.php.


Member Function Documentation

Whether this formatter can handle printing API errors.

If this returns false, then on API errors the default printer will be instantiated.

Since:
1.23
Returns:
bool

Reimplemented in ApiFormatFeedWrapper.

Definition at line 128 of file ApiFormatBase.php.

Finish printing.

Closes HTML tags.

Definition at line 208 of file ApiFormatBase.php.

References getIsHtml(), php, and pre.

Disable the formatter completely.

This causes calls to initPrinter(), printText() and closePrinter() to be ignored.

Definition at line 114 of file ApiFormatBase.php.

ApiFormatBase::formatHTML ( text) [protected]

Pretty-print various elements in HTML format, such as xml tags and URLs.

This method also escapes characters like <

Parameters:
string$text
Returns:
string

Definition at line 278 of file ApiFormatBase.php.

References $matches, array(), and wfUrlProtocolsWithoutProtRel().

Referenced by printText().

Get the contents of the buffer.

Returns:
string

Definition at line 252 of file ApiFormatBase.php.

Returns the description string for this module.

Returns:
string|array

Reimplemented from ApiBase.

Reimplemented in ApiFormatXml, ApiFormatWddx, ApiFormatJson, ApiFormatDump, ApiFormatDbg, ApiFormatTxt, ApiFormatYaml, ApiFormatPhp, and ApiFormatNone.

Definition at line 339 of file ApiFormatBase.php.

References getIsHtml().

Returns usage examples for this module.

Return false if no examples are available.

Returns:
bool|string|array

Reimplemented from ApiBase.

Definition at line 328 of file ApiFormatBase.php.

References array(), and ApiBase\getModuleName().

Get the internal format name.

Returns:
string

Definition at line 73 of file ApiFormatBase.php.

Returns:
bool|string|array Returns a false if the module has no help URL, else returns a (array of) string

Reimplemented from ApiBase.

Definition at line 335 of file ApiFormatBase.php.

Returns true when the HTML pretty-printer should be used.

The default implementation assumes that formats ending with 'fm' should be formatted in HTML.

Returns:
bool

Definition at line 96 of file ApiFormatBase.php.

Referenced by closePrinter(), ApiFormatWddx\execute(), ApiFormatXml\execute(), ApiFormatJson\execute(), getDescription(), getWantsHelp(), initPrinter(), markDeprecated(), printText(), and ApiFormatWddx\slowWddxPrinter().

Overriding class returns the MIME type that should be sent to the client.

This method is not called if getIsHtml() returns true.

Returns:
string

Reimplemented in ApiFormatXmlRsd, ApiFormatFeedWrapper, ApiFormatRaw, ApiFormatJson, ApiFormatXml, ApiFormatDbg, ApiFormatDump, ApiFormatTxt, ApiFormatWddx, ApiFormatYaml, ApiFormatNone, and ApiFormatPhp.

Referenced by initPrinter().

Whether this formatter needs raw data such as _element tags.

Returns:
bool

Reimplemented in ApiFormatFeedWrapper, ApiFormatJson, and ApiFormatXml.

Definition at line 65 of file ApiFormatBase.php.

Whether this formatter can format the help message in a nice way.

By default, this returns the same as getIsHtml(). When action=help is set explicitly, the help will always be shown

Returns:
bool

Reimplemented in ApiFormatJson.

Definition at line 106 of file ApiFormatBase.php.

References getIsHtml().

ApiFormatBase::initPrinter ( isHelpScreen)

Initialize the printer function and prepare the output headers, etc.

This method must be the first outputting method during execution. A human-targeted notice about available formats is printed for the HTML-based output, except for help screens (caused by either an error in the API parameters, the calling of action=help, or requesting the root script api.php).

Parameters:
bool$isHelpScreenWhether a help screen is going to be shown

Definition at line 140 of file ApiFormatBase.php.

References $mime, are, at, change, complete, format, ContextSource\getConfig(), getIsHtml(), ApiBase\getMain(), getMimeType(), href, is, of, output(), php, pre, see, title, and wfScript().

Definition at line 118 of file ApiFormatBase.php.

To avoid code duplication with the deprecation of dbg, dump, txt, wddx, and yaml, this method is added to do the necessary work.

It should be removed when those deprecated formats are removed.

Definition at line 348 of file ApiFormatBase.php.

References $name, getIsHtml(), ApiBase\getModuleName(), ApiBase\logFeatureUsage(), and ApiBase\setWarning().

Referenced by ApiFormatWddx\execute(), ApiFormatYaml\execute(), ApiFormatDump\execute(), ApiFormatTxt\execute(), and ApiFormatDbg\execute().

The main format printing function.

Call it to output the result string to the user. This function will automatically output HTML when format name ends in 'fm'.

Parameters:
string$text

Definition at line 228 of file ApiFormatBase.php.

References formatHTML(), and getIsHtml().

Referenced by ApiFormatXml\addXslt(), ApiFormatPhp\execute(), ApiFormatWddx\execute(), ApiFormatDump\execute(), ApiFormatDbg\execute(), ApiFormatTxt\execute(), ApiFormatXml\execute(), ApiFormatRaw\execute(), ApiFormatJson\execute(), and ApiFormatWddx\slowWddxPrinter().

Set the flag to buffer the result instead of printing it.

Parameters:
bool$value

Definition at line 260 of file ApiFormatBase.php.

References $value.

Sets whether the pretty-printer should format *bold*.

Parameters:
bool$help

Definition at line 268 of file ApiFormatBase.php.

References $help.

Specify whether or not sequences like &quot; should be unescaped to " .

This should only be set to true for the help message when rendered in the default (xmlfm) format. This is a temporary special-case fix that should be removed once the help has been reworked to use a fully HTML interface.

Parameters:
bool$bWhether or not ampersands should be escaped.

Definition at line 86 of file ApiFormatBase.php.


Member Data Documentation

ApiFormatBase::$mBuffer

Definition at line 34 of file ApiFormatBase.php.

ApiFormatBase::$mBufferResult = false [private]

Definition at line 34 of file ApiFormatBase.php.

ApiFormatBase::$mCleared

Definition at line 33 of file ApiFormatBase.php.

ApiFormatBase::$mDisabled = false

Definition at line 34 of file ApiFormatBase.php.

ApiFormatBase::$mFormat

Definition at line 33 of file ApiFormatBase.php.

ApiFormatBase::$mHelp

Definition at line 33 of file ApiFormatBase.php.

ApiFormatBase::$mIsHtml [private]

Definition at line 33 of file ApiFormatBase.php.

ApiFormatBase::$mUnescapeAmps

Definition at line 33 of file ApiFormatBase.php.


The documentation for this class was generated from the following file: