r81543 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81542‎ | r81543 | r81544 >
Date:21:25, 4 February 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Removed hardcoded WP stuff and added a setting for multiple wikis
Modified paths:
  • /trunk/extensions/IncludeWP/IncludeWP.class.php (modified) (history)
  • /trunk/extensions/IncludeWP/IncludeWP.settings.php (modified) (history)
  • /trunk/extensions/IncludeWP/ext.incwp.js (modified) (history)

Diff [purge]

Index: trunk/extensions/IncludeWP/IncludeWP.settings.php
@@ -20,3 +20,12 @@
2121 die( 'Not an entry point.' );
2222 }
2323
 24+$egIncWPWikis = array();
 25+
 26+$egIncWPWikis['wikipedia'] = array(
 27+ 'name' => 'Wikipedia',
 28+ 'path' => 'http://en.wikipedia.org/w',
 29+ 'url' => 'http://en.wikipedia.org/wiki',
 30+ 'licencename' => 'CC-BY-SA',
 31+ 'licenceurl' => 'http://creativecommons.org/licenses/by-sa/3.0/'
 32+);
Index: trunk/extensions/IncludeWP/IncludeWP.class.php
@@ -57,11 +57,17 @@
5858 * @return array
5959 */
6060 protected function getParameterInfo( $type ) {
 61+ global $egIncWPWikis;
 62+
6163 $params = array();
6264
6365 $params['page'] = new Parameter( 'page' );
6466 $params['page']->setDescription( wfMsg( 'includewp-include-par-page' ) );
6567
 68+ $params['wiki'] = new Parameter( 'wiki' );
 69+ $params['wiki']->setDefault( array_shift( array_keys( $egIncWPWikis ) ) );
 70+ $params['wiki']->addCriteria( new CriterionInArray( array_keys( $egIncWPWikis ) ) );
 71+
6672 return $params;
6773 }
6874
@@ -74,7 +80,7 @@
7581 * @return array
7682 */
7783 protected function getDefaultParameters( $type ) {
78 - return array( 'page' );
 84+ return array( 'page', 'wiki' );
7985 }
8086
8187 /**
@@ -100,7 +106,7 @@
101107 'pageid' => $nr,
102108 'class' => 'includewp-loading',
103109 'page' => $parameters['page'],
104 - 'wiki' => 'http://en.wikipedia.org/w' // TODO
 110+ 'wiki' => $parameters['wiki']
105111 ),
106112 wfMsgForContent( 'includewp-loading-page' )
107113 );
@@ -142,6 +148,8 @@
143149
144150 $loadedJs = true;
145151
 152+ $this->addJSWikiData();
 153+
146154 // For backward compatibility with MW < 1.17.
147155 if ( is_callable( array( $this->parser->getOutput(), 'addModules' ) ) ) {
148156 $this->parser->getOutput()->addModules( 'ext.incwp' );
@@ -164,6 +172,21 @@
165173 }
166174
167175 /**
 176+ * Ouput the wiki data needed to display the licence links.
 177+ *
 178+ * @since 0.1
 179+ */
 180+ protected function addJSWikiData() {
 181+ global $egIncWPWikis;
 182+
 183+ $this->parser->getOutput()->addHeadItem(
 184+ Html::inlineScript(
 185+ 'var wgIncWPWikis =' . json_encode( $egIncWPWikis ) . ';'
 186+ )
 187+ );
 188+ }
 189+
 190+ /**
168191 * Adds the needed JS messages to the page output.
169192 * This is for backward compatibility with pre-RL MediaWiki.
170193 *
Index: trunk/extensions/IncludeWP/ext.incwp.js
@@ -38,7 +38,7 @@
3939 */
4040 function loadPage( sender ) {
4141 $.getJSON(
42 - sender.attr( 'wiki' ) + '/api.php?callback=?',
 42+ window.wgIncWPWikis[sender.attr( 'wiki' )].path + '/api.php?callback=?',
4343 {
4444 'action': 'query',
4545 'format': 'json',
@@ -162,14 +162,16 @@
163163 * @param integer pageId
164164 */
165165 function showCopyright( pageName, pageId ) {
 166+ var wiki = window.wgIncWPWikis[$( '#includewp-loading-' + pageId ).attr( 'wiki' )];
 167+
166168 var licenceHtml = mediaWiki.msg( // TODO: make non WP-specific
167169 'includewp-licence-notice',
168 - 'Wikipedia',
169 - 'http://en.wikipedia.org/wiki/' + pageName,
 170+ wiki.name,
 171+ wiki.url + '/' + pageName,
170172 pageName,
171 - 'http://creativecommons.org/licenses/by-sa/3.0/',
172 - 'CC-BY-SA',
173 - 'http://en.wikipedia.org/wiki/' + pageName + '?action=history'
 173+ wiki.licenceurl,
 174+ wiki.licencename,
 175+ wiki.url + '/' + pageName + '?action=history'
174176 );
175177
176178 $( '#includewp-copyright-' + pageId ).html( licenceHtml );

Status & tagging log