Phantom42 has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/405665 )
Change subject: Fix multiple PHP class declarations in one file
......................................................................
Fix multiple PHP class declarations in one file
All files containing more than one PHP class were split into
multiple files.
Autoloader references were updated to match new class locations.
Bug: T177809
Change-Id: I25f6230396010d53f772408e083608d18dbe5a9c
---
M includes/setup/OWSpecials.php
A includes/specials/ExternalResources.php
M includes/specials/SpecialOWAddFromExternalAPI.php
R includes/specials/WordnikExtension.php
A includes/specials/WordnikWiktionaryExtension.php
A includes/specials/WordnikWordnetExtension.php
6 files changed, 199 insertions(+), 188 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikiLexicalData
refs/changes/65/405665/1
diff --git a/includes/setup/OWSpecials.php b/includes/setup/OWSpecials.php
index 27818f9..cb01023 100644
--- a/includes/setup/OWSpecials.php
+++ b/includes/setup/OWSpecials.php
@@ -106,6 +106,7 @@
$wgAutoloadClasses['SpecialImportTSV'] = $wgWldSpecialsScriptPath .
'SpecialImportTSV.php';
$wgAutoloadClasses['SpecialOWAddFromExternalAPI'] = $wgWldSpecialsScriptPath .
'SpecialOWAddFromExternalAPI.php';
+$wgAutoloadClasses['ExternalResources'] = $wgWldSpecialsScriptPath .
'ExternalResources.php';
// $wgAutoloadClasses['SpecialTransaction'] = $dir .
'OmegaWiki/SpecialTransaction.php';
@@ -136,9 +137,9 @@
$wgWldExtenalResourceLanguages = array();
if ( file_exists( $wgWldScriptPath . '/external/wordnik/wordnik/Swagger.php' )
) {
- $wgAutoloadClasses['WordnikExtension' ] = $wgWldSpecialsScriptPath .
'ExternalWordnik.php';
- $wgAutoloadClasses['WordnikWiktionaryExtension' ] =
$wgWldSpecialsScriptPath . 'ExternalWordnik.php';
- $wgAutoloadClasses['WordnikWordnetExtension' ] =
$wgWldSpecialsScriptPath . 'ExternalWordnik.php';
+ $wgAutoloadClasses['WordnikExtension' ] = $wgWldSpecialsScriptPath .
'WordnikExtension.php';
+ $wgAutoloadClasses['WordnikWiktionaryExtension' ] =
$wgWldSpecialsScriptPath . 'WordnikWiktionaryExtension.php';
+ $wgAutoloadClasses['WordnikWordnetExtension' ] =
$wgWldSpecialsScriptPath . 'WordnikWordnetExtension.php';
$wgWldProcessExternalAPIClasses['WordnikExtension'] = 'Wordnik';
$wgWldProcessExternalAPIClasses['WordnikWiktionaryExtension'] =
'Wordnik Wiktionary';
$wgWldProcessExternalAPIClasses['WordnikWordnetExtension'] = 'Wordnik
Wordnet';
diff --git a/includes/specials/ExternalResources.php
b/includes/specials/ExternalResources.php
new file mode 100644
index 0000000..5659fff
--- /dev/null
+++ b/includes/specials/ExternalResources.php
@@ -0,0 +1,175 @@
+<?php
+
+if ( !defined( 'MEDIAWIKI' ) ) die();
+
+require_once( __DIR__ . "/../../OmegaWiki/OmegaWikiDatabaseAPI.php" );
+/** @brief This class handles External Resources.
+ *
+ * This class is the base of individual external resources
+ *
+ * @note: To extend this class, the extended class needs its own __construct,
execute,
+ * checkExternalDefinition, setExternalDefinition functions.
+ *
+ */
+class ExternalResources {
+
+ protected $wgOut;
+ protected $externalLexicalData = array();
+ protected $owlLexicalData = array();
+ protected $spTitle;
+ protected $source;
+ protected $sourceLanguageId;
+ protected $collectionId;
+ protected $externalDefinition;
+ protected $externalExists = false; // bool
+ protected $owlDefinition;
+ protected $owlExists = false; // bool
+
+
+ /**
+ * @param spTitle str Special Page Title
+ * @param source str the source dictionary
+ * @param sourceLabel str the source dictionary name that will
appear.
+ * @param sourceLanguageId int The languageId of the source dictionary
+ * @param search str The expression/spelling( word ) to be
searched
+ * @param collectionId int The Collection Id
+ */
+ function __construct( $spTitle, $source, $sourceLanguageId, $search,
$collectionId ) {
+ global $wgOut;
+ $this->wgOut = $wgOut;
+ $this->spTitle = $spTitle;
+ $this->source = $source;
+ $this->sourceLabel = $source;
+ $this->sourceLanguageId = $sourceLanguageId;
+ $this->search = $search;
+ $this->collectionId = $collectionId;
+ }
+
+ public function execute() {
+ $this->outputTitle();
+ $this->getOptionPanel();
+ $this->checkConnectionStatus();
+
+ // inline css ( for future refactoring )
+ // removes from data when finished testing
+ $this->wgOut->addHTML( $this->temporaryCodeSpace() );
+
+ if ( $this->source ) {
+ switch ( $this->connection ) {
+ case true:
+ $this->checkExternalDefinition();
+ $this->checkOmegaWikiDefinition();
+ if ( $this->externalExists and
$this->owlExists ) {
+ $this->setExternalDefinition();
+ $this->setOmegaWikiDefinition();
+ $this->createChoice();
+ }
+ break;
+ case false:
+ $this->wgOut->addHtml( 'Sorry, there is
a problem with the connection. Can not find ' . $this->search );
+ break;
+ }
+ }
+ }
+
+ private function temporaryCodeSpace() {
+ return '<style>' .
+ '#ext-data {visibility: hidden; display: none }' .
+ '#owl-data {visibility: hidden; display: none }' .
+ '</style>';
+ }
+
+ private function createChoice() {
+ $owlLineProcessed = false;
+ $ctr = 0;
+ $this->wgOut->addHTML(
+ '<form id="flexible_form">'.
+ '<input type="hidden" name="title" value="Special:Ow
addFromExtAPI"/>'
+ );
+ $this->wgOut->addHTML(
+ '<div><div id="owl_def"></div><div
id="ext_def"></div><span id="selectChecks"><input type="button"
id="inputSelectButton" value="process"/></span><span id="skipChecks"><input
type="button" id="inputSkipSelectButton" value="next"/></span></div>'
+ );
+ $this->wgOut->addHTML(
+ '</form>'
+ );
+ }
+
+ private function outputTitle() {
+ $this->wgOut->setPageTitle( $this->spTitle );
+ }
+
+ private function getOptionPanel() {
+ global $wgWldProcessExternalAPIClasses,
$wgWldExtenalResourceLanguages;
+ $forms = new OmegaWikiForms;
+ $this->wgOut->addHTML( getOptionPanel(
+ array(
+ wfMessage( 'ow_api_source' )->text()
=> $forms->getSelect( 'api', $wgWldProcessExternalAPIClasses,
$this->source ),
+ wfMessage( 'ow_needs_xlation_source_lang'
)->text() => $forms->getSelect( 'from-lang', $wgWldExtenalResourceLanguages,
$this->sourceLanguageId ),
+ wfMessage( 'datasearch_search_text' )->text()
=> getTextBox( 'search-ext', $this->search ),
+ )
+ ) );
+ }
+
+ /**
+ */
+ function checkConnectionStatus() {
+ $this->connection = false;
+ if ( connection_status() === CONNECTION_NORMAL ) {
+ $this->connection = true;
+ }
+ }
+
+ protected function outputResult() {
+ if ( $this->externalLexicalData ) {
+ $this->wgOut->addHTML( json_encode(
$this->externalLexicalData ) . '<br/><br/>.' );
+ } else {
+ }
+ if ( $this->owlLexicalData ) {
+ $this->wgOut->addHTML( json_encode(
$this->owlLexicalData ) . '<br/><br/>' );
+ } else {
+ }
+ }
+
+ protected function checkOmegaWikiDefinition() {
+ if ( existSpelling( $this->search, $this->sourceLanguageId ) ) {
+ $this->owlExists = true;
+ }
+ }
+
+ protected function setOmegaWikiDefinition() {
+ // If expression exist in the source language, then proceed.
+ if ( existSpelling( $this->search, $this->sourceLanguageId ) ) {
+ $this->expressionId =
OwDatabaseAPI::getTheExpressionId( $this->search, $this->sourceLanguageId );
+ $dmList =
OwDatabaseAPI::getExpressionMeaningIdsForLanguages( $this->search,
$this->sourceLanguageId );
+ foreach( $dmList as $dmLine ) {
+ $text = getDefinedMeaningDefinitionForLanguage(
$dmLine, $this->sourceLanguageId );
+ if ( !$text ) {
+ $text =
getDefinedMeaningDefinitionForLanguage( $dmLine, WLD_ENGLISH_LANG_ID );
+ }
+
+ $synonyms = OwDatabaseAPI::getSynonyms(
$dmLine, $this->sourceLanguageId, $this->search );
+
+ $this->owlLexicalData[] = array(
+ 'processed' => null,
+ 'e' => $this->search,
+ 'dm_id' => $dmLine,
+ 'lang_id' => $this->sourceLanguageId,
+ 'text' => $text,
+ 'syn' => $synonyms
+ );
+ }
+ }
+
+ $this->owlLexicalDataJSON = json_encode( $this->owlLexicalData
);
+ // Line below for testing. When there's no internet connection
+ // $this->owlLexicalDataJSON =
'[{"processed":null,"dm_id":"5836","lang_id":"85","text":"A common, four-legged
animal (Sus scrofa) that has cloven hooves, bristles and a nose adapted for
digging and is farmed by humans for its
meat.","syn":null},{"processed":null,"dm_id":"1499810","lang_id":"85","text":"(Pejorative)
A fat or overweight
person.","syn":[["butterball","85","1","1499814"],["chubster","85","1","1499816"],["chunker","85","1","1499818"],["fat-ass","85","1","1499825"],["fatass","85","1","1499827"],["fatfuck","85","1","1499820"],["fatshit","85","1","1499829"],["fatso","85","1","1499811"],["fattie","85","1","1499822"],["fatty","85","1","1499823"],["lardass","85","1","1499831"],["lardo","85","1","1499833"],["obeast","85","1","1499837"],["oinker","85","1","1499835"],["podge","85","1","1499840"],["porker","85","1","1499842"],["pudge","85","1","1499844"],["salad
dodger","85","1","1499846"],["tub of
lard","85","1","1499848"]]},{"processed":null,"dm_id":"583600","lang_id":"85","text":"A
common, four-legged animal (Sus scrofa) that has cloven hooves, bristles and a
nose adapted for digging and is farmed by humans for its meat.","syn":null}]';
+
+ $this->wgOut->addHTML(
+ '<div id="owl-data">' . $this->owlLexicalDataJSON .
'</div>'
+ );
+ }
+
+ protected function getGroupName() {
+ return 'omegawiki'; // message
'specialpages-group-omegawiki'
+ }
+}
diff --git a/includes/specials/SpecialOWAddFromExternalAPI.php
b/includes/specials/SpecialOWAddFromExternalAPI.php
index 10a34c1..315ca21 100644
--- a/includes/specials/SpecialOWAddFromExternalAPI.php
+++ b/includes/specials/SpecialOWAddFromExternalAPI.php
@@ -152,174 +152,3 @@
return 'maintenance';
}
}
-
-/** @brief This class handles External Resources.
- *
- * This class is the base of individual external resources
- *
- * @note: To extend this class, the extended class needs its own __construct,
execute,
- * checkExternalDefinition, setExternalDefinition functions.
- *
- */
-class ExternalResources {
-
- protected $wgOut;
- protected $externalLexicalData = array();
- protected $owlLexicalData = array();
- protected $spTitle;
- protected $source;
- protected $sourceLanguageId;
- protected $collectionId;
- protected $externalDefinition;
- protected $externalExists = false; // bool
- protected $owlDefinition;
- protected $owlExists = false; // bool
-
-
- /**
- * @param spTitle str Special Page Title
- * @param source str the source dictionary
- * @param sourceLabel str the source dictionary name that will
appear.
- * @param sourceLanguageId int The languageId of the source dictionary
- * @param search str The expression/spelling( word ) to be
searched
- * @param collectionId int The Collection Id
- */
- function __construct( $spTitle, $source, $sourceLanguageId, $search,
$collectionId ) {
- global $wgOut;
- $this->wgOut = $wgOut;
- $this->spTitle = $spTitle;
- $this->source = $source;
- $this->sourceLabel = $source;
- $this->sourceLanguageId = $sourceLanguageId;
- $this->search = $search;
- $this->collectionId = $collectionId;
- }
-
- public function execute() {
- $this->outputTitle();
- $this->getOptionPanel();
- $this->checkConnectionStatus();
-
- // inline css ( for future refactoring )
- // removes from data when finished testing
- $this->wgOut->addHTML( $this->temporaryCodeSpace() );
-
- if ( $this->source ) {
- switch ( $this->connection ) {
- case true:
- $this->checkExternalDefinition();
- $this->checkOmegaWikiDefinition();
- if ( $this->externalExists and
$this->owlExists ) {
- $this->setExternalDefinition();
- $this->setOmegaWikiDefinition();
- $this->createChoice();
- }
- break;
- case false:
- $this->wgOut->addHtml( 'Sorry, there is
a problem with the connection. Can not find ' . $this->search );
- break;
- }
- }
- }
-
- private function temporaryCodeSpace() {
- return '<style>' .
- '#ext-data {visibility: hidden; display: none }' .
- '#owl-data {visibility: hidden; display: none }' .
- '</style>';
- }
-
- private function createChoice() {
- $owlLineProcessed = false;
- $ctr = 0;
- $this->wgOut->addHTML(
- '<form id="flexible_form">'.
- '<input type="hidden" name="title" value="Special:Ow
addFromExtAPI"/>'
- );
- $this->wgOut->addHTML(
- '<div><div id="owl_def"></div><div
id="ext_def"></div><span id="selectChecks"><input type="button"
id="inputSelectButton" value="process"/></span><span id="skipChecks"><input
type="button" id="inputSkipSelectButton" value="next"/></span></div>'
- );
- $this->wgOut->addHTML(
- '</form>'
- );
- }
-
- private function outputTitle() {
- $this->wgOut->setPageTitle( $this->spTitle );
- }
-
- private function getOptionPanel() {
- global $wgWldProcessExternalAPIClasses,
$wgWldExtenalResourceLanguages;
- $forms = new OmegaWikiForms;
- $this->wgOut->addHTML( getOptionPanel(
- array(
- wfMessage( 'ow_api_source' )->text()
=> $forms->getSelect( 'api', $wgWldProcessExternalAPIClasses,
$this->source ),
- wfMessage( 'ow_needs_xlation_source_lang'
)->text() => $forms->getSelect( 'from-lang', $wgWldExtenalResourceLanguages,
$this->sourceLanguageId ),
- wfMessage( 'datasearch_search_text' )->text()
=> getTextBox( 'search-ext', $this->search ),
- )
- ) );
- }
-
- /**
- */
- function checkConnectionStatus() {
- $this->connection = false;
- if ( connection_status() === CONNECTION_NORMAL ) {
- $this->connection = true;
- }
- }
-
- protected function outputResult() {
- if ( $this->externalLexicalData ) {
- $this->wgOut->addHTML( json_encode(
$this->externalLexicalData ) . '<br/><br/>.' );
- } else {
- }
- if ( $this->owlLexicalData ) {
- $this->wgOut->addHTML( json_encode(
$this->owlLexicalData ) . '<br/><br/>' );
- } else {
- }
- }
-
- protected function checkOmegaWikiDefinition() {
- if ( existSpelling( $this->search, $this->sourceLanguageId ) ) {
- $this->owlExists = true;
- }
- }
-
- protected function setOmegaWikiDefinition() {
- // If expression exist in the source language, then proceed.
- if ( existSpelling( $this->search, $this->sourceLanguageId ) ) {
- $this->expressionId =
OwDatabaseAPI::getTheExpressionId( $this->search, $this->sourceLanguageId );
- $dmList =
OwDatabaseAPI::getExpressionMeaningIdsForLanguages( $this->search,
$this->sourceLanguageId );
- foreach( $dmList as $dmLine ) {
- $text = getDefinedMeaningDefinitionForLanguage(
$dmLine, $this->sourceLanguageId );
- if ( !$text ) {
- $text =
getDefinedMeaningDefinitionForLanguage( $dmLine, WLD_ENGLISH_LANG_ID );
- }
-
- $synonyms = OwDatabaseAPI::getSynonyms(
$dmLine, $this->sourceLanguageId, $this->search );
-
- $this->owlLexicalData[] = array(
- 'processed' => null,
- 'e' => $this->search,
- 'dm_id' => $dmLine,
- 'lang_id' => $this->sourceLanguageId,
- 'text' => $text,
- 'syn' => $synonyms
- );
- }
- }
-
- $this->owlLexicalDataJSON = json_encode( $this->owlLexicalData
);
- // Line below for testing. When there's no internet connection
- // $this->owlLexicalDataJSON =
'[{"processed":null,"dm_id":"5836","lang_id":"85","text":"A common, four-legged
animal (Sus scrofa) that has cloven hooves, bristles and a nose adapted for
digging and is farmed by humans for its
meat.","syn":null},{"processed":null,"dm_id":"1499810","lang_id":"85","text":"(Pejorative)
A fat or overweight
person.","syn":[["butterball","85","1","1499814"],["chubster","85","1","1499816"],["chunker","85","1","1499818"],["fat-ass","85","1","1499825"],["fatass","85","1","1499827"],["fatfuck","85","1","1499820"],["fatshit","85","1","1499829"],["fatso","85","1","1499811"],["fattie","85","1","1499822"],["fatty","85","1","1499823"],["lardass","85","1","1499831"],["lardo","85","1","1499833"],["obeast","85","1","1499837"],["oinker","85","1","1499835"],["podge","85","1","1499840"],["porker","85","1","1499842"],["pudge","85","1","1499844"],["salad
dodger","85","1","1499846"],["tub of
lard","85","1","1499848"]]},{"processed":null,"dm_id":"583600","lang_id":"85","text":"A
common, four-legged animal (Sus scrofa) that has cloven hooves, bristles and a
nose adapted for digging and is farmed by humans for its meat.","syn":null}]';
-
- $this->wgOut->addHTML(
- '<div id="owl-data">' . $this->owlLexicalDataJSON .
'</div>'
- );
- }
-
- protected function getGroupName() {
- return 'omegawiki'; // message
'specialpages-group-omegawiki'
- }
-}
diff --git a/includes/specials/ExternalWordnik.php
b/includes/specials/WordnikExtension.php
similarity index 95%
rename from includes/specials/ExternalWordnik.php
rename to includes/specials/WordnikExtension.php
index 951fa06..bd1f0f3 100644
--- a/includes/specials/ExternalWordnik.php
+++ b/includes/specials/WordnikExtension.php
@@ -115,17 +115,3 @@
}
}
-
-class WordnikWiktionaryExtension extends WordnikExtension {
- function __construct( $spTitle, $source, $sourceLanguageId, $search,
$collectionId ) {
- parent::__construct( $spTitle, $source, $sourceLanguageId,
$search, $collectionId );
- $this->sourceDictionary = 'wiktionary';
- }
-}
-
-class WordnikWordnetExtension extends WordnikExtension {
- function __construct( $spTitle, $source, $sourceLanguageId, $search,
$collectionId ) {
- parent::__construct( $spTitle, $source, $sourceLanguageId,
$search, $collectionId );
- $this->sourceDictionary = 'wordnet';
- }
-}
diff --git a/includes/specials/WordnikWiktionaryExtension.php
b/includes/specials/WordnikWiktionaryExtension.php
new file mode 100644
index 0000000..ddf0984
--- /dev/null
+++ b/includes/specials/WordnikWiktionaryExtension.php
@@ -0,0 +1,10 @@
+<?php
+
+if ( !defined( 'MEDIAWIKI' ) ) die();
+
+class WordnikWiktionaryExtension extends WordnikExtension {
+ function __construct( $spTitle, $source, $sourceLanguageId, $search,
$collectionId ) {
+ parent::__construct( $spTitle, $source, $sourceLanguageId,
$search, $collectionId );
+ $this->sourceDictionary = 'wiktionary';
+ }
+}
diff --git a/includes/specials/WordnikWordnetExtension.php
b/includes/specials/WordnikWordnetExtension.php
new file mode 100644
index 0000000..938852b
--- /dev/null
+++ b/includes/specials/WordnikWordnetExtension.php
@@ -0,0 +1,10 @@
+<?php
+
+if ( !defined( 'MEDIAWIKI' ) ) die();
+
+class WordnikWordnetExtension extends WordnikExtension {
+ function __construct( $spTitle, $source, $sourceLanguageId, $search,
$collectionId ) {
+ parent::__construct( $spTitle, $source, $sourceLanguageId,
$search, $collectionId );
+ $this->sourceDictionary = 'wordnet';
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/405665
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I25f6230396010d53f772408e083608d18dbe5a9c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikiLexicalData
Gerrit-Branch: master
Gerrit-Owner: Phantom42 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits