wiki.techinc.nl/includes/parser/ParserOutputFlags.php
C. Scott Ananian 06ab90f163 Add new ParserOutput::{get,set}OutputFlag() interface
This is a uniform mechanism to access a number of bespoke boolean
flags in ParserOutput.  It allows extensibility in core (by adding new
field names to ParserOutputFlags) without exposing new getter/setter
methods to Parsoid.  It replaces the ParserOutput::{get,set}Flag()
interface which (a) doesn't allow access to certain flags, and (b) is
typically called with a string rather than a constant, and (c) has a
very generic name.  (Note that Parser::setOutputFlag() already called
these "output flags".)

In the future we might unify the representation so that we store
everything in $mFlags and don't have explicit properties in
ParserOutput, but those representation details should be invisible to
the clients of this API.  (We might also use a proper enumeration
for ParserOutputFlags, when PHP supports this.)

There is some overlap with ParserOutput::{get,set}ExtensionData(), but
I've left those methods as-is because (a) they allow for non-boolean
data, unlike the *Flag() methods, and (b) it seems worthwhile to
distingush properties set by extensions from properties used by core.

Code search:
https://codesearch.wmcloud.org/search/?q=%5BOo%5Dut%28put%29%3F%28%5C%28%5C%29%29%3F-%3E%28g%7Cs%29etFlag%5C%28&i=nope&files=&excludeFiles=&repos=

Bug: T292868
Change-Id: I39bc58d207836df6f328c54be9e3330719cebbeb
2021-10-15 14:25:54 -04:00

149 lines
4.4 KiB
PHP

<?php
/**
* Registry of flags used with ParserOutput::setOutputFlag() within
* MediaWiki core.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @since 1.38
*
* @file
* @ingroup Parser
*/
namespace MediaWiki\Parser;
/**
* Registry of flags used with ParserOutput::{get,set}OutputFlag() within
* MediaWiki core.
*
* All flags used should be defined in this class.
*
* It is recommended that new flag names in core should begin with 'mw-'
* in order to prevent namespace conflicts with legacy flags.
*
* @package MediaWiki\Parser
*/
class ParserOutputFlags {
// These flags are currently stored as ParserOutput properties
/**
* @var string No gallery on category page? (__NOGALLERY__).
* @see \ParserOutput::getNoGallery()
* @see \ParserOutput::setNoGallery()
*/
public const NO_GALLERY = 'mw-NoGallery';
/**
* @var string Whether OOUI should be enabled.
* @see \ParserOutput::getEnableOOUI()
* @see \ParserOutput::setEnableOOUI()
*/
public const ENABLE_OOUI = 'mw-EnableOOUI';
/**
* @var string Force index policy to be 'index'
* @see \ParserOutput::getIndexPolicy()
* @see \ParserOutput::setIndexPolicy()
*/
public const INDEX_POLICY = 'mw-IndexPolicy';
/**
* @var string Force index policy to be 'noindex'
* @see \ParserOutput::getIndexPolicy()
* @see \ParserOutput::setIndexPolicy()
*/
public const NO_INDEX_POLICY = 'mw-NoIndexPolicy';
/**
* @var string Show a new section link?
* @see \ParserOutput::getNewSection()
* @see \ParserOutput::setNewSection()
*/
public const NEW_SECTION = 'mw-NewSection';
/**
* @var string Hide the new section link?
* @see \ParserOutput::getHideNewSection()
* @see \ParserOutput::setHideNewSection()
*/
public const HIDE_NEW_SECTION = 'mw-HideNewSection';
/**
* @var string The prevent-clickjacking flag
* @see \ParserOutput::getPreventClickjacking()
* @see \ParserOutput::setPreventClickjacking()
*/
public const PREVENT_CLICKJACKING = 'mw-PreventClickjacking';
// These flags are stored in the ParserOutput::$mFlags array
/**
* @var string
*/
public const VARY_REVISION = 'vary-revision';
/**
* @var string Similar to VARY_REVISION, but used if we didn't
* guess the ID correctly. Informs the edit saving system that
* getting the canonical output after revision insertion requires
* a parse that used that exact revision ID.
*/
public const VARY_REVISION_ID = 'vary-revision-id';
/**
* @var string Similar to VARY_REVISION, but used if we didn't
* guess the timestamp correctly. Informs the edit saving system
* that getting the canonical output after revision insertion
* requires a parse that used an actual revision timestamp.
*/
public const VARY_REVISION_TIMESTAMP = 'vary-revision-timestamp';
/**
* @var string Similar to VARY_REVISION, but used if we didn't guess the
* content correctly.
*/
public const VARY_REVISION_SHA1 = 'vary-revision-sha1';
/**
* @var string Similar to VARY_REVISION
*/
public const VARY_REVISION_EXISTS = 'vary-revision-exists';
/**
* @var string Similar to VARY_REVISION, but used if we didn't guess the
* page id correctly. Informs the edit saving system that getting the
* canonical output after page insertion requires a parse that used that
* exact page id.
*/
public const VARY_PAGE_ID = 'vary-page-id';
/**
* @var string Similar to VARY_REVISION. Informs the edit saving
* system that getting the canonical output after revision
* insertion requires a parse that used the actual user ID.
*/
public const VARY_USER = 'vary-user';
/**
* @var string Used to avoid extremely stale user signature timestamps
* (T84843). Set if the signature wikitext contains another '~~~~' or
* similar (T230652).
*/
public const USER_SIGNATURE = 'user-signature';
}