mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CiteThisPage
synced 2024-11-30 10:24:30 +00:00
Inject services into SpecialCiteThisPage
MW1.36 needed for SpecialPage::getContentLanguage Bug: T259960 Change-Id: Ie0c8711c50fb732b16846fe0015d8fd571a02e3e
This commit is contained in:
parent
7eff466c0a
commit
885db8b85b
|
@ -4,7 +4,6 @@
|
|||
<exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationPrivate" />
|
||||
<exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationProtected" />
|
||||
<exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationPublic" />
|
||||
<exclude name="MediaWiki.Usage.ExtendClassUsage.FunctionConfigUsage" />
|
||||
</rule>
|
||||
<file>.</file>
|
||||
<arg name="extensions" value="php" />
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
"license-name": "GPL-2.0-or-later",
|
||||
"type": "specialpage",
|
||||
"requires": {
|
||||
"MediaWiki": ">= 1.31.0"
|
||||
"MediaWiki": ">= 1.36.0"
|
||||
},
|
||||
"ExtensionMessagesFiles": {
|
||||
"CiteThisPageAliases": "CiteThisPage.alias.php"
|
||||
|
@ -34,7 +34,14 @@
|
|||
"remoteExtPath": "CiteThisPage/modules"
|
||||
},
|
||||
"SpecialPages": {
|
||||
"CiteThisPage": "MediaWiki\\Extension\\CiteThisPage\\SpecialCiteThisPage"
|
||||
"CiteThisPage": {
|
||||
"class": "MediaWiki\\Extension\\CiteThisPage\\SpecialCiteThisPage",
|
||||
"services": [
|
||||
"SearchEngineFactory",
|
||||
"RevisionLookup",
|
||||
"ParserFactory"
|
||||
]
|
||||
}
|
||||
},
|
||||
"AutoloadNamespaces": {
|
||||
"MediaWiki\\Extension\\CiteThisPage\\": "includes/"
|
||||
|
|
|
@ -4,9 +4,11 @@ namespace MediaWiki\Extension\CiteThisPage;
|
|||
|
||||
use FormSpecialPage;
|
||||
use HTMLForm;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\RevisionLookup;
|
||||
use Parser;
|
||||
use ParserFactory;
|
||||
use ParserOptions;
|
||||
use SearchEngineFactory;
|
||||
use Title;
|
||||
|
||||
class SpecialCiteThisPage extends FormSpecialPage {
|
||||
|
@ -21,8 +23,29 @@ class SpecialCiteThisPage extends FormSpecialPage {
|
|||
*/
|
||||
protected $title = false;
|
||||
|
||||
public function __construct() {
|
||||
/** @var SearchEngineFactory */
|
||||
private $searchEngineFactory;
|
||||
|
||||
/** @var RevisionLookup */
|
||||
private $revisionLookup;
|
||||
|
||||
/** @var ParserFactory */
|
||||
private $parserFactory;
|
||||
|
||||
/**
|
||||
* @param SearchEngineFactory $searchEngineFactory
|
||||
* @param RevisionLookup $revisionLookup
|
||||
* @param ParserFactory $parserFactory
|
||||
*/
|
||||
public function __construct(
|
||||
SearchEngineFactory $searchEngineFactory,
|
||||
RevisionLookup $revisionLookup,
|
||||
ParserFactory $parserFactory
|
||||
) {
|
||||
parent::__construct( 'CiteThisPage' );
|
||||
$this->searchEngineFactory = $searchEngineFactory;
|
||||
$this->revisionLookup = $revisionLookup;
|
||||
$this->parserFactory = $parserFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,7 +96,7 @@ class SpecialCiteThisPage extends FormSpecialPage {
|
|||
* @return string[] Matching subpages
|
||||
*/
|
||||
public function prefixSearchSubpages( $search, $limit, $offset ) {
|
||||
return $this->prefixSearchString( $search, $limit, $offset );
|
||||
return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
|
||||
}
|
||||
|
||||
protected function getGroupName() {
|
||||
|
@ -87,9 +110,7 @@ class SpecialCiteThisPage extends FormSpecialPage {
|
|||
|
||||
$out = $this->getOutput();
|
||||
|
||||
$revTimestamp = MediaWikiServices::getInstance()
|
||||
->getRevisionLookup()
|
||||
->getTimestampFromId( $revId );
|
||||
$revTimestamp = $this->revisionLookup->getTimestampFromId( $revId );
|
||||
|
||||
if ( !$revTimestamp ) {
|
||||
$out->wrapWikiMsg( '<div class="errorbox">$1</div>',
|
||||
|
@ -101,13 +122,14 @@ class SpecialCiteThisPage extends FormSpecialPage {
|
|||
// Set the overall timestamp to the revision's timestamp
|
||||
$parserOptions->setTimestamp( $revTimestamp );
|
||||
|
||||
$parser = $this->getParser();
|
||||
$parser = $this->parserFactory->create();
|
||||
// Register our <citation> tag which just parses using a different
|
||||
// context
|
||||
$parser->setHook( 'citation', [ $this, 'citationTag' ] );
|
||||
|
||||
// Also hold on to a separate Parser instance for <citation> tag parsing
|
||||
// since we can't parse in a parse using the same Parser
|
||||
$this->citationParser = $this->getParser();
|
||||
$this->citationParser = $this->parserFactory->create();
|
||||
|
||||
$ret = $parser->parse(
|
||||
$this->getContentText(),
|
||||
|
@ -124,14 +146,6 @@ class SpecialCiteThisPage extends FormSpecialPage {
|
|||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Parser
|
||||
*/
|
||||
private function getParser() {
|
||||
$parserFactory = MediaWikiServices::getInstance()->getParserFactory();
|
||||
return $parserFactory->create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content to parse
|
||||
*
|
||||
|
@ -144,10 +158,9 @@ class SpecialCiteThisPage extends FormSpecialPage {
|
|||
# and the text moved into SpecialCite.i18n.php
|
||||
# This code is kept for b/c in case an installation has its own file "citethispage-content-xx"
|
||||
# for a previously not supported language.
|
||||
global $wgLanguageCode;
|
||||
$dir = __DIR__ . '/../';
|
||||
$code = MediaWikiServices::getInstance()->getContentLanguage()
|
||||
->lc( $wgLanguageCode );
|
||||
$contentLang = $this->getContentLanguage();
|
||||
$code = $contentLang->lc( $contentLang->getCode() );
|
||||
if ( file_exists( "${dir}citethispage-content-$code" ) ) {
|
||||
$msg = file_get_contents( "${dir}citethispage-content-$code" );
|
||||
} elseif ( file_exists( "${dir}citethispage-content" ) ) {
|
||||
|
|
Loading…
Reference in a new issue