r23142 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23141‎ | r23142 | r23143 >
Date:22:14, 20 June 2007
Author:aaron
Status:old
Tags:
Comment:
*Make hooked functions return a value
Modified paths:
  • /trunk/extensions/Blahtex/Blahtex.php (modified) (history)
  • /trunk/extensions/Citation/Citation.php (modified) (history)
  • /trunk/extensions/DisableSpecialPages/DisableSpecialPages.php (modified) (history)
  • /trunk/extensions/FarmNotice/FarmNotice.class.php (modified) (history)
  • /trunk/extensions/FootNote/Footnote.php (modified) (history)
  • /trunk/extensions/NewUserNotif/NewUserNotif.php (modified) (history)
  • /trunk/extensions/Nogomatch/Nogomatch.php (modified) (history)
  • /trunk/extensions/Review/Review.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SemanticToolbar/SMW_Toolbartab.php (modified) (history)
  • /trunk/extensions/SisterSites/SisterSites.php (modified) (history)
  • /trunk/extensions/SpecialTalk/SpecialTalk.php (modified) (history)
  • /trunk/extensions/Tasks/Tasks.php (modified) (history)
  • /trunk/extensions/Watchers/Watchers.php (modified) (history)
  • /trunk/extensions/Wikidata/App.php (modified) (history)
  • /trunk/extensions/examples/Parser_function.php (modified) (history)
  • /trunk/extensions/wikiwyg/share/MediaWiki/extensions/MediaWikiWyg.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Citation/Citation.php
@@ -4,28 +4,30 @@
55 # There is a <citation>author=Manske M ||title="The best paper ever" ||journal=''Biochemistry'' ||volume='''5''', 11</citation> citation here!
66
77
8 -$wgHooks['ParserBeforeTidy'][] = 'citation_hooker' ;
 8+$wgHooks['ParserBeforeTidy'][] = 'citation_hooker';
