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