r84550 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84549‎ | r84550 | r84551 >
Date:20:25, 22 March 2011
Author:ialex
Status:deferred (Comments)
Tags:
Comment:
Removed some useless extension function; changed the ones adding parser tags and functions to use ParserFirstCallInit hook
Modified paths:
  • /trunk/extensions/Preloader/Preloader.php (modified) (history)
  • /trunk/extensions/RSSNews/RSSNews.php (modified) (history)
  • /trunk/extensions/ScanSet/ScanSet.php (modified) (history)
  • /trunk/extensions/Seealso/Seealso.php (modified) (history)
  • /trunk/extensions/Sort/Sort.php (modified) (history)
  • /trunk/extensions/SyntaxHighlight_vim/Syntax.php (modified) (history)
  • /trunk/extensions/SyntaxHighlight_vim/SyntaxHook.php (modified) (history)
  • /trunk/extensions/TagContent/TagContent.php (modified) (history)
  • /trunk/extensions/TemplateLink/TemplateLink.setup.php (modified) (history)
  • /trunk/extensions/UserImages/UserImages.php (modified) (history)
  • /trunk/extensions/UserRightsNotif/UserRightsNotif.php (modified) (history)
  • /trunk/extensions/WiktionaryInflection/WiktionaryInflection.php (modified) (history)
  • /trunk/extensions/YouTubeAuthSub/YouTubeAuthSub.php (modified) (history)
  • /trunk/extensions/uniwiki/Layouts/Layouts.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Preloader/Preloader.php
