diff --git a/Preloader b/Preloader new file mode 100644 index 0000000..0af8fbf --- /dev/null +++ b/Preloader @@ -0,0 +1,75 @@ +PRELOADER EXTENSION + + Version 1.1.1 + © 2006 Rob Church + +== Overview == + +1. Introduction +2. Requirements +3. Installation +4. Configuration +5. Feedback +6. Change Log + +== 1. Introduction == + +The Preloader extension allows the creation of boilerplate text which will +be inserted into the edit form when creating new pages. Different boilerplate +text can be specified for different namespaces. + +In addition, a new parser tag, is introduced, which is used to +denote sections which should not be preloaded, ever; useful for instructions +and advice on the boilerplate pages. This tag has no effect during a regular +parse operation. + +== 2. Requirements == + +The Preloader extension requires MediaWiki 1.7.0 or later. + +== 3. Installation == + +To install the Preloader extension, download all files from Subversion, and +place them into your extensions directory. + +Then edit your LocalSettings.php file and add the following line: + + require_once( 'extensions/Preloader.php' ); + +Installation can be verified through the Special:Version page on your wiki. + +== 4. Configuration == + +Configuration of the boilerplate sources is done via the $wgPreloaderSource +configuration variable, which takes the following format: + + $wgPreloaderSource[ ] = PAGE TITLE; + +For instance + + $wgPreloaderSource[ NS_MAIN ] = 'Template:Boilerplate'; + $wgPreloaderSource[ NS_HELP ] = 'Template:Boilerplate help'; + +dictates 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. + +== 5. Feedback == + +Please submit comments, suggestions and bug reports to . + +== 6. Change Log == + +17/12/2006 +Version 1.0 + * Initial release + +31/12/2006 +Version 1.1 + * Trim preloaded text + * Fix newlines in tags + +13/03/2008 +Version 1.1.1 + * Add description message for [[Special:Version]] \ No newline at end of file diff --git a/Preloader.i18n.php b/Preloader.i18n.php new file mode 100644 index 0000000..6c3d772 --- /dev/null +++ b/Preloader.i18n.php @@ -0,0 +1,377 @@ + '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', +); + diff --git a/Preloader.php b/Preloader.php new file mode 100644 index 0000000..abd322d --- /dev/null +++ b/Preloader.php @@ -0,0 +1,103 @@ + which is used to mark sections which + * shouldn't be preloaded, ever; has no effect on the rendering of pages + * + * @file + * @ingroup Extensions + * @author Rob Church + */ + +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', + 'version' => '1.1.1', + 'url' => 'https://www.mediawiki.org/wiki/Extension: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'; +$wgHooks['ParserFirstCallInit'][] = 'Preloader::setParserHook'; + +class Preloader { + + public static function setParserHook( $parser ) { + $parser->setHook( 'nopreload', array( __CLASS__, 'parserHook' ) ); + return true; + } + + /** 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; + } + + /** Hook function for the parser */ + public static function parserHook( $input, $args, &$parser ) { + $output = $parser->parse( $input, $parser->getTitle(), $parser->getOptions(), false, false ); + return $output->getText(); + } + + /** + * 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 ) { + return trim( preg_replace( '/.*<\/nopreload>/s', '', $text ) ); + } +}