use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use MediaWiki\Session\SessionManager;
-use WrappedString\WrappedString;
-use WrappedString\WrappedStringList;
+use Wikimedia\RelPath;
+use Wikimedia\WrappedString;
+use Wikimedia\WrappedStringList;
/**
* This class should be covered by a general architecture document which does
/** @var bool */
protected $mCanonicalUrl = false;
- /**
- * @var array Additional stylesheets. Looks like this is for extensions.
- * Might be replaced by ResourceLoader.
- */
- protected $mExtStyles = [];
-
/**
* @var string Should be private - has getter and setter. Contains
* the HTML title */
*/
private $mEnableTOC = false;
- /**
- * @var bool Whether parser output should contain section edit links
- */
- private $mEnableSectionEditLinks = true;
-
/**
* @var string|null The URL to send in a <link> element with rel=license
*/
/**
* Redirect to $url rather than displaying the normal page
*
- * @param string $url URL
+ * @param string $url
* @param string $responsecode HTTP status code
*/
public function redirect( $url, $responsecode = '302' ) {
* Add a new "<meta>" tag
* To add an http-equiv meta tag, precede the name with "http:"
*
- * @param string $name Tag name
- * @param string $val Tag value
+ * @param string $name Name of the meta tag
+ * @param string $val Value of the meta tag
*/
function addMeta( $name, $val ) {
array_push( $this->mMetatags, [ $name, $val ] );
$this->mScripts .= $script;
}
- /**
- * Register and add a stylesheet from an extension directory.
- *
- * @deprecated since 1.27 use addModuleStyles() or addStyle() instead
- * @param string $url Path to sheet. Provide either a full url (beginning
- * with 'http', etc) or a relative path from the document root
- * (beginning with '/'). Otherwise it behaves identically to
- * addStyle() and draws from the /skins folder.
- */
- public function addExtensionStyle( $url ) {
- wfDeprecated( __METHOD__, '1.27' );
- array_push( $this->mExtStyles, $url );
- }
-
- /**
- * Get all styles added by extensions
- *
- * @deprecated since 1.27
- * @return array
- */
- function getExtStyle() {
- wfDeprecated( __METHOD__, '1.27' );
- return $this->mExtStyles;
- }
-
/**
* Add a JavaScript file out of skins/common, or a given relative path.
* Internal use only. Use OutputPage::addModules() if possible.
* Filter an array of modules to remove insufficiently trustworthy members, and modules
* which are no longer registered (eg a page is cached before an extension is disabled)
* @param array $modules
- * @param string|null $position If not null, only return modules with this position
+ * @param string|null $position Unused
* @param string $type
* @return array
*/
$module = $resourceLoader->getModule( $val );
if ( $module instanceof ResourceLoaderModule
&& $module->getOrigin() <= $this->getAllowedModules( $type )
- && ( is_null( $position ) || $module->getPosition() == $position )
) {
if ( $this->mTarget && !in_array( $this->mTarget, $module->getTargets() ) ) {
$this->warnModuleTargetFilter( $module->getName() );
* Get the list of modules to include on this page
*
* @param bool $filter Whether to filter out insufficiently trustworthy modules
- * @param string|null $position If not null, only return modules with this position
+ * @param string|null $position Unused
* @param string $param
* @param string $type
* @return array Array of module names
) {
$modules = array_values( array_unique( $this->$param ) );
return $filter
- ? $this->filterModules( $modules, $position, $type )
+ ? $this->filterModules( $modules, null, $type )
: $modules;
}
* Get the list of module JS to include on this page
*
* @param bool $filter
- * @param string|null $position
+ * @param string|null $position Unused
* @return array Array of module names
*/
public function getModuleScripts( $filter = false, $position = null ) {
- return $this->getModules( $filter, $position, 'mModuleScripts',
+ return $this->getModules( $filter, null, 'mModuleScripts',
ResourceLoaderModule::TYPE_SCRIPTS
);
}
* Get the list of module CSS to include on this page
*
* @param bool $filter
- * @param string|null $position
+ * @param string|null $position Unused
* @return array Array of module names
*/
public function getModuleStyles( $filter = false, $position = null ) {
- return $this->getModules( $filter, $position, 'mModuleStyles',
+ return $this->getModules( $filter, null, 'mModuleStyles',
ResourceLoaderModule::TYPE_STYLES
);
}
$this->mAdditionalBodyClasses = array_merge( $this->mAdditionalBodyClasses, (array)$classes );
}
- /**
- * @deprecated since 1.28 Obsolete - wgUseETag experiment was removed.
- * @param string $tag
- */
- public function setETag( $tag ) {
- }
-
/**
* Set whether the output should only contain the body of the article,
* without any skin, sidebar, etc.
# this breaks strtotime().
$clientHeader = preg_replace( '/;.*$/', '', $clientHeader );
- MediaWiki\suppressWarnings(); // E_STRICT system time bitching
+ Wikimedia\suppressWarnings(); // E_STRICT system time bitching
$clientHeaderTime = strtotime( $clientHeader );
- MediaWiki\restoreWarnings();
+ Wikimedia\restoreWarnings();
if ( !$clientHeaderTime ) {
wfDebug( __METHOD__
. ": unable to parse the client's If-Modified-Since header: $clientHeader\n" );
// Someone is trying to set a bogus pre-$wgUser PO. Check if it has
// been changed somehow, and keep it if so.
$anonPO = ParserOptions::newFromAnon();
- $anonPO->setEditSection( false );
$anonPO->setAllowUnsafeRawHtml( false );
if ( !$options->matches( $anonPO ) ) {
wfLogWarning( __METHOD__ . ': Setting a changed bogus ParserOptions: ' . wfGetAllCallers( 5 ) );
// ParserOptions for it. And don't cache this ParserOptions
// either.
$po = ParserOptions::newFromAnon();
- $po->setEditSection( false );
$po->setAllowUnsafeRawHtml( false );
$po->isBogus = true;
if ( $options !== null ) {
}
$this->mParserOptions = ParserOptions::newFromContext( $this->getContext() );
- $this->mParserOptions->setEditSection( false );
$this->mParserOptions->setAllowUnsafeRawHtml( false );
}
$popts->setTidy( $oldTidy );
- $this->addParserOutput( $parserOutput );
+ $this->addParserOutput( $parserOutput, [
+ 'enableSectionEditLinks' => false,
+ ] );
}
/**
// so that extensions may modify ParserOutput to toggle TOC.
// This cannot be moved to addParserOutputText because that is not
// called by EditPage for Preview.
- if ( $parserOutput->getTOCEnabled() && $parserOutput->getTOCHTML() ) {
+ if ( $parserOutput->getTOCHTML() ) {
$this->mEnableTOC = true;
}
}
*
* @since 1.24
* @param ParserOutput $parserOutput
+ * @param array $poOptions Options to ParserOutput::getText()
*/
- public function addParserOutputContent( $parserOutput ) {
- $this->addParserOutputText( $parserOutput );
+ public function addParserOutputContent( $parserOutput, $poOptions = [] ) {
+ $this->addParserOutputText( $parserOutput, $poOptions );
$this->addModules( $parserOutput->getModules() );
$this->addModuleScripts( $parserOutput->getModuleScripts() );
*
* @since 1.24
* @param ParserOutput $parserOutput
+ * @param array $poOptions Options to ParserOutput::getText()
*/
- public function addParserOutputText( $parserOutput ) {
- $text = $parserOutput->getText();
+ public function addParserOutputText( $parserOutput, $poOptions = [] ) {
+ $text = $parserOutput->getText( $poOptions );
// Avoid PHP 7.1 warning of passing $this by reference
$outputPage = $this;
Hooks::runWithoutAbort( 'OutputPageBeforeHTML', [ &$outputPage, &$text ] );
* Add everything from a ParserOutput object.
*
* @param ParserOutput $parserOutput
+ * @param array $poOptions Options to ParserOutput::getText()
*/
- function addParserOutput( $parserOutput ) {
+ function addParserOutput( $parserOutput, $poOptions = [] ) {
$this->addParserOutputMetadata( $parserOutput );
-
- // Touch section edit links only if not previously disabled
- if ( $parserOutput->getEditSectionTokens() ) {
- $parserOutput->setEditSectionTokens( $this->mEnableSectionEditLinks );
- }
-
- $this->addParserOutputText( $parserOutput );
+ $this->addParserOutputText( $parserOutput, $poOptions );
}
/**
$popts->setTargetLanguage( $oldLang );
}
- return $parserOutput->getText();
+ return $parserOutput->getText( [
+ 'enableSectionEditLinks' => false,
+ ] );
}
/**
return Parser::stripOuterParagraph( $parsed );
}
- /**
- * @param int $maxage
- * @deprecated since 1.27 Use setCdnMaxage() instead
- */
- public function setSquidMaxage( $maxage ) {
- wfDeprecated( __METHOD__, '1.27' );
- $this->setCdnMaxage( $maxage );
- }
-
/**
* Set the value of the "s-maxage" part of the "Cache-control" HTTP header
*
return $text;
}
- /**
- * Display a page stating that the Wiki is in read-only mode.
- * Should only be called after wfReadOnly() has returned true.
- *
- * Historically, this function was used to show the source of the page that the user
- * was trying to edit and _also_ permissions error messages. The relevant code was
- * moved into EditPage in 1.19 (r102024 / d83c2a431c2a) and removed here in 1.25.
- *
- * @deprecated since 1.25; throw the exception directly
- * @throws ReadOnlyError
- */
- public function readOnlyPage() {
- if ( func_num_args() > 0 ) {
- throw new MWException( __METHOD__ . ' no longer accepts arguments since 1.25.' );
- }
-
- throw new ReadOnlyError;
- }
-
- /**
- * Turn off regular page output and return an error response
- * for when rate limiting has triggered.
- *
- * @deprecated since 1.25; throw the exception directly
- */
- public function rateLimited() {
- wfDeprecated( __METHOD__, '1.25' );
- throw new ThrottledError;
- }
-
/**
* Show a warning about replica DB lag
*
}
/**
- * JS stuff to put at the bottom of the `<body>`. These are modules with position 'bottom',
- * legacy scripts ($this->mScripts), and user JS.
+ * JS stuff to put at the bottom of the `<body>`.
+ * These are legacy scripts ($this->mScripts), and user JS.
*
* @return string|WrappedStringList HTML
*/
&& ( $relevantTitle->exists() || $relevantTitle->quickUserCan( 'create', $user ) );
foreach ( $title->getRestrictionTypes() as $type ) {
+ // Following keys are set in $vars:
+ // wgRestrictionCreate, wgRestrictionEdit, wgRestrictionMove, wgRestrictionUpload
$vars['wgRestriction' . ucfirst( $type )] = $title->getRestrictions( $type );
}
] );
if ( $config->get( 'ReferrerPolicy' ) !== false ) {
- $tags['meta-referrer'] = Html::element( 'meta', [
- 'name' => 'referrer',
- 'content' => $config->get( 'ReferrerPolicy' )
- ] );
+ // Per https://w3c.github.io/webappsec-referrer-policy/#unknown-policy-values
+ // fallbacks should come before the primary value so we need to reverse the array.
+ foreach ( array_reverse( (array)$config->get( 'ReferrerPolicy' ) ) as $i => $policy ) {
+ $tags["meta-referrer-$i"] = Html::element( 'meta', [
+ 'name' => 'referrer',
+ 'content' => $policy,
+ ] );
+ }
}
$p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";
public function buildCssLinksArray() {
$links = [];
- // Add any extension CSS
- foreach ( $this->mExtStyles as $url ) {
- $this->addStyle( $url );
- }
- $this->mExtStyles = [];
-
foreach ( $this->styles as $file => $options ) {
$link = $this->styleLink( $file, $options );
if ( $link ) {
$remotePathPrefix = $remotePath = $uploadPath;
}
- $path = RelPath\getRelativePath( $path, $remotePath );
+ $path = RelPath::getRelativePath( $path, $remotePath );
return self::transformFilePath( $remotePathPrefix, $localDir, $path );
}
* Enables/disables section edit links, doesn't override __NOEDITSECTION__
* @param bool $flag
* @since 1.23
+ * @deprecated since 1.31, use $poOptions to addParserOutput() instead.
*/
public function enableSectionEditLinks( $flag = true ) {
- $this->mEnableSectionEditLinks = $flag;
+ wfDeprecated( __METHOD__, '1.31' );
}
/**
* @return bool
* @since 1.23
+ * @deprecated since 1.31, use $poOptions to addParserOutput() instead.
*/
public function sectionEditLinksEnabled() {
- return $this->mEnableSectionEditLinks;
+ wfDeprecated( __METHOD__, '1.31' );
+ return true;
}
/**