http://www.mediawiki.org/wiki/Special:Code/MediaWiki/99352
Revision: 99352 Author: ashley Date: 2011-10-09 14:10:46 +0000 (Sun, 09 Oct 2011) Log Message: ----------- WikiForum: *add ResourceLoader support *bump version number *drop backwards compatibility with pre-1.18 MediaWikis *add a few FIXME comments to the code *remove some unused globals *call Linker methods statically *add id "wpTextbox1" to the editing <textarea> so that clicking on an edit button actually *does* something (this ID has been hardcoded into mediawiki.action.edit.js for some odd reason) *add support for creating the DB tables when the user runs update.php Modified Paths: -------------- trunk/extensions/WikiForum/SpecialWikiForum.php trunk/extensions/WikiForum/WikiForum.alias.php trunk/extensions/WikiForum/WikiForum.php trunk/extensions/WikiForum/WikiForumClass.php trunk/extensions/WikiForum/WikiForumGui.php trunk/extensions/WikiForum/WikiForumHooks.php Modified: trunk/extensions/WikiForum/SpecialWikiForum.php =================================================================== --- trunk/extensions/WikiForum/SpecialWikiForum.php 2011-10-09 13:15:27 UTC (rev 99351) +++ trunk/extensions/WikiForum/SpecialWikiForum.php 2011-10-09 14:10:46 UTC (rev 99352) @@ -38,7 +38,7 @@ $values = array(); // Add CSS - $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/WikiForum/styles.css' ); + $wgOut->addModuleStyles( 'ext.wikiForum' ); // If a parameter to the special page is specified, check its type // and either display a forum (if parameter is a number) or a thread Modified: trunk/extensions/WikiForum/WikiForum.alias.php =================================================================== --- trunk/extensions/WikiForum/WikiForum.alias.php 2011-10-09 13:15:27 UTC (rev 99351) +++ trunk/extensions/WikiForum/WikiForum.alias.php 2011-10-09 14:10:46 UTC (rev 99352) @@ -16,9 +16,4 @@ /** Finnish (Suomi) */ $specialPageAliases['fi'] = array( 'WikiForum' => array( 'WikiFoorumi', 'Foorumi' ), -); - -/** - * For backwards compatibility with MediaWiki 1.15 and earlier. - */ -$aliases =& $specialPageAliases; \ No newline at end of file +); \ No newline at end of file Modified: trunk/extensions/WikiForum/WikiForum.php =================================================================== --- trunk/extensions/WikiForum/WikiForum.php 2011-10-09 13:15:27 UTC (rev 99351) +++ trunk/extensions/WikiForum/WikiForum.php 2011-10-09 14:10:46 UTC (rev 99352) @@ -7,7 +7,7 @@ * @author Michael Chlebek * @author Jack Phoenix <j...@countervandalism.net> * @date 6 October 2011 - * @version 1.2-SW + * @version 1.2.1-SW * @copyright Copyright © 2010 Unidentify Studios * @copyright Copyright © 2010-2011 Jack Phoenix <j...@countervandalism.net> * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 3.0 or later @@ -35,7 +35,7 @@ 'path' => __FILE__, 'name' => 'WikiForum', 'author' => array( 'Michael Chlebek', 'Jack Phoenix' ), - 'version' => '1.2-SW', + 'version' => '1.2.1-SW', 'url' => 'http://www.mediawiki.org/wiki/Extension:WikiForum', 'descriptionmsg' => 'wikiforum-desc' ); @@ -81,8 +81,16 @@ */ ); +// ResourceLoader support for MediaWiki 1.17+ +$wgResourceModules['ext.wikiForum'] = array( + 'styles' => 'styles.css', + 'localBasePath' => dirname( __FILE__ ), + 'remoteExtPath' => 'WikiForum', +); + // Hooked functions $wgHooks['ParserFirstCallInit'][] = 'WikiForumHooks::registerParserHooks'; $wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] = 'WikiForumHooks::addNavigationLink'; $wgHooks['SkinTemplateToolboxEnd'][] = 'WikiForumHooks::addNavigationLinkToToolbox'; -$wgHooks['BeforePageDisplay'][] = 'WikiForumHooks::addStyles'; \ No newline at end of file +$wgHooks['BeforePageDisplay'][] = 'WikiForumHooks::addStyles'; +$wgHooks['LoadExtensionSchemaUpdates'][] = 'WikiForumHooks::addTables'; \ No newline at end of file Modified: trunk/extensions/WikiForum/WikiForumClass.php =================================================================== --- trunk/extensions/WikiForum/WikiForumClass.php 2011-10-09 13:15:27 UTC (rev 99351) +++ trunk/extensions/WikiForum/WikiForumClass.php 2011-10-09 14:10:46 UTC (rev 99352) @@ -3,6 +3,9 @@ * Main class for WikiForum extension, contains all the logic to manage forums, * categories, individual topics, etc. * + * @todo FIXME: if this class isn't split into multiple classes soon, it'll be + * OVER 9000 lines long in no time... + * * @file * @ingroup Extensions */ @@ -22,6 +25,9 @@ public static function findThreadIDByTitle( $titleText ) { // Titles are stored with spaces in the DB but the query will otherwise // use friggin' underscores... + // @todo FIXME: come to think of it, this *is* awfully hacky... + // Maybe construct a Title object out of $titleText and use its + // getDBkey() method here instead? $titleText = str_replace( '_', ' ', $titleText ); $dbr = wfGetDB( DB_SLAVE ); @@ -2340,10 +2346,9 @@ global $wgContLang, $wgUser; if ( $username ) { - $sk = $wgUser->getSkin(); - $retVal = $sk->makeLinkObj( + $retVal = Linker::link( Title::newFromText( $wgContLang->getNsText( NS_USER ) . ':' . $username ), - htmlspecialchars( $username ) + htmlspecialchars( $username ) // @todo FIXME/CHECKME: double-escaping or not? ); $groups = User::newFromName( $username )->getEffectiveGroups(); Modified: trunk/extensions/WikiForum/WikiForumGui.php =================================================================== --- trunk/extensions/WikiForum/WikiForumGui.php 2011-10-09 13:15:27 UTC (rev 99351) +++ trunk/extensions/WikiForum/WikiForumGui.php 2011-10-09 14:10:46 UTC (rev 99352) @@ -261,14 +261,27 @@ $message . '</td></tr>'; } + /** + * Get the editor form for writing a new thread, a reply, etc. + * + * @param $type String: either 'addthread' or 'editthread', depending on + * what we are doing to a thread. + * @param $action Array: action parameter(s) to be passed to the WikiForum + * special page call (i.e. array( 'thread' => $threadId )) + * @param $input String: usually whatever WikiForumGui::getInput() returns + * @param $height String: height of the textarea, i.e. '10em' + * @param $text_prev + * @param $saveButton String: save button text + * @return String: HTML + */ public static function getWriteForm( $type, $action, $input, $height, $text_prev, $saveButton ) { - global $wgOut, $wgUser, $wgScriptPath, $wgWikiForumAllowAnonymous; + global $wgOut, $wgUser, $wgWikiForumAllowAnonymous; $output = ''; if ( $wgWikiForumAllowAnonymous || $wgUser->isLoggedIn() ) { // Required for the edit buttons to display - $wgOut->addScriptFile( 'edit.js' ); + $wgOut->addModules( 'mediawiki.action.edit' ); $toolbar = EditPage::getEditToolbar(); $specialPage = SpecialPage::getTitleFor( 'WikiForum' ); @@ -278,7 +291,7 @@ <td>' . $toolbar . '</td> </tr> <tr> - <td><textarea name="frmText" style="height: ' . $height . ';">' . $text_prev . '</textarea></td> + <td><textarea name="frmText" id="wpTextbox1" style="height: ' . $height . ';">' . $text_prev . '</textarea></td> </tr> <tr> <td> Modified: trunk/extensions/WikiForum/WikiForumHooks.php =================================================================== --- trunk/extensions/WikiForum/WikiForumHooks.php 2011-10-09 13:15:27 UTC (rev 99351) +++ trunk/extensions/WikiForum/WikiForumHooks.php 2011-10-09 14:10:46 UTC (rev 99352) @@ -64,7 +64,7 @@ * Takes only the following argument: num (used as the LIMIT for the SQL query) */ public static function renderWikiForumList( $input, $args, $parser, $frame ) { - global $wgUser, $wgLang, $wgScriptPath; + global $wgLang; if ( !isset( $args['num'] ) ) { $args['num'] = 5; @@ -123,21 +123,20 @@ } $specialPageObj = SpecialPage::getTitleFor( 'WikiForum' ); - $sk = $wgUser->getSkin(); // Build the links to the category and forum pages by using Linker - $categoryLink = $sk->link( + $categoryLink = Linker::link( $specialPageObj, $thread->wfc_category_name, array(), array( 'category' => $thread->wfc_category ) ); - $forumLink = $sk->link( + $forumLink = Linker::link( $specialPageObj, $thread->wff_forum_name, array(), array( 'forum' => $thread->wff_forum ) ); - $threadLink = $sk->link( + $threadLink = Linker::link( $specialPageObj, $thread->wft_thread_name, array(), @@ -172,7 +171,7 @@ * query), replies (whether to display replies) */ public static function renderWikiForumThread( $input, $args, $parser, $frame ) { - global $wgOut, $wgLang, $wgScriptPath; + global $wgOut, $wgLang; if ( isset( $args['id'] ) && $args['id'] > 0 ) { $dbr = wfGetDB( DB_SLAVE ); @@ -284,11 +283,34 @@ public static function addStyles( &$out, &$sk ) { static $cssDone = false; if ( !$cssDone ) { - global $wgScriptPath; - $out->addExtensionStyle( $wgScriptPath . '/extensions/WikiForum/styles.css' ); + $out->addModuleStyles( 'ext.wikiForum' ); $cssDone = true; } return true; } + /** + * Adds the four new tables to the database when the user runs + * maintenance/update.php. + * + * @param $updater Object: instance of DatabaseUpdater + * @return Boolean: true + */ + public static function addTables( $updater = null ) { + $dir = dirname( __FILE__ ); + $file = "$dir/wikiforum.sql"; + if ( $updater === null ) { + global $wgExtNewTables; + $wgExtNewTables[] = array( 'wikiforum_category', $file ); + $wgExtNewTables[] = array( 'wikiforum_forums', $file ); + $wgExtNewTables[] = array( 'wikiforum_threads', $file ); + $wgExtNewTables[] = array( 'wikiforum_replies', $file ); + } else { + $updater->addExtensionUpdate( array( 'addTable', 'wikiforum_category', $file, true ) ); + $updater->addExtensionUpdate( array( 'addTable', 'wikiforum_forums', $file, true ) ); + $updater->addExtensionUpdate( array( 'addTable', 'wikiforum_threads', $file, true ) ); + $updater->addExtensionUpdate( array( 'addTable', 'wikiforum_replies', $file, true ) ); + } + return true; + } } \ No newline at end of file _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs