Index: trunk/extensions/SharedHelpNamespace/SharedHelpNamespace.i18n.php |
— | — | @@ -0,0 +1,41 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalization file for the SharedHelpNamespace extension |
| 5 | + * |
| 6 | + * @since 1.0 |
| 7 | + * |
| 8 | + * @file SharedHelpNamespace.i18n.php |
| 9 | + * @ingroup SharedHelpNamespace |
| 10 | + * |
| 11 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 12 | + * @author Tim 'SVG' Weyer <SVG@Wikiunity.com> |
| 13 | + */ |
| 14 | + |
| 15 | +if (!defined('MEDIAWIKI')) { |
| 16 | + echo "THIS IS NOT VALID ENTRY POINT"; |
| 17 | + exit(1); |
| 18 | +} |
| 19 | + |
| 20 | +$messages = array(); |
| 21 | + |
| 22 | +/** English |
| 23 | + * @author SVG |
| 24 | + */ |
| 25 | +$messages['en'] = array( |
| 26 | + 'sharedhelpnamespace-desc' => 'Fetches the help namespace from a help wiki and includes them into other wikis on the wiki family', |
| 27 | +); |
| 28 | + |
| 29 | +/** Message documentation (Message documentation) |
| 30 | + * @author SVG |
| 31 | + */ |
| 32 | +$messages['qqq'] = array( |
| 33 | + 'sharedhelpnamespace-desc' => '{{desc}}', |
| 34 | +); |
| 35 | + |
| 36 | +/** German (Deutsch) |
| 37 | + * @author SVG |
| 38 | + */ |
| 39 | +$messages['de'] = array( |
| 40 | + 'sharedhelpnamespace-desc' => 'Nimmt den Hilfe-Namensraum aus einem Hilfe Wiki und bindet ihn in andere Wikis der Wiki-Family ein', |
| 41 | +); |
| 42 | + |
Property changes on: trunk/extensions/SharedHelpNamespace/SharedHelpNamespace.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 43 | + native |
Index: trunk/extensions/SharedHelpNamespace/SharedHelpNamespace.php |
— | — | @@ -0,0 +1,198 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | +* SharedHelpNamespace |
| 5 | +* |
| 6 | +* @package MediaWiki |
| 7 | +* @subpackage Extensions |
| 8 | +* |
| 9 | +* @author: Tim 'SVG' Weyer <SVG@Wikiunity.com> |
| 10 | +* |
| 11 | +* @copyright Copyright (C) 2011 Tim 'SVG' Weyer, Wikiunity |
| 12 | +* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 13 | +* |
| 14 | +*/ |
| 15 | + |
| 16 | +if (!defined('MEDIAWIKI')) { |
| 17 | + echo "THIS IS NOT VALID ENTRY POINT"; |
| 18 | + exit(1); |
| 19 | +} |
| 20 | + |
| 21 | +$wgExtensionCredits['specialpage'][] = array( |
| 22 | + 'name' => 'SharedHelpNamespace', |
| 23 | + 'author' => array( 'Tim Weyer' ), |
| 24 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:SharedHelpNamespace', |
| 25 | + 'descriptionmsg' => 'sharedhelpnamespace-desc', |
| 26 | + 'version' => '1.0', |
| 27 | +); |
| 28 | + |
| 29 | +// Internationalization |
| 30 | +$dir = dirname( __FILE__ ) . '/'; |
| 31 | +$wgExtensionMessagesFiles['SharedHelpNamespace'] = $dir . 'SharedHelpNamespace.i18n.php'; |
| 32 | + |
| 33 | +// Help wikis where the help namespace is fetched from |
| 34 | +$wgSharedHelpNamespaceFetchingWikis = array(); |
| 35 | + |
| 36 | +// Hooks |
| 37 | +$wgHooks['ShowMissingArticle'][] = 'wfSharedHelpNamespaceLoad'; |
| 38 | +$wgHooks['ArticlePageDataBefore'][] = 'wfSharedHelpNamespaceRedirectTalks'; |
| 39 | +$wgHooks['LinkBegin'][] = 'efSharedHelpNamespaceMakeBlueLinks'; |
| 40 | +$wgHooks['DoEditSectionLink'][] = 'wfSharedHelpNamespaceChangeEditSectionLink'; |
| 41 | +$wgHooks['getUserPermissionsErrors'][] = 'fnProtectSharedHelpNamespace'; |
| 42 | + |
| 43 | + |
| 44 | +function wfSharedHelpNamespaceLoad( $article ) { |
| 45 | + global $wgTitle, $wgOut, $wgContLang, $wgSharedHelpNamespaceFetchingWikis, $wgLanguageCode, $wgDBname; |
| 46 | + |
| 47 | + if ( $wgTitle->getNamespace() == NS_HELP ) { |
| 48 | + |
| 49 | + $replacewhitespace = str_replace( ' ', '_', $wgOut->getTitle() ); |
| 50 | + $title = str_replace( $wgContLang->namespaceNames[NS_HELP].':', '', $replacewhitespace ); |
| 51 | + |
| 52 | + foreach ( $wgSharedHelpNamespaceFetchingWikis as $language => $urls ) { |
| 53 | + foreach ( $urls as $url => $wgSharedHelpNamespaceFetchingWiki ) { |
| 54 | + if ( $wgLanguageCode == "$language" && $wgDBname != $wgSharedHelpNamespaceFetchingWiki ) { |
| 55 | + $dbr = wfGetDB( DB_SLAVE, array(), $wgSharedHelpNamespaceFetchingWiki ); |
| 56 | + $page = $dbr->query( 'SELECT page_title, page_namespace, page_latest FROM page WHERE page_namespace = 12 AND page_title = '.$dbr->addQuotes($title) ); |
| 57 | + $page = $dbr->fetchObject( $page ); |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + if ( !empty($page->page_title) ) { |
| 62 | + $rev = $dbr->select( 'revision', |
| 63 | + array( 'rev_id', 'rev_text_id' ), |
| 64 | + 'rev_id = '.$dbr->addQuotes($page->page_latest), |
| 65 | + __METHOD__ ); |
| 66 | + $rev = $dbr->fetchObject( $rev ); |
| 67 | + } else { |
| 68 | + return false; |
| 69 | + } |
| 70 | + $text = $dbr->select( 'text', |
| 71 | + array( 'old_id', 'old_text' ), |
| 72 | + 'old_id = '.$dbr->addQuotes($rev->rev_text_id), |
| 73 | + __METHOD__ ); |
| 74 | + $text = $dbr->fetchObject( $text ); |
| 75 | + |
| 76 | + if ( !empty($text->old_text) ) { |
| 77 | + echo $wgOut->addWikiText( $text->old_text ); |
| 78 | + return true; |
| 79 | + } else { |
| 80 | + return false; |
| 81 | + } |
| 82 | + |
| 83 | + } else { |
| 84 | + return false; |
| 85 | + } |
| 86 | + |
| 87 | +} |
| 88 | + |
| 89 | + |
| 90 | +function wfSharedHelpNamespaceRedirectTalks( $article, $fields ) { |
| 91 | + global $wgTitle, $wgOut, $wgContLang, $wgSharedHelpNamespaceFetchingWikis, $wgLanguageCode, $wgDBname; |
| 92 | + |
| 93 | + if ( $wgTitle->getNamespace() == NS_HELP_TALK ) { |
| 94 | + |
| 95 | + $replacewhitespace = str_replace( ' ', '_', $wgOut->getTitle() ); |
| 96 | + $title = str_replace( $wgContLang->namespaceNames[NS_HELP_TALK].':', '', $replacewhitespace ); |
| 97 | + |
| 98 | + foreach ( $wgSharedHelpNamespaceFetchingWikis as $language => $urls ) { |
| 99 | + foreach ( $urls as $url => $wgSharedHelpNamespaceFetchingWiki ) { |
| 100 | + if ( $wgLanguageCode == "$language" && $wgDBname != $wgSharedHelpNamespaceFetchingWiki ) { |
| 101 | + $dbr = wfGetDB( DB_SLAVE, array(), $wgSharedHelpNamespaceFetchingWiki ); |
| 102 | + $page = $dbr->query( 'SELECT page_title, page_namespace, page_latest FROM page WHERE page_namespace = 12 AND page_title = '.$dbr->addQuotes($title) ); |
| 103 | + $page = $dbr->fetchObject( $page ); |
| 104 | + } |
| 105 | + if ( !empty($page->page_title) ) { |
| 106 | + if ( $page->page_title == $title && !$wgTitle->exists() ) { |
| 107 | + $sharedHelpRedirectTalk = Title::newFromText( $url . '/index.php?title=' . str_replace( ' ', '_', $wgOut->getTitle() ) ); |
| 108 | + $redirectTalkPage = $sharedHelpRedirectTalk->getFullText(); |
| 109 | + $wgOut->redirect( $redirectTalkPage ); |
| 110 | + return true; |
| 111 | + } else { |
| 112 | + return false; |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + return true; |
| 118 | + } else { |
| 119 | + return false; |
| 120 | + } |
| 121 | +} |
| 122 | + |
| 123 | + |
| 124 | +function efSharedHelpNamespaceMakeBlueLinks( $skin, $target, &$text, &$customAttribs, &$query, &$options, &$ret ) { |
| 125 | + |
| 126 | + if ( is_null( $target ) ) { |
| 127 | + return true; |
| 128 | + } |
| 129 | + |
| 130 | + // only affects non-existing Help pages |
| 131 | + if ( $target->getNamespace() != NS_HELP || $target->exists() ) { |
| 132 | + return true; |
| 133 | + } |
| 134 | + |
| 135 | + // remove "broken" assumption/override |
| 136 | + $brokenKey = array_search( 'broken', $options ); |
| 137 | + if ( $brokenKey !== false ) { |
| 138 | + unset( $options[$brokenKey] ); |
| 139 | + } |
| 140 | + |
| 141 | + // make the link "blue" |
| 142 | + $options[] = 'known'; |
| 143 | + |
| 144 | + return true; |
| 145 | +} |
| 146 | + |
| 147 | + |
| 148 | +function wfSharedHelpNamespaceChangeEditSectionLink( $skin, $title, $section, $tooltip, $result, $lang = false ) { |
| 149 | + global $wgSharedHelpNamespaceFetchingWikis, $wgLanguageCode, $wgDBname; |
| 150 | + |
| 151 | + foreach ( $wgSharedHelpNamespaceFetchingWikis as $language => $urls ) { |
| 152 | + foreach ( $urls as $url => $wgSharedHelpNamespaceFetchingWiki ) { |
| 153 | + if ( $wgLanguageCode == "$language" && $wgDBname != $wgSharedHelpNamespaceFetchingWiki ) { |
| 154 | + $result = '<span class="editsection">[<a href="'.$url.'/index.php?title='.str_replace( ' ', '_', $title ).'&action=edit&section='.$section.'" title="'.wfMsg( 'editsectionhint', $tooltip ).'">'.wfMsg( 'editsection' ).'</a>]</span>'; |
| 155 | + } |
| 156 | + } |
| 157 | + } |
| 158 | + return true; |
| 159 | +} |
| 160 | + |
| 161 | + |
| 162 | +function fnProtectSharedHelpNamespace( &$title, &$user, $action, &$result) { |
| 163 | + global $wgSharedHelpNamespaceFetchingWikis, $wgDBname; |
| 164 | + |
| 165 | + foreach ( $wgSharedHelpNamespaceFetchingWikis as $language => $urls ) { |
| 166 | + foreach ( $urls as $url => $wgSharedHelpNamespaceFetchingWiki ) { |
| 167 | + // only protect Help pages on non-help-pages-fetching wikis |
| 168 | + if( $wgDBname != $wgSharedHelpNamespaceFetchingWiki ) { |
| 169 | + |
| 170 | + // block actions 'edit' and 'create' |
| 171 | + if( $action != 'edit' && $action != 'create' ) { |
| 172 | + return true; |
| 173 | + } |
| 174 | + |
| 175 | + $dbr = wfGetDB(DB_SLAVE, array(), $wgSharedHelpNamespaceFetchingWiki); |
| 176 | + $res = $dbr->query( 'SELECT page_title, page_namespace FROM page WHERE page_namespace = 12 AND page_title = '.$dbr->addQuotes(str_replace( ' ', '_', $title->getText())) ); |
| 177 | + |
| 178 | + if ( $dbr->numRows($res) < 1 ) { |
| 179 | + return true; |
| 180 | + } |
| 181 | + |
| 182 | + $ns = $title->getNamespace(); |
| 183 | + |
| 184 | + // check namespaces |
| 185 | + if( $ns == 12 || $ns == 13 ) { |
| 186 | + |
| 187 | + // error message if action is blocked |
| 188 | + $result = array('protectedpagetext'); |
| 189 | + |
| 190 | + // bail, and stop the request |
| 191 | + return false; |
| 192 | + } |
| 193 | + } |
| 194 | + } |
| 195 | + } |
| 196 | + |
| 197 | + return true; |
| 198 | +} |
| 199 | + |
Property changes on: trunk/extensions/SharedHelpNamespace/SharedHelpNamespace.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 200 | + native |