Page MenuHomeDevCentral

D1562.id4037.diff
No OneTemporary

D1562.id4037.diff

Index: .gitignore
===================================================================
--- /dev/null
+++ .gitignore
@@ -0,0 +1,3 @@
+# Compose
+/vendor/
+composer.lock
Index: Notifications/Notification.php
===================================================================
--- /dev/null
+++ Notifications/Notification.php
@@ -0,0 +1,133 @@
+<?php
+
+namespace Nasqueron\SAAS\MediaWiki\Maintenance\Notifications;
+
+use MediaWiki\Http\HttpRequestFactory;
+use MediaWiki\Logger\LoggerFactory;
+
+class Notification {
+
+ /**
+ * @var HttpRequestFactory
+ */
+ private $httpRequestFactory;
+
+ public function __construct (
+ HttpRequestFactory $httpRequestFactory,
+ $options = []
+ ) {
+ $this->httpRequestFactory = $httpRequestFactory;
+ $this->setProperties( $options );
+ }
+
+ ///
+ /// Notifications properties
+ ///
+
+ /**
+ * The notification's source service (e.g. GitHub, Phabricator, Jenkins)
+ *
+ * @var string
+ */
+ public $service;
+
+ /**
+ * The notification's target project (e.g. Wikimedia, Nasqueron, Wolfplex)
+ *
+ * @var string
+ */
+ public $project;
+
+ /**
+ * The notification's target group (e.g. Tasacora, Operations)
+ *
+ * @var string
+ */
+ public $group;
+
+ /**
+ * The notification's source payload, data or message
+ *
+ * @var mixed
+ */
+ public $rawContent;
+
+ /**
+ * The notification's type (e.g. "commits", "task")
+ *
+ * @var string
+ */
+ public $type;
+
+ /**
+ * The notification's text
+ *
+ * @var string
+ */
+ public $text;
+
+ /**
+ * The notification's URL, to be used as the main link for widgets
+ *
+ * @var string
+ */
+ public $link;
+
+ ///
+ /// Properties filler helper methods
+ ///
+
+ private function setProperties ( array $properties ) : void {
+ foreach ( $properties as $key->value ) {
+ $this->setProperty( $key, $value )
+ }
+ }
+
+ private function setProperty ( string $key, string $value ) : void {
+ if ( property_exists( $this, $key ) ) {
+ $this->$key = $value;
+ } else {
+ $this->handleNonExistingProperty( $key, $value, __METHOD__ );
+ }
+ }
+
+ private function handleNonExistingProperty (
+ string $key,
+ string $value,
+ string $method
+ ) : void {
+ static $logger = null;
+ if ( $logger === null ) {
+ $logger = LoggerFactory::getInstance( 'NasqueronMaintenance' );
+ }
+
+ $logger->warning(
+ "Property {property} is unknown for notification",
+ [
+ 'method' => __METHOD__,
+ 'property' => $key,
+ ]
+ );
+ }
+ }
+
+ ///
+ /// Fire notification helper methods
+ ///
+
+ public function send() : void {
+ $request = $this->httpRequestFactory->create(
+ $this->getGateUrl(),
+ [
+ 'method' => "POST",
+ 'postData' => json_encode( $this ),
+ ]
+ );
+ }
+
+ private function getGateUrl(): string {
+ return "https://notifications.nasqueron.org/gate/Notification/"
+ . $this->project;
+ }
+
+}
Index: README.md
===================================================================
--- /dev/null
+++ README.md
@@ -0,0 +1,9 @@
+# NasqueronMaintenance
+
+This **MediaWiki extension** is a repository to host a collection
+of scripts useful on the Nasqueron MediaWiki SaaS. It contains scripts
+specific to our installation and architecture.
+
+https://agora.nasqueron.org/MediaWiki_SaaS/NasqueronMaintenance
+
+The idea is taken from https://www.mediawiki.org/wiki/Extension:WikimediaMaintenance.
Index: Utilities/addWiki.php
===================================================================
--- /dev/null
+++ Utilities/addWiki.php
@@ -0,0 +1,177 @@
+<?php
+
+namespace Nasqueron\SAAS\MediaWiki\Maintenance\Utilities;
+
+use Nasqueron\SAAS\MediaWiki\Maintenance\Notifications\Notification;
+
+use Wikimedia\Rdbms\Database;
+use MediaWiki\MediaWikiServices;
+use MediaWiki\Http\HttpRequestFactory;
+
+use ContentHandler;
+use Title;
+use WikiPage;
+
+require_once "$IP/maintenance/Maintenance.php";
+
+class AddWiki extends Maintenance {
+
+ /**
+ * @var Database
+ */
+ private $db;
+
+ /**
+ * @var HttpRequestFactory
+ */
+ private $httpRequestFactory;
+
+ /**
+ * @var string
+ */
+ private $serverName;
+
+ /**
+ * @var string
+ */
+ private $databaseName;
+
+ /**
+ * @var string
+ */
+ private $languageCode;
+
+ ///
+ /// Constructor and maintenance script entry function
+ ///
+
+ public function __construct () {
+ global $wgCanonicalServer, $wgDBname, $wgLanguageCode;
+
+ parent::__construct();
+ $this->mDescription = "Add a new wiki instance to the service.";
+
+ $this->serverName = $wgCanonicalServer;
+ $this->databaseName = $wgDBname;
+ $this->languageCode = $wgLanguageCode;
+ }
+
+ public function execute() {
+ $this->initialiseServices();
+
+ $this->createDatabaseAndTables();
+ $this->publishMainPage();
+ $this->sendNotification();
+ }
+
+ ///
+ /// Services
+ ///
+
+ private function initialiseServices () {
+ $this->db = $this->getDatabase();
+ $this->httpRequestFactory = MediaWikiServices::GetInstance()
+ ->getHttpRequestFactory();
+ }
+
+ private function getDatabase() : Database {
+ $db = MediaWikiServices::GetInstance()
+ ->getDbLoadBalancer()
+ ->getConnection( DB_MASTER );
+ $db->query( "SET storage_engine=InnoDB" );
+ return $db;
+ }
+
+ ///
+ /// SQL code
+ ///
+
+ /**
+ * @throws \Wikimedia\Rdbms\DBConnectionError
+ */
+ private function createDatabaseAndTables () : void {
+ $this->db->query(
+ "CREATE DATABASE IF NOT EXISTS " . $this->databaseName
+ );
+
+ $this->createCoreTables();
+ $this->createExtensionTables();
+ }
+
+ private function createCoreTables () {
+ $this->db->sourceFile( "$IP/maintenance/tables.sql" );
+ }
+
+ private function createExtensionTables () {
+ // $this->db->sourceFile( "$IP/extensions/Math/db/math.mysql.sql" );
+ }
+
+ ///
+ /// Main page code
+ ///
+
+ private function publishMainPage() : void {
+ $title = $this->getMainPageTitle()
+ WikiPage::factory( $title )->doEditContent(
+ ContentHandler::makeContent(
+ $this->getMainPageText(),
+ $title
+ ),
+ '',
+ EDIT_NEW | EDIT_AUTOSUMMARY
+ );
+ }
+
+ private function getMainPageTitle() : Title {
+ return Title::newFromText(
+ wfMessage( 'mainpage' )->plain()
+ );
+ }
+
+ private function getMainPageText() : string {
+ $path = dirname( __DIR__ ) . "/Views/MainPage";
+ $file = $path . "/" . $this->languageCode . ".txt";
+ if ( !file_exists( $file ) ) {
+ $file = "$path/en.txt";
+ }
+
+ return file_get_contents( $file );
+ }
+
+ ///
+ /// Notification code
+ ///
+
+ private function sendNotification(): void {
+ $this->getNotification()->send();
+ }
+
+ private function getNotification () : Notification {
+ $metadata = $this->getMetadata();
+
+ $notification = new Notification( $this->httpRequestFactory );
+ $notification->service = 'SaaS MediaWiki';
+ $notification->project = 'Nasqueron';
+ $notification->group = 'ops';
+ $notification->rawContent = $metadata;
+ $notification->type = 'create';
+ $notification->text = "A new wiki has been created by $metadata[user]";
+ $notification->link = $this->serverName;
+ }
+
+ private function getMetadata () : array {
+ return [
+ 'user' => $this->getRuntimeUser(),
+ 'database' => $this->DBname,
+ 'host' => $this->serverName,
+ ];
+ }
+
+ private function getRuntimeUser () : string {
+ return $_ENV['SUDO_USER'] ?? $_ENV['USER'];
+ }
+
+}
+
+$maintClass = AddWiki::class;
+require_once RUN_MAINTENANCE_IF_MAIN;
Index: Views/MainPage/en.txt
===================================================================
--- /dev/null
+++ Views/MainPage/en.txt
@@ -0,0 +1,12 @@
+This is the homepage of the $this->serverName wiki.
+
+This is a MediaWiki installation running on the Nasqueron MediaWiki SaaS.
+
+Consult the [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide] for information on using the wiki software.
+
+== Getting started ==
+* You can read the [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]
+on the MediaWiki site. Please note any configuration change is to do against our SaaS configuration repository.
+* If you need any assistance, you can <a href="https://devcentral.nasqueron.org/maniphest/task/edit/form/1/?project=MediaWiki_SaaS">fill a task on DevCentral</a>.
+* Edit this page to put the homepage, generally pointers to the main sections of the wiki.
+* Don't edit the wiki if you wish to import a full dump from another wiki installation before the import is done, to avoid to overwrite your changes.
Index: Views/MainPage/fr.txt
===================================================================
--- /dev/null
+++ Views/MainPage/fr.txt
@@ -0,0 +1,14 @@
+'''Bienvenue sur la page d'accueil de ce wiki.'''
+
+Cette page constitue l'accueil du wiki $this->serverName.
+
+Il s'agit d'une installation de MediaWiki propulsée par le SaaS MediaWiki de Nasqueron.
+
+Vous pouvez consulter [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide] pour découvrir comment utiliser ce logiciel.
+
+== Démarrer avec MediaWiki ==
+* Lisez la [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ] sur le site de MediaWiki.
+* Si vous souhaitez modifier la configuration, vous pouvez créer un commit sur le dépôt de configuration du SaaS.
+* Si vous avez besoin d'aide, <a href="https://devcentral.nasqueron.org/maniphest/task/edit/form/1/?project=MediaWiki_SaaS">préparez une tâche sur DevCentral</a> avec ce dont vous avez besoin.
+* Modifiez cette page pour la transformer en une page d'accueil, généralement des liens vers les sections du wiki.
+* N'éditez pas immédiatement ce wiki si vous désirez importer un dump en provenance d'une autre installation, pour éviter d'écraser vos changements.
Index: composer.json
===================================================================
--- /dev/null
+++ composer.json
@@ -0,0 +1,17 @@
+{
+ "name": "nasqueron/mediawiki-nasqueron-maintenance",
+ "type": "project",
+ "require-dev": {
+ "phan/phan": "^0.12.5",
+ "mediawiki/mediawiki-codesniffer": "^17.0",
+ "squizlabs/php_codesniffer": "^3.2"
+ },
+ "license": "GPL-2.0-or-later",
+ "authors": [
+ {
+ "name": "Sébastien Santoro",
+ "email": "dereckson@espace-win.org"
+ }
+ ],
+ "require": {}
+}
Index: extension.json
===================================================================
--- /dev/null
+++ extension.json
@@ -0,0 +1,18 @@
+{
+ "name": "NasqueronMaintenance",
+ "author": "Sébastien Santoro aka Dereckson",
+ "manifest_version": 1,
+ "url": "https://agora.nasqueron.org/MediaWiki_SaaS/NasqueronMaintenance",
+ "license-name": "GPL-2.0-or-later",
+ "type": "other",
+ "descriptionmsg": "nasqueronmaintenance-desc",
+ "MessagesDirs": {
+ "NasqueronMaintenance": [
+ "i18n"
+ ]
+ },
+ "AutoloadClasses": {
+ "Nasqueron\\SAAS\\MediaWiki\\Maintenance\\Notifications\\Notification": "Notifications/Notification.php",
+ "Nasqueron\\SAAS\\MediaWiki\\Maintenance\\Utilities\\AddWiki": "Utilities/addWiki.php"
+ },
+}
Index: i18n/en.json
===================================================================
--- /dev/null
+++ i18n/en.json
@@ -0,0 +1,9 @@
+{
+ "@metadata": {
+ "authors": [
+ "Dereckson"
+ ],
+ "message-documentation": "qqq"
+ },
+ "nasqueronmaintenance-desc": "Provides a collection of maintenance scripts useful on Nasqueron MediaWiki SaaS."
+}
Index: i18n/qqq.json
===================================================================
--- /dev/null
+++ i18n/qqq.json
@@ -0,0 +1,8 @@
+{
+ "@metadata": {
+ "authors": [
+ "Dereckson"
+ ]
+ },
+ "wikimediamaintenance-desc": "{{desc|name=NasqueronMaintenance|url=https://agora.nasqueron.org/MediaWiki_SaaS/NasqueronMaintenance}}"
+}

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 18, 22:17 (21 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2251348
Default Alt Text
D1562.id4037.diff (12 KB)

Event Timeline