r53092 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53091‎ | r53092 | r53093 >
Date:02:07, 11 July 2009
Author:avar
Status:deferred
Tags:
Comment:
Hooks -> Hook
Modified paths:
  • /trunk/extensions/SlippyMap/SlippyMap.hook.php (added) (history)
  • /trunk/extensions/SlippyMap/SlippyMap.hooks.php (deleted) (history)
  • /trunk/extensions/SlippyMap/SlippyMap.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SlippyMap/SlippyMap.hooks.php
@@ -1,124 +0,0 @@
2 -<?php
3 -/**
4 - * Hooks for SlippyMap extension
5 - *
6 - * @file
7 - * @ingroup Extensions
8 - */
9 -
10 -class SlippyMapHook {
11 -
12 - /**
13 - * Each map we render gets a unique ID. Required to avoid
14 - * JavaScript namespace collisions.
15 - *
16 - * @var int
17 - */
18 - var $mId;
19 -
20 - /**
21 - * Property: SlippyMapMarkerList
22 - * Evil hack as documented at
23 - * http://www.mediawiki.org/wiki/Manual:Tag_extensions#How_can_I_avoid_modification_of_my_extension.27s_HTML_output.3F
24 - * This is here so that random <p> and <pre> tags aren't added to the inline JavaScript output
25 - */
26 - var $mParserMarkers = array();
27 -
28 - public function __construct() {
29 - global $wgParser, $wgHooks, $wgOut, $wgScriptPath, $wgStyleVersion;
30 -
31 - // Load i18n
32 - self::loadMessages();
33 -
34 - // Initialize unique map id
35 - $this->mId = 0;
36 -
37 - // Hook for adding JS variables to <head>
38 - $wgHooks['MakeGlobalVariablesScript'][] = array( &$this, 'jsVariables' );
39 -
40 - // Add JavaScript files to <head>
41 - $wgOut->addScriptFile( $wgScriptPath . '/extensions/SlippyMap/OpenLayers/public/OpenLayers.js?' . $wgStyleVersion );
42 - $wgOut->addScriptFile( $wgScriptPath . '/extensions/SlippyMap/SlippyMap.js?' . $wgStyleVersion );
43 -
44 - // Add our CSS to <head>
45 - $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/SlippyMap/SlippyMap.css?' . $wgStyleVersion );
46 -
47 - // Expand our maps after tidy has run
48 - $wgHooks['ParserAfterTidy'][] = array( &$this, 'afterTidy' );
49 -
50 - // Register the hook with the parser
51 - $wgParser->setHook( 'slippymap', array( &$this, 'render' ) );
52 -
53 - // Continue
54 - return true;
55 - }
56 -
57 - public function render( $input, $args, $parser ) {
58 - // Create SlippyMap
59 - $slippyMap = new SlippyMap( $parser );
60 -
61 - // Hack to ease testing for invalid/valid paramater values
62 - // when we're running parsertests.
63 - $return_dummy_map = false;
64 - if ( isset( $args['dummy'] ) && class_exists("ParserTest") ) {
65 - $return_dummy_map = true;
66 - }
67 - unset( $args['dummy'] );
68 -
69 - // Configure slippyMap
70 - $had_errors = ! $slippyMap->extractOptions( $input, $args );
71 -
72 - // Render & return output
73 - if ( $had_errors ) {
74 - return $slippyMap->renderErrors();
75 - } else {
76 - if ( $return_dummy_map ) {
77 - return "A dummy map";
78 - } else {
79 - $marker = $this->stashMarker( $slippyMap->render( $this->mId ) );
80 - $this->mId += 1;
81 - return $marker;
82 - }
83 - }
84 - }
85 -
86 - /**
87 - * Hook to add JS variables to <head>
88 - */
89 - public function jsVariables( $vars ) {
90 - global $wgLang, $wgSlippyMapAutoLoadMaps;
91 -
92 - $vars['wgSlippyMapCode'] = wfMsg( 'slippymap_code' );
93 - $vars['wgSlippyMapButtonCode'] = wfMsg( 'slippymap_button_code' );
94 - $vars['wgSlippyMapResetview'] = wfMsg( 'slippymap_resetview' );
95 - $vars['wgSlippyMapLanguageCode'] = $wgLang->getCode();
96 - $vars['wgSlippyMapSlippyByDefault'] = $wgSlippyMapAutoLoadMaps;
97 -
98 - return true;
99 - }
100 -
101 - private function stashMarker( $text ) {
102 - $pMarker = "SlippyMap-marker{$this->mId}-SlippyMap";
103 - $this->mParserMarkers[$this->mId] = $text;
104 - return $pMarker;
105 - }
106 -
107 - public function afterTidy( &$parser, &$text ) {
108 - $keys = array();
109 - $marker_count = count( $this->mParserMarkers );
110 -
111 - for ($i = 0; $i < $marker_count; $i++) {
112 - $keys[] = 'SlippyMap-marker' . $i . '-SlippyMap';
113 - }
114 -
115 - $text = str_replace( $keys, $this->mParserMarkers, $text );
116 -
117 - return true;
118 - }
119 -
120 - private static function loadMessages() {
121 - wfProfileIn( __METHOD__ );
122 - wfLoadExtensionMessages( 'SlippyMap' );
123 - wfProfileOut( __METHOD__ );
124 - }
125 -}
Index: trunk/extensions/SlippyMap/SlippyMap.hook.php
@@ -0,0 +1,124 @@
 2+<?php
 3+/**
 4+ * Hooks for SlippyMap extension
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+class SlippyMapHook {
 11+
 12+ /**
 13+ * Each map we render gets a unique ID. Required to avoid
 14+ * JavaScript namespace collisions.
 15+ *
 16+ * @var int
 17+ */
 18+ var $mId;
 19+
 20+ /**
 21+ * Property: SlippyMapMarkerList
 22+ * Evil hack as documented at
 23+ * http://www.mediawiki.org/wiki/Manual:Tag_extensions#How_can_I_avoid_modification_of_my_extension.27s_HTML_output.3F
 24+ * This is here so that random <p> and <pre> tags aren't added to the inline JavaScript output
 25+ */
 26+ var $mParserMarkers = array();
 27+
 28+ public function __construct() {
 29+ global $wgParser, $wgHooks, $wgOut, $wgScriptPath, $wgStyleVersion;
 30+
 31+ // Load i18n
 32+ self::loadMessages();
 33+
 34+ // Initialize unique map id
 35+ $this->mId = 0;
 36+
 37+ // Hook for adding JS variables to <head>
 38+ $wgHooks['MakeGlobalVariablesScript'][] = array( &$this, 'jsVariables' );
 39+
 40+ // Add JavaScript files to <head>
 41+ $wgOut->addScriptFile( $wgScriptPath . '/extensions/SlippyMap/OpenLayers/public/OpenLayers.js?' . $wgStyleVersion );
 42+ $wgOut->addScriptFile( $wgScriptPath . '/extensions/SlippyMap/SlippyMap.js?' . $wgStyleVersion );
 43+
 44+ // Add our CSS to <head>
 45+ $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/SlippyMap/SlippyMap.css?' . $wgStyleVersion );
 46+
 47+ // Expand our maps after tidy has run
 48+ $wgHooks['ParserAfterTidy'][] = array( &$this, 'afterTidy' );
 49+
 50+ // Register the hook with the parser
 51+ $wgParser->setHook( 'slippymap', array( &$this, 'render' ) );
 52+
 53+ // Continue
 54+ return true;
 55+ }
 56+
 57+ public function render( $input, $args, $parser ) {
 58+ // Create SlippyMap
 59+ $slippyMap = new SlippyMap( $parser );
 60+
 61+ // Hack to ease testing for invalid/valid paramater values
 62+ // when we're running parsertests.
 63+ $return_dummy_map = false;
 64+ if ( isset( $args['dummy'] ) && class_exists("ParserTest") ) {
 65+ $return_dummy_map = true;
 66+ }
 67+ unset( $args['dummy'] );
 68+
 69+ // Configure slippyMap
 70+ $had_errors = ! $slippyMap->extractOptions( $input, $args );
 71+
 72+ // Render & return output
 73+ if ( $had_errors ) {
 74+ return $slippyMap->renderErrors();
 75+ } else {
 76+ if ( $return_dummy_map ) {
 77+ return "A dummy map";
 78+ } else {
 79+ $marker = $this->stashMarker( $slippyMap->render( $this->mId ) );
 80+ $this->mId += 1;
 81+ return $marker;
 82+ }
 83+ }
 84+ }
 85+
 86+ /**
 87+ * Hook to add JS variables to <head>
 88+ */
 89+ public function jsVariables( $vars ) {
 90+ global $wgLang, $wgSlippyMapAutoLoadMaps;
 91+
 92+ $vars['wgSlippyMapCode'] = wfMsg( 'slippymap_code' );
 93+ $vars['wgSlippyMapButtonCode'] = wfMsg( 'slippymap_button_code' );
 94+ $vars['wgSlippyMapResetview'] = wfMsg( 'slippymap_resetview' );
 95+ $vars['wgSlippyMapLanguageCode'] = $wgLang->getCode();
 96+ $vars['wgSlippyMapSlippyByDefault'] = $wgSlippyMapAutoLoadMaps;
 97+
 98+ return true;
 99+ }
 100+
 101+ private function stashMarker( $text ) {
 102+ $pMarker = "SlippyMap-marker{$this->mId}-SlippyMap";
 103+ $this->mParserMarkers[$this->mId] = $text;
 104+ return $pMarker;
 105+ }
 106+
 107+ public function afterTidy( &$parser, &$text ) {
 108+ $keys = array();
 109+ $marker_count = count( $this->mParserMarkers );
 110+
 111+ for ($i = 0; $i < $marker_count; $i++) {
 112+ $keys[] = 'SlippyMap-marker' . $i . '-SlippyMap';
 113+ }
 114+
 115+ $text = str_replace( $keys, $this->mParserMarkers, $text );
 116+
 117+ return true;
 118+ }
 119+
 120+ private static function loadMessages() {
 121+ wfProfileIn( __METHOD__ );
 122+ wfLoadExtensionMessages( 'SlippyMap' );
 123+ wfProfileOut( __METHOD__ );
 124+ }
 125+}
Property changes on: trunk/extensions/SlippyMap/SlippyMap.hook.php
___________________________________________________________________
Name: svn:mergeinfo
1126 +
Name: svn:eol-style
2127 + native
Index: trunk/extensions/SlippyMap/SlippyMap.php
@@ -39,7 +39,7 @@
4040 $wgExtensionMessagesFiles['SlippyMap'] = $dir . 'SlippyMap.i18n.php';
4141
4242 /* The classes which make up our extension*/
43 -$wgAutoloadClasses['SlippyMapHook'] = $dir . 'SlippyMap.hooks.php';
 43+$wgAutoloadClasses['SlippyMapHook'] = $dir . 'SlippyMap.hook.php';
4444 $wgAutoloadClasses['SlippyMap'] = $dir . 'SlippyMap.class.php';
4545 $wgAutoloadClasses['SlippyMapExportCgiBin'] = $dir . 'SlippyMapExportCgiBin.class.php';
4646 $wgAutoloadClasses['WorldWind'] = $dir . 'SlippyMap.worldwind.php';

Status & tagging log