Commit e8636673 authored by Jack Phoenix's avatar Jack Phoenix Committed by Sam

Some modernization & code cleanup

* Move the Preloader class into its own file + add $wgAutoloadClasses entry
* Coding style tweaks, as per MediaWiki's coding conventions
* Converted from PHP-based i18n to JSON i18n
* Version 1.3 with the appropriate changelog entries and whatnot
* Deprecated Preloader.php (but didn't fully remove it yet) in favor of extension.json -- MediaWiki 1.25 or newer is now required for this extension
* Added myself into authors
* Changed the Special:Version URL back to MediaWiki.org as it should be the canonical location for extension (and skin etc.) documentation; since this is an updated version of [[mw:Extension:Preloader]] it should be no problem to update that page to point to the correct repository etc.
* Tweak the README file to account for new MW requirements + extension loading method
* Fix $wgPreloaderSource so that it works again ( HT @legoktm )
parent d6c2dd56
Preloader Changelog
===================
## 2017-01-04 Version 1.3 - Jack Phoenix
* Code cleanup
* Support for JSON-based internationalization (i18n) files
* Support for extension registration (extension.json)
* MediaWiki 1.25 or newer is now required
## 2015-01-03 Version 1.2.2 - Troy Engel
* Add composer.json to support Composer (Pierre Rudloff)
* Submit composer package to Pkgist
......
<?php
class Preloader {
/** Hook function for the preloading */
public static function mainHook( &$text, &$title ) {
$src = self::preloadSource( $title->getNamespace() );
if ( $src ) {
$stx = self::sourceText( $src );
if ( $stx ) {
$text = $stx;
}
}
return true;
}
/**
* Determine what page should be used as the source of preloaded text
* for a given namespace and return the title (in text form)
*
* @param int $namespace Namespace to check for
* @return string|bool Name of the page to be preloaded or bool false
*/
static function preloadSource( $namespace ) {
global $wgPreloaderSource;
if ( isset( $wgPreloaderSource[$namespace] ) ) {
return $wgPreloaderSource[$namespace];
} else {
return false;
}
}
/**
* Grab the current text of a given page if it exists
*
* @param string $page Text form of the page title
* @return string|bool
*/
static function sourceText( $page ) {
$title = Title::newFromText( $page );
if ( $title && $title->exists() ) {
$revision = Revision::newFromTitle( $title );
return self::transform( $revision->getText() );
} else {
return false;
}
}
/**
* Remove sections from the text and trim whitespace
*
* @param $text
* @return string
*/
static function transform( $text ) {
$text = trim( preg_replace( '/<\/?includeonly>/s', '', $text ) );
return trim( preg_replace( '/<noinclude>.*<\/noinclude>/s', '', $text ) );
}
}
\ No newline at end of file
<?php
/**
* Internationalisation file for Preloader extension.
*
* @file
* @ingroup Extensions
*/
$messages = array();
/** English
* @author Rob Church
*/
$messages['en'] = array(
'preloader-desc' => 'Provides customisable per-namespace boilerplate text for new pages',
);
/** Message documentation (Message documentation)
* @author Purodha
* @author The Evil IP address
*/
$messages['qqq'] = array(
'preloader-desc' => '{{desc}}',
);
/** Arabic (العربية)
* @author Meno25
*/
$messages['ar'] = array(
'preloader-desc' => 'يوفر نص بويلربلات مخصص لكل نطاق للصفحات الجديدة',
);
/** Egyptian Spoken Arabic (مصرى)
* @author Meno25
*/
$messages['arz'] = array(
'preloader-desc' => 'يوفر نص بويلربلات مخصص لكل نطاق للصفحات الجديدة',
);
/** Asturian (asturianu)
* @author Xuacu
*/
$messages['ast'] = array(
'preloader-desc' => 'Proporciona un testu patrón personalizable por espaciu de nome pa les páxines nueves',
);
/** Belarusian (Taraškievica orthography) (беларуская (тарашкевіца)‎)
* @author EugeneZelenko
*/
$messages['be-tarask'] = array(
'preloader-desc' => 'Дадае тыпавыя тэксты для новых старонак, якія магчыма настройваць па прасторах назваў',
);
/** Breton (brezhoneg)
* @author Fulup
*/
$messages['br'] = array(
'preloader-desc' => 'Pourchas a ra prenestroù testenn personeladus evit pep esaouenn anv, evit ar pajennoù nevez',
);
/** Bosnian (bosanski)
* @author CERminator
*/
$messages['bs'] = array(
'preloader-desc' => 'Omogućuje unos po imenskom prostoru prilagodljivih šablona za nove stranice',
);
/** Danish (dansk)
* @author Byrial
*/
$messages['da'] = array(
'preloader-desc' => 'Giver en forhåndsbestemt starttekst for nye sider for hvert navnerum',
);
/** German (Deutsch)
* @author Raimond Spekking
*/
$messages['de'] = array(
'preloader-desc' => 'Ermöglicht das Hinzufügen pro Namensraum anpassbarer Vorlagen bei der Erstellung neuer Seiten',
);
/** Lower Sorbian (dolnoserbski)
* @author Michawiki
*/
$messages['dsb'] = array(
'preloader-desc' => 'Zmóžnja pśiměrjujobne tekstowe elementy za nowe boki na mjenjowy rum',
);
/** Greek (Ελληνικά)
* @author Omnipaedista
*/
$messages['el'] = array(
'preloader-desc' => 'Παρέχει για τις καινούργιες σελίδες εξατομικευμένο πανομοιότυπο κείμενο κατά περιοχή ονομάτων',
);
/** Esperanto (Esperanto)
* @author Yekrats
*/
$messages['eo'] = array(
'preloader-desc' => 'Provizas ŝanĝeblan norman tekston laŭ nomspaco por novaj paĝoj',
);
/** Spanish (español)
* @author Sanbec
*/
$messages['es'] = array(
'preloader-desc' => 'Provee texto por defecto para las páginas nuevas configurable para cada espacio de nombres',
);
/** Finnish (suomi)
* @author Mobe
*/
$messages['fi'] = array(
'preloader-desc' => 'Tarjoaa muokattavan nimiavaruuskohtaisen pohjatekstin uusille sivuille.',
);
/** French (français)
* @author Grondin
* @author Zetud
*/
$messages['fr'] = array(
'preloader-desc' => 'Fournit, pour les nouvelles pages, des fenêtres de texte personnalisables par nom d’espace',
);
/** Galician (galego)
* @author Toliño
*/
$messages['gl'] = array(
'preloader-desc' => 'Proporciona, para as páxinas novas, ventás de texto personalizable para os nomes dos espazos',
);
/** Ancient Greek (Ἀρχαία ἑλληνικὴ)
* @author Omnipaedista
*/
$messages['grc'] = array(
'preloader-desc' => 'Παρέχει συνηθισμένον πανομοιότυπον κείμενον κατὰ ὀνοματεῖον διὰ τὰς καινοὺς δέλτους',
);
/** Swiss German (Alemannisch)
* @author Als-Holder
*/
$messages['gsw'] = array(
'preloader-desc' => 'Macht s megli pro Namensruum aapassbarei Vorlage zuezfiege bim Aalege vu neje Syte',
);
/** Hebrew (עברית)
* @author Rotemliss
*/
$messages['he'] = array(
'preloader-desc' => 'אפשרות לתבנית טקסט עבור דפים חדשים, שניתנת להתאמה לפי מרחב שם',
);
/** Hiligaynon (Ilonggo)
* @author Tagimata
*/
$messages['hil'] = array(
'preloader-desc' => 'Nagahatag sang gin-obra na daan kada-ngalanespasyo boilerplate teksto para sa mga bag-o nga pahina',
);
/** Upper Sorbian (hornjoserbsce)
* @author Michawiki
*/
$messages['hsb'] = array(
'preloader-desc' => 'Dodawa tekstowe elementy za nowe strony přiměrjomne na mjenowy rum',
);
/** Hungarian (magyar)
* @author Tgr
*/
$messages['hu'] = array(
'preloader-desc' => 'Névterenként más-más rendszerüzenet az új oldalakhoz',
);
/** Interlingua (interlingua)
* @author McDutchie
*/
$messages['ia'] = array(
'preloader-desc' => 'Permitte predefinir un modello de texto pro nove paginas, un pro cata spatio de nomines',
);
/** Indonesian (Bahasa Indonesia)
* @author Bennylin
*/
$messages['id'] = array(
'preloader-desc' => 'Menyediakan teks pembuka yang dapat dikustomisasi per ruang nama untuk halaman-halaman baru',
);
/** Italian (italiano)
* @author Darth Kule
*/
$messages['it'] = array(
'preloader-desc' => 'Fornisce un testo standard personalizzabile per ciascun namespace per le nuove pagine',
);
/** Japanese (日本語)
* @author Fryed-peach
* @author Shirayuki
*/
$messages['ja'] = array(
'preloader-desc' => '新しいページ用に名前空間ごとのカスタマイズ可能な雛形文章を提供する',
);
/** Korean (한국어)
* @author 아라
*/
$messages['ko'] = array(
'preloader-desc' => '새 문서에 대해 사용자 정의 이름공간마다 상용구를 제공',
);
/** Colognian (Ripoarisch)
* @author Purodha
*/
$messages['ksh'] = array(
'preloader-desc' => 'Määt et müjjelesch, för jedes Appachtemang ene Täx förzejävve, dä eets ens ne de neu Sigge erin küt.',
);
/** Luxembourgish (Lëtzebuergesch)
* @author Robby
*/
$messages['lb'] = array(
'preloader-desc' => 'Erméiglecht et personabiliséierten Text fir nei Säiten pro Nummraum derbäizesetzen',
);
/** Macedonian (македонски)
* @author Bjankuloski06
*/
$messages['mk'] = array(
'preloader-desc' => 'Овозможува кориснички-прилагодлив фиксен текст за нови страници',
);
/** Marathi (मराठी)
* @author Kaustubh
*/
$messages['mr'] = array(
'preloader-desc' => 'नवीन पानांसाठी बदलता येण्याजोगी नामविश्व बॉइलरप्लेट देते',
);
/** Malay (Bahasa Melayu)
* @author Anakmalaysia
*/
$messages['ms'] = array(
'preloader-desc' => 'Menyediakan teks plat dandang seruang nama yang boleh disuaikan untuk laman baru',
);
/** Norwegian Bokmål (norsk (bokmål)‎) */
$messages['nb'] = array(
'preloader-desc' => 'Gir egendefinerbar forhåndslastet tekst for nye sider i de enkelte navnerommene',
);
/** Low German (Plattdüütsch)
* @author Slomox
*/
$messages['nds'] = array(
'preloader-desc' => 'Verlöövt dat Tofögen vun ännerbore Vörlagen, de för elk Naamruum bi’t Opstellen vun ne’e Sieden wiest warrt',
);
/** Dutch (Nederlands)
* @author Siebrand
*/
$messages['nl'] = array(
'preloader-desc' => "Geeft de mogelijkheid aan te passen per naamruimte tekstblokken te maken voor nieuwe pagina's",
);
/** Norwegian Nynorsk (norsk (nynorsk)‎)
* @author Harald Khan
* @author Njardarlogar
*/
$messages['nn'] = array(
'preloader-desc' => 'Gjev ein eigendefinerbar førehandslasta tekst for nye sider i dei enkelte namneromma',
);
/** Occitan (occitan)
* @author Cedric31
*/
$messages['oc'] = array(
'preloader-desc' => 'Provesís, per las paginas novèlas, de fenèstras de tèxte personalizablas per nom d’espaci',
);
/** Polish (polski)
* @author Sp5uhe
*/
$messages['pl'] = array(
'preloader-desc' => 'Zapewnia odrębny dla każdej przestrzeni nazw domyślny tekst nowej strony',
);
/** Piedmontese (Piemontèis)
* @author Dragonòt
*/
$messages['pms'] = array(
'preloader-desc' => 'A dà test përsonalisà për-namespace për neuve pàgine',
);
/** Portuguese (português)
* @author Hamilton Abreu
* @author Waldir
*/
$messages['pt'] = array(
'preloader-desc' => 'Fornece textos-modelo para novas páginas, personalizáveis por espaço nominal',
);
/** Brazilian Portuguese (português do Brasil)
* @author Eduardo.mps
*/
$messages['pt-br'] = array(
'preloader-desc' => 'Fornece textos-modelo para novas páginas, personalizáveis por domínio',
);
/** tarandíne (tarandíne)
* @author Joetaras
*/
$messages['roa-tara'] = array(
'preloader-desc' => 'Avène ausete pe de le pre-namespace ca sonde personalizzabbele pe le pàggene nueve',
);
/** Russian (русский)
* @author Александр Сигачёв
*/
$messages['ru'] = array(
'preloader-desc' => 'Предоставляет настраиваемые по пространствам имён типовые тексты для новых страниц',
);
/** Slovak (slovenčina)
* @author Helix84
*/
$messages['sk'] = array(
'preloader-desc' => 'Poskytuje prispôsobiteľný šablónový text pre nové stránky na báze menných priestorov',
);
/** Seeltersk (Seeltersk)
* @author Pyt
*/
$messages['stq'] = array(
'preloader-desc' => 'Moaket dät Bietouföigjen muugelk fon pro Noomensruum anpaasboare Foarloagen bie dät Moakjen fon näie Sieden',
);
/** Swedish (svenska)
* @author M.M.S.
*/
$messages['sv'] = array(
'preloader-desc' => 'Ger en egendefinierad förhandsladdad text för nya sidor',
);
/** Telugu (తెలుగు)
* @author Veeven
*/
$messages['te'] = array(
'preloader-desc' => 'కొత్త పేజీలకి పేరుబరివారీగా మార్చుకొనగలిగే మూస పాఠ్యాన్ని అందిస్తుంది',
);
/** Tagalog (Tagalog)
* @author AnakngAraw
*/
$messages['tl'] = array(
'preloader-desc' => 'Nagbibigay na maipapasadyang pang-bawat espasyo ng pangalang teksto ng pakuluang-bakal para sa bagong mga pahina',
);
/** Turkish (Türkçe)
* @author Vito Genovese
*/
$messages['tr'] = array(
'preloader-desc' => 'Yeni sayfalar için isim alanına özel kişiselleştirilebilir hazır metinler sunar',
);
/** Ukrainian (українська)
* @author Alex Khimich
*/
$messages['uk'] = array(
'preloader-desc' => 'Забезпечення настроюваних за імен по стандартним типовим текстам для нової сторінки',
);
/** Vietnamese (Tiếng Việt)
* @author Vinhtantran
*/
$messages['vi'] = array(
'preloader-desc' => 'Cung cấp những mẫu văn bản viết sẵn theo từng không gian tên khi tạo trang mới',
);
......@@ -11,81 +11,15 @@
* @author Rob Church <[email protected]>
*/
if( !defined( 'MEDIAWIKI' ) ) {
echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
exit( 1 );
}
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'Preloader',
'author' => 'Rob Church, Troy Engel',
'version' => '1.2.2',
'url' => 'https://github.com/troyengel/Preloader',
'descriptionmsg' => 'preloader-desc',
);
$wgExtensionMessagesFiles['Preloader'] = dirname(__FILE__) . '/Preloader.i18n.php';
/**
* Sources of preloaded content for each namespace
*/
$wgPreloaderSource[ NS_MAIN ] = 'Template:Preload';
$wgHooks['EditFormPreloadText'][] = 'Preloader::mainHook';
class Preloader {
/** Hook function for the preloading */
public static function mainHook( &$text, &$title ) {
$src = self::preloadSource( $title->getNamespace() );
if( $src ) {
$stx = self::sourceText( $src );
if( $stx )
$text = $stx;
}
return true;
}
/**
* Determine what page should be used as the source of preloaded text
* for a given namespace and return the title (in text form)
*
* @param $namespace Namespace to check for
* @return mixed
*/
static function preloadSource( $namespace ) {
global $wgPreloaderSource;
if( isset( $wgPreloaderSource[ $namespace ] ) ) {
return $wgPreloaderSource[ $namespace ];
} else {
return false;
}
}
/**
* Grab the current text of a given page if it exists
*
* @param $page Text form of the page title
* @return mixed
*/
static function sourceText( $page ) {
$title = Title::newFromText( $page );
if( $title && $title->exists() ) {
$revision = Revision::newFromTitle( $title );
return self::transform( $revision->getText() );
} else {
return false;
}
}
/**
* Remove sections from the text and trim whitespace
*
* @param $text
* @return string
*/
static function transform( $text ) {
$text = trim( preg_replace( '/<\/?includeonly>/s', '', $text ) );
return trim( preg_replace( '/<noinclude>.*<\/noinclude>/s', '', $text ) );
}
}
if ( function_exists( 'wfLoadExtension' ) ) {
wfLoadExtension( 'Preloader' );
// Keep i18n globals so mergeMessageFileList.php doesn't break
$wgMessagesDirs['Preloader'] = __DIR__ . '/i18n';
wfWarn(
'Deprecated PHP entry point used for Preloader extension. Please use wfLoadExtension instead, ' .
'see https://www.mediawiki.org/wiki/Extension_registration for more details.'
);
return true;
} else {
die( 'This version of the Preloader extension requires MediaWiki 1.25+' );
}
\ No newline at end of file
Preloader MediaWiki Extension
=============================
Fork of http://www.mediawiki.org/wiki/Extension:Preloader
See http://www.mediawiki.org/wiki/Extension:Preloader
## Overview
......@@ -20,11 +20,11 @@ This extension supports the standard `<includeonly>` and `<noinclude>` tags in t
## 2. Requirements
The Preloader extension requires MediaWiki 1.7.0 or later.
The Preloader extension requires MediaWiki 1.25.0 or later.
## 3. Installation
Git - clone the Github repository into your extensions subdirectory:
Git - clone the GitHub repository into your extensions subdirectory:
```
cd /path/to/wiki/extensions
......@@ -38,7 +38,7 @@ Composer - the package is available via Composer / Packagist:
Then edit your `LocalSettings.php` file and add the following line:
```
require_once "$IP/extensions/Preloader/Preloader.php";
wfLoadExtension( 'Preloader' );
```
Installation can be verified through the **Special:Version** page on your wiki.
......@@ -48,14 +48,14 @@ Installation can be verified through the **Special:Version** page on your wiki.
Configuration of the boilerplate sources is done via the `$wgPreloaderSource` configuration variable, which takes the following format:
```
$wgPreloaderSource[ <namespace index> ] = PAGE TITLE;
$wgPreloaderSource[<namespace index>] = PAGE TITLE;
```
For instance:
```
$wgPreloaderSource[ NS_MAIN ] = 'Template:Boilerplate';
$wgPreloaderSource[ NS_HELP ] = 'Template:Boilerplate help';
$wgPreloaderSource[NS_MAIN] = 'Template:Boilerplate';
$wgPreloaderSource[NS_HELP] = 'Template:Boilerplate help';
```
...indicates that the boilerplate text for pages in the main namespace should be loaded from **Template:Boilerplate**, while pages in the Help namespace will be preloaded from **Template:Boilerplate_help**. Other namespaces have no boilerplate configured.
......
{
"name": "Preloader",
"version": "1.3",
"author": [
"Rob Church",
"Troy Engel",
"Jack Phoenix"
],
"license-name": "MIT",
"url": "https://www.mediawiki.org/wiki/Extension:Preloader",
"descriptionmsg": "preloader-desc",
"type": "parserhook",
"config": {
"PreloaderSource": {
"0": "Template:Preload",
"_merge_strategy": "array_plus"
}
},