r74905 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74904‎ | r74905 | r74906 >
Date:18:13, 17 October 2010
Author:ashley
Status:deferred
Tags:
Comment:
Semantic MediaWiki: coding style tweaks to maintenance scripts
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/maintenance/SMW_conceptCache.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/maintenance/SMW_dumpRDF.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/maintenance/SMW_refreshData.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/maintenance/SMW_setup.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/maintenance/SMW_refreshData.php
@@ -38,8 +38,8 @@
3939 $optionsWithArgs = array( 'd', 's', 'e', 'b', 'server', 'page' ); // -d <delay>, -s <startid>, -e <endid>, -b <backend>
4040
4141 require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
42 - ? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc"
43 - : dirname( __FILE__ ) . '/../../../maintenance/commandLine.inc' );
 42+ ? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc"
 43+ : dirname( __FILE__ ) . '/../../../maintenance/commandLine.inc' );
4444
4545 global $smwgEnableUpdateJobs, $wgServer;
4646 $smwgEnableUpdateJobs = false; // do not fork additional update jobs while running this script
@@ -89,7 +89,7 @@
9090 if ( array_key_exists( 't', $options ) ) {
9191 $filterarray[] = SMW_NS_TYPE;
9292 }
93 -$filter = count( $filterarray ) > 0 ? $filterarray:false;
 93+$filter = count( $filterarray ) > 0 ? $filterarray : false;
9494
9595 if ( array_key_exists( 'f', $options ) ) {
9696 print "\n Deleting all stored data completely and rebuilding it again later!\n Semantic data in the wiki might be incomplete for some time while this operation runs.\n\n NOTE: It is usually necessary to run this script ONE MORE TIME after this operation,\n since some properties' types are not stored yet in the first run.\n The first run can normally use the parameter -p to refresh only properties.\n\n";
@@ -97,28 +97,28 @@
9898 print " WARNING: -s or -e are used, so some pages will not be refreshed at all!\n Data for those pages will only be available again when they have been\n refreshed as well!\n\n";
9999 }
100100
101 - print "Abort with control-c in the next five seconds ... ";
 101+ print 'Abort with control-c in the next five seconds ... ';
102102
103103 // TODO
104104 // Remove the following section and replace it with a simple
105 - // wfCountDown as soon as we switch to MediaWiki 1.16.
 105+ // wfCountDown as soon as we switch to MediaWiki 1.16.
106106 // Currently, wfCountDown is only supported from
107107 // revision 51650 (Jun 9 2009) onward.
108108 $n = 6;
109 - if ( function_exists( "wfCountDown" ) ) {
 109+ if ( function_exists( 'wfCountDown' ) ) {
110110 wfCountDown( $n );
111111 } else {
112 - for ( $i = $n; $i >= 0; $i-- ) {
113 - if ( $i != $n ) {
114 - echo str_repeat( "\x08", strlen( $i + 1 ) );
115 - }
116 - echo $i;
117 - flush();
118 - if ( $i ) {
119 - sleep( 1 );
120 - }
121 - }
122 - echo "\n";
 112+ for ( $i = $n; $i >= 0; $i-- ) {
 113+ if ( $i != $n ) {
 114+ echo str_repeat( "\x08", strlen( $i + 1 ) );
 115+ }
 116+ echo $i;
 117+ flush();
 118+ if ( $i ) {
 119+ sleep( 1 );
 120+ }
 121+ }
 122+ echo "\n";
123123 }
124124 // Remove up to here and just uncomment the following line:
125125 // wfCountDown( 6 );
@@ -143,7 +143,7 @@
144144 " 1000) were refreshed, please abort with CTRL-C and resume this script\n" .
145145 " at the last processed page id using the parameter -s (use -v to display\n" .
146146 " page ids during refresh). Continue this until all pages were refreshed.\n---\n";
147 - print "Processing all IDs from $start to " . ( $end ? "$end":"last ID" ) . " ...\n";
 147+ print "Processing all IDs from $start to " . ( $end ? "$end" : 'last ID' ) . " ...\n";
148148
149149 $id = $start;
150150 while ( ( ( !$end ) || ( $id <= $end ) ) && ( $id > 0 ) ) {
Index: trunk/extensions/SemanticMediaWiki/maintenance/SMW_conceptCache.php
@@ -15,11 +15,11 @@
1616 $optionsWithArgs = array( 'concept', 'old', 's', 'e' );
1717
1818 require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
19 - ? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/commandLine.inc'
20 - : dirname( __FILE__ ) . '/../../../maintenance/commandLine.inc' );
 19+ ? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/commandLine.inc'
 20+ : dirname( __FILE__ ) . '/../../../maintenance/commandLine.inc' );
