r86101 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86100‎ | r86101 | r86102 >
Date:23:35, 14 April 2011
Author:reedy
Status:deferred
Tags:
Comment:
Strict, while to foreach

Unused globals
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_AutoEditAjaxHandler.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_AutocompleteAPI.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_FormClasses.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_FormEditPage.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_FormEditTab.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_Utils.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_CreateForm.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_FormStart.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_RunQuery.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_UploadWindow.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_UploadWindow2.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_FormStart.php
@@ -24,7 +24,7 @@
2525 }
2626
2727 function execute( $query ) {
28 - global $wgOut, $wgRequest, $sfgScriptPath;
 28+ global $wgOut, $wgRequest;
2929
3030 $this->setHeaders();
3131
@@ -42,7 +42,7 @@
4343 // redirect to 'FormEdit' for this target page.
4444 if ( isset( $queryparts[1] ) ) {
4545 $target_name = $queryparts[1];
46 - self::doRedirect( $form_name, $target_name, $params );
 46+ $this->doRedirect( $form_name, $target_name, $params );
4747 }
4848
4949 // Get namespace from the URL, if it's there.
@@ -83,7 +83,7 @@
8484 $wgOut->addHTML( htmlspecialchars( wfMsg( 'sf_formstart_badtitle', $page_name ) ) );
8585 return;
8686 } else {
87 - self::doRedirect( $form_name, $page_name, $params );
 87+ $this->doRedirect( $form_name, $page_name, $params );
8888 return;
8989 }
9090 }
Index: trunk/extensions/SemanticForms/specials/SF_CreateForm.php
@@ -45,7 +45,7 @@
4646 }
4747 echo self::showInputTypeOptions( $inputType, $fieldFormText, $paramValues );
4848 } else {
49 - self::doSpecialCreateForm();
 49+ $this->doSpecialCreateForm();
5050 }
5151 }
5252
@@ -89,7 +89,7 @@
9090 array( 'page_namespace' => NS_TEMPLATE, 'page_is_redirect' => 0 ),
9191 array( 'ORDER BY' => 'page_title' ) );
9292 if ( $db->numRows( $res ) > 0 ) {
93 - while ( $row = $db->fetchRow( $res ) ) {
 93+ foreach ( $res as $row ) {
9494 $template_name = str_replace( '_', ' ', $row[0] );
9595 $all_templates[] = $template_name;
9696 }
Index: trunk/extensions/SemanticForms/specials/SF_RunQuery.php
@@ -32,7 +32,7 @@
3333 }
3434
3535 static function printPage( $form_name, $embedded = false ) {
36 - global $wgOut, $wgRequest, $wgScriptPath, $sfgScriptPath, $sfgFormPrinter, $wgParser;
 36+ global $wgOut, $wgRequest, $sfgFormPrinter, $wgParser;
3737
3838 // Get contents of form-definition page.
3939 $form_title = Title::makeTitleSafe( SF_NS_FORM, $form_name );
Index: trunk/extensions/SemanticForms/specials/SF_UploadWindow.php
@@ -744,7 +744,6 @@
745745 * @access private
746746 */
747747 function saveTempUploadedFile( $saveName, $tempName ) {
748 - global $wgOut;
749748 $repo = RepoGroup::singleton()->getLocalRepo();
750749 $status = $repo->storeTemp( $saveName, $tempName );
751750 if ( !$status->isGood() ) {
@@ -891,7 +890,7 @@
892891 function mainUploadWindowForm( $msg = '' ) {
893892 global $wgOut, $wgUser, $wgContLang;
894893 global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
895 - global $wgRequest, $wgAllowCopyUploads;
 894+ global $wgAllowCopyUploads;
896895 global $wgStylePath, $wgStyleVersion;
897896
898897 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
@@ -1047,7 +1046,6 @@
10481047 );
10491048
10501049 if ( $licenseshtml != '' ) {
1051 - global $wgStylePath;
10521050 $wgOut->addHTML( "
10531051 <td align='$align1'><label for='wpLicense'>$license</label></td>
10541052 <td align='$align2'>
Index: trunk/extensions/SemanticForms/specials/SF_UploadWindow2.php
@@ -120,7 +120,7 @@
121121 * Special page entry point
122122 */
123123 public function execute( $par ) {
124 - global $wgUser, $wgOut, $wgRequest;
 124+ global $wgUser, $wgOut;
125125 // Disable $wgOut - we'll print out the page manually, taking
126126 // the body created by the form, plus the necessary Javascript
127127 // files, and turning them into an HTML page.
@@ -296,12 +296,8 @@
297297 * @param array $warnings
298298 */
299299 protected function uploadWarning( $warnings ) {
300 - global $wgUser;
301 -
302300 $sessionKey = $this->mUpload->stashSession();
303301
304 - $sk = $wgUser->getSkin();
305 -
306302 $warningHtml = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n"
307303 . '<ul class="warning">';
308304 foreach ( $warnings as $warning => $args ) {
@@ -582,7 +578,7 @@
583579 * consisting of one or more <li> elements if there is a warning.
584580 */
585581 public static function getExistsWarning( $exists ) {
586 - global $wgUser, $wgContLang;
 582+ global $wgUser;
587583
588584 if ( !$exists )
589585 return '';
@@ -711,8 +707,6 @@
712708 protected $mSourceIds;
713709
714710 public function __construct( $options = array() ) {
715 - global $wgLang;
716 -
717711 $this->mWatch = !empty( $options['watch'] );
718712 $this->mForReUpload = !empty( $options['forreupload'] );
719713 $this->mSessionKey = isset( $options['sessionkey'] )
@@ -928,8 +922,6 @@
929923 * @return array Descriptor array
930924 */
931925 protected function getOptionsSection() {
932 - global $wgOut;
933 -
934926 $descriptor = array(
935927 'Watchthis' => array(
936928 'type' => 'check',
@@ -1031,9 +1023,6 @@
10321024 global $wgEnableFirefogg, $wgEnableJS2system;
10331025 global $wgOut;
10341026
1035 - $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
1036 - $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
1037 -
10381027 $scriptVars = array(
10391028 'wgAjaxUploadDestCheck' => $wgUseAjax && $wgAjaxUploadDestCheck,
10401029 'wgAjaxLicensePreview' => $wgUseAjax && $wgAjaxLicensePreview,
Index: trunk/extensions/SemanticForms/includes/SF_FormEditPage.php
@@ -49,7 +49,6 @@
5050 }
5151
5252 protected function showContentForm() {
53 - global $sfgIP;
5453 $target_title = $this->mArticle->getTitle();
5554 $target_name = SFUtils::titleString( $target_title );
5655 if ( $target_title->exists() ) {
Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php
@@ -19,8 +19,6 @@
2020 var $mPageTitle;
2121
2222 public function __construct() {
23 - global $smwgContLang;
24 -
2523 // Initialize variables.
2624 $this->mSemanticTypeHooks = array();
2725 $this->mInputTypeHooks = array();
@@ -574,7 +572,7 @@
575573 $existing_page_content = str_replace( $existing_template_text, '{{{insertionpoint}}}', $existing_page_content );
576574 }
577575 } else {
578 - $existing_page_content = self::strReplaceFirst( $existing_template_text, '', $existing_page_content );
 576+ $existing_page_content = $this->strReplaceFirst( $existing_template_text, '', $existing_page_content );
579577 }
580578 // If this is not a multiple-instance template, and we've found
581579 // a match in the source page, there's a good chance that this
@@ -1284,7 +1282,7 @@
12851283 // wikis before SF 2.0.9.
12861284 'class' => "multipleTemplateInstance multipleTemplate"
12871285 ),
1288 - self::multipleTemplateInstanceTableHTML( $section )
 1286+ $this->multipleTemplateInstanceTableHTML( $section )
12891287 ) . "\n";
12901288
12911289 // this will cause the section to be re-parsed on the next go
@@ -1297,7 +1295,7 @@
12981296 'class' => "multipleTemplateStarter",
12991297 'style' => "display: none",
13001298 ),
1301 - self::multipleTemplateInstanceTableHTML( $section )
 1299+ $this->multipleTemplateInstanceTableHTML( $section )
13021300 ) . "\n";
13031301 $form_text .= <<<END
13041302 </div><!-- multipleTemplateList -->
@@ -1433,8 +1431,6 @@
14341432 * Create the HTML and Javascript to display this field within a form
14351433 */
14361434 function formFieldHTML( $form_field, $cur_value ) {
1437 - global $smwgContLang;
1438 -
14391435 // also get the actual field, with all the semantic information (type is
14401436 // SFTemplateField, instead of SFFormField)
14411437 $template_field = $form_field->template_field;
Index: trunk/extensions/SemanticForms/includes/SF_AutoEditAjaxHandler.php
@@ -59,7 +59,7 @@
6060 */
6161 private function storeSemanticData ( $prefillFromExisting = true ) {
6262
63 - global $wgOut, $wgRequest, $wgUser, $wgParser, $wgTitle;
 63+ global $wgOut, $wgRequest, $wgParser, $wgTitle;
6464
6565 if ( !array_key_exists( 'ok text', $this -> mOptions ) ) {
6666 $this -> mOptions[ 'ok text' ] = wfMsg( 'sf_autoedit_success' );
@@ -187,9 +187,6 @@
188188 }
189189
190190 private function parseDataFromHTMLFrag ( &$data, $html, $formID ) {
191 -
192 - global $wgOut;
193 -
194191 $doc = new DOMDocument();
195192 @$doc -> loadHTML(
196193 '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head><body>'
@@ -297,9 +294,6 @@
298295 * @return <type>
299296 */
300297 private function parseDataFromQueryString ( &$data, $queryString, $expand = false ) {
301 -
302 - global $wgParser, $wgOut;
303 -
304298 $params = explode( '&', $queryString );
305299
306300 foreach ( $params as $i => $param ) {
@@ -326,9 +320,6 @@
327321 // Format: 1stLevelName[2ndLevel][3rdLevel][...], i.e. normal array notation
328322 // $value: the value to insert
329323 private function addToArray ( &$array, $key, $value ) {
330 -
331 - global $wgOut, $wgParser;
332 -
333324 $matches = array( );
334325
335326 if ( preg_match( '/^([^\[\]]*)\[([^\[\]]*)\](.*)/', $key, $matches ) ) {
Index: trunk/extensions/SemanticForms/includes/SF_FormClasses.php
@@ -127,7 +127,7 @@
128128 foreach ( $matches[1] as $i => $field_name ) {
129129 if ( ! in_array( $field_name, $fieldNamesArray ) ) {
130130 $propertyName = $matches[2][$i];
131 - self::handlePropertySettingInTemplate( $field_name, $propertyName, true, $templateFields, $templateText );
 131+ $this->handlePropertySettingInTemplate( $field_name, $propertyName, true, $templateFields, $templateText );
132132 $fieldNamesArray[] = $field_name;
133133 }
134134 }
@@ -139,7 +139,7 @@
140140 $field_name = trim( $matches[2][$i] );
141141 if ( ! in_array( $field_name, $fieldNamesArray ) ) {
142142 $propertyName = trim( $propertyName );
143 - self::handlePropertySettingInTemplate( $field_name, $propertyName, false, $templateFields, $templateText );
 143+ $this->handlePropertySettingInTemplate( $field_name, $propertyName, false, $templateFields, $templateText );
144144 $fieldNamesArray[] = $field_name;
145145 }
146146 }
@@ -154,7 +154,7 @@
155155 $fieldName = trim( $matches2[2][$i] );
156156 if ( ! in_array( $fieldName, $fieldNamesArray ) ) {
157157 $propertyName = trim( $propertyName );
158 - self::handlePropertySettingInTemplate( $fieldName, $propertyName, false, $templateFields, $templateText );
 158+ $this->handlePropertySettingInTemplate( $fieldName, $propertyName, false, $templateFields, $templateText );
159159 $fieldNamesArray[] = $fieldName;
160160 }
161161 }
@@ -172,7 +172,7 @@
173173 $propertyName = trim( $keyAndVal[0] );
174174 $fieldName = trim( $keyAndVal[1] );
175175 if ( ! in_array( $fieldName, $fieldNamesArray ) ) {
176 - self::handlePropertySettingInTemplate( $fieldName, $propertyName, false, $templateFields, $templateText );
 176+ $this->handlePropertySettingInTemplate( $fieldName, $propertyName, false, $templateFields, $templateText );
177177 $fieldNamesArray[] = $fieldName;
178178 }
179179 }
Index: trunk/extensions/SemanticForms/includes/SF_AutocompleteAPI.php
@@ -19,8 +19,6 @@
2020 }
2121
2222 public function execute() {
23 - global $wgContLang;
24 -
2523 $params = $this->extractRequestParams();
2624 $substr = $params['substr'];
2725 $namespace = $params['namespace'];
@@ -147,7 +145,7 @@
148146 $res = $db->select( $from_clause, "DISTINCT $value_field",
149147 $conditions, __METHOD__, $sql_options );
150148
151 - while ( $row = $db->fetchRow( $res ) ) {
 149+ foreach ( $res as $row ) {
152150 if ( $substring != null ) {
153151 $values[] = array( 'title' => str_replace( '_', ' ', $row[0] ) );
154152 } else {
Index: trunk/extensions/SemanticForms/includes/SF_FormEditTab.php
@@ -130,8 +130,7 @@
131131 * special pages)
132132 */
133133 static function displayForm( $action, $article ) {
134 - global $wgOut;
135 - global $sfgIP, $sfgUseFormEditPage;
 134+ global $wgOut, $sfgUseFormEditPage;
136135
137136 // return "true" if the call failed (meaning, pass on handling
138137 // of the hook to others), and "false" otherwise
Index: trunk/extensions/SemanticForms/includes/SF_Utils.php
@@ -92,7 +92,7 @@
9393 $res = $db->select( $db->tableName( 'categorylinks' ),
9494 'distinct cl_to', $conditions, __METHOD__ );
9595 if ( $db->numRows( $res ) > 0 ) {
96 - while ( $row = $db->fetchRow( $res ) ) {
 96+ foreach ( $res as $row ) {
9797 $categories[] = $row[0];
9898 }
9999 }
@@ -127,8 +127,6 @@
128128 * Creates HTML linking to a wiki page
129129 */
130130 static function linkText( $namespace, $name, $text = NULL ) {
131 - global $wgContLang;
132 -
133131 $title = Title::makeTitleSafe( $namespace, $name );
134132 if ( $title === NULL ) {
135133 return $name; // TODO maybe report an error here?
@@ -316,7 +314,7 @@
317315 __METHOD__,
318316 array( 'ORDER BY' => 'page_title' ) );
319317 $form_names = array();
320 - while ( $row = $dbr->fetchRow( $res ) ) {
 318+ foreach ( $res as $row ) {
321319 $form_names[] = str_replace( '_', ' ', $row[0] );
322320 }
323321 $dbr->freeResult( $res );
@@ -486,7 +484,7 @@
487485 'page_title',
488486 $conditions, __METHOD__,
489487 array( 'ORDER BY' => 'page_title' ) );
490 - while ( $row = $db->fetchRow( $res ) ) {
 488+ foreach ( $res as $row ) {
491489 $cur_value = str_replace( '_', ' ', $row[0] );
492490 if ( $substring == null ) {
493491 $pages[] = $cur_value;

Follow-up revisions

RevisionCommit summaryAuthorDate
r86128follow up to r86101; fetchRow cannot just be replaced like fetchObject :)jeroendedauw18:35, 15 April 2011
r86141follow up to r86101; fetchRow cannot just be replaced like fetchObject :)jeroendedauw21:38, 15 April 2011