r80762 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80761‎ | r80762 | r80763 >
Date:20:15, 22 January 2011
Author:ialex
Status:deferred
Tags:
Comment:
* Naming local variables after a global ones is not a good idea for code readability
* Removed copy to $wgArticle in the MediaWikiArticleFromTitle hook, this just breaks things when a call to MediaWiki::articleFromTitle() is not made by index.php
Modified paths:
  • /trunk/extensions/MetavidWiki/includes/MV_Hooks.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/specials/MV_SpecialCRUDStream.php (modified) (history)
  • /trunk/extensions/MetavidWiki/maintenance/maintenance_util.inc.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MetavidWiki/maintenance/maintenance_util.inc.php
@@ -75,11 +75,10 @@
7676 }
7777 return $mv_valid_people_cache[$person_key];
7878 }
79 -function append_to_wiki_page( $wgTitle, $append_text, $unique = true ) {
80 - global $botUserName;
81 - if ( $wgTitle->exists() ) {
82 - $wgArticle = new Article( $wgTitle );
83 - $cur_text = $wgArticle->getContent();
 79+function append_to_wiki_page( $title, $append_text, $unique = true ) {
 80+ if ( $title->exists() ) {
 81+ $article = new Article( $title );
 82+ $cur_text = $article->getContent();
8483 if ( $unique ) {
8584 if ( strpos( $cur_text, $append_text ) !== false ) {
8685 print "no insert $append_text already present\n";
@@ -89,21 +88,21 @@
9089 $cur_text .= "\n\n" . $append_text;
9190 // do the edit:
9291 $sum_txt = 'metavid append';
93 - $wgArticle->doEdit( $cur_text, $sum_txt , EDIT_FORCE_BOT);
94 - print "did append on " . $wgTitle->getDBkey() . "\n";
 92+ $article->doEdit( $cur_text, $sum_txt , EDIT_FORCE_BOT);
 93+ print "did append on " . $title->getDBkey() . "\n";
9594 } else {
9695 print "append request to empty page... creating\n";
97 - do_update_wiki_page( $wgTitle, $append_text );
 96+ do_update_wiki_page( $title, $append_text );
9897 }
9998 }
100 -function do_update_wiki_page( $wgTitle, $wikiText, $ns = null, $forceUpdate = false ) {
 99+function do_update_wiki_page( $title, $wikiText, $ns = null, $forceUpdate = false ) {
101100 global $botUserName;
102 - if ( !is_object( $wgTitle ) ) {
 101+ if ( !is_object( $title ) ) {
103102 // get the title and make sure the first letter is uper case
104 - $wgTitle = Title::makeTitle( $ns, ucfirst( $wgTitle ) );
 103+ $title = Title::makeTitle( $ns, ucfirst( $title ) );
105104 }
106105
107 - if ( trim( $wgTitle->getDBkey() ) == '' ) {
 106+ if ( trim( $title->getDBkey() ) == '' ) {
108107 print "empty title (no insert /update) \n";
109108 return ;
110109 }
@@ -111,33 +110,33 @@
112111 // make sure the text is utf8 encoded:
113112 $wikiText = utf8_encode( $wikiText );
114113
115 - $wgArticle = new Article( $wgTitle );
116 - if ( !mvDoMvPage( $wgTitle, $wgArticle, false ) ) {
117 - print "bad title: " . $wgTitle->getNsText() . ':' . $wgTitle->getDBkey() . " no edit";
118 - if ( $wgTitle->exists() ) {
 114+ $article = new Article( $title );
 115+ if ( !mvDoMvPage( $title, $article, false ) ) {
 116+ print "bad title: " . $title->getNsText() . ':' . $title->getDBkey() . " no edit";
 117+ if ( $title->exists() ) {
119118 print "remove article";
120 - $wgArticle->doDeleteArticle( 'bad title' );
 119+ $article->doDeleteArticle( 'bad title' );
121120 }
122121 // some how mvdIndex and mvd pages got out of sync do a separate check for the mvd:
123 - if ( MV_Index::getMVDbyTitle( $wgArticle->mTitle->getDBkey() ) != null ) {
 122+ if ( MV_Index::getMVDbyTitle( $title->getDBkey() ) != null ) {
124123 print ', rm mvd';
125 - MV_Index::remove_by_wiki_title( $wgArticle->mTitle->getDBkey() );
 124+ MV_Index::remove_by_wiki_title( $title->getDBkey() );
126125 }
127126 print "\n";
128127 return ;
129128 }
130 - if ( $wgTitle->getNamespace() == MV_NS_MVD && MV_Index::getMVDbyTitle( $wgTitle->getDBkey() ) == null ) {
 129+ if ( $title->getNamespace() == MV_NS_MVD && MV_Index::getMVDbyTitle( $title->getDBkey() ) == null ) {
131130 // print "missing assoc mvd ...update \n";
132131 } else {
133 - if ( $wgTitle->exists() ) {
 132+ if ( $title->exists() ) {
134133 // if last edit!=mvBot skip (don't overwite peoples improvments')
135 - $rev = & Revision::newFromTitle( $wgTitle );
 134+ $rev = & Revision::newFromTitle( $title );
136135 if ( $botUserName != $rev->getRawUserText() && !$forceUpdate ) {
137 - print ' skiped page ' . $wgTitle->getNsText() . ':' . $wgTitle->getText() . ' edited by user:' . $rev->getRawUserText() . " != $botUserName \n";
 136+ print ' skiped page ' . $title->getNsText() . ':' . $title->getText() . ' edited by user:' . $rev->getRawUserText() . " != $botUserName \n";
138137 return ;
139138 }
140139 // proc article:
141 - $cur_text = $wgArticle->getContent();
 140+ $cur_text = $article->getContent();
142141 // if its a redirect skip
143142 if ( substr( $cur_text, 0, strlen( '#REDIRECT' ) ) == '#REDIRECT' && !$forceUpdate ) {
144143 print ' skiped page moved by user:' . $rev->getRawUserText() . "\n";
@@ -145,7 +144,7 @@
146145 }
147146 // check if text is identical:
148147 if ( trim( $cur_text ) == trim( $wikiText ) ) {
149 - print "text " . $wgTitle->getNsText() . ':' . $wgTitle->getText() . " is identical (no update)\n";
 148+ print "text " . $title->getNsText() . ':' . $title->getText() . " is identical (no update)\n";
150149 // if force update double check the mvd for consistancy?
151150 return ;
152151 }
@@ -155,7 +154,7 @@
156155 // got here do the edit:
157156 $sum_txt = 'metavid bot insert';
158157
159 - $wgArticle->doEdit( $wikiText, $sum_txt, EDIT_FORCE_BOT );
 158+ $article->doEdit( $wikiText, $sum_txt, EDIT_FORCE_BOT );
160159 print "did edit on " . $wgTitle->getNsText() . ':' . $wgTitle->getDBkey() . "\n";
161160 // die;
162161 }
Index: trunk/extensions/MetavidWiki/includes/specials/MV_SpecialCRUDStream.php
@@ -187,8 +187,8 @@
188188
189189 // insert page
190190 $streamTitle = Title::newFromText( $this->stream_name, MV_NS_STREAM );
191 - $wgArticle = new Article( $streamTitle );
192 - $status = $wgArticle->doEdit( $this->stream_desc, wfMsg( 'mv_summary_add_stream' ) );
 191+ $article = new Article( $streamTitle );
 192+ $status = $article->doEdit( $this->stream_desc, wfMsg( 'mv_summary_add_stream' ) );
193193 if ( $status === true || ( is_object( $status ) && $status->isOK() ) ) {
194194 // stream inserted sucesfully report to output
195195 $out = wfMsg('mv_stream_added', $sk->makeLinkObj( $streamTitle, $this->stream_name ) );
Index: trunk/extensions/MetavidWiki/includes/MV_Hooks.php
@@ -243,8 +243,6 @@
244244 * by processing the given title request/namespace
245245 */
246246 function mvDoMvPage ( &$title, &$article, $doOutput = true ) {
247 - global $wgOut, $wgTitle, $wgArticle;
248 -
249247 //add js
250248 mvAddPerNamespaceJS( $title );
251249
@@ -273,7 +271,6 @@
274272 return false;
275273 }
276274 }
277 - $wgArticle = $article;
278275 return true;
279276 }
280277 function mvCatHook( &$catArticle ) {

Status & tagging log