r104438 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104437‎ | r104438 | r104439 >
Date:15:21, 28 November 2011
Author:cervidae
Status:deferred
Tags:
Comment:
Renaming SharedHelpNamespace to HelpCommons
Modified paths:
  • /trunk/extensions/HelpCommons (added) (history)
  • /trunk/extensions/HelpCommons/HelpCommons.i18n.php (added) (history)
  • /trunk/extensions/HelpCommons/HelpCommons.php (added) (history)
  • /trunk/extensions/HelpCommons/SharedHelpNamespace.i18n.php (deleted) (history)
  • /trunk/extensions/HelpCommons/SharedHelpNamespace.php (deleted) (history)

Diff [purge]

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

Follow-up revisions

RevisionCommit summaryAuthorDate
r104969r104438 : Consistency tweaks in preparation for adding extension to translate...raymond14:08, 2 December 2011
r104970r104438: Adding extension to translatewiki.netraymond14:09, 2 December 2011

Status & tagging log