2121
22 -$output_level = array_key_exists( 'quiet', $options ) ? 0:
23 - ( array_key_exists( 'verbose', $options ) ? 2 : 1 );
 22+$output_level = array_key_exists( 'quiet', $options ) ? 0 :
 23+ ( array_key_exists( 'verbose', $options ) ? 2 : 1 );
2424
2525 if ( array_key_exists( 'help', $options ) ) {
2626 $action = 'help';
@@ -37,23 +37,23 @@
3838 if ( outputMessage( print "Waiting for $delay seconds ... " ) ) {
3939 // TODO
4040 // Remove the following section and replace it with a simple
41 - // wfCountDown as soon as we switch to MediaWiki 1.16.
 41+ // wfCountDown as soon as we switch to MediaWiki 1.16.
4242 // Currently, wfCountDown is only supported from
4343 // revision 51650 (Jun 9 2009) onward.
4444 if ( function_exists( 'wfCountDown' ) ) {
4545 wfCountDown( $delay );
4646 } else {
47 - for ( $i = $delay; $i >= 0; $i-- ) {
48 - if ( $i != $delay ) {
49 - echo str_repeat( "\x08", strlen( $i + 1 ) );
50 - }
51 - echo $i;
52 - flush();
53 - if ( $i ) {
54 - sleep( 1 );
55 - }
56 - }
57 - echo "\n";
 47+ for ( $i = $delay; $i >= 0; $i-- ) {
 48+ if ( $i != $delay ) {
 49+ echo str_repeat( "\x08", strlen( $i + 1 ) );
 50+ }
 51+ echo $i;
 52+ flush();
 53+ if ( $i ) {
 54+ sleep( 1 );
 55+ }
 56+ }
 57+ echo "\n";
5858 }
5959 // Remove up to here and just uncomment the following line:
6060 // wfCountDown( $delay );
@@ -109,8 +109,9 @@
110110 }
111111
112112 global $smwgIP;
113 -if ( ! isset( $smwgIP ) )
114 - $smwgIP = dirname( __FILE__ ) . '/../';
 113+if ( !isset( $smwgIP ) ) {
 114+ $smwgIP = dirname( __FILE__ ) . '/../';
 115+}
115116
116117 require_once( $smwgIP . 'includes/SMW_GlobalFunctions.php' );
117118
@@ -127,8 +128,8 @@
128129 $select_old = isset( $options['old'] ) ? intval( $options['old'] ) : false;
129130
130131 if ( isset( $options['concept'] ) ) { // single concept mode
131 - // $concept = SMWDataValueFactory::newTypeIDValue('_wpg');
132 - // $concept->setValues('African_countries',SMW_NS_CONCEPT);
 132+ // $concept = SMWDataValueFactory::newTypeIDValue( '_wpg' );
 133+ // $concept->setValues( 'African_countries', SMW_NS_CONCEPT );
133134 global $wgContLang;
134135 $concept = Title::newFromText( $wgContLang->getNsText( SMW_NS_CONCEPT ) . ':' . $options['concept'] );
135136 if ( $concept !== null ) {
@@ -140,7 +141,7 @@
141142 } else {
142143 $start = 0;
143144 }
144 - $end = $db->selectField( 'page', 'max(page_id)', false, 'SMW_refreshData' );
 145+ $end = $db->selectField( 'page', 'MAX(page_id)', false, 'SMW_refreshData' );
145146 if ( array_key_exists( 'e', $options ) ) {
146147 $end = min( intval( $options['e'] ), $end );
147148 }
@@ -148,7 +149,9 @@
149150
150151 for ( $id = $start; $id <= $end; $id++ ) {
151152 $title = Title::newFromID( $id );
152 - if ( ( $title === null ) || ( $title->getNamespace() != SMW_NS_CONCEPT ) ) continue;
 153+ if ( ( $title === null ) || ( $title->getNamespace() != SMW_NS_CONCEPT ) ) {
 154+ continue;
 155+ }
153156 $num_lines += doAction( $title, $num_lines );
154157 }
155158 }
@@ -168,15 +171,15 @@
169172 $skip = 'page not cachable (no concept description, maybe a redirect)';
170173 } elseif ( ( $select_update ) && ( $status['status'] != 'full' ) ) {
171174 $skip = 'page not cached yet';
172 - } elseif ( ( $select_old ) && ( $status['status'] == 'full' ) && ( $status['date'] > ( strtotime( "now" ) - $select_old * 60 ) ) ) {
 175+ } elseif ( ( $select_old ) && ( $status['status'] == 'full' ) && ( $status['date'] > ( strtotime( 'now' ) - $select_old * 60 ) ) ) {
173176 $skip = 'cache is not old yet';
174177 } elseif ( ( $select_hard ) && ( $smwgQMaxSize >= $status['size'] ) &&
175 - ( $smwgQMaxDepth >= $status['depth'] &&
176 - ( ( ~( ~( $status['features'] + 0 ) | $smwgQFeatures ) ) == 0 ) ) ) {
 178+ ( $smwgQMaxDepth >= $status['depth'] &&
 179+ ( ( ~( ~( $status['features'] + 0 ) | $smwgQFeatures ) ) == 0 ) ) ) {
177180 $skip = 'concept is not "hard" according to wiki settings';
178181 }
179182 if ( $skip ) {
180 - $pref = ( $numlines !== false ) ? "($numlines) ":'';
 183+ $pref = ( $numlines !== false ) ? "($numlines) " : '';
181184 return ( outputMessage( $pref . 'Skipping concept "' . $title->getPrefixedText() . "\": $skip\n", 2 ) ) ? 1 : 0;
182185 }
183186 if ( $numlines !== false ) {
@@ -196,17 +199,17 @@
197200 if ( $status['status'] == 'no' ) {
198201 outputMessage( "Concept not known or redirect.\n" );
199202 } elseif ( $status['status'] == 'full' ) {
200 - outputMessage( 'Cache created at ' . date( "Y-m-d H:i:s", $status['date'] ) . ' (' . floor( ( strtotime( "now" ) - $status['date'] ) / 60 ) . " minutes old), " . $status['count'] . " elements in cache\n" );
 203+ outputMessage( 'Cache created at ' . date( 'Y-m-d H:i:s', $status['date'] ) . ' (' . floor( ( strtotime( 'now' ) - $status['date'] ) / 60 ) . ' minutes old), ' . $status['count'] . " elements in cache\n" );
201204 } else {
202205 outputMessage( "Not cached.\n" );
203206 }
204207 break;
205208 }
206 -
 209+
207210 if ( count( $errors ) > 0 ) {
208211 outputMessage( ' ' . implode( $errors, "\n " ) . "\n" );
209212 }
210 -
 213+
211214 return 1;
212215 }
213216
Index: trunk/extensions/SemanticMediaWiki/maintenance/SMW_setup.php
@@ -43,8 +43,8 @@
4444 $optionsWithArgs = array( 'b', 'user', 'password' );
4545
4646 require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
47 - ? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc"
48 - : dirname( __FILE__ ) . '/../../../maintenance/commandLine.inc' );
 47+ ? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc"
 48+ : dirname( __FILE__ ) . '/../../../maintenance/commandLine.inc' );
4949
5050 global $smwgDefaultStore;
5151
@@ -72,12 +72,13 @@
7373
7474
7575 global $smwgIP;
76 -if ( ! isset( $smwgIP ) )
77 - $smwgIP = dirname( __FILE__ ) . '/../';
 76+if ( !isset( $smwgIP ) ) {
 77+ $smwgIP = dirname( __FILE__ ) . '/../';
 78+}
7879
7980 require_once( $smwgIP . 'includes/SMW_GlobalFunctions.php' );
8081
81 -if ( array_key_exists( 'delete', $options ) ) {
 82+if ( array_key_exists( 'delete', $options ) ) {
8283 print "\n Deleting all stored data for $smwgDefaultStore completely!\n \n\n";
8384 if ( $alternativestore ) {
8485 print " This store is currently not used by SMW. Deleting it\n should not cause problems in the wiki.\n\n";
@@ -91,23 +92,23 @@
9293
9394 // TODO
9495 // Remove the following section and replace it with a simple
95 - // wfCountDown as soon as we switch to MediaWiki 1.16.
 96+ // wfCountDown as soon as we switch to MediaWiki 1.16.
9697 // Currently, wfCountDown is only supported from
9798 // revision 51650 (Jun 9 2009) onward.
98 - if ( function_exists( "wfCountDown" ) ) {
 99+ if ( function_exists( 'wfCountDown' ) ) {
99100 wfCountDown( $delay );
100101 } else {
101 - for ( $i = $delay; $i >= 0; $i-- ) {
102 - if ( $i != $delay ) {
103 - echo str_repeat( "\x08", strlen( $i + 1 ) );
104 - }
105 - echo $i;
106 - flush();
107 - if ( $i ) {
108 - sleep( 1 );
109 - }
110 - }
111 - echo "\n";
 102+ for ( $i = $delay; $i >= 0; $i-- ) {
 103+ if ( $i != $delay ) {
 104+ echo str_repeat( "\x08", strlen( $i + 1 ) );
 105+ }
 106+ echo $i;
 107+ flush();
 108+ if ( $i ) {
 109+ sleep( 1 );
 110+ }
 111+ }
 112+ echo "\n";
112113 }
113114 // Remove up to here and just uncomment the following line:
114115 // wfCountDown( $delay );
@@ -125,5 +126,3 @@
126127 }
127128
128129 print "\n\nDone.\n";
129 -
130 -
Index: trunk/extensions/SemanticMediaWiki/maintenance/SMW_dumpRDF.php
@@ -1,5 +1,4 @@
22 <?php
3 -
43 /**
54 * Usage:
65 * php SMW_dumpRDF.php [options...]
@@ -8,7 +7,7 @@
98 * then the MW_INSTALL_PATH environment variable must be set.
109 * See README in the maintenance directory.
1110 *
12 - * -o <filename> output file, stdout is used if omitted;
 11+ * -o <filename> output file, stdout is used if omitted;
1312 * file output is generally better and strongly recommended for large wikis
1413 * --categories do only categories
1514 * --concepts do only concepts
@@ -31,8 +30,8 @@
3231 $optionsWithArgs = array( 'o', 'd', 'e', 'server' );
3332
3433 require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
35 - ? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc"
36 - : dirname( __FILE__ ) . '/../../../maintenance/commandLine.inc' );
 34+ ? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc"
 35+ : dirname( __FILE__ ) . '/../../../maintenance/commandLine.inc' );
3736 global $smwgIP, $wgServer;
3837 require_once( "$smwgIP/specials/Export/SMW_SpecialOWLExport.php" );
3938
@@ -53,17 +52,17 @@
5453 }
5554
5655
57 -if ( array_key_exists( 'categories' , $options ) ) {
 56+if ( array_key_exists( 'categories', $options ) ) {
5857 $export_ns = NS_CATEGORY;
59 -} elseif ( array_key_exists( 'concepts' , $options ) ) {
 58+} elseif ( array_key_exists( 'concepts', $options ) ) {
6059 $export_ns = SMW_NS_CONCEPT;
61 -} elseif ( array_key_exists( 'classes' , $options ) ) {
 60+} elseif ( array_key_exists( 'classes', $options ) ) {
6261 $export_ns = array( NS_CATEGORY, SMW_NS_CONCEPT );
63 -} elseif ( array_key_exists( 'properties' , $options ) ) {
 62+} elseif ( array_key_exists( 'properties', $options ) ) {
6463 $export_ns = SMW_NS_PROPERTY;
65 -} elseif ( array_key_exists( 'types' , $options ) ) {
 64+} elseif ( array_key_exists( 'types', $options ) ) {
6665 $export_ns = SMW_NS_TYPE;
67 -} elseif ( array_key_exists( 'individuals' , $options ) ) {
 66+} elseif ( array_key_exists( 'individuals', $options ) ) {
6867 $export_ns = - 1;
6968 } else {
7069 $export_ns = false;

Status & tagging log