ApiParse: Use the right Skin object for building section edit links
Apparently the section edit links may depend on state that is available through context in the Skin object, but not necessarily through the global context, such as the current user and page title. Allow ParserOutput::getText() to take a 'skin' option for this purpose. Bug: T234868 Change-Id: Iaa83e5f801c7776bf8218d8ce7484e2485b227d4
This commit is contained in:
parent
55e798f57c
commit
965b788178
2 changed files with 10 additions and 4 deletions
|
|
@ -290,6 +290,7 @@ class ApiParse extends ApiBase {
|
|||
}
|
||||
|
||||
$outputPage = null;
|
||||
$context = null;
|
||||
if ( $skin || isset( $prop['headhtml'] ) || isset( $prop['categorieshtml'] ) ) {
|
||||
// Enabling the skin via 'useskin', 'headhtml', or 'categorieshtml'
|
||||
// gets OutputPage and Skin involved, which (among others) applies
|
||||
|
|
@ -345,6 +346,7 @@ class ApiParse extends ApiBase {
|
|||
'enableSectionEditLinks' => !$params['disableeditsection'],
|
||||
'wrapperDivClass' => $params['wrapoutputclass'],
|
||||
'deduplicateStyles' => !$params['disablestylededuplication'],
|
||||
'skin' => $context ? $context->getSkin() : null,
|
||||
] );
|
||||
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -306,6 +306,7 @@ class ParserOutput extends CacheTime {
|
|||
* - enableSectionEditLinks: (bool) Include section edit links, assuming
|
||||
* section edit link tokens are present in the HTML. Default is true,
|
||||
* but might be statefully overridden.
|
||||
* - skin: (Skin) Skin object used for transforming section edit links.
|
||||
* - unwrap: (bool) Return text without a wrapper div. Default is false,
|
||||
* meaning a wrapper div will be added if getWrapperDivClass() returns
|
||||
* a non-empty string.
|
||||
|
|
@ -325,6 +326,7 @@ class ParserOutput extends CacheTime {
|
|||
$options += [
|
||||
'allowTOC' => true,
|
||||
'enableSectionEditLinks' => true,
|
||||
'skin' => null,
|
||||
'unwrap' => false,
|
||||
'deduplicateStyles' => true,
|
||||
'wrapperDivClass' => $this->getWrapperDivClass(),
|
||||
|
|
@ -338,9 +340,12 @@ class ParserOutput extends CacheTime {
|
|||
}
|
||||
|
||||
if ( $options['enableSectionEditLinks'] ) {
|
||||
// TODO: Passing the skin should be required
|
||||
$skin = $options['skin'] ?: RequestContext::getMain()->getSkin();
|
||||
|
||||
$text = preg_replace_callback(
|
||||
self::EDITSECTION_REGEX,
|
||||
function ( $m ) {
|
||||
function ( $m ) use ( $skin ) {
|
||||
$editsectionPage = Title::newFromText( htmlspecialchars_decode( $m[1] ) );
|
||||
$editsectionSection = htmlspecialchars_decode( $m[2] );
|
||||
$editsectionContent = isset( $m[4] ) ? Sanitizer::decodeCharReferences( $m[3] ) : null;
|
||||
|
|
@ -349,12 +354,11 @@ class ParserOutput extends CacheTime {
|
|||
throw new MWException( "Bad parser output text." );
|
||||
}
|
||||
|
||||
$context = RequestContext::getMain();
|
||||
return $context->getSkin()->doEditSectionLink(
|
||||
return $skin->doEditSectionLink(
|
||||
$editsectionPage,
|
||||
$editsectionSection,
|
||||
$editsectionContent,
|
||||
$context->getLanguage()
|
||||
$skin->getLanguage()
|
||||
);
|
||||
},
|
||||
$text
|
||||
|
|
|
|||
Loading…
Reference in a new issue