r28569 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r28568‎ | r28569 | r28570 >
Date:21:11, 16 December 2007
Author:tlaqua
Status:old
Tags:
Comment:
* Fix phpBB hooks (proper handling of previous_hook_result and proper hook returns)
* Add Return to Forum links when toForum query string argument exists in the
* Switch to $wgServer for toWiki arguments in #phpbblink output
Modified paths:
  • /trunk/extensions/phpbbData/hook_!OutputBufferHook.php (modified) (history)
  • /trunk/extensions/phpbbData/hook_handleFromWikiQuery.php (modified) (history)
  • /trunk/extensions/phpbbData/phpbbData.php (modified) (history)

Diff [purge]

Index: trunk/extensions/phpbbData/hook_handleFromWikiQuery.php
@@ -1,5 +1,11 @@
22 <?php
3 -function efPhpbbData_handleToWiki(&$hooks, $outputCache) {
 3+
 4+function efPhpbbData_handleToWiki(&$hook, $outputCache) {
 5+ $result = $hook->previous_hook_result('BeforePageDisplay');
 6+ if (!empty($result['result'])) {
 7+ $outputCache = $result['result'];
 8+ }
 9+
410 if ( isset( $_REQUEST['toWiki'] ) ) {
511
612 $domDoc = new DOMDocument();
@@ -29,12 +35,17 @@
3036
3137 return $domDoc->saveHTML();
3238 } else {
33 - return false;
 39+ return $outputCache;
3440 }
3541 }
3642 $phpbb_hook->register('BeforePageDisplay', 'efPhpbbData_handleToWiki');
3743
38 -function efPhpbbData_doTokenReplacement(&$hooks, $outputCache) {
 44+function efPhpbbData_doTokenReplacement(&$hook, $outputCache) {
 45+ $result = $hook->previous_hook_result('BeforePageDisplay');
 46+ if (!empty($result['result'])) {
 47+ $outputCache = $result['result'];
 48+ }
 49+
3950 $validQueryKeys = array('f','t');
4051 $queryString = '';
4152
@@ -48,7 +59,9 @@
4960 }
5061
5162 $tokens = array(
52 - '{PAGE_URL_LOCAL_ESCAPED}' => urlencode( $_SERVER['PHP_SELF'] . $queryString ) );
 63+ '{PAGE_URL_LOCAL_ESCAPED}' => urlencode( $_SERVER['PHP_SELF'] . $queryString ),
 64+ urlencode('{PAGE_URL_LOCAL_ESCAPED}') => urlencode( $_SERVER['PHP_SELF'] . $queryString ),
 65+ );
5366
5467 foreach ($tokens as $key => $value) {
5568 $outputCache = str_replace($key,$value,$outputCache);
Index: trunk/extensions/phpbbData/hook_!OutputBufferHook.php
@@ -1,25 +1,32 @@
22 <?php
 3+class OutputBufferHook {
 4+ function hookTemplateDisplay(&$hook, $handle, $include_once = true) {
 5+ $result = $hook->previous_hook_result(array('template', 'display'));
36
4 -class OutputBufferHook {
5 - function hookTemplateDisplay(&$hooks, $handle, $include_once = true) {
67 ob_start();
 8+ return $result['result'];
79 }
810
9 - function hookExitHandler(&$hooks) {
 11+ function hookExitHandler(&$hook) {
1012 $outputCache = ob_get_contents();
1113 ob_end_clean();
1214
 15+ $result = $hook->previous_hook_result('exit_handler');
 16+
1317 global $phpbb_hook;
14 - if ( !empty($phpbb_hook) && $phpbb_hook->call_hook('BeforePageDisplay', $outputCache) ) {
15 - if ($phpbb_hook->hook_return('BeforePageDisplay')) {
16 - $hookReturn = $phpbb_hook->hook_return_result('BeforePageDisplay');
 18+ if ( !empty($hook) && $hook->call_hook('BeforePageDisplay', $outputCache) ) {
 19+ if ($hook->hook_return('BeforePageDisplay')) {
 20+ $hookReturn = $hook->hook_return_result('BeforePageDisplay');
1721 if ($hookReturn) {
 22+ //return $hookReturn;
1823 $outputCache = $hookReturn;
1924 }
2025 }
2126 }
2227
2328 eval(' ?>' . $outputCache . '<?php ');
 29+
 30+ return $result['result'];
2431 }
2532 }
2633
Index: trunk/extensions/phpbbData/phpbbData.php
@@ -20,7 +20,8 @@
2121 );
2222
2323 $wgExtensionFunctions[] = 'efPhpbbData_Setup';
24 -$wgHooks['LanguageGetMagic'][] = 'efPhpbbData_LanguageGetMagic';
 24+$wgHooks['LanguageGetMagic' ][] = 'efPhpbbData_LanguageGetMagic';
 25+$wgHooks['BeforePageDisplay'][] = 'efPhpbbData_BeforePageDisplay';
2526
2627 function efPhpbbData_Setup() {
2728 global $wgParser, $wgMessageCache;
@@ -38,6 +39,32 @@
3940 return true;
4041 }
4142
 43+function efPhpbbData_BeforePageDisplay(&$out) {
 44+ global $wgRequest;
 45+
 46+ # Check for toForum query string argument
 47+ if ($wgRequest->getText('toForum')) {
 48+ # Make a link that returns to the forum page the user
 49+ # just came from
 50+ $link = '<div style="float: right;"><a href="' .
 51+ htmlspecialchars($wgRequest->getText('toForum')) .
 52+ '">&rarr; Return to Forum</a></div>' . $text;
 53+
 54+ # Add the Return to Forum link in to the page title
 55+ # Since we're making it render HTML in a second,
 56+ # encode special characters in the old page title
 57+ $out->mPagetitle = $link . htmlspecialchars($out->getPageTitle());
 58+
 59+ # Content of mPageLinkTitle doesn't actually get displayed
 60+ # When there is a value in mPageLinkTitle, the template
 61+ # forces HTML rather than Text rendering of $out->mPagetitle
 62+ $out->mPageLinkTitle = $out->mPagetitle;
 63+ }
 64+
 65+ # Be nice.
 66+ return true;
 67+}
 68+
4269 function efPhpbbData_LanguageGetMagic( &$magicWords, $langCode ) {
4370 # Add the magic word
4471 # The first array element is case sensitive, in this case it is not case sensitive
@@ -49,16 +76,16 @@
5077 }
5178
5279 function efPhpbbData_makeTopicWikiLink($display_text='', $forum_id=null, $topic_id=null, $post_id=null) {
53 - global $wgPhpbbDataRootPath, $wgTitle;
 80+ global $wgPhpbbDataRootPath, $wgTitle, $wgServer;
5481
5582 if (!empty($post_id)) {
56 - $urlText = "{{SERVER}}/{$wgPhpbbDataRootPath}viewpost.php?p={$post_id}&toWiki=" .
 83+ $urlText = "{$wgServer}/{$wgPhpbbDataRootPath}viewpost.php?p={$post_id}&toWiki=" .
5784 urlencode($wgTitle->escapeLocalURL());
5885 } elseif (!empty($topic_id)) {
59 - $urlText = "{{SERVER}}/{$wgPhpbbDataRootPath}viewtopic.php?t={$topic_id}&toWiki=" .
 86+ $urlText = "{$wgServer}/{$wgPhpbbDataRootPath}viewtopic.php?t={$topic_id}&toWiki=" .
6087 urlencode($wgTitle->escapeLocalURL());
6188 } elseif (!empty($forum_id)) {
62 - $urlText = "{{SERVER}}/{$wgPhpbbDataRootPath}viewforum.php?t={$forum_id}&toWiki=" .
 89+ $urlText = "{$wgServer}/{$wgPhpbbDataRootPath}viewforum.php?t={$forum_id}&toWiki=" .
6390 urlencode($wgTitle->escapeLocalURL());
6491 }
6592

Status & tagging log