r67408 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67407‎ | r67408 | r67409 >
Date:16:45, 5 June 2010
Author:tisane
Status:deferred
Tags:
Comment:
Change name. Integration->InterwikiIntegration
Modified paths:
  • /trunk/extensions/Integration (deleted) (history)
  • /trunk/extensions/InterwikiIntegration (added) (history)
  • /trunk/extensions/InterwikiIntegration/Integration.hooks.php (deleted) (history)
  • /trunk/extensions/InterwikiIntegration/Integration.i18n.php (deleted) (history)
  • /trunk/extensions/InterwikiIntegration/Integration.php (deleted) (history)
  • /trunk/extensions/InterwikiIntegration/InterwikiIntegration.hooks.php (added) (history)
  • /trunk/extensions/InterwikiIntegration/InterwikiIntegration.i18n.php (added) (history)
  • /trunk/extensions/InterwikiIntegration/InterwikiIntegration.php (added) (history)
  • /trunk/extensions/InterwikiIntegration/SpecialIntegration.php (deleted) (history)
  • /trunk/extensions/InterwikiIntegration/SpecialInterwikiIntegration.php (added) (history)
  • /trunk/extensions/InterwikiIntegration/integration-db.sql (deleted) (history)
  • /trunk/extensions/InterwikiIntegration/integration-namespace.sql (deleted) (history)
  • /trunk/extensions/InterwikiIntegration/interwikiintegration-db.sql (added) (history)
  • /trunk/extensions/InterwikiIntegration/interwikiintegration-namespace.sql (added) (history)

Diff [purge]

Index: trunk/extensions/InterwikiIntegration/InterwikiIntegration.php
@@ -0,0 +1,50 @@
 2+<?php
 3+/**
 4+ * InterwikiIntegration extension by Tisane
 5+ * URL: http://www.mediawiki.org/wiki/Extension:InterwikiIntegration
 6+ *
 7+ * This program is free software. You can redistribute it and/or modify
 8+ * it under the terms of the GNU General Public License as published by
 9+ * the Free Software Foundation; either version 2 of the License, or
 10+ * (at your option) any later version. You can also redistribute it and/or
 11+ * modify it under the terms of the Creative Commons Attribution 3.0 license
 12+ * or any later version.
 13+ *
 14+ * This extension causes interwiki links to turn blue if the target page exists on
 15+ * the target wiki, and red if it does not. It only works when the target wiki
 16+ * is on the same wiki farm and is set up with this same extension.
 17+ */
 18+
 19+/* Alert the user that this is not a valid entry point to MediaWiki if they try to access the
 20+special pages file directly.*/
 21+
 22+if ( !defined( 'MEDIAWIKI' ) ) {
 23+ echo <<<EOT
 24+ To install the InterwikiIntegration extension, put the following line in LocalSettings.php:
 25+ require( "extensions/InterwikiIntegration/InterwikiIntegration.php" );
 26+EOT;
 27+ exit( 1 );
 28+}
 29+
 30+$wgExtensionCredits['other'][] = array(
 31+ 'path' => __FILE__,
 32+ 'name' => 'Interwiki Integration',
 33+ 'author' => 'Tisane',
 34+ 'url' => 'http://www.mediawiki.org/wiki/Extension:InterwikiIntegration',
 35+ 'descriptionmsg' => 'integration-desc',
 36+ 'version' => '1.0.1',
 37+);
 38+
 39+$dir = dirname( __FILE__ ) . '/';
 40+$wgAutoloadClasses['InterwikiIntegrationHooks'] = $dir . 'InterwikiIntegration.hooks.php';
 41+$wgAutoloadClasses['PopulateInterwikiIntegrationTable'] = "$dir/SpecialInterwikiIntegration.php";
 42+$wgExtensionMessagesFiles['InterwikiIntegration'] = $dir . 'InterwikiIntegration.i18n.php';
 43+$wgHooks['LoadExtensionSchemaUpdates'][] = 'InterwikiIntegrationHooks::InterwikiIntegrationCreateTable';
 44+$wgHooks['LinkBegin'][] = 'InterwikiIntegrationHooks::InterwikiIntegrationLink';
 45+$wgSpecialPages['PopulateInterwikiIntegrationTable'] = 'PopulateInterwikiIntegrationTable';
 46+$wgSharedTables[] = 'integration_db';
 47+$wgSharedTables[] = 'integration_namespace';
 48+$wgInterwikiIntegrationBrokenLinkStyle = "color: red";
 49+
 50+$wgAvailableRights[] = 'integration';
 51+$wgGroupPermissions['bureaucrat']['integration'] = true;
