r47527 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47526‎ | r47527 | r47528 >
Date:01:07, 20 February 2009
Author:tomasz
Status:ok
Tags:
Comment:
adding option to generate just one template and choice of disk write or stdout
Modified paths:
  • /trunk/extensions/CentralNotice/rebuildTemplates.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/rebuildTemplates.php
@@ -9,17 +9,21 @@
1010 if ( isset( $options['help'] ) ) {
1111 echo "Rebuilds templates for all notices in DB.\n";
1212 echo "Usage:\n";
13 - echo " php extensions/CentralNotice/rebuildTemplates\n";
 13+ echo " php extensions/CentralNotice/rebuildTemplates [-o|Output to disk] [-n test/en|Output just a single notice]\n";
1414 } else {
1515 echo "Rebuilding templates ...\n";
1616
1717 // Hack for parser to avoid barfing from no $wgTitle
1818 $wgTitle = Title::newFromText( wfMsg( 'mainpage' ) );
1919
20 - $projects = $wgNoticeProjects;
21 - $langs = array_keys( Language::getLanguageNames() );
22 - // $langs = array( 'en' );
23 -
 20+ if ( isset( $options['n'] ) ) {
 21+ $notice = explode( "/", $args[0] );
 22+ $projects = array( $notice[0] );
 23+ $langs = array( $notice[1] );
 24+ } else {
 25+ $projects = $wgNoticeProjects;
 26+ $langs = array_keys( Language::getLanguageNames() );
 27+ }
2428 foreach ( $projects as $project ) {
2529 foreach ( $langs as $lang ) {
2630 $key = "$project/$lang";
@@ -28,16 +32,20 @@
2933 $builder = new SpecialNoticeText();
3034 $js = $builder->getJsOutput( $key );
3135
32 - $outputDir = "$wgNoticeCentralDirectory/$project/$lang";
33 - if ( wfMkDirParents( $outputDir ) ) {
34 - $outputFile = "$outputDir/centralnotice.js";
35 - $ok = file_put_contents( $outputFile, $js );
36 - if ( !$ok ) {
37 - echo "FAILED to write $outputFile!\n";
38 - }
39 - } else {
40 - echo "FAILED to create $outputDir!\n";
41 - }
 36+ if ( isset( $options['o'] ) ) {
 37+ $outputDir = "$wgNoticeCentralDirectory/$project/$lang";
 38+ if ( wfMkDirParents( $outputDir ) ) {
 39+ $outputFile = "$outputDir/centralnotice.js";
 40+ $ok = file_put_contents( $outputFile, $js );
 41+ if ( !$ok ) {
 42+ echo "FAILED to write $outputFile!\n";
 43+ }
 44+ } else {
 45+ echo "FAILED to create $outputDir!\n";
 46+ }
 47+ } else {
 48+ echo $js;
 49+ }
4250 }
4351 }
4452 }

Status & tagging log