Index: trunk/extensions/SidebarDonateBox/SidebarDonateBox.php |
— | — | @@ -0,0 +1,42 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * SidebarDonateBox |
| 5 | + * @package SidebarDonateBox |
| 6 | + * @author Daniel Friesen (http://mediawiki.org/wiki/User:Dantman) <mediawiki@danielfriesen.name> |
| 7 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU General Public License |
| 11 | + * as published by the Free Software Foundation; either version 2 |
| 12 | + * of the License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License |
| 20 | + * along with this program; if not, write to the Free Software |
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 | + */ |
| 23 | + |
| 24 | +if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki package and cannot be run standalone." ); |
| 25 | + |
| 26 | +$wgExtensionCredits['parserhook'][] = array ( |
| 27 | + 'name' => 'SidebarDonateBox', |
| 28 | + 'url' => 'http://mediawiki.org/wiki/Extension:SidebarDonateBox', |
| 29 | + 'version' => '1.1a', |
| 30 | + 'author' => "[http://mediawiki.org/wiki/User:Dantman Daniel Friesen]", |
| 31 | + 'description' => "Adds a custom donate box to the sidebar" |
| 32 | +); |
| 33 | + |
| 34 | +$wgHooks['SkinBuildSidebar'][] = 'efSidebarDonateBox'; |
| 35 | + |
| 36 | +function efSidebarDonateBox( $skin, &$bar ) { |
| 37 | + global $egSidebarDonateBoxContent; |
| 38 | + $bar['DONATE'] = $egSidebarDonateBoxContent; |
| 39 | + return true; |
| 40 | +} |
| 41 | + |
| 42 | +# Config variable holding the HTML content of the sidebar |
| 43 | +$egSidebarDonateBoxContent = ''; |
Index: trunk/extensions/StarterWiki/maintenance/createWikiDBFromStarter.php |
— | — | @@ -0,0 +1,210 @@ |
| 2 | +<?php
|
| 3 | +/**
|
| 4 | + * StarterWiki
|
| 5 | + * @package StarterWiki
|
| 6 | + * @author Daniel Friesen (http://mediawiki.org/wiki/User:Dantman) <mediawiki@danielfriesen.name>
|
| 7 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
|
| 8 | + *
|
| 9 | + * This program is free software; you can redistribute it and/or
|
| 10 | + * modify it under the terms of the GNU General Public License
|
| 11 | + * as published by the Free Software Foundation; either version 2
|
| 12 | + * of the License, or (at your option) any later version.
|
| 13 | + *
|
| 14 | + * This program is distributed in the hope that it will be useful,
|
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 | + * GNU General Public License for more details.
|
| 18 | + *
|
| 19 | + * You should have received a copy of the GNU General Public License
|
| 20 | + * along with this program; if not, write to the Free Software
|
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
| 22 | + */
|
| 23 | +
|
| 24 | +/**
|
| 25 | + * Use the current wiki database (starter) as a base for creating a new one.
|
| 26 | + */
|
| 27 | +
|
| 28 | +$optionsWithArgs = array( 'database' );
|
| 29 | +$wgUseMasterForMaintenance = true;
|
| 30 | +require_once( "commandLine.inc" );
|
| 31 | +$wgTitle = Title::newFromText( "StarterWiki Database Creator" );
|
| 32 | +$dbclass = 'Database' . ucfirst( $wgDBtype );
|
| 33 | +
|
| 34 | +# Do a pre-emptive check to ensure we've got credentials supplied
|
| 35 | +# We can't, at this stage, check them, but we can detect their absence,
|
| 36 | +# which seems to cause most of the problems people whinge about
|
| 37 | +if( !isset( $wgDBadminuser ) || !isset( $wgDBadminpassword ) ) {
|
| 38 | + echo( "No superuser credentials could be found. Please provide the details\n" );
|
| 39 | + echo( "of a user with appropriate permissions to update the database. See\n" );
|
| 40 | + echo( "AdminSettings.sample for more details.\n\n" );
|
| 41 | + exit();
|
| 42 | +}
|
| 43 | +
|
| 44 | +# Attempt to connect to the database as a privileged user
|
| 45 | +# This will vomit up an error if there are permissions problems
|
| 46 | +$wgDatabase = new $dbclass( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname, 1 );
|
| 47 | +
|
| 48 | +if( !isset($wgDatabase) || !$wgDatabase->isOpen() ) {
|
| 49 | + # Appears to have failed
|
| 50 | + echo( "A connection to the database could not be established. Check the\n" );
|
| 51 | + echo( "values of \$wgDBadminuser and \$wgDBadminpassword.\n" );
|
| 52 | + exit();
|
| 53 | +}
|
| 54 | +
|
| 55 | +function usageInfo() {
|
| 56 | + echo <<<TEXT
|
| 57 | +Usage:
|
| 58 | + php createWikiDBFromStarter.php --help
|
| 59 | + php createWikiDBFromStarter.php --database=<database>
|
| 60 | +
|
| 61 | + --help : This help message
|
| 62 | + --database=<database> : The name of the database to create.
|
| 63 | +
|
| 64 | +TEXT;
|
| 65 | + exit(0);
|
| 66 | +}
|
| 67 | +
|
| 68 | +function tryRunCreate( $db ) {
|
| 69 | + global $options;
|
| 70 | + if( isset( $options['help'] ) || !isset( $options['database'] ) ) usageInfo();
|
| 71 | + if( doCreateWiki( $db, $options['database'] ) ) {
|
| 72 | + echo "Finished...\n";
|
| 73 | + exit(0);
|
| 74 | + } else {
|
| 75 | + echo "Failed...\n";
|
| 76 | + exit(1);
|
| 77 | + }
|
| 78 | +}
|
| 79 | +
|
| 80 | +function doCreateWiki( $db, $newDB ) {
|
| 81 | + global $wgDBname, $wgStarterWikiPageAliases, $wgStarterWikiOmitNamespaces;
|
| 82 | + // Create the new Database, and make sure to use the same character set and collation as this one.
|
| 83 | + $dbData = $db->selectRow( '`INFORMATION_SCHEMA`.`SCHEMATA`',
|
| 84 | + array( "DEFAULT_CHARACTER_SET_NAME AS 'character_set'", "DEFAULT_COLLATION_NAME AS 'collation'" ),
|
| 85 | + array( 'SCHEMA_NAME' => $wgDBname ), __METHOD__ );
|
| 86 | +
|
| 87 | + if( (bool) $db->query("CREATE DATABASE `{$newDB}` CHARACTER SET {$dbData->character_set} COLLATE {$dbData->collation}") ) {
|
| 88 | + echo "New database created\n";
|
| 89 | + } else {
|
| 90 | + echo "Could not create the database, it may already exist.\n";
|
| 91 | + return false;
|
| 92 | + }
|
| 93 | +
|
| 94 | + // Copy the structure of all the Starter tables to the new wiki.
|
| 95 | + $res = $db->query("SHOW TABLES FROM `{$wgDBname}`");
|
| 96 | + while( $row = $db->fetchRow($res) ) {
|
| 97 | + $table = $row["Tables_in_{$wgDBname}"];
|
| 98 | + if( (bool) $db->query("CREATE TABLE `{$newDB}`.`{$table}` LIKE `{$wgDBname}`.`{$table}`") ) {
|
| 99 | + echo "Cloned structure for table `{$table}` from starter.\n";
|
| 100 | + } else {
|
| 101 | + echo "Failed to clone structure for table `{$table}` from starter.\n";
|
| 102 | + return false;
|
| 103 | + }
|
| 104 | + }
|
| 105 | +
|
| 106 | + // We need a common time to add things in at.
|
| 107 | + $now = $db->timestamp(time());
|
| 108 | + if( isset($wgStarterWikiOmitNamespaces) && is_array($wgStarterWikiOmitNamespaces) ) {
|
| 109 | + // Output a nice SELECT statment that gives us only the starter data we need.
|
| 110 | + $notNamespaces = $db->makeList( $wgStarterWikiOmitNamespaces, LIST_COMMA );
|
| 111 | + if( $notNamespaces !='' ) {
|
| 112 | + $notNamespaces = "AND page_namespace NOT IN ({$notNamespaces})";
|
| 113 | + }
|
| 114 | + }
|
| 115 | + $res = $db->query("
|
| 116 | +SELECT
|
| 117 | + page_namespace AS namespace,
|
| 118 | + page_title AS title,
|
| 119 | + page_restrictions AS restrictions,
|
| 120 | + 0 AS page_counter,
|
| 121 | + page_is_redirect AS is_redirect,
|
| 122 | + 0 AS page_is_new,
|
| 123 | + page_random AS random,
|
| 124 | + rev_comment AS comment,
|
| 125 | + rev_len AS length,
|
| 126 | + old_text AS text,
|
| 127 | + old_flags AS flags
|
| 128 | +FROM
|
| 129 | + `{$wgDBname}`.`page`,
|
| 130 | + `{$wgDBname}`.`revision`,
|
| 131 | + `{$wgDBname}`.`text`
|
| 132 | +WHERE
|
| 133 | + page_id=rev_page
|
| 134 | + AND page_latest=rev_id
|
| 135 | + AND rev_text_id=old_id
|
| 136 | + {$notNamespaces}
|
| 137 | +GROUP BY page_id ASC
|
| 138 | +ORDER BY rev_id DESC");
|
| 139 | +
|
| 140 | + while( $row = $db->fetchObject($res) ) {
|
| 141 | + // Don't copy overrided pages.
|
| 142 | + if( in_array( "{$row->namespace}:{$row->title}", $wgStarterWikiPageAliases ) ) continue;
|
| 143 | +
|
| 144 | + // Insert Text Data into the Database.
|
| 145 | + $oldId = $db->nextSequenceValue('text_old_id_seq');
|
| 146 | + $db->insert( "`{$newDB}`.`text`", array(
|
| 147 | + 'old_id' => $oldId,
|
| 148 | + 'old_text' => $row->text,
|
| 149 | + 'old_flags' => $row->flags
|
| 150 | + ) );
|
| 151 | + $oldId = $db->insertId();
|
| 152 | + if( $db->affectedRows() > 0 ) {
|
| 153 | + echo "Inserted text data for {$row->namespace}:{$row->title}\n";
|
| 154 | + } else {
|
| 155 | + echo "Failed to insert text data for {$row->namespace}:{$row->title}\n";
|
| 156 | + return false;
|
| 157 | + }
|
| 158 | + // Insert Revision Data into the Database.
|
| 159 | + $revId = $db->nextSequenceValue('revision_rev_id_seq');
|
| 160 | + $db->insert( "`{$newDB}`.`revision`", array(
|
| 161 | + 'rev_id' => $revId,
|
| 162 | + 'rev_text_id' => $oldId,
|
| 163 | + 'rev_comment' => $row->comment,
|
| 164 | + 'rev_user' => 0,
|
| 165 | + 'rev_user_text' => "MediaWiki default",
|
| 166 | + 'rev_timestamp' => $now,
|
| 167 | + 'rev_len' => $row->length
|
| 168 | + ) );
|
| 169 | + $revId = $db->insertId();
|
| 170 | + if( $db->affectedRows() > 0 ) {
|
| 171 | + echo "Created initial revision for {$row->namespace}:{$row->title}\n";
|
| 172 | + } else {
|
| 173 | + echo "Failed to create initial revision for {$row->namespace}:{$row->title}\n";
|
| 174 | + return false;
|
| 175 | + }
|
| 176 | + // Insert Page Data into the Database.
|
| 177 | + $pageId = $db->nextSequenceValue('page_page_id_seq');
|
| 178 | + $alias = null;
|
| 179 | + if( isset($wgStarterWikiPageAliases["{$row->namespace}:{$row->title}"]) ) {
|
| 180 | + $alias = array();
|
| 181 | + list( $alias['namespace'], $alias['title'] ) = explode( ':', $wgStarterWikiPageAliases["{$row->namespace}:{$row->title}"], 2 );
|
| 182 | + }
|
| 183 | + $db->insert( "`{$newDB}`.`page`", array(
|
| 184 | + 'page_id' => $pageId,
|
| 185 | + 'page_namespace' => isset($alias) ? $alias['namespace'] : $row->namespace,
|
| 186 | + 'page_title' => isset($alias) ? $alias['title'] : $row->title,
|
| 187 | + 'page_is_redirect' => $row->is_redirect,
|
| 188 | + 'page_random' => $row->random,
|
| 189 | + 'page_touched' => $now,
|
| 190 | + 'page_latest' => $revId,
|
| 191 | + 'page_len' => $row->length
|
| 192 | + ) );
|
| 193 | + $pageId = $db->insertId();
|
| 194 | + if( $db->affectedRows() > 0 ) {
|
| 195 | + echo "Inserted page row for {$row->namespace}:[]$row->title}\n";
|
| 196 | + } else {
|
| 197 | + echo "Failed to insert page row for {$row->namespace}:[]$row->title}\n";
|
| 198 | + return false;
|
| 199 | + }
|
| 200 | + if( $db->set( "`{$newDB}`.`revision`",
|
| 201 | + 'rev_page', $pageId,
|
| 202 | + "rev_id = {$revId}" ) ) {
|
| 203 | + echo "Set rev_id for {$row->namespace}:{$row->title} to the correct value.\n";
|
| 204 | + } else {
|
| 205 | + echo "Failed to set rev_id for {$row->namespace}:{$row->title} to the correct value.\n";
|
| 206 | + }
|
| 207 | + }
|
| 208 | + return true;
|
| 209 | +}
|
| 210 | +
|
| 211 | +tryRunCreate( $wgDatabase ); |
Index: trunk/extensions/StarterWiki/README |
— | — | @@ -0,0 +1 @@ |
| 2 | +Please see the INSTALL file for information on how to install the extension. |
\ No newline at end of file |
Index: trunk/extensions/CodeTest/CodeTest.php |
— | — | @@ -0,0 +1,34 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * CodeTest |
| 5 | + * @package CodeTest |
| 6 | + * @author Daniel Friesen (http://mediawiki.org/wiki/User:Dantman) <mediawiki@danielfriesen.name> |
| 7 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU General Public License |
| 11 | + * as published by the Free Software Foundation; either version 2 |
| 12 | + * of the License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License |
| 20 | + * along with this program; if not, write to the Free Software |
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 | + */ |
| 23 | + |
| 24 | +if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki package and cannot be run standalone." ); |
| 25 | + |
| 26 | +$wgExtensionCredits['parserhook'][] = array ( |
| 27 | + 'name' => 'CodeTest', |
| 28 | + 'url' => 'http://mediawiki.org/wiki/Extension:CodeTest', |
| 29 | + 'version' => '0.1a', |
| 30 | + 'author' => "[http://mediawiki.org/wiki/User:Dantman Daniel Friesen]", |
| 31 | + 'description' => "Mutates Code Tags into forms useful for testing the output of parser functions and tags." |
| 32 | +); |
| 33 | + |
| 34 | +$wgHooks['ParserAfterStrip'][] = 'CodeTest::ParserAfterStrip'; |
| 35 | +$wgAutoloadClasses['CodeTest'] = dirname(__FILE__).'/CodeTest.class.php'; |
Index: trunk/extensions/CodeTest/CodeTest.class.php |
— | — | @@ -0,0 +1,72 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * CodeTest |
| 5 | + * @package CodeTest |
| 6 | + * @author Daniel Friesen (http://mediawiki.org/wiki/User:Dantman) <mediawiki@danielfriesen.name> |
| 7 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU General Public License |
| 11 | + * as published by the Free Software Foundation; either version 2 |
| 12 | + * of the License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License |
| 20 | + * along with this program; if not, write to the Free Software |
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 | + */ |
| 23 | + |
| 24 | +if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki package and cannot be run standalone." ); |
| 25 | + |
| 26 | +class CodeTest { |
| 27 | + |
| 28 | + static function ParserAfterStrip( &$parser, &$text, &$stripState ) { |
| 29 | + $match = array(); |
| 30 | + $text = $parser->extractTagsAndParams( array('codetest'), $text, $match, $parser->uniqPrefix() ); |
| 31 | + foreach( $match as $uniq => $data ) { |
| 32 | + list( $tag, $content, $params, $original ) = $data; |
| 33 | + if( $tag != 'codetest' ) { |
| 34 | + # This sometimes happends with comments, but in the case of |
| 35 | + # anything unforseen, just spit the original back out |
| 36 | + $text = str_replace($uniq,$original,$text); |
| 37 | + continue; |
| 38 | + } |
| 39 | + |
| 40 | + $codeData = array_map( 'trim', explode( "\n", trim($content) ) ); |
| 41 | + $expected = array(); |
| 42 | + if( isset($params['sep']) ) |
| 43 | + foreach( $codeData as &$code ) |
| 44 | + list( $code, $expected[] ) = explode( $params['sep'], $code, 2 ); |
| 45 | + switch( $params['mode'] ) { |
| 46 | + case 'table': |
| 47 | + $content = self::tableModeReplace($codeData,$expected); |
| 48 | + break; |
| 49 | + } |
| 50 | + |
| 51 | + $text = str_replace($uniq,$content,$text); |
| 52 | + } |
| 53 | + return true; |
| 54 | + } |
| 55 | + |
| 56 | + static function tableModeReplace( $codeData, $expected = array() ) { |
| 57 | + $expecting = count($codeData) == count($expected); |
| 58 | + $table = "\n{|\n"; |
| 59 | + $table .= "|-\n"; |
| 60 | + $table .= "!| Code\n"; |
| 61 | + $table .= "!| Result\n"; |
| 62 | + if( $expecting ) $table .= "!| Expecting\n"; |
| 63 | + foreach( $codeData as $n => $code ) { |
| 64 | + $table .= "|-\n"; |
| 65 | + $table .= "||\n<nowiki>".htmlspecialchars($code)."</nowiki>\n"; |
| 66 | + $table .= "||\n{$code}\n"; |
| 67 | + if( $expecting ) $table .= "||\n{$expected[$n]}\n"; |
| 68 | + } |
| 69 | + $table .= "|}\n"; |
| 70 | + return $table; |
| 71 | + } |
| 72 | + |
| 73 | +} |
Index: trunk/extensions/ReplaceSet/ReplaceSet.class.php |
— | — | @@ -0,0 +1,94 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * ReplaceSet |
| 5 | + * @package ReplaceSet |
| 6 | + * @author Daniel Friesen (http://mediawiki.org/wiki/User:Dantman) <mediawiki@danielfriesen.name> |
| 7 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU General Public License |
| 11 | + * as published by the Free Software Foundation; either version 2 |
| 12 | + * of the License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License |
| 20 | + * along with this program; if not, write to the Free Software |
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 | + */ |
| 23 | + |
| 24 | +if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki package and cannot be run standalone." ); |
| 25 | + |
| 26 | +class ReplaceSet { |
| 27 | + static function parserFunction( &$parser, $string ) { |
| 28 | + global $egReplaceSetCallLimit, $egReplaceSetPregLimit; |
| 29 | + if( !isset($egReplaceSetCallLimit) ) $egReplaceSetCallLimit = 25; |
| 30 | + if( !isset($egReplaceSetPregLimit) ) $egReplaceSetPregLimit = 50; |
| 31 | + static $called = 0; |
| 32 | + $called++; |
| 33 | + if( $called > $egReplaceSetCallLimit ) |
| 34 | + return self::error('replaceset-error-calllimit'); |
| 35 | + // Set basic statics |
| 36 | + static $regexStarts = '/!#=([{'; |
| 37 | + static $regexEnds = '/!#=)]}'; |
| 38 | + static $regexModifiers = 'imsxADU'; |
| 39 | + // Grab our args |
| 40 | + $args = func_get_args(); |
| 41 | + array_shift($args);// Shift off the Parser |
| 42 | + array_shift($args);// Shift off the String |
| 43 | + |
| 44 | + // Create our list of replacements |
| 45 | + $replacements = array(); |
| 46 | + $withs = array(); |
| 47 | + foreach( $args as $arg ) { |
| 48 | + // Replacements without a = are invalid. |
| 49 | + if( strpos($arg,'=') === false ) continue; |
| 50 | + list( $replace, $with ) = explode( '=', $arg, 2 ); |
| 51 | + $replace = trim($replace); |
| 52 | + $with = trim($with); |
| 53 | + if( false !== $delimPos = strpos( $regexStarts, $replace[0] ) ) { |
| 54 | + // Is Regex Replace |
| 55 | + $start = $replace[0]; |
| 56 | + $end = $regexEnds[$delimPos]; |
| 57 | + |
| 58 | + $pos = 1; |
| 59 | + $endPos = null; |
| 60 | + while(!isset($endPos)) { |
| 61 | + $pos = strpos($replace, $end, $pos); |
| 62 | + if( $pos === false ) return self::error('replaceset-error-regexnoend', $replace, $end); |
| 63 | + $backslashes = 0; |
| 64 | + for( $l = $pos-1; $l >= 0; $l-- ) { |
| 65 | + if( $replace[$l] == '\\' ) $backslashes++; |
| 66 | + else break; |
| 67 | + } |
| 68 | + if($backslashes % 2 == 0) $endPos = $pos; |
| 69 | + $pos++; |
| 70 | + } |
| 71 | + $startRegex = (string)substr($replace, 0, $endPos).$end; |
| 72 | + $endRegex = (string)substr($replace, $endPos+1); |
| 73 | + $len = strlen($endRegex); |
| 74 | + for( $c = 0; $c < $len; $c++ ) { |
| 75 | + if( strpos($regexModifiers, $endRegex[$c]) === false ) |
| 76 | + return self::error('replaceset-error-regexbadmodifier', $endRegex[$c]); |
| 77 | + } |
| 78 | + $finalRegex = $startRegex.$endRegex.'u'; |
| 79 | + |
| 80 | + $replacements[] = $finalRegex; |
| 81 | + $withs[] = $with; |
| 82 | + } else { |
| 83 | + // Is String Replace |
| 84 | + $replacements[] = '/'.preg_quote($replace,'/').'/'; |
| 85 | + $withs[] = str_replace('\\','\\\\',$with); |
| 86 | + } |
| 87 | + } |
| 88 | + return preg_replace($replacements, $withs, $string, $egReplaceSetPregLimit); |
| 89 | + } |
| 90 | + static function error( $msg /*, ... */ ) { |
| 91 | + wfLoadExtensionMessages('ReplaceSet'); |
| 92 | + $args = func_get_args(); |
| 93 | + return '<strong class="error">' . call_user_func_array( 'wfMsgForContent', $args ) . '</strong>'; |
| 94 | + } |
| 95 | +} |
Index: trunk/extensions/ReplaceSet/ReplaceSet.i18n.php |
— | — | @@ -0,0 +1,31 @@ |
| 2 | +<?php
|
| 3 | +/**
|
| 4 | + * ReplaceSet
|
| 5 | + * @package ReplaceSet
|
| 6 | + * @author Daniel Friesen (http://mediawiki.org/wiki/User:Dantman) <mediawiki@danielfriesen.name>
|
| 7 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
|
| 8 | + *
|
| 9 | + * This program is free software; you can redistribute it and/or
|
| 10 | + * modify it under the terms of the GNU General Public License
|
| 11 | + * as published by the Free Software Foundation; either version 2
|
| 12 | + * of the License, or (at your option) any later version.
|
| 13 | + *
|
| 14 | + * This program is distributed in the hope that it will be useful,
|
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 | + * GNU General Public License for more details.
|
| 18 | + *
|
| 19 | + * You should have received a copy of the GNU General Public License
|
| 20 | + * along with this program; if not, write to the Free Software
|
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
| 22 | + */
|
| 23 | +
|
| 24 | +if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki package and cannot be run standalone." );
|
| 25 | +
|
| 26 | +$messages = array();
|
| 27 | +
|
| 28 | +$messages['en'] = array(
|
| 29 | + 'replaceset-error-calllimit' => 'The ReplaceSet call limit has been reached.',
|
| 30 | + 'replaceset-error-regexnoend' => 'The regex pattern "$1" is missing the ending delimiter \'$2\'',
|
| 31 | + 'replaceset-error-regexbadmodifier' => 'The regex modifier \'$1\' is not valid.'
|
| 32 | +);
|
Index: trunk/extensions/ReplaceSet/ReplaceSet.php |
— | — | @@ -0,0 +1,59 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * ReplaceSet |
| 5 | + * @package ReplaceSet |
| 6 | + * @author Daniel Friesen (http://mediawiki.org/wiki/User:Dantman) <mediawiki@danielfriesen.name> |
| 7 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU General Public License |
| 11 | + * as published by the Free Software Foundation; either version 2 |
| 12 | + * of the License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License |
| 20 | + * along with this program; if not, write to the Free Software |
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 | + */ |
| 23 | + |
| 24 | +if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki package and cannot be run standalone." ); |
| 25 | + |
| 26 | +$wgExtensionCredits['parserhook'][] = array ( |
| 27 | + 'name' => 'ReplaceSet', |
| 28 | + 'url' => 'http://mediawiki.org/wiki/Extension:ReplaceSet', |
| 29 | + 'version' => '1.0a', |
| 30 | + 'author' => "[http://mediawiki.org/wiki/User:Dantman Daniel Friesen]", |
| 31 | + 'description' => "Adds a <nowiki>{{#replaceset}}</nowiki> parserfunction used for replacing sections of text with specially formatted data." |
| 32 | +); |
| 33 | + |
| 34 | +$wgExtensionFunctions[] = 'efReplaceSetSetup'; |
| 35 | +$wgHooks['LanguageGetMagic'][] = 'efReplaceSetSetupLanguageMagic'; |
| 36 | +$wgAutoloadClasses['ReplaceSet'] = dirname(__FILE__).'/ReplaceSet.class.php'; |
| 37 | +$wgExtensionMessagesFiles['ReplaceSet'] = dirname(__FILE__).'/ReplaceSet.i18n.php'; |
| 38 | + |
| 39 | +function efReplaceSetSetup() { |
| 40 | + global $wgParser; |
| 41 | + |
| 42 | + // Check for SFH_OBJECT_ARGS capability |
| 43 | + if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { |
| 44 | + $wgHooks['ParserFirstCallInit'][] = 'efReplaceSetRegisterParser'; |
| 45 | + } else { |
| 46 | + if ( class_exists( 'StubObject' ) && !StubObject::isRealObject( $wgParser ) ) { |
| 47 | + $wgParser->_unstub(); |
| 48 | + } |
| 49 | + efReplaceSetRegisterParser( $wgParser ); |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +function efReplaceSetRegisterParser( &$parser ) { |
| 54 | + $parser->setFunctionHook( 'replaceset', array( 'ReplaceSet', 'parserFunction' ) ); |
| 55 | +} |
| 56 | + |
| 57 | +function efReplaceSetSetupLanguageMagic( &$magicWords, $langCode ) { |
| 58 | + $magicWords['replaceset'] = array( 0, 'replaceset' ); |
| 59 | + return true; |
| 60 | +} |
Index: trunk/extensions/SwarmExport/swarmExport.php |
— | — | @@ -0,0 +1,91 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * SwarmExport |
| 5 | + * @author Daniel Friesen http://mediawiki.org/wiki/User:Dantman |
| 6 | + * @version 1.0 |
| 7 | + * |
| 8 | + * This program is free software; you can redistribute it and/or |
| 9 | + * modify it under the terms of the GNU General Public License |
| 10 | + * as published by the Free Software Foundation; either version 2 |
| 11 | + * of the License, or (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public License |
| 19 | + * along with this program; if not, write to the Free Software |
| 20 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 21 | + */ |
| 22 | + |
| 23 | +require_once ( getenv('MW_INSTALL_PATH') !== false |
| 24 | + ? getenv('MW_INSTALL_PATH')."/maintenance/commandLine.inc" |
| 25 | + : dirname( __FILE__ ) . '/../../maintenance/commandLine.inc' ); |
| 26 | + |
| 27 | +if( !isset($options['outfile']) ) { |
| 28 | + echo <<<SH |
| 29 | +Usage: php swarmExport.php --outfile=... [options...] |
| 30 | + |
| 31 | + --outfile=<file> File to output swarm history to |
| 32 | + --append Append new history instead of rebuilding |
| 33 | + --startid=<id> For use with --append, specify a revision number instead |
| 34 | + of autodetecting |
| 35 | + --pageprefix=<prefix> Prefix to add before titles, good if you are outputting |
| 36 | + multiple wiki's into the same swarm log |
| 37 | + --namespaces=<ids> Comma separated list of namespace id's to restrict to |
| 38 | + --usersonly Ignore anon users and system users (anyone with id=0) |
| 39 | +SH; |
| 40 | + exit(0); |
| 41 | +} |
| 42 | +$file = $options['outfile']; |
| 43 | +$append = isset($options['append']); |
| 44 | +$start = isset($options['startid']) ? $options['startid'] : null; |
| 45 | +$prefix = isset($options['pageprefix']) ? $options['pageprefix'] : ''; |
| 46 | +$namespaces = isset($options['namespaces']) |
| 47 | + ? array_map('intval', explode(',', $options['namespaces'])) |
| 48 | + : null; |
| 49 | + |
| 50 | +if( !isset($start) ) { |
| 51 | + if( $append ) { |
| 52 | + if( $f = fopen( $file, 'r' ) ) { |
| 53 | + while(!feof($f)) { |
| 54 | + $line = fgets( $f ); |
| 55 | + $x = explode('|', $line); |
| 56 | + $num = $x[0]; |
| 57 | + if( is_numeric($num) ) $start = intval($num); |
| 58 | + } |
| 59 | + } |
| 60 | + if( !isset($start) ) die('Failed, could not guess rev id to start with'); |
| 61 | + } else $start = 0; |
| 62 | +} |
| 63 | + |
| 64 | +if( $append ) { |
| 65 | + echo "Appending new history items to file starting at revision $start\n"; |
| 66 | +} else { |
| 67 | + if( $start == 0 ) echo "Generating complete history report\n"; |
| 68 | + else echo "Generating history report with only revision $start onwards\n"; |
| 69 | +} |
| 70 | + |
| 71 | +$f = fopen( $file, $append ? 'a' : 'w' ); |
| 72 | + |
| 73 | +$db =& wfGetDB( DB_SLAVE ); |
| 74 | +$conds = array( 'rev_page=page_id', 'rev_deleted' => 0, "rev_id > $start" ); |
| 75 | +if( isset($namespaces) ) $conds['page_namespace'] = $namespaces; |
| 76 | +if( isset($options['usersonly']) ) $conds[] = 'rev_user != 0'; |
| 77 | + |
| 78 | +echo "Starting db query:\n"; |
| 79 | + |
| 80 | +$res = $db->select( array( 'revision', 'page' ), |
| 81 | + array( 'rev_id', 'page_namespace', 'page_title', 'rev_user_text', /*'rev_minor_edit',*/ 'rev_timestamp' ), |
| 82 | + $conds, null, array( 'ORDER BY' => 'rev_id' ) ); |
| 83 | + |
| 84 | +printf("Writing data for %s rows\n", $res->numRows()); |
| 85 | + |
| 86 | +while( $row = $res->fetchObject() ) { |
| 87 | + $time = wfTimestamp(TS_UNIX, $row->rev_timestamp); |
| 88 | + $title = $prefix.$wgCanonicalNamespaceNames[$row->page_namespace].':'.$row->page_title; |
| 89 | + fwrite( $f, "{$row->rev_id}|{$title}|{$row->rev_user_text}|{$time}\n" ); |
| 90 | +} |
| 91 | + |
| 92 | +printf("Completed output of %s history items to %s\n", $res->numRows(), $file); |