\ No newline at end of file
Property changes on: trunk/extensions/InterwikiIntegration/InterwikiIntegration.php
___________________________________________________________________
Name: svn:eol-style
152 + native
Index: trunk/extensions/InterwikiIntegration/SpecialInterwikiIntegration.php
@@ -0,0 +1,106 @@
 2+<?php
 3+class PopulateInterwikiIntegrationTable extends SpecialPage {
 4+ function __construct() {
 5+ parent::__construct( 'PopulateInterwikiIntegrationTable','integration' );
 6+ wfLoadExtensionMessages( 'InterwikiIntegration' );
 7+ }
 8+
 9+ function execute( $par ) {
 10+ global $wgRequest, $wgOut, $wgUser, $wgLanguageCode
 11+ ,$wgLocalisationCacheConf, $wgExtraNamespaces
 12+ , $wgLocalDatabases, $wgInterwikiIntegrationPrefix
 13+ , $wgMetaNamespace, $wgMetaNamespaceTalk
 14+ , $wgSitename, $wgInterwikiIntegrationPWD;
 15+ if ( !$this->userCanExecute($wgUser) ) {
 16+ $this->displayRestrictionError();
 17+ return;
 18+ }
 19+ $dbr = wfGetDB( DB_SLAVE );
 20+ $dbw = wfGetDB( DB_MASTER );
 21+
 22+ $localDBname = $dbr -> getProperty ( 'mDBname' );
 23+
 24+ $dbw->delete ( 'integration_db', '*' );
 25+ if ( isset ( $wgInterwikiIntegrationPrefix ) ) {
 26+
 27+ foreach ( $wgInterwikiIntegrationPrefix as $thisPrefix => $thisDatabase ) {
 28+ $thisPWD = 0;
 29+ if ( isset ( $wgInterwikiIntegrationPWD[$thisDatabase])
 30+ && $wgInterwikiIntegrationPWD[$thisDatabase] == true) {
 31+ $thisPWD = '1';
 32+ }
 33+ $newDatabaseRow = array (
 34+ 'integration_dbname' => $thisDatabase,
 35+ 'integration_prefix' => $thisPrefix,
 36+ 'integration_pwd' => $thisPWD
 37+ );
 38+ $dbw->insert ( 'integration_db', $newDatabaseRow );
 39+
 40+ foreach ( $wgLocalDatabases as $thisDB ) {
 41+ $foreignDbr = wfGetDB ( DB_SLAVE, array(), $thisDB );
 42+ $foreignDbw = wfGetDB ( DB_MASTER, array(), $thisDB );
 43+
 44+ if ( $thisDB != $localDBname && $thisDatabase == $localDBname ) {
 45+ $foreignResult = $foreignDbr->selectRow(
 46+ 'interwiki',
 47+ 'iw_prefix',
 48+ array( "iw_prefix" => $thisPrefix )
 49+ );
 50+ if ( !$foreignResult ) {
 51+ $localTitle = Title::newFromText ( 'Foobarfoobar' );
 52+ $localURL = $localTitle->getFullURL();
 53+ $localURL = str_replace ( 'Foobarfoobar','$1',$localURL );
 54+ $newInterwikiRow = array (
 55+ 'iw_prefix' => $thisPrefix,
 56+ 'iw_url' => $localURL,
 57+ 'iw_local' => '1',
 58+ 'iw_trans' => '0'
 59+ );
 60+ $foreignDbw->insert ( 'interwiki', $newInterwikiRow );
 61+ }
 62+ }
 63+ }
 64+ }
 65+ }
 66+
 67+ $myCache = new LocalisationCache ( $wgLocalisationCacheConf );
 68+
 69+ $namespaceNames = $myCache->getItem ( $wgLanguageCode,'namespaceNames' );
 70+ $namespaceNames[NS_PROJECT] = $wgMetaNamespace;
 71+ $namespaceNames[NS_PROJECT_TALK] = $wgMetaNamespace."_talk";
 72+ $dbw->delete ( 'integration_namespace', array( 'integration_dbname' => $localDBname ) );
 73+
 74+ foreach ( $namespaceNames as $key => $thisName ) {
 75+ $newNamespaceRow = array ( 'integration_dbname' => $localDBname,
 76+ 'integration_namespace_index' => $key,
 77+ 'integration_namespace_title' => $thisName
 78+ );
 79+ $dbw->insert ( 'integration_namespace', $newNamespaceRow);
 80+ }
 81+ foreach ( $wgExtraNamespaces as $key => $thisName ) {
 82+ $newNamespaceRow = array ( 'integration_dbname' => $localDBname,
 83+ 'integration_namespace_index' => $key,
 84+ 'integration_namespace_title' => $thisName
 85+ );
 86+ $dbw->insert ( 'integration_namespace', $newNamespaceRow);
 87+ }
 88+ $newNamespaceRow = array ( 'integration_dbname' => $localDBname,
 89+ 'integration_namespace_index' => NS_SPECIAL,
 90+ 'integration_namespace_title' => 'DisregardSpecial'
 91+ );
 92+ $dbw->insert ( 'integration_namespace', $newNamespaceRow);
 93+ $newNamespaceRow = array ( 'integration_dbname' => $localDBname,
 94+ 'integration_namespace_index' => NS_MEDIA,
 95+ 'integration_namespace_title' => 'DisregardForPWD'
 96+ );
 97+ $dbw->insert ( 'integration_namespace', $newNamespaceRow);
 98+ $newNamespaceRow = array ( 'integration_dbname' => $localDBname,
 99+ 'integration_namespace_index' => NS_FILE,
 100+ 'integration_namespace_title' => 'DisregardForPWD'
 101+ );
 102+ $dbw->insert ( 'integration_namespace', $newNamespaceRow);
 103+ $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
 104+ $wgOut->addWikiMsg( 'integration-setuptext', $wgSitename );
 105+ return;
 106+ }
 107+}
