Skip to content

Commit

Permalink
Special page and QQQ added
Browse files Browse the repository at this point in the history
  • Loading branch information
lucamauri committed Jul 5, 2020
1 parent f6c2871 commit 4da35f8
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 7 deletions.
3 changes: 0 additions & 3 deletions PageToGitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public static function onPageContentSaveComplete($wikiPage, $user, $content, $su

$P2GNameSpace = $config->get('P2GNameSpace');
$P2GKeyword = $config->get('P2GKeyword');
//wfDebugLog('PageToGitHub', '[PageToGitHub]Keyword type: '.gettype($P2GKeyword[0]));
//$P2GignoreMinor = true;
$P2GIgnoreMinor = $config->get('P2GIgnoreMinor');

wfDebugLog('PageToGitHub', '[PageToGitHub]Entered');
Expand All @@ -64,7 +62,6 @@ public static function onPageContentSaveComplete($wikiPage, $user, $content, $su
wfDebugLog('PageToGitHub', '[PageToGitHub]NOT ignoring Minor');
if ($pageNameSpace == $P2GNameSpace) {
wfDebugLog('PageToGitHub', '[PageToGitHub]Namespace OK');
// || $P2GKeyword == '' || strpos($pageContent, $P2GKeyword) > -1
wfDebugLog('PageToGitHub', '[PageToGitHub]Keyword count: '.count($P2GKeyword));
wfDebugLog('PageToGitHub', '[PageToGitHub]Keyword: '.$P2GKeyword[0]);
if ($P2GKeyword[0] == null or $P2GKeyword == '' or (strpos($pageContent, $P2GKeyword) > -1)) {
Expand Down
9 changes: 7 additions & 2 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"author": "[https://www.lucamauri.com/ Luca Mauri]",
"url": "https://github.com/lucamauri/PageToGitHub",
"description": "Allow the transport of page content to GitHub on page save",
"version": "1.1",
"version": "1.2",
"license-name": "GPL-2.0-or-later",
"type": "parserhook",
"manifest_version": 1,
"AutoloadClasses": {
"PageToGitHubHooks": "PageToGitHub.php"
"PageToGitHubCommon": "includes/P2GCommon.php",
"PageToGitHubHooks": "PageToGitHub.php",
"PageToGitHubSpecial": "includes/P2GSpecial.php"
},
"Hooks": {
"PageContentSaveComplete": ["PageToGitHubHooks::onPageContentSaveComplete"]
Expand Down Expand Up @@ -47,6 +49,9 @@
"ConfigRegistry": {
"PageToGitHub": "GlobalVarConfig::newInstance"
},
"SpecialPages": {
"PageToGitHub": "PageToGitHubSpecial"
},
"MessagesDirs": {
"PageToGitHub": ["i18n"]
}
Expand Down
6 changes: 5 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
"auto-upload": "Auto upload by PageToGitHub on",
"auto-commit": "Auto commit by PageToGitHub",
"code-from-page": "This code from page",
"p2g-config-namespace": "Label of the namespace to check"
"p2g-config-namespace": "Label of the namespace to check",
"pagetogithub": "Page To GitHub",
"p2g-specialpage-text": "This page shows details on ''PageToGitHub'' configuration",
"p2g-specialpage-variables-text": "This section shows the values of ''PageToGitHub'' configuration variables",
"p2g-specialpage-config-title": "==Configuration=="
}
6 changes: 5 additions & 1 deletion i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
"auto-upload": "Upload automatica di PageToGitHub il",
"auto-commit": "Commit automatico di PageToGitHub",
"code-from-page": "Questo codice proviene da",
"p2g-config-namespace": "Nome del namespace da controllare"
"p2g-config-namespace": "Nome del namespace da controllare",
"pagetogithub": "Page To GitHub",
"p2g-specialpage-text": "Questa pagina mostra dettagli sulla configurazione di ''PageToGitHub''",
"p2g-specialpage-variables-text": "Questa sezione mostra i valori delle varibili di configurazione di ''PageToGitHub''",
"p2g-specialpage-config-title": "==Configurazione=="
}
13 changes: 13 additions & 0 deletions i18n/qqq.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"@metadata": {
"authors": ["Luca Mauri"]
},
"auto-upload": "''Auto upload'' message on GitHub",
"auto-commit": "''Auto commit'' message on GitHub",
"code-from-page": "Prefix to the page name",
"p2g-config-namespace": "Description of the namespace",
"pagetogithub": "Placeholder for product name",
"p2g-specialpage-text": "Intro of the ''Special'' page",
"p2g-specialpage-variables-text": "Intro of the ''Configuration'' section",
"p2g-specialpage-config-title": "Title of the ''config'' section"
}
14 changes: 14 additions & 0 deletions includes/P2GCommon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
use MediaWiki\MediaWikiServices;

class PageToGitHubCommon {
function __construct() {
parent::__construct('PageToGitHub');

$variablesNames = ["P2GNameSpace", "P2GKeyword", "P2GAddKeyword", "P2GIgnoreMinor","P2GAuthToken", "P2GOwner", "P2GRepo"];
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig('PageToGitHub');
foreach ($variablesNames as $variableName) {
${$variableName} = $config->get($variableName);
}
}
}
52 changes: 52 additions & 0 deletions includes/P2GSpecial.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
use MediaWiki\MediaWikiServices;

class PageToGitHubSpecial extends SpecialPage {
function __construct() {
parent::__construct('PageToGitHub');
}

function execute( $par ) {
$variablesNames = ["P2GNameSpace", "P2GKeyword", "P2GAddKeyword", "P2GIgnoreMinor","P2GAuthToken", "P2GOwner", "P2GRepo"];
$request = $this->getRequest();
$output = $this->getOutput();
$this->setHeaders();

# Get request data from, e.g.
$param = $request->getText( 'param' );

# Do stuff
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig('PageToGitHub');

// https://doc.wikimedia.org/mediawiki-core/master/php/classOutputPage.html
$output->addWikiMsg('p2g-specialpage-text');
$output->addWikiMsg('p2g-specialpage-config-title');
$output->addWikiMsg('p2g-specialpage-variables-text');

$output->addHTML('<table class="wikitable plainlinks" id="p2g-variables"><tbody>
<tr>
<th>Variabile</th>
<th>Valore</th>
</tr>');

foreach ($variablesNames as $variableName) {
${$variableName} = $config->get($variableName);
$output->addHTML('<tr>');
$output->addHTML('<th>' . $variableName . '</th>');
if ($variableName == 'P2GAuthToken') {
$variableContent = "''hidden''";
} else {
$variableContent = "<code>" . ${$variableName} . "</code>";
}
$output->addHTML('<td>');
$output->addWikiTextAsContent($variableContent);
$output->addHTML('</td>');
$output->addHTML('</tr>');
}

$output->addHTML('</tbody></table>');

//$wikitext = 'Hello world!';
//$output->addWikiTextAsInterface( $wikitext );
}
}

0 comments on commit 4da35f8

Please sign in to comment.