99 $wgHooks['ParserClearState'][] = 'citation_clear_state';
1010
1111 $wgExtensionFunctions[] = "wfCitation";
1212
13 -function wfCitation () {
 13+function wfCitation() {
1414 global $wgParser ;
15 - $wgParser->setHook ( "citation" , 'parse_citation' ) ;
 15+ $wgParser->setHook( "citation" , 'parse_citation' ) ;
1616 $wgParser->isMainParser = true ;
1717 }
1818
19 -$wgCitationCache = array () ;
 19+$wgCitationCache = array() ;
2020 $wgCitationCounter = 1 ;
2121 $wgCitationRunning = false ;
2222
23 -function citation_hooker ( $parser , $text ) {
 23+function citation_hooker( $parser , $text ) {
2424 global $wgCitationCache , $wgCitationCounter , $wgCitationRunning ;
25 - if ( $wgCitationRunning ) return ;
26 - if ( count ( $wgCitationCache ) == 0 ) return ;
27 - if ( !isset ( $parser->isMainParser ) ) return ;
 25+ if( $wgCitationRunning ) return ;
 26+ if( count( $wgCitationCache ) == 0 )
 27+ return false;
 28+ if( !isset( $parser->isMainParser ) )
 29+ return false;
2830 $ret = "" ;
29 - foreach ( $wgCitationCache AS $num => $entry ) {
 31+ foreach( $wgCitationCache AS $num => $entry ) {
3032 $x = "<li>" . $entry . " <a href='#citeback{$num}'>&uarr;</a></li>\n" ;
3133 $ret .= $x ;
3234 }
@@ -36,60 +38,62 @@
3739
3840 function citation_clear_state() {
3941 global $wgCitationCache, $wgCitationCounter, $wgCitationRunning;
40 - $wgCitationCache = array () ;
 42+ $wgCitationCache = array();
4143 $wgCitationCounter = 1 ;
42 - $wgCitationRunning = false ;
 44+ $wgCitationRunning = false;
 45+
 46+ return false;
4347 }
4448
45 -function parse_citation ( $text , $params , $parser ) {
 49+function parse_citation( $text , $params , $parser ) {
4650 global $wgCitationRunning ;
47 - if ( $wgCitationRunning ) return ;
 51+ if( $wgCitationRunning ) return ;
4852 $ret = "" ;
4953 $attheend = false ;
50 - $res = array () ;
51 - $res2 = array () ;
 54+ $res = array() ;
 55+ $res2 = array() ;
5256 $href = "" ;
53 - $a = explode ( "||" , $text ) ;
 57+ $a = explode( "||" , $text ) ;
5458
55 - foreach ( $a AS $line ) {
56 - $data = explode ( "=" , $line , 2 ) ;
57 - while ( count ( $data ) < 2 ) $data[] = "" ;
58 - $key = urlencode ( trim ( strtolower ( array_shift ( $data ) ) ) ) ;
59 - $value = array_shift ( $data ) ;
 59+ foreach( $a AS $line ) {
 60+ $data = explode( "=" , $line , 2 ) ;
 61+ while( count( $data ) < 2 ) $data[] = "" ;
 62+ $key = urlencode( trim( strtolower( array_shift( $data ) ) ) ) ;
 63+ $value = array_shift( $data ) ;
6064
6165 // Parsed now : "$key" = "$value"
62 - if ( substr ( $value , 0 , 3 ) == "{{{" ) {} // Unset variable, ignore
63 - else if ( $key == "attheend" ) $attheend = true ;
64 - else if ( $key == "href" ) $href = $value ;
65 - else if ( $value != "" ) {
66 - $x = array ( "key" => $key , "value" => $value ) ;
 66+ if( substr( $value , 0 , 3 ) == "{{{" ) {} // Unset variable, ignore
 67+ else if( $key == "attheend" ) $attheend = true ;
 68+ else if( $key == "href" ) $href = $value ;
 69+ else if( $value != "" ) {
 70+ $x = array( "key" => $key , "value" => $value ) ;
6771 $res[] = $x ;
6872 $res2[$key] = $value ;
6973 }
7074 }
7175
7276 // Creating output string
73 - foreach ( $res AS $item ) {
 77+ foreach( $res AS $item ) {
7478 $key = $item["key"] ;
7579 $value = $item["value"] ;
76 - $key2 = urldecode ( $key ) ;
77 - if ( strtolower ( substr ( $key2 , 0 , 3 ) ) == "if:" ) {
78 - $key2 = trim ( substr ( $key2 , 3 ) ) ;
79 - $key = urlencode ( $key2 ) ;
 80+ $key2 = urldecode( $key ) ;
 81+ if( strtolower( substr( $key2 , 0 , 3 ) ) == "if:" ) {
 82+ $key2 = trim( substr( $key2 , 3 ) ) ;
 83+ $key = urlencode( $key2 ) ;
8084 }
81 - if ( isset ( $res2[$key] ) ) $ret .= $value ;
 85+ if( isset( $res2[$key] ) ) $ret .= $value ;
8286 }
8387
84 - if ( $href != "" ) $ret .= " [{$href}]" ;
 88+ if( $href != "" ) $ret .= " [{$href}]" ;
8589
8690 // Adding to footer list or showing inline
8791 $localParser = new Parser ;
8892 $wgCitationRunning = true ;
89 - $ret = $localParser->parse ( $ret , $parser->getTitle(), $parser->getOptions(), false ) ;
 93+ $ret = $localParser->parse( $ret , $parser->getTitle(), $parser->getOptions(), false ) ;
9094 $wgCitationRunning = false ;
9195 $ret = $ret->getText();
9296
93 - if ( $attheend ) {
 97+ if( $attheend ) {
9498 global $wgCitationCache , $wgCitationCounter ;
9599 $ret = "<a name='citation{$wgCitationCounter}'></a>{$ret}" ;
96100 $wgCitationCache[$wgCitationCounter] = $ret ;
Index: trunk/extensions/SemanticMediaWiki/includes/SemanticToolbar/SMW_Toolbartab.php
@@ -21,6 +21,8 @@
2222 'href' => 'javascript:smw_togglemenuvisibility()' //show/hide semantic tool bar
2323 );
2424 $content_actions = array_merge( $content_actions, $main_action); //add a new action
 25+
 26+ return true;
2527 }
2628
2729 ?>
\ No newline at end of file
Index: trunk/extensions/SpecialTalk/SpecialTalk.php
@@ -45,6 +45,8 @@
4646 // check existance
4747 true
4848 );
 49+
 50+ return true;
4951 }
5052 }
5153
Index: trunk/extensions/Review/Review.php
@@ -341,7 +341,7 @@
342342 if( !wfReviewExtensionDoesNamespaceApply ( $wgTitle->getNamespace() )
343343 or $wgUser->isBlocked()
344344 or ( $action != "view" )
345 - ) return;
 345+ ) return false;
346346
347347 # Initialize
348348 $do_merge = $wgRequest->getBool ( 'do_merge' , false ) ;
Index: trunk/extensions/SisterSites/SisterSites.php
@@ -27,6 +27,7 @@
2828 $out->addHtml( wfSisterList( $matches ) );
2929 }
3030 }
 31+ return true;
3132 }
3233
3334 function wfSisterList( $sites ) {
Index: trunk/extensions/examples/Parser_function.php
@@ -30,6 +30,7 @@
3131 # The first array element is case sensitivity, in this case it is not case sensitive
3232 # All remaining elements are synonyms for our parser function
3333 $magicWords['example'] = array( 0, 'example' );
 34+ return true;
3435 }
3536
3637 function wfExampleParserFunction_Render( &$parser, $param1 = '', $param2 = '' ) {
Index: trunk/extensions/DisableSpecialPages/DisableSpecialPages.php
@@ -35,6 +35,7 @@
3636 if( $title && !efDspWhitelisted( $title ) && isset( $list[ $title->getText() ] ) )
3737 unset( $list[ $title->getText() ] );
3838 }
 39+ return true;
3940 }
4041
4142 function efDspOldMethod() {
@@ -44,6 +45,7 @@
4546 if( $title && !efDspWhitelisted( $title ) && isset( $wgSpecialPages[ $title->getText() ] ) )
4647 SpecialPage::removePage( $title->getText() );
4748 }
 49+ return true;
4850 }
4951
5052 function efDspMakeTitle( $page ) {
Index: trunk/extensions/Tasks/Tasks.php
@@ -419,6 +419,7 @@
420420 function wfTasksExtensionPreventOtherActiveTabs( &$skin, &$prevent_active_tabs ) { # Checked for HTML and MySQL insertion attacks
421421 global $action;
422422 $prevent_active_tabs = ( $action == 'tasks' );
 423+ return true;
423424 }
424425
425426 /**
Index: trunk/extensions/FarmNotice/FarmNotice.class.php
@@ -29,6 +29,8 @@
3030 $extra = $this->fetchNotice();
3131 if( $extra )
3232 $notice = $extra . $notice;
 33+
 34+ return true;
3335 }
3436
3537 function fetchNotice() {
@@ -125,6 +127,7 @@
126128 $wgMemc->delete( $this->getLocalCacheKey() );
127129 }
128130 }
 131+ return true;
129132 }
130133
131134 function getSourceUrl( $lang ) {
Index: trunk/extensions/NewUserNotif/NewUserNotif.php
@@ -34,6 +34,8 @@
3535 $user =& $wgUser;
3636 $notifier = new NewUserNotifier();
3737 $notifier->execute( $user );
 38+
 39+ return true;
3840 }
3941
4042 class NewUserNotifier {
Index: trunk/extensions/FootNote/Footnote.php
@@ -51,8 +51,8 @@
5252
5353 wfDebug("insert_endnotes:\n<<<$text>>>\n");
5454
55 - if( $footnoteRecursionGuard ) return;
56 - if( count( $footnoteNotes ) == 0 ) return ;
 55+ if( $footnoteRecursionGuard ) return false;
 56+ if( count( $footnoteNotes ) == 0 ) return false;
5757
5858 $ret = "" ;
5959 foreach( $footnoteNotes AS $num => $entry ) {
@@ -67,6 +67,8 @@
6868 /* Clear global array after rendering */
6969 $footnoteNotes = array();
7070 $footnoteCount = 1 ;
 71+
 72+ return true;
7173 }
7274
7375 function parse_footnote( $text, $params, &$parser ) {
Index: trunk/extensions/Nogomatch/Nogomatch.php
@@ -16,4 +16,5 @@
1717
1818 function wfNogomatchHook( &$title ) {
1919 wfDebugLog( 'nogomatch', $title->getText(), false );
 20+ return true;
2021 }
Index: trunk/extensions/Watchers/Watchers.php
@@ -62,11 +62,11 @@
6363 global $wgTitle;
6464 if( $wgTitle->isTalkPage() ) {
6565 # No talk pages please
66 - return;
 66+ return false;
6767 }
6868 if( $wgTitle->getNamespace() < 0 ) {
6969 # No special pages please
70 - return;
 70+ return false;
7171 }
7272
7373 wfWatchersAddCache();
@@ -79,6 +79,7 @@
8080 echo wfMsg('watchers_link_title');
8181 echo "</a></li>\n" ;
8282
 83+ return true;
8384 }
8485
8586 /**
Index: trunk/extensions/wikiwyg/share/MediaWiki/extensions/MediaWikiWyg.php
@@ -75,6 +75,7 @@
7676 }
7777 }
7878 $text = $full;
 79+ return true;
7980 }
8081
8182 # Not a valid entry point, skip unless MEDIAWIKI is defined
Index: trunk/extensions/Wikidata/App.php
@@ -45,28 +45,31 @@
4646 require_once("{$IP}/extensions/Wikidata/OmegaWiki/SpecialConceptMapping.php");
4747
4848 function addWikidataHeader() {
49 - global $wgOut,$wgScriptPath;
50 - $wgOut->addScript("<script type='text/javascript' src='{$wgScriptPath}/extensions/Wikidata/OmegaWiki/suggest.js'></script>");
51 - $wgOut->addLink(array('rel'=>'stylesheet','type'=>'text/css','media'=>'screen, projection','href'=>"{$wgScriptPath}/extensions/Wikidata/OmegaWiki/suggest.css"));
52 - $wgOut->addLink(array('rel'=>'stylesheet','type'=>'text/css','media'=>'screen, projection','href'=>"{$wgScriptPath}/extensions/Wikidata/OmegaWiki/tables.css"));
 49+ global $wgOut,$wgScriptPath;
 50+ $wgOut->addScript("<script type='text/javascript' src='{$wgScriptPath}/extensions/Wikidata/OmegaWiki/suggest.js'></script>");
 51+ $wgOut->addLink(array('rel'=>'stylesheet','type'=>'text/css','media'=>'screen, projection','href'=>"{$wgScriptPath}/extensions/Wikidata/OmegaWiki/suggest.css"));
 52+ $wgOut->addLink(array('rel'=>'stylesheet','type'=>'text/css','media'=>'screen, projection','href'=>"{$wgScriptPath}/extensions/Wikidata/OmegaWiki/tables.css"));
 53+ return true;
5354 }
5455
5556 function addWikidataEditLinkTrail(&$trail) {
56 - global $wgTitle;
57 - $ns=Namespace::get($wgTitle->getNamespace());
58 - if($ns->getHandlerClass()=='OmegaWiki' || $ns->getHandlerClass()=='DefinedMeaning') {
59 - $dc=wdGetDatasetContext();
60 - $trail="&dataset=$dc";
61 - }
 57+ global $wgTitle;
 58+ $ns=Namespace::get($wgTitle->getNamespace());
 59+ if($ns->getHandlerClass()=='OmegaWiki' || $ns->getHandlerClass()=='DefinedMeaning') {
 60+ $dc=wdGetDatasetContext();
 61+ $trail="&dataset=$dc";
 62+ }
 63+ return true;
6264 }
6365
6466 function addHistoryLinkTrail(&$trail) {
65 - global $wgTitle;
66 - $ns=Namespace::get($wgTitle->getNamespace());
67 - if($ns->getHandlerClass()=='OmegaWiki' || $ns->getHandlerClass()=='DefinedMeaning') {
68 - $dc=wdGetDatasetContext();
69 - $trail="&dataset=$dc";
70 - }
 67+ global $wgTitle;
 68+ $ns=Namespace::get($wgTitle->getNamespace());
 69+ if($ns->getHandlerClass()=='OmegaWiki' || $ns->getHandlerClass()=='DefinedMeaning') {
 70+ $dc=wdGetDatasetContext();
 71+ $trail="&dataset=$dc";
 72+ }
 73+ return true;
7174 }
7275
7376 function initializeWikidata() {
@@ -126,7 +129,7 @@
127130 'options'=>$datasetarray
128131 );
129132
130 -
 133+ return true;
131134 }
132135
133136 ?>
Index: trunk/extensions/Blahtex/Blahtex.php
@@ -118,6 +118,8 @@
119119 $errmsg = $br->getErrmsg();
120120 wfDebug('Blahtex MathML: ' . $br->mr->mathml . "\n");
121121 wfDebug('Blahtex errmsg: ' . $errmsg . "\n");
 122+
 123+ return true;
122124 }
123125
124126 /**
@@ -152,6 +154,8 @@
153155 }
154156 $parser->blahtexMathtags = $mathtags;
155157 $text = $stripped . substr( $text, $pos );
 158+
 159+ return true;
156160 }
157161
158162 /**
@@ -162,6 +166,8 @@
163167 function efBlahtexParserAfterTidy( &$parser, &$text ) {
164168 global $wgBlahtexMathContent, $wgBlahtexMathTags;
165169 $text = strtr( $text, $parser->blahtexMathtags );
 170+
 171+ return true;
166172 }
167173
168174 class BlahtexRenderer {

Status & tagging log