Property changes on: trunk/extensions/InterwikiIntegration/SpecialInterwikiIntegration.php
___________________________________________________________________
Name: svn:eol-style
1108 + native
Index: trunk/extensions/InterwikiIntegration/InterwikiIntegration.hooks.php
@@ -0,0 +1,120 @@
 2+<?php
 3+
 4+class InterwikiIntegrationHooks {
 5+
 6+ /*
 7+ * Creates necessary tables
 8+ */
 9+ public static function InterwikiIntegrationCreateTable() {
 10+ global $wgExtNewTables;
 11+ $wgExtNewTables[] = array(
 12+ 'integration_db',
 13+ dirname( __FILE__ ) . '/integration-db.sql'
 14+ );
 15+ $wgExtNewTables[] = array(
 16+ 'integration_namespace',
 17+ dirname( __FILE__ ) . '/integration-namespace.sql'
 18+ );
 19+ /*$wgExtNewTables[] = array(
 20+ 'integration_namespace',
 21+ dirname( __FILE__ ) . '/integration-disregard.sql'
 22+ );*/
 23+ return true;
 24+ }
 25+
 26+ /*
 27+ * Determines whether an interwiki link to a wiki on the same wiki
 28+ * farm is broken or not; if so, it will be colored red and link to the
 29+ * edit page on the target wiki
 30+ */
 31+ public static function InterwikiIntegrationLink( $skin, $target, &$text,
 32+ &$customAttribs, &$query, &$options, &$ret ) {
 33+ global $wgInterwikiIntegrationBrokenLinkStyle, $wgPureWikiDeletionInEffect;
 34+
 35+ if ( $target->isExternal() ) {
 36+ $dbr = wfGetDB( DB_SLAVE );
 37+
 38+ $interwikiPrefix = $target->getInterwiki ();
 39+ $interwikiPrefix{0} = strtolower($interwikiPrefix{0});
 40+ $result = $dbr->selectRow(
 41+ 'integration_db',
 42+ 'integration_dbname',
 43+ array( "integration_prefix" => $interwikiPrefix )
 44+ );
 45+
 46+ if ( !$result ) {
 47+ return true;
 48+ }
 49+
 50+ $targetDb = $result->integration_dbname;
 51+
 52+ $dbrLocal = wfGetDB( DB_SLAVE, array(), $targetDb );
 53+
 54+ $title = $target->getDBkey ();
 55+ $colonPos = strpos ( $title, ':' );
 56+ $namespaceIndex = '';
 57+ if ( $colonPos ) {
 58+ $namespace = ucfirst ( substr ( $title, 0, $colonPos ) );
 59+ $newTitle = substr ( $title, $colonPos + 1,
 60+ strlen ( $title ) - $colonPos - 1 );
 61+ $namespaceResult = $dbrLocal->selectRow (
 62+ 'integration_namespace',
 63+ 'integration_namespace_index',
 64+ array ( "integration_namespace_title" => $namespace )
 65+ );
 66+ if ( $namespaceResult ) {
 67+ $namespaceIndex = $namespaceResult->integration_namespace_index;
 68+ $title = $newTitle;
 69+ }
 70+ }
 71+
 72+ $pageResult = $dbrLocal->selectRow(
 73+ 'page',
 74+ 'page_id',
 75+ array ( "page_title" => ucfirst ( $title ),
 76+ "page_namespace" => $namespaceIndex )
 77+ );
 78+
 79+ $disregardSpecial = $dbrLocal->selectRow (
 80+ 'integration_namespace',
 81+ 'integration_namespace_title',
 82+ array ( "integration_namespace_index" => $namespaceIndex,
 83+ "integration_namespace_title" => 'DisregardSpecial'
 84+ )
 85+ );
 86+ if ( $disregardSpecial ) {
 87+ return true;
 88+ }
 89+
 90+ $pureWikiDeletionInEffect = $dbrLocal->selectRow (
 91+ 'integration_db',
 92+ 'integration_pwd',
 93+ array ( "integration_prefix" => ( $interwikiPrefix ) )
 94+ );
 95+
 96+ if ( $pageResult && $pureWikiDeletionInEffect->integration_pwd == 1 ) {
 97+ $disregardForPWD = $dbrLocal->selectRow (
 98+ 'integration_namespace',
 99+ 'integration_namespace_title',
 100+ array ( "integration_namespace_index" => $namespaceIndex,
 101+ "integration_namespace_title" => 'DisregardForPWD'
 102+ )
 103+ );
 104+ if ( $disregardForPWD ) {
 105+ return true;
 106+ }
 107+ $blankResult = $dbrLocal->selectRow( 'blanked_page', 'blank_page_id'
 108+ , array( "blank_page_id" => $pageResult->page_id ) );
 109+
 110+ }
 111+
 112+ if ( !$pageResult || isset ( $blankResult ) && $blankResult ) {
 113+ $query['action'] = "edit";
 114+ $customAttribs['style'] = $wgInterwikiIntegrationBrokenLinkStyle;
 115+
 116+ }
 117+ }
 118+ return true;
 119+ }
 120+}
 121+
