parser: Improve ParserOutput docs and fix absoluteURLs default

* Document the bodyContentOnly option.
  Introduced in Ica09a4284c (cfd9c516e1) and renamed in
  commit I04e56ff2c3 (abee9b61f0).

* Fix default for absoluteURLs option.
  Introduced in Id660e10261 (d334de960a).

* Match order between docs and defaults for readability
  and easier review for correctness.

* Move potentially duplicate brief and ingroup from file doc
  to class doc and clean up file doc to be less novel and more like
  99% of other class files in MediaWiki. See also
  <https://gerrit.wikimedia.org/r/q/message:ingroup+owner:Krinkle>

* Document what the class does and it relates to several other
  prominent in MediaWiki core.

Bug: T341244
Change-Id: Id2e3124652315a74869f504056fa8a99ad794350
This commit is contained in:
Timo Tijhof 2023-10-03 20:11:44 -07:00
parent 231a562c37
commit 54693fc907

View file

@ -1,4 +1,22 @@
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
use MediaWiki\HookContainer\HookRunner;
use MediaWiki\Html\Html;
@ -25,27 +43,17 @@ use Wikimedia\Parsoid\Core\TOCData;
use Wikimedia\Reflection\GhostFieldAccessTrait;
/**
* Output of the PHP parser.
* Rendered output of a wiki page, as parsed from wikitext.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* ParserOutput objects are created by the ParserOutputAccess service,
* which automatically caches them via ParserCache when possible,
* and produces new output from the Parser (or Parsoid) as-needed.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* Higher-level access is also available via the ContentHandler class,
* with as its main consumers our APIs and OutputPage/Skin frontend.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup Parser
*/
class ParserOutput extends CacheTime implements ContentMetadataCollector {
use GhostFieldAccessTrait;
use JsonUnserializableTrait;
@ -402,6 +410,7 @@ class ParserOutput extends CacheTime implements ContentMetadataCollector {
* of the `data-mw-deduplicate` attribute.
* - absoluteURLs: (bool) use absolute URLs in all links. Default: false
* - includeDebugInfo: (bool) render PP limit report in HTML. Default: false
* - bodyContentOnly: (bool) . Default: true
* @return string HTML
* @return-taint escaped
*/
@ -410,11 +419,12 @@ class ParserOutput extends CacheTime implements ContentMetadataCollector {
'allowTOC' => true,
'injectTOC' => true,
'enableSectionEditLinks' => true,
'skin' => null,
'userLang' => null,
'skin' => null,
'unwrap' => false,
'deduplicateStyles' => true,
'wrapperDivClass' => $this->getWrapperDivClass(),
'deduplicateStyles' => true,
'absoluteURLs' => false,
'includeDebugInfo' => false,
'bodyContentOnly' => true,
];
@ -545,7 +555,7 @@ class ParserOutput extends CacheTime implements ContentMetadataCollector {
}
// Expand all relative URLs
if ( ( $options['absoluteURLs'] ?? false ) && $text ) {
if ( $options['absoluteURLs'] && $text ) {
$text = Linker::expandLocalLinks( $text );
}