User:Leucosticte/Junkyard

function fetch_all( $resulttype = MYSQLI_NUM ) { if ( method_exists( 'mysqli_result', 'fetch_all' ) ) { # Compatibility layer with PHP < 5.3 $res = parent::fetch_all( $resulttype ); } else { for ( $res = array; $tmp = $this->fetch_array( $resulttype ); ) { $res[] = $tmp; }     return $res; }

$ret = $wiki->query ( '?action=createaccount&format=php'     . '&rcid=' . $row['mbrcq_rc_id']      . '&logid=' . $row['mbrcq_rc_logid']      . '&pageid=' . $row['mbrcq_rc_cur_id']      . '&pagenamespace=' . $row['mbrcq_rc_namespace']      . '&pagetitle=' . $row['mbrcq_rc_title']      . '&type=' . $row['mbrcq_rc_logtype']      . '&logaction=' . $row['mbrcq_rc_log_action']      . '&user=' . $row['mbrcq_rc_user_text']      . '&userid=' . $row['mbrcq_rc_user']      . '&timestamp=' . $row['mbrcq_rc_timestamp']      . '&comment=' . $row['mbrcq_rc_comment']      . '&tags=' . $row['mbrcq_tags']      . '&token=' . $token     , true ); // Post

$wgAutoloadClasses['MirrorEditPage'] = $dir. 'MirrorTools.classes.php';

$r['username'] = $params['user'];

public function getResultProperties { return array(			'createaccount' => array( 'result' => array(					ApiBase::PROP_TYPE => array( 'success', 'warning', 'needtoken' )				),				'username' => array(					ApiBase::PROP_TYPE => 'string',					ApiBase::PROP_NULLABLE => true				), 'userid' => array(					ApiBase::PROP_TYPE => 'int',					ApiBase::PROP_NULLABLE => true				), 'token' => array(					ApiBase::PROP_TYPE => 'string',					ApiBase::PROP_NULLABLE => true				), )		);	} die ( "Allowable options: rc, rev, us\n" );

$pageTitlesFile = 'PageTitlesFile.txt'; if ( !file_exists ( $pageTitlesFile) ) { $pageTitles = fopen ( $pageTitlesFile, 'w' ); } else { if ( $overwrite ) { echo "$pageTitlesFile exists; overwriting.\n"; } else { die ( "$pageTitlesFile exists; aborting.\n" ); } } $pageTitles = fopen ( $pageTitlesFile, 'w' );

// If it's in the interwiki table but not on the new list, or on the // blacklist, maybe time to remove it from the interwiki table? if ( !isset ( $apiPulls[$row->iw_prefix] )                               || isset ( $blacklist[$row->iw_prefix] ) ) { // But if it's on the whitelist, don't remove if ( !isset ( $whitelist[$row->iw_prefix] ) ) { $remove[] = $row->iw_prefix; }                       // If it's on the new list but not in the interwiki table, and not in the // blacklist, maybe time to add it to the interwiki table? } elseif // See if this whitelist entry has a specific url; if so, leave it                       // alone if ( !$whitelist[$row->iw_prefix] ) { // No specific url on the whitelist, so see if the url // needs to be modified if ( $apiPulls[$row->iw_prefix] != $row->iw_url ) { $modify = }                       }                        } -- WikiIndex page title, used because it's sure to be unique iwm_iw_wikiindex_page_title varchar(255) binary,

if ( $rowFields ) { $firstOne = true; $queryFields = '(';       $queryValues = '('; foreach ( $rowFields as $field => $value ) { if ( !$firstOne ) { $queryFields .= ', '; $queryValues .= ', '; }           $firstOne = false; $queryFields .= $field; $queryValues .= $value; }       $queryFields .= ')';        $queryValues .= ')'; $query = "INSERT INTO parsed_mirrored_wikiindex $queryFields VALUES $queryValues";

It's been suggested at https://meta.wikimedia.org/wiki/Forum#Interwiki_list that the 93-item interwiki.list be updated to include the 700+ items in meta's interwiki map ( https://meta.wikimedia.org/wiki/Interwiki_map ), or to be more exact, the siprop=interwikimap list that results from a script periodically pushing that map into the database: https://meta.wikimedia.org/w/api.php?action=query&meta=siteinfo&siprop=interwikimap. This seems like a good idea, since the choice of some of those 93 appears a bit arbitrary.

 * This bot takes the PMWTable generated by ParseMirroredWikiIndex and * converts it to a wikitable, which it then puts in MediaWiki:PMWTable. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html */

/* Setup my classes. */ include( 'botclasses.php' ); $wiki     = new wikipedia; $wiki->url = 'http://localhost/test13/w/api.php';

// Two modes: Gather data from APIs or convert to table define ( "GATHER_DATA", 1); define ( "CONVERT_TO_TABLE", 1); $mode = GATHER_DATA;

// Database $host = 'localhost'; $dbUser = 'root'; $dbPass = 'REMOVED'; $dbName = 'parse_mirrored_wikiindex_bot'; $tables = array(   'parsed_mirrored_wikiindex' => 'parsed-mirrored-wikiindex.sql', ); $db = new mysqli( $host, $dbUser, $dbPass, $dbName ); if ( !$db ) { die( 'Could not connect: ' . mysql_error); } $db->select_db ( "$dbName" ); // These statuses should all be lowercase $goodStatuses = array (     'vibrant',      'active',      'new',      'in preparation',      'dormant',      'needslove',      'spammed',      'goalreached' );

$pushUser = 'Nate'; $pushPass = 'password'; $wiki->login( $pushUser, $pushPass ); $token = $wiki->getedittoken ;

$wikitable = '{| class="wikitable sortable" style="font-size: 86%;' . "\n"; $fields = array (     'wikiindex page title',      'name',      'URL',      'logo',      'wide logo',      'iw_url',      'recentchanges URL',      'wikinode URL',      'status',      'language',      'editmode',      'engine',      'license',      'maintopic',      'backupurl',      'backupdate',      'pages',      'statistics URL',      'wikiFactor',      'wikiFactor URL', ); $RCPossibilities = array(	'Посебно:СкорашњеИзмене',	'Посебно:Скорашње_измене',	'Sipesol:Nupela senis',	'Extra:Neuste_Änderunge',	'Extra:Änderunge',	'Spèciâl:Dèrriérs_changements',	'Spèciâl:DèrriérsChangements',	'Speçiale:Ûrtime modiffiche',	'Sapaq:NaqhaHukchasqa',	'Wiki:Koartlyn feroare',	'Wiki:Koarts feroare',	'Spezial:Letzte_Änderungen',	'Spécial:Modifications_récentes',	'Spécial:Modifications_recentes',	'Spécial:ModificationsRécentes', 'Spécial:ModificationsRecentes', 'Especial:Zaguers_cambeos', 'Especial:Cambeos_recients', 'Spesiaal:Onlangse_wysigings', 'Spesiaal:Onlangsewysigings', 'Specialnje:Aktualne_změny', 'พิเศษ:ปรับปรุงล่าสุด', 'Especial:TrocamientosFreskos', 'Ippiziari:UlthimiMudìfigghi', 'Spezial:Toletzt ännert', 'Spezial:Neeste Ännern', 'Spezial:Toletzt ännert', 'Spezial:Neeste Ännern', 'විශේෂ:මෑත_වෙනස්වීම්', 'Xüsusi:SonDəyişikliklər', '特殊:最近更改', 'Arbednek:Chanjyow_a-dhiwedhes', 'Служебная:Свежие_правки', 'Schbädsjaal:Lädsdâ_Änârungâ', 'Special:Modificationes_recente', 'Serstakt:Seinastu broytingar', 'Specialus:Naujausi_keitimai', 'Spesial:Siste_endringar', '特殊:最近更改', 'Арнайы:Жуықтағы_өзгерістер', 'Spesial:Siste_endringer', 'Спэцыяльныя:Апошнія_зьмены', 'ارنايى:جۋىقتاعى_وزگەرىستەر', 'ବିଶେଷ:ନଗଦବଦଳ', 'Speciale:NdryshimeSëFundmi', 'Special:Nov_changes', 'Specialis:Nuper mutata', 'Specialis:Mutationes recentes', 'Speciális:Friss_változtatások', 'Speciaal:Lètste_verangeringe', 'Špeciálne:PoslednéÚpravy', 'Башка:УлхкомбаньПолафнематне', 'বিশেষ:শেহতীয়া_সালসলনি', 'Цастәи:АрҽеираҾыцқәа', 'Erenoamáš:Varas_rievdadusat', 'Pàtàkì:ÀwọnÀtúnṣeTuntun', 'Aptaca:NoeltafBetakseem', 'Especial:Cambios_recentes', 'Maalum:MabadalikoyaKaribuni', 'Сæрмагонд:ФæстагИвдтытæ', 'Specjalna:Ostatnie_zmiany', 'Specjalna:OZ', 'ހާއްޞަ:އެންމެ ފަހުގެ ބަދަލްތައް', 'Istimiwa:Paubahan_pahanyarnya', 'Posebno:Nedavne_promjene', 'Özel:SonDeğişiklikler', 'Kerfissíða:Nýlegar_breytingar', 'Speċjali:TibdilRiċenti', 'പ്രത്യേകം:സമീപകാലമാറ്റങ്ങൾ', 'Speciální:Poslední_změny', 'Speciální:Posledni_zmeny', 'Special:CambiamentRecent', 'Speciâl:UltinsCambiaments', 'Maasus:BitkiDiişikmäklär', '特別:最近修改', 'विशेष:अलीकडील_बदल', 'ځانګړی:اوسني_بدلونونه', 'Махсус:Соңгы_үзгәртүләр', 'Istimewa:Perubahan_terbaru', 'Istimewa:PerubahanTerbaru', 'Istimewa:RC', 'Istimewa:PT', 'מיוחד:שינויים_אחרונים', 'Speciaal:RecenteWijzigingen', 'ພິເສດ:ການດັດແກ້ຫຼ້າສຸດ', 'Սպասարկող:Վերջինփոփոխությունները', 'Posebno:NedavneIzmjene', 'વિશેષ:તાજાફેરફારો', 'Jagleel:Coppite yu mujj', '특수기능:최근바뀜', 'ܕܝܠܢܝܐ:ܫܘܚܠܦ̈ܐ_ܚܕ̈ܬܐ', 'Espesiál:Mudansa_foufoun_sira', 'Специјална:СкорешниПромени', 'Husus:AnyarRobah', 'خاص:اخر_تعديلات', 'Xısusi:VurnayışêPeyêni', 'באַזונדער:לעצטע_ענדערונגען', 'Specialine:TantoižedToižetused', 'Speciale:UltimeModifiche', 'სპეციალური:ბოლოცვლილებები', 'Arnawlı:Aqırg\'ı o\'zgerisler', 'Espesyal:Bag-ongGiusab', 'Spiciali:ÙrtimiCanciamenti', 'Especial:Mudanças_recentes', 'Especial:Recentes', 'Especial:Mudanças_recentes', 'Espesyal:ChanjmanResan', 'Especial:CambiosRecientes', 'Especial:Cambios_recientes', 'ప్రత్యేక:ఇటీవలిమార్పులు', 'Manokana:Fanovàna_farany', 'विशेषम्:नवीनतम_परिवर्तन', 'ویژه:تغییرات_اخیر', 'خاص:أحدث_التغييرات', '特別:最近の更新', '特別:最近更新したページ', 'Đặc_biệt:Thay_đổi_gần_đây', 'Башка тевень:ЧыяконьПолавтомат', 'Toiminnot:Tuoreet_muutokset', 'Arnaýı:Jwıqtağı_özgerister', 'حاص:نوکین تغییرات', 'Posebno:ZadnjeSpremembe', 'Special:Schimbări_recente', 'Spezial:Rezent_Ännerungen', 'Berezi:AzkenAldaketak', 'Xususi:Ән_нујә_дәгишон', 'Taybet:Guherandinên_dawî', 'Posebno:Nedavne_izmjene', 'Specialaĵo:Lastaj_ŝanĝoj', 'Especial:Darrièrs_cambiaments', 'Especial:DarrièrsCambiaments', 'Especial:Darrièras_Modificacions', 'ពិសេស:បំលាស់ប្ដូរថ្មីៗ', 'Ειδικό:ΠρόσφατεςΑλλαγές', 'Eri:Viimased_muudatused', 'Speciel:Seneste_ændringer', 'Papa_nui:NāLoliHou', 'Papa_nui:NaLoliHou', 'Special:最近更改', 'Лӱмын_ыштыме:Пытартыш_тӧрлатымаш-влак', 'Spesyal:BakaseywanKenki', 'Спеціальна:Нові_редагування', 'Natatangi:Mga_huling_binago', 'Natatangi:HulingBinago', 'Специални:Последни_промени', 'Specala:RecentaChanji', 'تایبەت:دوایین_گۆڕانکارییەکان', 'Especial:Canvis_recents', 'Khas:Perubahan_terkini', 'Special:Senaste_ändringar', 'Шпеціална:Послїднї_зміны', 'Speciale:ÙltimiCanbiamenti', 'Spesiaal:Leste_wiezigingen', 'Kusuih:Neuubah_baro', 'Specialne:Aktualne_změny', 'خاص:تازيون تبديليون', 'Special:RecentChanges', 'Patikos:Votükamsnulik', 'Dibar:KemmoùDiwezhañ' );

// Retrieve the interwiki map $wgInterwikiMapUserAgent = 'User-Agent: LeucosticteBot (http://mediawiki.org/wiki/User:LeucosticteBot)'; $opts = array(       'http'=>array( 'method' => "GET", 'header' => $wgInterwikiMapUserAgent ) ); $wgInterwikiMapApiArgs = '?action=query&meta=siteinfo&siprop=interwikimap&format=json'; $url = 'https://meta.wikipedia.org/w/api.php'; $url .= $wgInterwikiMapApiArgs; $streamContext = stream_context_create( $opts ); $contents = file_get_contents ( $url, false, $streamContext ); if ( !$contents ) { die ( "Retrieval from $url failed\n" ); } $apiPull = json_decode ( $contents, true ); if ( !$apiPull ) { die( "json decode of $url failed\n" ); } $apiPull = $apiPull['query']['interwikimap']; foreach ( $apiPull as $apiPullElement ) { $apiResult[$apiPullElement["prefix"]] = $apiPullElement["url"]; }
 * 1) var_dump ( $apiPull );
 * 2) die;

foreach ( $fields as $field ) { $wikitable .= "! $field\n"; } $wikitable .= "|-\n";

$res = $db->query ( "SELECT * FROM parsed_mirrored_wikiindex" ); while ( $row = $res->fetch_assoc ) { #echo $row['pmw_data']. "\n"; $unserialized = unserialize ( $row['pmw_data'] ); $unserialized['wikiindex page title'] = $row['pmw_wikiindex_page_title']; // Get the RC URL $unserialized['iw_url'] = ''; if ( isset ( $unserialized['recentchanges URL'] ) ) { foreach ( $RCPossibilities as $RCPossibility ) { if ( strpos ( $unserialized['recentchanges URL'], $RCPossibility ) ) { $unserialized['iw_url'] = str_replace ( $RCPossibility, '$1',			     $unserialized['recentchanges URL'] ); }	   }	    $unserialized['iw_prefix'] = ''; foreach ( $apiPull as $apiPullElement ) { if ( $unserialized['iw_url'] == $apiPullElement['url'] ) { $unserialized['iw_prefix'] = $apiPullElement['prefix']; }	   }      }      // If it's either in meta-wiki's map or has an active status if ( $unserialized['iw_prefix'] || in_array ( strtolower ( $unserialized['status'] ), $goodStatuses ) ) { $wikitable .= '|'; foreach ( $fields as $field ) { if ( isset ( $unserialized[$field] ) ) { $wikitable .= $unserialized[$field]; }		 $wikitable .= " || "; }	   $wikitable .= "\n|-\n"; } } $wikitable .= "|}\n"; $file = fopen ( 'PMWOutput.txt', 'w' ); fwrite ( $file, $wikitable ); fclose ( $file );
 * 1) echo $wikitable;

// Resort to the default values } else { $value[$attribute] = $defaultAttributes[$key]; }

$wgHooks['ParserFirstCallInit'][] = 'PerPageLicense::setLicenseHook'; public static function setLicenseHook( &$parser ) { $parser->setHook( "pagelicense", "PerPageLicense::pageLicense" ); #$parser->setHook( "pagelicense", "PerPageLicense::pageLicense2" ); return true; }

public static function pageLicense( $parser, $param1 = , $param2 =  ) { global $wgFooterIcons, $wgRightsIcon, $wgPerPageLicenseLicenses; global $wgStylePath; /*               $param1 = trim( $param1 ); if ( isset ( $wgPerPageLicenseLicenses[$param1] ) ) { $wgFooterIcons['copyright']['copyright'] = $wgPerPageLicenseLicenses[$param1]; }               $wgRightsIcon = "{$wgStylePath}/common/images/cc-by-nc-sa.png"; $wgFooterIcons['copyright']['copyright']['src'] = "{$wgStylePath}/common/images/cc-by-nc-sa.png"; */                       $wgRightsIcon = "/test13/w/skins/common/images/cc-by.png"; $wgFooterIcons['copyright']['copyright']['src'] = "/test13/w/skins/common/images/cc-by.png"; return 'yo'; }

public static function pageLicense2( $input, array $args, Parser $parser, PPFrame $frame ) { global $wgFooterIcons, $wgRightsIcon, $wgRightsUrl, $wgRightsText, $wgPerPageLicenseLicenses, $wgStylePath; $input = trim( $input ); if ( isset ( $args['license'] ) ) { if ( isset ( $wgPerPageLicenseLicenses[$args['license']] ) ) { $wgFooterIcons['copyright']['copyright'] = $wgPerPageLicenseLicenses[$args['license']]; }                       $wgRightsText = $wgPerPageLicenseLicenses[$args['license']]['alt']; $wgRightsIcon = $wgPerPageLicenseLicenses[$args['license']]['src']; $wgRightsText = $wgPerPageLicenseLicenses[$args['license']]['alt']; /*$wgRightsIcon['copyright']['copyright']['src'] = "{$wgStylePath}/common/images/cc-by-nc-sa.png";*/ }               return ''; } }

foreach ( $res as $row ) { $watchingUser = User::newFromID( $row->wl_user ); if ( $watchingUser->getOption( 'enotifdelwatchlistpages' ) ) { $watchers[] = intval( $row->wl_user ); }				}		// Build a list of users to notify $watchers = array; if ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) { $dbw = wfGetDB( DB_MASTER ); $setArray = array( /* SET */				'wl_notificationtimestamp' => $dbw->timestamp( $timestamp ) ); if ( $wgEnotifDeletionsWatchlist && $pageStatus == 'deleted' ) { $res = $dbw->select( array( 'watchlist', 'user_properties' ),					array( 'wl_user' ),					array( 'wl_user != '. intval( $editor->getID ), 'wl_namespace' => $title->getNamespace, 'wl_title' => $title->getDBkey, 'wl_del_notificationtimestamp IS NULL', 'up_property' => 'enotifdelwatchlistpages', 'up_value' => '1' ), __METHOD__, array,					array ( 'LEFT JOIN' => 'wl_user = up_user' )				); $setArray['wl_del_notificationtimestamp'] = $dbw->timestamp( $timestamp ); } else { $res = $dbw->select( array( 'watchlist' ),					array( 'wl_user' ),					array( 'wl_user != '. intval( $editor->getID ), 'wl_namespace' => $title->getNamespace, 'wl_title' => $title->getDBkey, 'wl_notificationtimestamp IS NULL', ), __METHOD__				); }			foreach ( $res as $row ) { $watchers[] = intval( $row->wl_user ); }			if ( $watchers ) { // Update wl_notificationtimestamp for all watching users except the editor #var_dump ( $watchers ); #die; $fname = __METHOD__; $dbw->onTransactionIdle(					function use ( $dbw, $timestamp, $watchers, $title, $fname ) {						$dbw->begin( $fname );						$dbw->update( 'watchlist', $setArray, array( /* WHERE */								'wl_user' => $watchers,								'wl_namespace' => $title->getNamespace,								'wl_title' => $title->getDBkey,							), $fname );						$dbw->commit( $fname );					}				); }		}