Commit c9de42d9 authored by Troy Engel's avatar Troy Engel Committed by GitHub

Merge pull request #3 from mary-kate/master

Some modernization & code cleanup
parents d6c2dd56 e8636673
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
This diff is collapsed.
......@@ -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"
}
},
"MessagesDirs": {
"Preloader": [
"i18n"
]
},
"AutoloadClasses": {
"Preloader": "Preloader.class.php"
},
"Hooks": {
"EditFormPreloadText": "Preloader::mainHook"
},
"manifest_version": 1
}
{
"@metadata": {
"authors": [
"Meno25"
]
},
"preloader-desc": "يوفر نص بويلربلات مخصص لكل نطاق للصفحات الجديدة"
}
{
"@metadata": {
"authors": [
"Meno25"
]
},
"preloader-desc": "يوفر نص بويلربلات مخصص لكل نطاق للصفحات الجديدة"
}
{
"@metadata": {
"authors": [
"Xuacu"
]
},
"preloader-desc": "Proporciona un testu patrón personalizable por espaciu de nome pa les páxines nueves"
}
{
"@metadata": {
"authors": [
"EugeneZelenko"
]
},
"preloader-desc": "Дадае тыпавыя тэксты для новых старонак, якія магчыма настройваць па прасторах назваў"
}
{
"@metadata": {
"authors": [
"Fulup"
]
},
"preloader-desc": "Pourchas a ra prenestroù testenn personeladus evit pep esaouenn anv, evit ar pajennoù nevez"
}
{
"@metadata": {
"authors": [
"CERminator"
]
},
"preloader-desc": "Omogućuje unos po imenskom prostoru prilagodljivih šablona za nove stranice"
}
{
"@metadata": {
"authors": [
"Byrial"
]
},
"preloader-desc": "Giver en forhåndsbestemt starttekst for nye sider for hvert navnerum"
}
{
"@metadata": {
"authors": [
"Raimond Spekking"
]
},
"preloader-desc": "Ermöglicht das Hinzufügen pro Namensraum anpassbarer Vorlagen bei der Erstellung neuer Seiten"
}
{
"@metadata": {
"authors": [
"Michawiki"
]
},
"preloader-desc": "Zmóžnja pśiměrjujobne tekstowe elementy za nowe boki na mjenjowy rum"
}
{
"@metadata": {
"authors": [
"Omnipaedista"
]
},
"preloader-desc": "Παρέχει για τις καινούργιες σελίδες εξατομικευμένο πανομοιότυπο κείμενο κατά περιοχή ονομάτων"
}
{
"@metadata": {
"authors": [
"Rob Church"
]
},
"preloader-desc": "Provides customisable per-namespace boilerplate text for new pages"
}
{
"@metadata": {
"authors": [
"Yekrats"
]
},
"preloader-desc": "Provizas ŝanĝeblan norman tekston laŭ nomspaco por novaj paĝoj"
}
{
"@metadata": {
"authors": [
"Sanbec"
]
},
"preloader-desc": "Provee texto por defecto para las páginas nuevas configurable para cada espacio de nombres"
}
{
"@metadata": {
"authors": [
"Mobe"
]
},
"preloader-desc": "Tarjoaa muokattavan nimiavaruuskohtaisen pohjatekstin uusille sivuille."
}
{
"@metadata": {
"authors": [
"Grondin",
"Zetud"
]
},
"preloader-desc": "Fournit, pour les nouvelles pages, des fenêtres de texte personnalisables par nom d’espace"
}
{
"@metadata": {
"authors": [
"Toliño"
]
},
"preloader-desc": "Proporciona, para as páxinas novas, ventás de texto personalizable para os nomes dos espazos"
}
{
"@metadata": {
"authors": [
"Omnipaedista"
]
},
"preloader-desc": "Παρέχει συνηθισμένον πανομοιότυπον κείμενον κατὰ ὀνοματεῖον διὰ τὰς καινοὺς δέλτους"
}
{
"@metadata": {
"authors": [
"Als-Holder"
]
},
"preloader-desc": "Macht s megli pro Namensruum aapassbarei Vorlage zuezfiege bim Aalege vu neje Syte"
}
{
"@metadata": {
"authors": [
"Rotemliss"
]
},
"preloader-desc": "אפשרות לתבנית טקסט עבור דפים חדשים, שניתנת להתאמה לפי מרחב שם"
}
{
"@metadata": {
"authors": [
"Tagimata"
]
},
"preloader-desc": "Nagahatag sang gin-obra na daan kada-ngalanespasyo boilerplate teksto para sa mga bag-o nga pahina"
}
{
"@metadata": {
"authors": [
"Michawiki"
]
},
"preloader-desc": "Dodawa tekstowe elementy za nowe strony přiměrjomne na mjenowy rum"
}
{
"@metadata": {
"authors": [
"Tgr"
]
},
"preloader-desc": "Névterenként más-más rendszerüzenet az új oldalakhoz"
}
{
"@metadata": {
"authors": [
"McDutchie"
]
},
"preloader-desc": "Permitte predefinir un modello de texto pro nove paginas, un pro cata spatio de nomines"
}
{
"@metadata": {
"authors": [
"Bennylin"
]
},
"preloader-desc": "Menyediakan teks pembuka yang dapat dikustomisasi per ruang nama untuk halaman-halaman baru"
}
{
"@metadata": {
"authors": [
"Darth Kule"
]
},
"preloader-desc": "Fornisce un testo standard personalizzabile per ciascun namespace per le nuove pagine"
}
{
"@metadata": {
"authors": [
"Fryed-peach",
"Shirayuki"
]
},
"preloader-desc": "新しいページ用に名前空間ごとのカスタマイズ可能な雛形文章を提供する"
}
{
"@metadata": {
"authors": [
"아라"
]
},
"preloader-desc": "새 문서에 대해 사용자 정의 이름공간마다 상용구를 제공"
}
{
"@metadata": {
"authors": [
"Purodha"
]
},
"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."
}
{
"@metadata": {
"authors": [
"Robby"
]
},
"preloader-desc": "Erméiglecht et personabiliséierten Text fir nei Säiten pro Nummraum derbäizesetzen"
}
{
"@metadata": {
"authors": [
"Bjankuloski06"
]
},
"preloader-desc": "Овозможува кориснички-прилагодлив фиксен текст за нови страници"
}
{
"@metadata": {
"authors": [
"Kaustubh"
]
},
"preloader-desc": "नवीन पानांसाठी बदलता येण्याजोगी नामविश्व बॉइलरप्लेट देते"
}
{
"@metadata": {
"authors": [
"Anakmalaysia"
]
},
"preloader-desc": "Menyediakan teks plat dandang seruang nama yang boleh disuaikan untuk laman baru"
}
{
"@metadata": {
"authors": []
},
"preloader-desc": "Gir egendefinerbar forhåndslastet tekst for nye sider i de enkelte navnerommene"
}
{
"@metadata": {
"authors": [
"Slomox"
]
},
"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"
}
{
"@metadata": {
"authors": [
"Siebrand"
]
},
"preloader-desc": "Geeft de mogelijkheid aan te passen per naamruimte tekstblokken te maken voor nieuwe pagina's"
}
{
"@metadata": {
"authors": [
"Harald Khan",
"Njardarlogar"
]
},
"preloader-desc": "Gjev ein eigendefinerbar førehandslasta tekst for nye sider i dei enkelte namneromma"
}
{
"@metadata": {
"authors": [
"Cedric31"
]
},
"preloader-desc": "Provesís, per las paginas novèlas, de fenèstras de tèxte personalizablas per nom d’espaci"
}
{
"@metadata": {
"authors": [
"Sp5uhe"
]
},
"preloader-desc": "Zapewnia odrębny dla każdej przestrzeni nazw domyślny tekst nowej strony"
}
{
"@metadata": {
"authors": [
"Dragonòt"
]
},
"preloader-desc": "A dà test përsonalisà për-namespace për neuve pàgine"
}