@@ -17,7 +17,6 @@
1818 exit( 1 );
1919 }
2020
21 -$wgExtensionFunctions[] = 'efPreloader';
2221 $wgExtensionCredits['other'][] = array(
2322 'path' => __FILE__,
2423 'name' => 'Preloader',
@@ -33,21 +32,21 @@
3433 */
3534 $wgPreloaderSource[ NS_MAIN ] = 'Template:Preload';
3635
37 -function efPreloader() {
38 - new Preloader();
39 -}
 36+$wgHooks['EditFormPreloadText'][] = 'Preloader::mainHook';
 37+$wgHooks['ParserFirstCallInit'][] = 'Preloader::setParserHook';
4038
4139 class Preloader {
4240
43 - function __construct() {
44 - $this->setHooks();
 41+ public static function setParserHook( $parser ) {
 42+ $parser->setHook( 'nopreload', array( __CLASS__, 'parserHook' ) );
 43+ return true;
4544 }
4645
4746 /** Hook function for the preloading */
48 - function mainHook( &$text, &$title ) {
49 - $src = $this->preloadSource( $title->getNamespace() );
 47+ public static function mainHook( &$text, &$title ) {
 48+ $src = self::preloadSource( $title->getNamespace() );
5049 if( $src ) {
51 - $stx = $this->sourceText( $src );
 50+ $stx = self::sourceText( $src );
5251 if( $stx )
5352 $text = $stx;
5453 }
@@ -55,7 +54,7 @@
5655 }
5756
5857 /** Hook function for the parser */
59 - function parserHook( $input, $args, &$parser ) {
 58+ public static function parserHook( $input, $args, &$parser ) {
6059 $output = $parser->parse( $input, $parser->getTitle(), $parser->getOptions(), false, false );
6160 return $output->getText();
6261 }
@@ -67,7 +66,7 @@
6867 * @param $namespace Namespace to check for
6968 * @return mixed
7069 */
71 - function preloadSource( $namespace ) {
 70+ static function preloadSource( $namespace ) {
7271 global $wgPreloaderSource;
7372 if( isset( $wgPreloaderSource[ $namespace ] ) ) {
7473 return $wgPreloaderSource[ $namespace ];
@@ -82,11 +81,11 @@
8382 * @param $page Text form of the page title
8483 * @return mixed
8584 */
86 - function sourceText( $page ) {
 85+ static function sourceText( $page ) {
8786 $title = Title::newFromText( $page );
8887 if( $title && $title->exists() ) {
8988 $revision = Revision::newFromTitle( $title );
90 - return $this->transform( $revision->getText() );
 89+ return self::transform( $revision->getText() );
9190 } else {
9291 return false;
9392 }
@@ -98,14 +97,7 @@
9998 * @param $text
10099 * @return string
101100 */
102 - function transform( $text ) {
 101+ static function transform( $text ) {
103102 return trim( preg_replace( '/<nopreload>.*<\/nopreload>/s', '', $text ) );
104103 }
105 -
106 - /** Register the hook functions with MediaWiki */
107 - function setHooks() {
108 - global $wgHooks, $wgParser;
109 - $wgHooks['EditFormPreloadText'][] = array( &$this, 'mainHook' );
110 - $wgParser->setHook( 'nopreload', array( &$this, 'parserHook' ) );
111 - }
112104 }
Index: trunk/extensions/uniwiki/Layouts/Layouts.php
@@ -43,10 +43,10 @@
4444
4545 /* ---- TAGS ---- */
4646
47 -$wgExtensionFunctions[] = "UW_Layouts_EF";
48 -function UW_Layouts_EF() {
49 - global $wgParser;
50 - $wgParser->setHook ( "layout", "UW_Layouts_EF_Render" );
 47+$wgHooks['ParserFirstCallInit'][] = 'UW_Layouts_ParserFirstCallInit';
 48+function UW_Layouts_ParserFirstCallInit( $parser ) {
 49+ $parser->setHook( 'layout', 'UW_Layouts_EF_Render' );
 50+ return true;
5151 }
5252
5353 /* render a note to display the name of the
Index: trunk/extensions/Seealso/Seealso.php
@@ -19,30 +19,26 @@
2020 'descriptionmsg' => 'seealso-desc',
2121 );
2222
23 -$wgExtensionFunctions[] = "wfSeealso";
 23+$wgHooks['ParserFirstCallInit'][] = 'wfSeealsoSetHooks';
2424
2525 $dir = dirname(__FILE__) . '/';
2626 $wgExtensionMessagesFiles['seealso'] = $dir . 'Seealso.i18n.php';
2727
28 -function wfSeealso () {
29 - wfLoadExtensionMessages( 'seealso' );
30 - global $wgParser ;
31 - $wgParser->setHook ('seealso', 'parse_seealso' ) ;
 28+function wfSeealsoSetHooks( $parser ) {
 29+ $parser->setHook( 'seealso', 'parse_seealso' );
3230 $l = trim ( 'seealso-local', "" ) ;
3331 if ( $l != "" )
34 - $wgParser->setHook ( $l , 'parse_seealso' ) ;
 32+ $parser->setHook( $l, 'parse_seealso' );
 33+ return true;
3534 }
3635
37 -function parse_seealso ( $text, $params, &$parser ) {
38 - $a = explode ( "\n" , $text ) ;
39 - $ret = "== " . trim ( wfMsg('seealso')) . " ==\n" ;
 36+function parse_seealso( $text, $params, $parser ) {
 37+ $a = explode ( "\n" , $text );
 38+ $ret = "== " . trim ( wfMsg( 'seealso' ) ) . " ==\n";
4039 foreach ( $a AS $x ) {
4140 $x = trim ( $x ) ;
42 - if ( $x == "" ) continue ;
43 - $ret .= "* [[" . $x . "]]\n" ;
 41+ if ( $x == "" ) continue;
 42+ $ret .= "* [[" . $x . "]]\n";
4443 }
45 - $p = new Parser ;
46 - $ret = $p->parse ( $ret , $parser->getTitle() , $parser->getOptions(), false ) ;
47 - $ret = $ret->getText();
48 - return $ret ;
 44+ return $parser->recursiveTagParse( $ret );
4945 }
Index: trunk/extensions/WiktionaryInflection/WiktionaryInflection.php
@@ -7,11 +7,11 @@
88 'author' => '',
99 );
1010
11 -$wgExtensionFunctions[] = "wfInflectionExtension";
 11+$wgHooks['ParserFirstCallInit'][] = 'wfInflectionSetHook';
1212
13 -function wfInflectionExtension() {
14 - global $wgParser;
15 - $wgParser->setHook("infl", "renderInflection");
 13+function wfInflectionSetHook( $parser ) {
 14+ $parser->setHook( 'infl', 'renderInflection' );
 15+ return true;
1616 }
1717
1818 class InflectionRule {
Index: trunk/extensions/ScanSet/ScanSet.php
@@ -21,12 +21,12 @@
2222 );
2323
2424 $wgExtensionMessagesFiles['ScanSet'] = dirname(__FILE__) . '/ScanSet.i18n.php';
25 -$wgExtensionFunctions[] = 'wfScanSetSetup';
 25+$wgHooks['ParserFirstCallInit'][] = 'wfScanSetSetup';
2626 $wgScanSetSettings = array();
2727
28 -function wfScanSetSetup() {
29 - global $wgParser;
30 - $wgParser->setHook( 'scanset', 'wfScanSetHook' );
 28+function wfScanSetSetup( $parser ) {
 29+ $parser->setHook( 'scanset', 'wfScanSetHook' );
 30+ return true;
3131 }
3232
3333 function wfScanSetHook( $content, $params, &$parser ) {
Index: trunk/extensions/UserRightsNotif/UserRightsNotif.php
@@ -16,7 +16,6 @@
1717 die( 1 );
1818 }
1919
20 -$wgExtensionFunctions[] = 'efUserRightsNotifierSetup';
2120 $wgExtensionCredits['other'][] = array(
2221 'path' => __FILE__,
2322 'name' => 'User Rights Email Notification',
@@ -31,11 +30,7 @@
3231 # Change this to alter the email sender
3332 $wgUserRightsNotif['sender'] = $wgPasswordSender;
3433
35 -function efUserRightsNotifierSetup() {
36 - global $wgHooks;
37 - wfLoadExtensionMessages( 'UserRightsNotif' );
38 - $wgHooks['UserRights'][] = 'efUserRightsNotifier';
39 -}
 34+$wgHooks['UserRights'][] = 'efUserRightsNotifier';
4035
4136 function efUserRightsNotifier( &$user, $added, $removed ) {
4237 global $wgUserRightsNotif;
Index: trunk/extensions/SyntaxHighlight_vim/Syntax.php
@@ -10,64 +10,58 @@
1111 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1212 */
1313
14 -$wgExtensionFunctions[] = 'wfSyntax';
1514 $wgExtensionCredits['other'][] = array(
1615 'name' => 'Syntax',
1716 'author' => 'Ævar Arnfjörð Bjarmason',
1817 'description' => 'A syntax highlight library'
1918 );
2019
21 -function wfSyntax() {
22 - wfUsePHP( 5.1 );
23 - wfUseMW( '1.6alpha' );
24 -
25 - class Syntax {
26 - private $mIn;
27 - private $mInFile, $mOutFile;
28 - private $mVimrc;
 20+class Syntax {
 21+ private $mIn;
 22+ private $mInFile, $mOutFile;
 23+ private $mVimrc;
2924
30 - public function __construct( $in, $format = null, $colorscheme = null, $background = null ) {
31 - $this->mVimrc = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'vimrc.vim';
 25+ public function __construct( $in, $format = null, $colorscheme = null, $background = null ) {
 26+ $this->mVimrc = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'vimrc.vim';
3227
33 - $this->mIn = $in;
34 - }
 28+ $this->mIn = $in;
 29+ }
3530
36 - public function getOut() {
37 - $this->genTemp();
38 -
39 - if ( ! $handle = fopen( $this->mInFile, 'a' ) )
40 - die( 'AAAAAAA' );
41 - if ( fwrite( $handle, $this->mIn ) === false )
42 - die( 'OOOOOOOOO' );
 31+ public function getOut() {
 32+ $this->genTemp();
4333
44 - $html = $this->run();
 34+ if ( ! $handle = fopen( $this->mInFile, 'a' ) )
 35+ die( 'AAAAAAA' );
 36+ if ( fwrite( $handle, $this->mIn ) === false )
 37+ die( 'OOOOOOOOO' );
4538
46 - $html = preg_replace( '~^\s*<html>.*?<body.*?<pre>~s', '<pre style="background-color: black; color: gray">', $html );
47 - $html = preg_replace( '~</p>\s*</body>.*?$~s', '</style>', $html );
 39+ $html = $this->run();
4840
49 - $this->rmTemp();
50 -
51 - return $html;
52 - }
 41+ $html = preg_replace( '~^\s*<html>.*?<body.*?<pre>~s', '<pre style="background-color: black; color: gray">', $html );
 42+ $html = preg_replace( '~</p>\s*</body>.*?$~s', '</style>', $html );
5343
54 - private function genTemp() {
55 - $this->mInFile = $this->mktemp();
56 - $this->mOutFile = $this->mktemp();
57 - }
58 -
59 - private static function mktemp() {
60 - return rtrim( shell_exec( 'mktemp -u' ), "\n" );
61 - }
62 -
63 - private function rmTemp() {
64 - unlink( $this->mInFile );
65 - unlink( $this->mOutFile );
66 - }
 44+ $this->rmTemp();
6745
68 - private function run() {
69 - shell_exec( "vim -u {$this->mVimrc} -e +'run! syntax/2html.vim' +':w {$this->mOutFile}' +':qa!' {$this->mInFile}" );
70 -
71 - return file_get_contents( $this->mOutFile );
72 - }
 46+ return $html;
7347 }
 48+
 49+ private function genTemp() {
 50+ $this->mInFile = $this->mktemp();
 51+ $this->mOutFile = $this->mktemp();
 52+ }
 53+
 54+ private static function mktemp() {
 55+ return rtrim( shell_exec( 'mktemp -u' ), "\n" );
 56+ }
 57+
 58+ private function rmTemp() {
 59+ unlink( $this->mInFile );
 60+ unlink( $this->mOutFile );
 61+ }
 62+
 63+ private function run() {
 64+ shell_exec( "vim -u {$this->mVimrc} -e +'run! syntax/2html.vim' +':w {$this->mOutFile}' +':qa!' {$this->mInFile}" );
 65+
 66+ return file_get_contents( $this->mOutFile );
 67+ }
7468 }
Index: trunk/extensions/SyntaxHighlight_vim/SyntaxHook.php
@@ -10,35 +10,22 @@
1111 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1212 */
1313
14 -$wgExtensionFunctions[] = 'wfSyntaxHook';
1514 $wgExtensionCredits['parserhook'][] = array(
1615 'name' => 'Syntax',
1716 'author' => 'Ævar Arnfjörð Bjarmason',
1817 'description' => 'adds a <code>&lt;syntax&gt;</code> parser hook for highlighting'
1918 );
2019
21 -function wfSyntaxHook() {
22 - wfUsePHP( 5.1 );
23 - wfUseMW( '1.6alpha' );
24 -
25 - class SyntaxHook {
26 - public function __construct() {
27 - $this->setHook();
28 - }
29 -
30 - private function setHook() {
31 - global $wgParser;
 20+$wgHooks['ParserFirstCallInit'][] = 'wfSyntaxHighlightVimSetHook';
3221
33 - $wgParser->setHook( 'syntax', array( $this, 'hook' ) );
34 - }
 22+function wfSyntaxHighlightVimSetHook( $parser ) {
 23+ $parser->setHook( 'syntax', 'wfSyntaxHighlightVimRender' );
 24+ return true;
 25+}
3526
36 - public function hook( $in, array $argv ) {
37 - $in = ltrim( $in, "\n" );
38 - $syntax = new Syntax( $in );
 27+function wfSyntaxHighlightVimRender( $in, array $argv ) {
 28+ $in = ltrim( $in, "\n" );
 29+ $syntax = new Syntax( $in );
3930
40 - return $syntax->getOut();
41 - }
42 - }
43 -
44 - new SyntaxHook;
 31+ return $syntax->getOut();
4532 }
Index: trunk/extensions/TagContent/TagContent.php
@@ -39,7 +39,7 @@
4040 'description' => 'Translate from tags to parser functions'
4141 );
4242
43 -$wgExtensionFunctions[] = 'efTagContentSetup';
 43+$wgHooks['ParserFirstCallInit'][] = 'efTagContentSetHooks';
4444 $wgExtensionMessagesFiles['TagContent'] = dirname(__FILE__) . '/TagContent.i18n.php';
4545
4646 $egTagContentDefine = array(
@@ -195,14 +195,14 @@
196196 * Setup function for the extension
197197 @return True is returned unconditionally
198198 */
199 -function efTagContentSetup () {
200 - global $wgParser, $egTagContentBlacklist, $egTagContentDefine;
 199+function efTagContentSetHooks( $parser ) {
 200+ global $egTagContentBlacklist, $egTagContentDefine;
201201 wfLoadExtensionMessages('TagContent');
202202 foreach ($egTagContentDefine as $k => $a) {
203203 $template = $a[0];
204204 $tag = strtolower($k);
205205 $c = new TagContent($tag, $template, $a[1], false);
206 - $wgParser->setHook( $tag, array( $c, 'onRender' ));
 206+ $parser->setHook( $tag, array( $c, 'onRender' ));
207207 }
208208 $defs = explode("\n", wfMsgNoTrans( 'tags-definition' ));
209209 foreach ($defs as $line) {
@@ -213,7 +213,7 @@
214214 $tag = strtolower(trim($a[0]));
215215 if ( !$egTagContentBlacklist[$tag] && !isset($egTagContentDefine[$tag])) {
216216 $c = new TagContent($tag, $template, $a[2], true);
217 - $wgParser->setHook( $tag, array( $c, 'onRender' ));
 217+ $parser->setHook( $tag, array( $c, 'onRender' ));
218218 }
219219 }
220220 }
Index: trunk/extensions/Sort/Sort.php
@@ -16,7 +16,7 @@
1717 }
1818
1919 $wgAutoloadClasses['Sorter'] = dirname( __FILE__ ) . '/Sort.class.php';
20 -$wgExtensionFunctions[] = 'efSort';
 20+$wgHooks['ParserFirstCallInit'][] = 'efSortSetHook';
2121 $wgExtensionCredits['parserhook'][] = array(
2222 'path' => __FILE__,
2323 'name' => 'Sort',
@@ -28,9 +28,9 @@
2929 /**
3030 * Register hook function
3131 */
32 -function efSort() {
33 - global $wgParser;
34 - $wgParser->setHook( 'sort', 'efRenderSort' );
 32+function efSortSetHook( $parser ) {
 33+ $parser->setHook( 'sort', 'efRenderSort' );
 34+ return true;
3535 }
3636
3737 /**
Index: trunk/extensions/YouTubeAuthSub/YouTubeAuthSub.php
@@ -15,8 +15,6 @@
1616 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1717 */
1818
19 -$wgExtensionFunctions[] = 'wfYouTubeAuthSub';
20 -
2119 $wgYTAS_UseClientLogin = true;
2220
2321 # Fill out if you are using $wgUseClientLogin
@@ -44,13 +42,9 @@
4543 $wgAutoloadClasses['SpecialYouTubeAuthSub'] = $dir . 'YouTubeAuthSub_body.php';
4644 $wgSpecialPages['YouTubeAuthSub'] = 'SpecialYouTubeAuthSub';
4745
48 -function wfYouTubeAuthSub() {
49 - global $wgYTAS_UseNamespace, $wgExtraNamespaces;
 46+$wgExtraNamespaces[NS_YOUTUBE] = "YouTube";
 47+$wgExtraNamespaces[NS_YOUTUBE_TALK] = "YouTube_talk";
5048
51 - $wgExtraNamespaces[NS_YOUTUBE] = "YouTube";
52 - $wgExtraNamespaces[NS_YOUTUBE_TALK] = "YouTube_talk";
53 -}
54 -
5549 function wfSpecialYouTubePost ($url, $content, $headers = null) {
5650 // Set the date of your post
5751 $issued=gmdate("Y-m-d\TH:i:s\Z", time());
Index: trunk/extensions/RSSNews/RSSNews.php
@@ -10,11 +10,11 @@
1111 'url' => 'http://www.mediawiki.org/wiki/Extension:RSSNews',
1212 );
1313
14 -$wgExtensionFunctions[] = "wfRSSFeedExtension";
 14+$wgHooks['ParserFirstCallInit'][] = 'wfRSSFeedSetHook';
1515
16 -function wfRSSFeedExtension() {
17 - global $wgParser;
18 - $wgParser->setHook( "rss", "renderRSS" );
 16+function wfRSSFeedSetHook( $parser ) {
 17+ $parser->setHook( 'rss', 'renderRSS' );
 18+ return true;
1919 }
2020
2121 function renderRSS( $paramstring ) {
Index: trunk/extensions/UserImages/UserImages.php
@@ -27,7 +27,7 @@
2828 $dir = dirname(__FILE__) . '/';
2929 $wgExtensionMessagesFiles['UserImages'] = $dir . 'UserImages.i18n.php';
3030 $wgAutoloadClasses['UserImagesGallery'] = $dir . 'UserImages.class.php';
31 -$wgExtensionFunctions[] = 'efUserImages';
 31+$wgHooks['ParserFirstCallInit'][] = 'efUserImagesSetHook';
3232
3333 /**
3434 * Set this to true to disable the parser cache for pages which
@@ -39,9 +39,9 @@
4040 /**
4141 * Extension initialisation function
4242 */
43 -function efUserImages() {
44 - global $wgParser;
45 - $wgParser->setHook( 'userimages', 'efUserImagesRender' );
 43+function efUserImagesSetHook( $parser ) {
 44+ $parser->setHook( 'userimages', 'efUserImagesRender' );
 45+ return true;
4646 }
4747
4848 /**
Index: trunk/extensions/TemplateLink/TemplateLink.setup.php
@@ -43,11 +43,11 @@
4444 $wgSpecialPages['TemplateLink'] = 'TemplateLink'; # Let MediaWiki know about your new special page.
4545
4646 # The tag
47 -$wgExtensionFunctions[] = 'efTemplateLinkSetup';
 47+$wgHooks['ParserFirstCallInit'][] = 'efTemplateLinkSetHook';
4848
49 -function efTemplateLinkSetup(){
50 - global $wgParser;
51 - $wgParser->setHook( 'templatelink', 'efTemplateLink' );
 49+function efTemplateLinkSetHook( $parser ){
 50+ $parser->setHook( 'templatelink', 'efTemplateLink' );
 51+ return true;
5252 }
5353
5454 function efTemplateLink( $input, $args, $parser ){

Comments

#Comment by Aaron Schulz (talk | contribs)   00:34, 18 June 2011

Checked SyntaxHighlight/Sort.

Status & tagging log