Index: trunk/extensions/Push/Push.php |
— | — | @@ -54,27 +54,45 @@ |
55 | 55 | $wgAvailableRights[] = 'pushadmin'; |
56 | 56 | $wgGroupPermissions['sysop']['pushadmin'] = true; |
57 | 57 | |
58 | | -$moduleTemplate = array( |
59 | | - 'localBasePath' => dirname( __FILE__ ), |
60 | | - 'remoteBasePath' => $egPushScriptPath, |
61 | | - 'group' => 'ext.push' |
| 58 | +$egPushJSMessages = array( |
| 59 | + 'push-button-pushing', |
| 60 | + 'push-button-completed', |
| 61 | + 'push-button-failed', |
| 62 | + 'push-import-revision-message', |
62 | 63 | ); |
63 | 64 | |
64 | | -$wgResourceModules['ext.push.tab'] = $moduleTemplate + array( |
65 | | - 'scripts' => 'includes/ext.push.tab.js', |
66 | | - 'dependencies' => array(), |
67 | | - 'messages' => array( |
68 | | - 'push-button-pushing', |
69 | | - 'push-button-completed', |
70 | | - 'push-button-failed', |
71 | | - 'push-import-revision-message', |
72 | | - ) |
73 | | -); |
| 65 | +// For backward compatibility with MW < 1.17. |
| 66 | +if ( is_callable( array( 'OutputPage', 'addModules' ) ) ) { |
| 67 | + $moduleTemplate = array( |
| 68 | + 'localBasePath' => dirname( __FILE__ ), |
| 69 | + 'remoteBasePath' => $egPushScriptPath, |
| 70 | + 'group' => 'ext.push' |
| 71 | + ); |
| 72 | + |
| 73 | + $wgResourceModules['ext.push.tab'] = $moduleTemplate + array( |
| 74 | + 'scripts' => 'includes/ext.push.tab.js', |
| 75 | + 'dependencies' => array(), |
| 76 | + 'messages' => $egPushJSMessages |
| 77 | + ); |
| 78 | +} |
74 | 79 | |
75 | | -// This function has been deprecated in 1.16, but needed for earlier versions. |
76 | | -// It's present in 1.16 as a stub, but lets check if it exists in case it gets removed at some point. |
77 | | -if ( function_exists( 'wfLoadExtensionMessages' ) ) { |
78 | | - wfLoadExtensionMessages( 'Push' ); |
| 80 | +function efPushAddJSLocalisation( $parser = false ) { |
| 81 | + global $egPushJSMessages; |
| 82 | + |
| 83 | + $data = array(); |
| 84 | + |
| 85 | + foreach ( $egPushJSMessages as $msg ) { |
| 86 | + $data[$msg] = wfMsgNoTrans( $msg ); |
| 87 | + } |
| 88 | + |
| 89 | + $js = 'var wgPushMessages = ' . json_encode( $data ) . ';'; |
| 90 | + |
| 91 | + if ( $parser ) { |
| 92 | + $parser->getOutput()->addHeadItem( Html::inlineScript( $js ) ); |
| 93 | + } else { |
| 94 | + global $wgOut; |
| 95 | + $wgOut->addInlineScript( $js ); |
| 96 | + } |
79 | 97 | } |
80 | 98 | |
81 | 99 | require_once 'Push_Settings.php'; |
Index: trunk/extensions/Push/includes/Push_Tab.php |
— | — | @@ -62,20 +62,49 @@ |
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
| 66 | + * Loads the needed JavaScript. |
| 67 | + * Takes care of non-RL compatibility. |
| 68 | + * |
| 69 | + * @since 0.1 |
| 70 | + */ |
| 71 | + protected static function loadJs() { |
| 72 | + global $wgOut; |
| 73 | + |
| 74 | + // For backward compatibility with MW < 1.17. |
| 75 | + if ( is_callable( array( $wgOut, 'addModules' ) ) ) { |
| 76 | + $wgOut->addModules( 'ext.push.tab' ); |
| 77 | + } |
| 78 | + else { |
| 79 | + global $egPushScriptPath; |
| 80 | + |
| 81 | + efPushAddJSLocalisation(); |
| 82 | + |
| 83 | + // TODO: jquery |
| 84 | + |
| 85 | + $wgOut->addHeadItem( |
| 86 | + 'ext.push.tab', |
| 87 | + Html::linkedScript( $egPushScriptPath . '/includes/ext.push.tab.js' ) |
| 88 | + ); |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + /** |
66 | 93 | * The function called if we're in index.php (as opposed to one of the |
67 | 94 | * special pages) |
| 95 | + * |
| 96 | + * @since 0.1 |
68 | 97 | */ |
69 | 98 | public static function displayPushPage( Article $article ) { |
70 | 99 | global $wgOut, $wgUser, $wgTitle; |
71 | 100 | |
72 | 101 | $wgOut->setPageTitle( wfMsgExt( 'push-tab-title', 'parsemag', $article->getTitle()->getText() ) ); |
73 | 102 | |
| 103 | + self::loadJs(); |
| 104 | + |
74 | 105 | $wgOut->addHTML( |
75 | 106 | Html::hidden( 'pageName', $wgTitle->getFullText(), array( 'id' => 'pageName' ) ) |
76 | 107 | ); |
77 | 108 | |
78 | | - $wgOut->addModules( 'ext.push.tab' ); |
79 | | - |
80 | 109 | if ( $wgUser->isAllowed( 'push' ) ) { |
81 | 110 | self::displayPushList(); |
82 | 111 | } |
— | — | @@ -88,6 +117,11 @@ |
89 | 118 | return false; |
90 | 119 | } |
91 | 120 | |
| 121 | + /** |
| 122 | + * Displays a list with all targets to which can be pushed. |
| 123 | + * |
| 124 | + * @since 0.1 |
| 125 | + */ |
92 | 126 | protected static function displayPushList() { |
93 | 127 | global $wgOut, $egPushTargets; |
94 | 128 | |
— | — | @@ -120,6 +154,16 @@ |
121 | 155 | ); |
122 | 156 | } |
123 | 157 | |
| 158 | + /** |
| 159 | + * Returns the HTML for a single push target. |
| 160 | + * |
| 161 | + * @since 0.1 |
| 162 | + * |
| 163 | + * @param string $name |
| 164 | + * @param string $url |
| 165 | + * |
| 166 | + * @return string |
| 167 | + */ |
124 | 168 | protected static function getPushItem( $name, $url ) { |
125 | 169 | return Html::rawElement( |
126 | 170 | 'tr', |
— | — | @@ -146,6 +190,11 @@ |
147 | 191 | // TODO: add edit and delete stuff |
148 | 192 | } |
149 | 193 | |
| 194 | + /** |
| 195 | + * Displays a form via which a new psuh item can be added. |
| 196 | + * |
| 197 | + * @since 0.1 |
| 198 | + */ |
150 | 199 | protected static function displayNewPushItem() { |
151 | 200 | global $wgOut; |
152 | 201 | |
Index: trunk/extensions/Push/includes/ext.push.tab.js |
— | — | @@ -7,6 +7,8 @@ |
8 | 8 | |
9 | 9 | $( document ).ready( function() { |
10 | 10 | |
| 11 | + // TODO: message b/c |
| 12 | + |
11 | 13 | $('.push-button').click(function() { |
12 | 14 | this.disabled = true; |
13 | 15 | this.innerHTML = mediaWiki.msg( 'push-button-pushing' ); |