Property changes on: trunk/extensions/InterwikiIntegration/InterwikiIntegration.hooks.php
___________________________________________________________________
Name: svn:eol-style
1122 + native
Index: trunk/extensions/InterwikiIntegration/interwikiintegration-namespace.sql
@@ -0,0 +1,11 @@
 2+BEGIN;
 3+
 4+CREATE TABLE integration_namespace (
 5+integration_namespace_id int UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
 6+integration_dbname varchar(256) binary NOT NULL,
 7+integration_namespace_index int NOT NULL,
 8+integration_namespace_title varchar(256) binary NOT NULL
 9+)
 10+CHARACTER SET utf8 COLLATE utf8_unicode_ci;
 11+
 12+COMMIT;
\ No newline at end of file
Property changes on: trunk/extensions/InterwikiIntegration/interwikiintegration-namespace.sql
___________________________________________________________________
Name: svn:eol-style
113 + native
Index: trunk/extensions/InterwikiIntegration/interwikiintegration-db.sql
@@ -0,0 +1,10 @@
 2+BEGIN;
 3+
 4+CREATE TABLE integration_db (
 5+integration_prefix varchar(256) binary NOT NULL PRIMARY KEY,
 6+integration_dbname varchar(256) binary NOT NULL,
 7+integration_pwd tinyint unsigned NOT NULL default 0
 8+)
 9+CHARACTER SET utf8 COLLATE utf8_unicode_ci;
 10+
 11+COMMIT;
\ No newline at end of file
Property changes on: trunk/extensions/InterwikiIntegration/interwikiintegration-db.sql
___________________________________________________________________
Name: svn:eol-style
112 + native
Index: trunk/extensions/InterwikiIntegration/InterwikiIntegration.i18n.php
@@ -0,0 +1,25 @@
 2+<?php
 3+/**
 4+ * Internationalisation file for the InterwikiIntegration extension
 5+ * @addtogroup Extensions
 6+ */
 7+
 8+$messages = array();
 9+
 10+/* English
 11+ * @author Tisane
 12+ */
 13+$messages['en'] = array(
 14+ 'integration' => 'InterwikiIntegration',
 15+ 'integration-desc' => 'Comprehensive interwiki integration',
 16+ 'populateintegrationtable' => 'Populate integration table',
 17+ 'integration-setuptext' => '$1\'s tables have been configured. Be sure '
 18+ .'to configure the tables on your other wikis as well.'
 19+);
 20+
 21+$aliases = array();
 22+
 23+$aliases['en'] = array(
 24+ 'PopulateInterwikiIntegrationTable' => array( 'PopulateInterwikiIntegrationTable' ),
 25+ );
 26+
Property changes on: trunk/extensions/InterwikiIntegration/InterwikiIntegration.i18n.php
___________________________________________________________________
Name: svn:eol-style
127 + native

Status & tagging log