r17820 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17819‎ | r17820 | r17821 >
Date:09:53, 21 November 2006
Author:tstarling
Status:old
Tags:
Comment:
* Introduced StringUtils.php, populated it with some generic string functions, both new and collected from various other files.
* Removed some backtracking regexes with an O(N^2) worst case, replaced with StringUtils::delimiterReplace(). There is a beneficial functional difference: /*/ is no longer considered to be a complete CSS comment.
* Changed the parser strip state from an array to an object. This should hopefully avoid the PHP bugs with array references. StripState uses the new ReplacementArray to do the replacements, thereby supporting FSS.
* Removed DatabaseFunctions.php from the default startup sequence. Moved wfGetDB() to GlobalFunctions.php.
* Introduced the SiteStats class, with a collection of cached site stats accessor functions.
* Removed all global functions from Parser.php, they don't belong there.
* Made LanguageConverter use the new ReplacementArray class instead of managing its own FSS objects.
Modified paths:
  • /trunk/extensions/Cache404/extensions/Cache404.php (modified) (history)
  • /trunk/extensions/FindSpam/FindSpam_body.php (modified) (history)
  • /trunk/extensions/MakeDBError/MakeDBError_body.php (modified) (history)
  • /trunk/extensions/ShowProcesslist/ShowProcesslist_body.php (modified) (history)
  • /trunk/extensions/StableVersion/StableVersion.php (modified) (history)
  • /trunk/extensions/experimental/SpecialValidate.php (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/BagOStuff.php (modified) (history)
  • /trunk/phase3/includes/Block.php (modified) (history)
  • /trunk/phase3/includes/CoreParserFunctions.php (modified) (history)
  • /trunk/phase3/includes/Database.php (modified) (history)
  • /trunk/phase3/includes/DatabaseFunctions.php (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/Image.php (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/MagicWord.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)
  • /trunk/phase3/includes/Sanitizer.php (modified) (history)
  • /trunk/phase3/includes/SiteStats.php (added) (history)
  • /trunk/phase3/includes/SiteStats.php (added) (history)
  • /trunk/phase3/includes/SiteStatsUpdate.php (deleted) (history)
  • /trunk/phase3/includes/SpecialStatistics.php (modified) (history)
  • /trunk/phase3/includes/SpecialWatchlist.php (modified) (history)
  • /trunk/phase3/includes/Xml.php (modified) (history)
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageKk.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageSr.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageZh.php (modified) (history)
  • /trunk/phase3/maintenance/namespace2sql.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/LanguageConverter.php
@@ -12,9 +12,7 @@
1313 var $mMainLanguageCode;
1414 var $mVariants, $mVariantFallbacks;
1515 var $mTablesLoaded = false;
16 - var $mUseFss = false;
1716 var $mTables;
18 - var $mFssObjects;
1917 var $mTitleDisplay='';
2018 var $mDoTitleConvert=true, $mDoContentConvert=true;
2119 var $mCacheKey;
@@ -49,9 +47,6 @@
5048 $this->mMarkup = array_merge($m, $markup);
5149 $f = array('A'=>'A', 'T'=>'T');
5250 $this->mFlags = array_merge($f, $flags);
53 - if ( function_exists( 'fss_prep_replace' ) ) {
54 - $this->mUseFss = true;
55 - }
5651 }
5752
5853 /**
@@ -194,19 +189,12 @@
195190 * @return string Translated text
196191 */
197192 function translate( $text, $variant ) {
 193+ wfProfileIn( __METHOD__ );
198194 if( !$this->mTablesLoaded )
199195 $this->loadTables();
200 - if ( $this->mUseFss ) {
201 - wfProfileIn( __METHOD__.'-fss' );
202 - $text = fss_exec_replace( $this->mFssObjects[$variant], $text );
203 - wfProfileOut( __METHOD__.'-fss' );
204 - return $text;
205 - } else {
206 - wfProfileIn( __METHOD__.'-strtr' );
207 - $text = strtr( $text, $this->mTables[$variant] );
208 - wfProfileOut( __METHOD__.'-strtr' );
209 - return $text;
210 - }
 196+ $text = $this->mTables[$variant]->replace( $text );
 197+ wfProfileOut( __METHOD__ );
 198+ return $text;
211199 }
212200
213201 /**
@@ -407,13 +395,9 @@
408396 continue;
409397 if(!array_key_exists($vto, $carray))
410398 continue;
411 - $this->mTables[$vto][$carray[$vfrom]] = $carray[$vto];
412 -
 399+ $this->mTables[$vto]->setPair($carray[$vfrom], $carray[$vto]);
413400 }
414401 }
415 - if ( $this->mUseFss ) {
416 - $this->generateFssObjects();
417 - }
418402 }
419403 }
420404 else {
@@ -557,8 +541,8 @@
558542 $this->mTables = $wgMemc->get( $this->mCacheKey );
559543 wfProfileOut( __METHOD__.'-cache' );
560544 }
561 - if ( !$this->mTables ) {
562 - wfProfileOut( __METHOD__.'-recache' );
 545+ if ( !$this->mTables || !isset( $this->mTables['VERSION 2'] ) ) {
 546+ wfProfileIn( __METHOD__.'-recache' );
563547 // not in cache, or we need a fresh reload.
564548 // we will first load the default tables
565549 // then update them using things in MediaWiki:Zhconversiontable/*
@@ -566,10 +550,11 @@
567551 $this->loadDefaultTables();
568552 foreach($this->mVariants as $var) {
569553 $cached = $this->parseCachedTable($var);
570 - $this->mTables[$var] = array_merge($this->mTables[$var], $cached);
 554+ $this->mTables[$var]->mergeArray($cached);
571555 }
572556
573557 $this->postLoadTables();
 558+ $this->mTables['VERSION 2'] = true;
574559
575560 if($this->lockCache()) {
576561 $wgMemc->set($this->mCacheKey, $this->mTables, 43200);
@@ -577,23 +562,9 @@
578563 }
579564 wfProfileOut( __METHOD__.'-recache' );
580565 }
581 - if ( $this->mUseFss ) {
582 - wfProfileIn( __METHOD__.'-fss' );
583 - $this->generateFssObjects();
584 - wfProfileOut( __METHOD__.'-fss' );
585 - }
586566 wfProfileOut( __METHOD__ );
587567 }
588568
589 - /**
590 - * Generate FSS objects. The FSS extension must be available.
591 - */
592 - function generateFssObjects() {
593 - foreach ( $this->mTables as $variant => $table ) {
594 - $this->mFssObjects[$variant] = fss_prep_replace( $table );
595 - }
596 - }
597 -
598569 /**
599570 * Hook for post processig after conversion tables are loaded
600571 *
Index: trunk/phase3/languages/classes/LanguageSr.php
@@ -53,12 +53,13 @@
5454 );
5555
5656 function loadDefaultTables() {
57 - $this->mTables = array();
58 - $this->mTables['sr-ec'] = $this->mToCyrillics;
59 - $this->mTables['sr-jc'] = $this->mToCyrillics;
60 - $this->mTables['sr-el'] = $this->mToLatin;
61 - $this->mTables['sr-jl'] = $this->mToLatin;
62 - $this->mTables['sr'] = array();
 57+ $this->mTables = array(
 58+ 'sr-ec' => new ReplacementArray( $this->mToCyrillics ),
 59+ 'sr-jc' => new ReplacementArray( $this->mToCyrillics),
 60+ 'sr-el' => new ReplacementArray( $this->mToLatin),
 61+ 'sr-jl' => new ReplacementArray( $this->mToLatin),
 62+ 'sr' => new ReplacementArray()
 63+ );
6364 }
6465
6566 /* rules should be defined as -{ekavian | iyekavian-} -or-
@@ -139,7 +140,7 @@
140141 $matches = preg_split($reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE);
141142
142143 $m = array_shift($matches);
143 - $ret = strtr($m[0], $this->mTables[$toVariant]);
 144+ $ret = $this->mTables[$toVariant]->replace( $m[0] );
144145 $mstart = $m[1]+strlen($m[0]);
145146 foreach($matches as $m) {
146147 $ret .= substr($text, $mstart, $m[1]-$mstart);
@@ -149,8 +150,6 @@
150151
151152 return $ret;
152153 }
153 -
154 -
155154 }
156155
157156 class LanguageSr extends LanguageSr_ec {
Index: trunk/phase3/languages/classes/LanguageZh.php
@@ -9,17 +9,18 @@
1010 class ZhConverter extends LanguageConverter {
1111 function loadDefaultTables() {
1212 require( "includes/ZhConversion.php" );
13 - $this->mTables = array();
14 - $this->mTables['zh-cn'] = $zh2CN;
15 - $this->mTables['zh-tw'] = $zh2TW;
16 - $this->mTables['zh-sg'] = array_merge($zh2CN, $zh2SG);
17 - $this->mTables['zh-hk'] = array_merge($zh2TW, $zh2HK);
18 - $this->mTables['zh'] = array();
 13+ $this->mTables = array(
 14+ 'zh-cn' => new ReplacementArray( $zh2CN ),
 15+ 'zh-tw' => new ReplacementArray( $zh2TW ),
 16+ 'zh-sg' => new ReplacementArray( array_merge($zh2CN, $zh2SG) ),
 17+ 'zh-hk' => new ReplacementArray( array_merge($zh2TW, $zh2HK) ),
 18+ 'zh' => new ReplacementArray
 19+ );
1920 }
2021
2122 function postLoadTables() {
22 - $this->mTables['zh-sg'] = array_merge($this->mTables['zh-cn'], $this->mTables['zh-sg']);
23 - $this->mTables['zh-hk'] = array_merge($this->mTables['zh-tw'], $this->mTables['zh-hk']);
 23+ $this->mTables['zh-sg']->merge( $this->mTables['zh-cn'] );
 24+ $this->mTables['zh-hk']->merge( $this->mTables['zh-tw'] );
2425 }
2526
2627 /* there shouldn't be any latin text in Chinese conversion, so no need
Index: trunk/phase3/languages/classes/LanguageKk.php
@@ -89,11 +89,12 @@
9090 );
9191
9292 function loadDefaultTables() {
93 - $this->mTables = array();
94 - $this->mTables['kk-kz'] = $this->mLatinToCyrillic;
95 - $this->mTables['kk-tr'] = $this->mCyrillicToLatin;
96 - $this->mTables['kk-cn'] = $this->mCyrillicToArabic;
97 - $this->mTables['kk'] = array();
 93+ $this->mTables = array(
 94+ 'kk-kz' => new ReplacementArray( $this->mLatinToCyrillic ),
 95+ 'kk-tr' => new ReplacementArray( $this->mCyrillicToLatin ),
 96+ 'kk-cn' => new ReplacementArray( $this->mCyrillicToArabic ),
 97+ 'kk' => new ReplacementArray()
 98+ );
9899 }
99100
100101 /*
Index: trunk/phase3/maintenance/namespace2sql.php
@@ -6,8 +6,8 @@
77 require_once( "commandLine.inc" );
88
99 for ($i = -2; $i < 16; ++$i) {
10 - $nsname = wfStrencode( $wgLang->getNsText( $i ) );
11 - $dbname = wfStrencode( $wgDBname );
 10+ $nsname = mysql_escape_string( $wgLang->getNsText( $i ) );
 11+ $dbname = mysql_escape_string( $wgDBname );
1212 print "INSERT INTO ns_name(ns_db, ns_num, ns_name) VALUES('$dbname', $i, '$nsname');\n";
1313 }
1414
Index: trunk/phase3/includes/SiteStatsUpdate.php
@@ -1,92 +0,0 @@
2 -<?php
3 -/**
4 - * See deferred.txt
5 - *
6 - * @package MediaWiki
7 - */
8 -
9 -/**
10 - *
11 - * @package MediaWiki
12 - */
13 -class SiteStatsUpdate {
14 -
15 - var $mViews, $mEdits, $mGood, $mPages, $mUsers;
16 -
17 - function SiteStatsUpdate( $views, $edits, $good, $pages = 0, $users = 0 ) {
18 - $this->mViews = $views;
19 - $this->mEdits = $edits;
20 - $this->mGood = $good;
21 - $this->mPages = $pages;
22 - $this->mUsers = $users;
23 - }
24 -
25 - function appendUpdate( &$sql, $field, $delta ) {
26 - if ( $delta ) {
27 - if ( $sql ) {
28 - $sql .= ',';
29 - }
30 - if ( $delta < 0 ) {
31 - $sql .= "$field=$field-1";
32 - } else {
33 - $sql .= "$field=$field+1";
34 - }
35 - }
36 - }
37 -
38 - function doUpdate() {
39 - $fname = 'SiteStatsUpdate::doUpdate';
40 - $dbw =& wfGetDB( DB_MASTER );
41 -
42 - # First retrieve the row just to find out which schema we're in
43 - $row = $dbw->selectRow( 'site_stats', '*', false, $fname );
44 -
45 - $updates = '';
46 -
47 - $this->appendUpdate( $updates, 'ss_total_views', $this->mViews );
48 - $this->appendUpdate( $updates, 'ss_total_edits', $this->mEdits );
49 - $this->appendUpdate( $updates, 'ss_good_articles', $this->mGood );
50 -
51 - if ( isset( $row->ss_total_pages ) ) {
52 - # Update schema if required
53 - if ( $row->ss_total_pages == -1 && !$this->mViews ) {
54 - $dbr =& wfGetDB( DB_SLAVE, array( 'SpecialStatistics', 'vslow') );
55 - extract( $dbr->tableNames( 'page', 'user' ) );
56 -
57 - $sql = "SELECT COUNT(page_namespace) AS total FROM $page";
58 - $res = $dbr->query( $sql, $fname );
59 - $pageRow = $dbr->fetchObject( $res );
60 - $pages = $pageRow->total + $this->mPages;
61 -
62 - $sql = "SELECT COUNT(user_id) AS total FROM $user";
63 - $res = $dbr->query( $sql, $fname );
64 - $userRow = $dbr->fetchObject( $res );
65 - $users = $userRow->total + $this->mUsers;
66 -
67 - if ( $updates ) {
68 - $updates .= ',';
69 - }
70 - $updates .= "ss_total_pages=$pages, ss_users=$users";
71 - } else {
72 - $this->appendUpdate( $updates, 'ss_total_pages', $this->mPages );
73 - $this->appendUpdate( $updates, 'ss_users', $this->mUsers );
74 - }
75 - }
76 - if ( $updates ) {
77 - $site_stats = $dbw->tableName( 'site_stats' );
78 - $sql = $dbw->limitResultForUpdate("UPDATE $site_stats SET $updates", 1);
79 - $dbw->begin();
80 - $dbw->query( $sql, $fname );
81 - $dbw->commit();
82 - }
83 -
84 - /*
85 - global $wgDBname, $wgTitle;
86 - if ( $this->mGood && $wgDBname == 'enwiki' ) {
87 - $good = $dbw->selectField( 'site_stats', 'ss_good_articles', '', $fname );
88 - error_log( $good . ' ' . $wgTitle->getPrefixedDBkey() . "\n", 3, '/home/wikipedia/logs/million.log' );
89 - }
90 - */
91 - }
92 -}
93 -?>
Index: trunk/phase3/includes/MagicWord.php
@@ -298,7 +298,7 @@
299299 * Replaces the word with something else
300300 */
301301 function replace( $replacement, $subject, $limit=-1 ) {
302 - $res = preg_replace( $this->getRegex(), wfRegexReplacement( $replacement ), $subject, $limit );
 302+ $res = preg_replace( $this->getRegex(), StringUtils::escapeRegexReplacement( $replacement ), $subject, $limit );
303303 $this->mModified = !($res === $subject);
304304 return $res;
305305 }
Index: trunk/phase3/includes/SpecialStatistics.php
@@ -15,40 +15,15 @@
1616 $action = $wgRequest->getVal( 'action' );
1717
1818 $dbr =& wfGetDB( DB_SLAVE );
19 - extract( $dbr->tableNames( 'page', 'site_stats', 'user', 'user_groups' ) );
 19+ extract( $dbr->tableNames( 'site_stats', 'user', 'user_groups' ) );
2020
21 - $row = $dbr->selectRow( 'site_stats', '*', false, $fname );
22 - $views = $row->ss_total_views;
23 - $edits = $row->ss_total_edits;
24 - $good = $row->ss_good_articles;
25 - $images = $row->ss_images;
 21+ $views = SiteStats::views();
 22+ $edits = SiteStats::edits();
 23+ $good = SiteStats::articles();
 24+ $images = SiteStats::images();
 25+ $total = SiteStats::pages();
 26+ $users = SiteStats::users();
2627
27 - # This code is somewhat schema-agnostic, because I'm changing it in a minor release -- TS
28 - if ( isset( $row->ss_total_pages ) && $row->ss_total_pages == -1 ) {
29 - # Update schema
30 - $u = new SiteStatsUpdate( 0, 0, 0 );
31 - $u->doUpdate();
32 - $row = $dbr->selectRow( 'site_stats', '*', false, $fname );
33 - }
34 -
35 - if ( isset( $row->ss_total_pages ) ) {
36 - $total = $row->ss_total_pages;
37 - } else {
38 - $sql = "SELECT COUNT(page_namespace) AS total FROM $page";
39 - $res = $dbr->query( $sql, $fname );
40 - $pageRow = $dbr->fetchObject( $res );
41 - $total = $pageRow->total;
42 - }
43 -
44 - if ( isset( $row->ss_users ) ) {
45 - $users = $row->ss_users;
46 - } else {
47 - $sql = "SELECT MAX(user_id) AS total FROM $user";
48 - $res = $dbr->query( $sql, $fname );
49 - $userRow = $dbr->fetchObject( $res );
50 - $users = $userRow->total;
51 - }
52 -
5328 $admins = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), $fname );
5429 $numJobs = $dbr->selectField( 'job', 'COUNT(*)', '', $fname );
5530
Index: trunk/phase3/includes/AutoLoader.php
@@ -86,7 +86,6 @@
8787 'FileStore' => 'includes/FileStore.php',
8888 'FSException' => 'includes/FileStore.php',
8989 'FSTransaction' => 'includes/FileStore.php',
90 - 'ReplacerCallback' => 'includes/GlobalFunctions.php',
9190 'HTMLForm' => 'includes/HTMLForm.php',
9291 'HistoryBlob' => 'includes/HistoryBlob.php',
9392 'ConcatenatedGzipHistoryBlob' => 'includes/HistoryBlob.php',
@@ -150,7 +149,8 @@
151150 'SearchUpdate' => 'includes/SearchUpdate.php',
152151 'SearchUpdateMyISAM' => 'includes/SearchUpdate.php',
153152 'SiteConfiguration' => 'includes/SiteConfiguration.php',
154 - 'SiteStatsUpdate' => 'includes/SiteStatsUpdate.php',
 153+ 'SiteStats' => 'includes/SiteStats.php',
 154+ 'SiteStatsUpdate' => 'includes/SiteStats.php',
155155 'Skin' => 'includes/Skin.php',
156156 'MediaWiki_I18N' => 'includes/SkinTemplate.php',
157157 'SkinTemplate' => 'includes/SkinTemplate.php',
@@ -215,6 +215,12 @@
216216 'WantedPagesPage' => 'includes/SpecialWantedpages.php',
217217 'WhatLinksHerePage' => 'includes/SpecialWhatlinkshere.php',
218218 'SquidUpdate' => 'includes/SquidUpdate.php',
 219+ 'ReplacementArray' => 'includes/StringUtils.php',
 220+ 'Replacer' => 'includes/StringUtils.php',
 221+ 'RegexlikeReplacer' => 'includes/StringUtils.php',
 222+ 'DoubleReplacer' => 'includes/StringUtils.php',
 223+ 'HashtableReplacer' => 'includes/StringUtils.php',
 224+ 'StringUtils' => 'includes/StringUtils.php',
219225 'Title' => 'includes/Title.php',
220226 'User' => 'includes/User.php',
221227 'MailAddress' => 'includes/UserMailer.php',
Index: trunk/phase3/includes/Database.php
@@ -295,7 +295,7 @@
296296 * Turns on (false) or off (true) the automatic generation and sending
297297 * of a "we're sorry, but there has been a database error" page on
298298 * database errors. Default is on (false). When turned off, the
299 - * code should use wfLastErrno() and wfLastError() to handle the
 299+ * code should use lastErrno() and lastError() to handle the
300300 * situation as appropriate.
301301 */
302302 function ignoreErrors( $ignoreErrors = NULL ) {
@@ -1296,7 +1296,7 @@
12971297 }
12981298
12991299 /**
1300 - * Makes a wfStrencoded list from an array
 1300+ * Makes an encoded list of strings from an array
13011301 * $mode:
13021302 * LIST_COMMA - comma separated, no field names
13031303 * LIST_AND - ANDed WHERE clause (without the WHERE)
Index: trunk/phase3/includes/Linker.php
@@ -959,7 +959,7 @@
960960 $match[1] = substr($match[1], 1);
961961 $thelink = $this->makeLink( $match[1], $text, "", $trail );
962962 }
963 - $comment = preg_replace( $linkRegexp, wfRegexReplacement( $thelink ), $comment, 1 );
 963+ $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 );
964964 }
965965 wfProfileOut( __METHOD__ );
966966 return $comment;
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -26,7 +26,6 @@
2727 $wgTotalEdits = -1;
2828
2929
30 -require_once( 'DatabaseFunctions.php' );
3130 require_once( 'LogPage.php' );
3231 require_once( 'normal/UtfNormalUtil.php' );
3332 require_once( 'XmlFunctions.php' );
@@ -1736,16 +1735,10 @@
17371736 }
17381737
17391738 /**
1740 - * Escape a string to make it suitable for inclusion in a preg_replace()
1741 - * replacement parameter.
1742 - *
1743 - * @param string $string
1744 - * @return string
 1739+ * @deprecated use StringUtils::escapeRegexReplacement
17451740 */
17461741 function wfRegexReplacement( $string ) {
1747 - $string = str_replace( '\\', '\\\\', $string );
1748 - $string = str_replace( '$', '\\$', $string );
1749 - return $string;
 1742+ return StringUtils::escapeRegexReplacement( $string );
17501743 }
17511744
17521745 /**
@@ -1815,42 +1808,12 @@
18161809 }
18171810
18181811 /**
1819 - * More or less "markup-safe" explode()
1820 - * Ignores any instances of the separator inside <...>
1821 - * @param string $separator
1822 - * @param string $text
1823 - * @return array
 1812+ * @deprecated use StringUtils::explodeMarkup
18241813 */
18251814 function wfExplodeMarkup( $separator, $text ) {
1826 - $placeholder = "\x00";
1827 -
1828 - // Just in case...
1829 - $text = str_replace( $placeholder, '', $text );
1830 -
1831 - // Trim stuff
1832 - $replacer = new ReplacerCallback( $separator, $placeholder );
1833 - $cleaned = preg_replace_callback( '/(<.*?>)/', array( $replacer, 'go' ), $text );
1834 -
1835 - $items = explode( $separator, $cleaned );
1836 - foreach( $items as $i => $str ) {
1837 - $items[$i] = str_replace( $placeholder, $separator, $str );
1838 - }
1839 -
1840 - return $items;
 1815+ return StringUtils::explodeMarkup( $separator, $text );
18411816 }
18421817
1843 -class ReplacerCallback {
1844 - function ReplacerCallback( $from, $to ) {
1845 - $this->from = $from;
1846 - $this->to = $to;
1847 - }
1848 -
1849 - function go( $matches ) {
1850 - return str_replace( $this->from, $this->to, $matches[1] );
1851 - }
1852 -}
1853 -
1854 -
18551818 /**
18561819 * Convert an arbitrarily-long digit string from one numeric base
18571820 * to another, optionally zero-padding to a minimum column width.
@@ -2074,4 +2037,20 @@
20752038 }
20762039 }
20772040
 2041+/*
 2042+ * Get a Database object
 2043+ * @param integer $db Index of the connection to get. May be DB_MASTER for the
 2044+ * master (for write queries), DB_SLAVE for potentially lagged
 2045+ * read queries, or an integer >= 0 for a particular server.
 2046+ *
 2047+ * @param array $groups Query groups. A list of group names that this query
 2048+ * belongs to.
 2049+ */
 2050+function &wfGetDB( $db = DB_LAST, $groups = array() ) {
 2051+ global $wgLoadBalancer;
 2052+ $ret =& $wgLoadBalancer->getConnection( $db, true, $groups );
 2053+ return $ret;
 2054+}
 2055+
 2056+
20782057 ?>
Index: trunk/phase3/includes/Parser.php
@@ -97,7 +97,7 @@
9898 var $mTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables;
9999
100100 # Cleared with clearState():
101 - var $mOutput, $mAutonumber, $mDTopen, $mStripState = array();
 101+ var $mOutput, $mAutonumber, $mDTopen, $mStripState;
102102 var $mIncludeCount, $mArgStack, $mLastSection, $mInPre;
103103 var $mInterwikiLinkHolders, $mLinkHolders, $mUniqPrefix;
104104 var $mIncludeSizes;
@@ -112,7 +112,9 @@
113113 $mTitle, // Title context, used for self-link rendering and similar things
114114 $mOutputType, // Output type, one of the OT_xxx constants
115115 $ot, // Shortcut alias, see setOutputType()
116 - $mRevisionId; // ID to display in {{REVISIONID}} tags
 116+ $mRevisionId, // ID to display in {{REVISIONID}} tags
 117+ $mRevisionTimestamp, // The timestamp of the specified revision ID
 118+ $mRevIdForTs; // The revision ID which was used to fetch the timestamp
117119
118120 /**#@-*/
119121
@@ -174,7 +176,6 @@
175177 }
176178
177179 $this->initialiseVariables();
178 -
179180 $this->mFirstCall = false;
180181 wfProfileOut( __METHOD__ );
181182 }
@@ -194,7 +195,7 @@
195196 $this->mLastSection = '';
196197 $this->mDTopen = false;
197198 $this->mIncludeCount = array();
198 - $this->mStripState = array();
 199+ $this->mStripState = new StripState;
199200 $this->mArgStack = array();
200201 $this->mInPre = false;
201202 $this->mInterwikiLinkHolders = array(
@@ -208,8 +209,8 @@
209210 'texts' => array(),
210211 'titles' => array()
211212 );
212 - $this->mRevisionId = null;
213 -
 213+ $this->mRevisionTimestamp = $this->mRevisionId = null;
 214+
214215 /**
215216 * Prefix for temporary replacement strings for the multipass parser.
216217 * \x07 should never appear in input as it's disallowed in XML.
@@ -286,23 +287,18 @@
287288 $this->mOptions = $options;
288289 $this->mTitle =& $title;
289290 $oldRevisionId = $this->mRevisionId;
 291+ $oldRevisionTimestamp = $this->mRevisionTimestamp;
290292 if( $revid !== null ) {
291293 $this->mRevisionId = $revid;
 294+ $this->mRevisionTimestamp = null;
292295 }
293296 $this->setOutputType( OT_HTML );
294 -
295 - //$text = $this->strip( $text, $this->mStripState );
296 - // VOODOO MAGIC FIX! Sometimes the above segfaults in PHP5.
297 - $x =& $this->mStripState;
298 -
299 - wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$x ) );
300 - $text = $this->strip( $text, $x );
301 - wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$x ) );
302 -
 297+ wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
 298+ $text = $this->strip( $text, $this->mStripState );
 299+ wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
303300 $text = $this->internalParse( $text );
 301+ $text = $this->mStripState->unstripGeneral( $text );
304302
305 - $text = $this->unstrip( $text, $this->mStripState );
306 -
307303 # Clean up special characters, only run once, next-to-last before doBlockLevels
308304 $fixtags = array(
309305 # french spaces, last one Guillemet-left
@@ -324,7 +320,7 @@
325321 # Side-effects: this calls $this->mOutput->setTitleText()
326322 $text = $wgContLang->parserConvert( $text, $this );
327323
328 - $text = $this->unstripNoWiki( $text, $this->mStripState );
 324+ $text = $this->mStripState->unstripNoWiki( $text );
329325
330326 wfRunHooks( 'ParserBeforeTidy', array( &$this, &$text ) );
331327
@@ -374,6 +370,7 @@
375371 }
376372 $this->mOutput->setText( $text );
377373 $this->mRevisionId = $oldRevisionId;
 374+ $this->mRevisionTimestamp = $oldRevisionTimestamp;
378375 wfProfileOut( $fname );
379376 wfProfileOut( __METHOD__ );
380377
@@ -405,16 +402,14 @@
406403 $this->setOutputType( OT_PREPROCESS );
407404 $this->mOptions = $options;
408405 $this->mTitle = $title;
409 - $x =& $this->mStripState;
410 - wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$x ) );
411 - $text = $this->strip( $text, $x );
412 - wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$x ) );
 406+ wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
 407+ $text = $this->strip( $text, $this->mStripState );
 408+ wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
413409 if ( $this->mOptions->getRemoveComments() ) {
414410 $text = Sanitizer::removeHTMLcomments( $text );
415411 }
416412 $text = $this->replaceVariables( $text );
417 - $text = $this->unstrip( $text, $x );
418 - $text = $this->unstripNowiki( $text, $x );
 413+ $text = $this->mStripState->unstripBoth( $text );
419414 wfProfileOut( __METHOD__ );
420415 return $text;
421416 }
@@ -521,8 +516,9 @@
522517 * Strips and renders nowiki, pre, math, hiero
523518 * If $render is set, performs necessary rendering operations on plugins
524519 * Returns the text, and fills an array with data needed in unstrip()
525 - * If the $state is already a valid strip state, it adds to the state
526520 *
 521+ * @param StripState $state
 522+ *
527523 * @param bool $stripcomments when set, HTML comments <!-- like this -->
528524 * will be stripped in addition to other tags. This is important
529525 * for section editing, where these comments cause confusion when
@@ -533,12 +529,12 @@
534530 *
535531 * @private
536532 */
537 - function strip( $text, &$state, $stripcomments = false , $dontstrip = array () ) {
 533+ function strip( $text, $state, $stripcomments = false , $dontstrip = array () ) {
538534 wfProfileIn( __METHOD__ );
539535 $render = ($this->mOutputType == OT_HTML);
540536
541537 $uniq_prefix = $this->mUniqPrefix;
542 - $commentState = array();
 538+ $commentState = new ReplacementArray;
543539
544540 $elements = array_merge(
545541 array( 'nowiki', 'gallery' ),
@@ -583,7 +579,7 @@
584580 }
585581 // Shouldn't happen otherwise. :)
586582 case 'nowiki':
587 - $output = wfEscapeHTMLTagsOnly( $content );
 583+ $output = Xml::escapeTagsOnly( $content );
588584 break;
589585 case 'math':
590586 $output = MathRenderer::renderMath( $content );
@@ -607,14 +603,14 @@
608604
609605 // Unstrip the output, because unstrip() is no longer recursive so
610606 // it won't do it itself
611 - $output = $this->unstrip( $output, $state );
 607+ $output = $state->unstripBoth( $output );
612608
613609 if( !$stripcomments && $element == '!--' ) {
614 - $commentState[$marker] = $output;
 610+ $commentState->setPair( $marker, $output );
615611 } elseif ( $element == 'html' || $element == 'nowiki' ) {
616 - $state['nowiki'][$marker] = $output;
 612+ $state->nowiki->setPair( $marker, $output );
617613 } else {
618 - $state['general'][$marker] = $output;
 614+ $state->general->setPair( $marker, $output );
619615 }
620616 }
621617
@@ -624,7 +620,7 @@
625621 # a comment.)
626622 if ( !$stripcomments ) {
627623 // Put them all back and forget them
628 - $text = strtr( $text, $commentState );
 624+ $text = $commentState->replace( $text );
629625 }
630626
631627 wfProfileOut( __METHOD__ );
@@ -636,35 +632,27 @@
637633 *
638634 * always call unstripNoWiki() after this one
639635 * @private
 636+ * @deprecated use $this->mStripState->unstrip()
640637 */
641638 function unstrip( $text, $state ) {
642 - if ( !isset( $state['general'] ) ) {
643 - return $text;
644 - }
645 -
646 - wfProfileIn( __METHOD__ );
647 - # TODO: good candidate for FSS
648 - $text = strtr( $text, $state['general'] );
649 - wfProfileOut( __METHOD__ );
650 - return $text;
 639+ return $state->unstripGeneral( $text );
651640 }
652641
653642 /**
654643 * Always call this after unstrip() to preserve the order
655644 *
656645 * @private
 646+ * @deprecated use $this->mStripState->unstrip()
657647 */
658648 function unstripNoWiki( $text, $state ) {
659 - if ( !isset( $state['nowiki'] ) ) {
660 - return $text;
661 - }
 649+ return $state->unstripNoWiki( $text );
 650+ }
662651
663 - wfProfileIn( __METHOD__ );
664 - # TODO: good candidate for FSS
665 - $text = strtr( $text, $state['nowiki'] );
666 - wfProfileOut( __METHOD__ );
667 -
668 - return $text;
 652+ /**
 653+ * @deprecated use $this->mStripState->unstripBoth()
 654+ */
 655+ function unstripForHTML( $text ) {
 656+ return $this->mStripState->unstripBoth( $text );
669657 }
670658
671659 /**
@@ -676,10 +664,7 @@
677665 */
678666 function insertStripItem( $text, &$state ) {
679667 $rnd = $this->mUniqPrefix . '-item' . Parser::getRandomString();
680 - if ( !$state ) {
681 - $state = array();
682 - }
683 - $state['general'][$rnd] = $text;
 668+ $state->general->setPair( $rnd, $text );
684669 return $rnd;
685670 }
686671
@@ -815,7 +800,7 @@
816801 if ( preg_match( '/^(:*)\{\|(.*)$/', $x, $matches ) ) {
817802 $indent_level = strlen( $matches[1] );
818803
819 - $attributes = $this->unstripForHTML( $matches[2] );
 804+ $attributes = $this->mStripState->unstripBoth( $matches[2] );
820805
821806 $t[$k] = str_repeat( '<dl><dd>', $indent_level ) .
822807 '<table' . Sanitizer::fixTagAttributes ( $attributes, 'table' ) . '>' ;
@@ -849,7 +834,7 @@
850835 array_push ( $tr , false ) ;
851836 array_push ( $td , false ) ;
852837 array_push ( $ltd , '' ) ;
853 - $attributes = $this->unstripForHTML( $x );
 838+ $attributes = $this->mStripState->unstripBoth( $x );
854839 array_push ( $ltr , Sanitizer::fixTagAttributes ( $attributes, 'tr' ) ) ;
855840 }
856841 else if ( '|' == $fc || '!' == $fc || '|+' == substr ( $x , 0 , 2 ) ) { # Caption
@@ -865,7 +850,7 @@
866851 // FIXME: This can result in improper nesting of tags processed
867852 // by earlier parser steps, but should avoid splitting up eg
868853 // attribute values containing literal "||".
869 - $after = wfExplodeMarkup( '||', $after );
 854+ $after = StringUtils::explodeMarkup( '||', $after );
870855
871856 $t[$k] = '' ;
872857
@@ -906,7 +891,7 @@
907892 if ( count ( $y ) == 1 )
908893 $y = "{$z}<{$l}>{$y[0]}" ;
909894 else {
910 - $attributes = $this->unstripForHTML( $y[0] );
 895+ $attributes = $this->mStripState->unstripBoth( $y[0] );
911896 $y = "{$z}<{$l}".Sanitizer::fixTagAttributes($attributes, $l).">{$y[1]}" ;
912897 }
913898 $t[$k] .= $y ;
@@ -955,7 +940,7 @@
956941 # Remove <noinclude> tags and <includeonly> sections
957942 $text = strtr( $text, array( '<onlyinclude>' => '' , '</onlyinclude>' => '' ) );
958943 $text = strtr( $text, array( '<noinclude>' => '', '</noinclude>' => '') );
959 - $text = preg_replace( '/<includeonly>.*?<\/includeonly>/s', '', $text );
 944+ $text = StringUtils::delimiterReplace( '<includeonly>', '</includeonly>', '', $text );
960945
961946 $text = Sanitizer::removeHTMLtags( $text, array( &$this, 'attributeStripCallback' ) );
962947
@@ -1611,7 +1596,7 @@
16121597
16131598 wfProfileOut( "$fname-misc" );
16141599 wfProfileIn( "$fname-title" );
1615 - $nt = Title::newFromText( $this->unstripNoWiki($link, $this->mStripState) );
 1600+ $nt = Title::newFromText( $this->mStripState->unstripNoWiki($link) );
16161601 if( !$nt ) {
16171602 $s .= $prefix . '[[' . $line;
16181603 wfProfileOut( "$fname-title" );
@@ -2434,15 +2419,15 @@
24352420 case 'revisionid':
24362421 return $this->mRevisionId;
24372422 case 'revisionday':
2438 - return intval( substr( wfRevisionTimestamp( $this->mRevisionId ), 6, 2 ) );
 2423+ return intval( substr( $this->getRevisionTimestamp(), 6, 2 ) );
24392424 case 'revisionday2':
2440 - return substr( wfRevisionTimestamp( $this->mRevisionId ), 6, 2 );
 2425+ return substr( $this->getRevisionTimestamp(), 6, 2 );
24412426 case 'revisionmonth':
2442 - return intval( substr( wfRevisionTimestamp( $this->mRevisionId ), 4, 2 ) );
 2427+ return intval( substr( $this->getRevisionTimestamp(), 4, 2 ) );
24432428 case 'revisionyear':
2444 - return substr( wfRevisionTimestamp( $this->mRevisionId ), 0, 4 );
 2429+ return substr( $this->getRevisionTimestamp(), 0, 4 );
24452430 case 'revisiontimestamp':
2446 - return wfRevisionTimestamp( $this->mRevisionId );
 2431+ return $this->getRevisionTimestamp();
24472432 case 'namespace':
24482433 return str_replace('_',' ',$wgContLang->getNsText( $this->mTitle->getNamespace() ) );
24492434 case 'namespacee':
@@ -2484,15 +2469,15 @@
24852470 case 'localdow':
24862471 return $varCache[$index] = $wgContLang->formatNum( $localDayOfWeek );
24872472 case 'numberofarticles':
2488 - return $varCache[$index] = $wgContLang->formatNum( wfNumberOfArticles() );
 2473+ return $varCache[$index] = $wgContLang->formatNum( SiteStats::articles() );
24892474 case 'numberoffiles':
2490 - return $varCache[$index] = $wgContLang->formatNum( wfNumberOfFiles() );
 2475+ return $varCache[$index] = $wgContLang->formatNum( SiteStats::images() );
24912476 case 'numberofusers':
2492 - return $varCache[$index] = $wgContLang->formatNum( wfNumberOfUsers() );
 2477+ return $varCache[$index] = $wgContLang->formatNum( SiteStats::users() );
24932478 case 'numberofpages':
2494 - return $varCache[$index] = $wgContLang->formatNum( wfNumberOfPages() );
 2479+ return $varCache[$index] = $wgContLang->formatNum( SiteStats::pages() );
24952480 case 'numberofadmins':
2496 - return $varCache[$index] = $wgContLang->formatNum( wfNumberOfAdmins() );
 2481+ return $varCache[$index] = $wgContLang->formatNum( SiteStats::admins() );
24972482 case 'currenttimestamp':
24982483 return $varCache[$index] = wfTimestampNow();
24992484 case 'localtimestamp':
@@ -3079,14 +3064,13 @@
30803065 if ( !$noparse ) {
30813066 # If there are any <onlyinclude> tags, only include them
30823067 if ( in_string( '<onlyinclude>', $text ) && in_string( '</onlyinclude>', $text ) ) {
3083 - $m = array();
3084 - preg_match_all( '/<onlyinclude>(.*?)\n?<\/onlyinclude>/s', $text, $m );
3085 - $text = '';
3086 - foreach ($m[1] as $piece)
3087 - $text .= $piece;
 3068+ $replacer = new OnlyIncludeReplacer;
 3069+ StringUtils::delimiterReplaceCallback( '<onlyinclude>', '</onlyinclude>',
 3070+ array( &$replacer, 'replace' ), $text );
 3071+ $text = $replacer->output;
30883072 }
30893073 # Remove <noinclude> sections and <includeonly> tags
3090 - $text = preg_replace( '/<noinclude>.*?<\/noinclude>/s', '', $text );
 3074+ $text = StringUtils::delimiterReplace( '<noinclude>', '</noinclude>', '', $text );
30913075 $text = strtr( $text, array( '<includeonly>' => '' , '</includeonly>' => '' ) );
30923076
30933077 if( $this->ot['html'] || $this->ot['pre'] ) {
@@ -3481,8 +3465,7 @@
34823466
34833467 # The canonized header is a version of the header text safe to use for links
34843468 # Avoid insertion of weird stuff like <math> by expanding the relevant sections
3485 - $canonized_headline = $this->unstrip( $headline, $this->mStripState );
3486 - $canonized_headline = $this->unstripNoWiki( $canonized_headline, $this->mStripState );
 3469+ $canonized_headline = $this->mStripState->unstripBoth( $headline );
34873470
34883471 # Remove link placeholders by the link text.
34893472 # <!--LINK number-->
@@ -3604,15 +3587,14 @@
36053588 $this->clearState();
36063589 }
36073590
3608 - $stripState = false;
 3591+ $stripState = new StripState;
36093592 $pairs = array(
36103593 "\r\n" => "\n",
36113594 );
36123595 $text = str_replace( array_keys( $pairs ), array_values( $pairs ), $text );
36133596 $text = $this->strip( $text, $stripState, true, array( 'gallery' ) );
36143597 $text = $this->pstPass2( $text, $stripState, $user );
3615 - $text = $this->unstrip( $text, $stripState );
3616 - $text = $this->unstripNoWiki( $text, $stripState );
 3598+ $text = $stripState->unstripBoth( $text );
36173599 return $text;
36183600 }
36193601
@@ -3915,7 +3897,6 @@
39163898 */
39173899 function replaceLinkHolders( &$text, $options = 0 ) {
39183900 global $wgUser;
3919 - global $wgOutputReplace;
39203901 global $wgContLang;
39213902
39223903 $fname = 'Parser::replaceLinkHolders';
@@ -4095,7 +4076,7 @@
40964077
40974078 # Construct search and replace arrays
40984079 wfProfileIn( $fname.'-construct' );
4099 - $wgOutputReplace = array();
 4080+ $replacePairs = array();
41004081 foreach ( $this->mLinkHolders['namespaces'] as $key => $ns ) {
41014082 $pdbk = $pdbks[$key];
41024083 $searchkey = "<!--LINK $key-->";
@@ -4104,27 +4085,27 @@
41054086 $linkCache->addBadLinkObj( $title );
41064087 $colours[$pdbk] = 0;
41074088 $this->mOutput->addLink( $title, 0 );
4108 - $wgOutputReplace[$searchkey] = $sk->makeBrokenLinkObj( $title,
 4089+ $replacePairs[$searchkey] = $sk->makeBrokenLinkObj( $title,
41094090 $this->mLinkHolders['texts'][$key],
41104091 $this->mLinkHolders['queries'][$key] );
41114092 } elseif ( $colours[$pdbk] == 1 ) {
4112 - $wgOutputReplace[$searchkey] = $sk->makeKnownLinkObj( $title,
 4093+ $replacePairs[$searchkey] = $sk->makeKnownLinkObj( $title,
41134094 $this->mLinkHolders['texts'][$key],
41144095 $this->mLinkHolders['queries'][$key] );
41154096 } elseif ( $colours[$pdbk] == 2 ) {
4116 - $wgOutputReplace[$searchkey] = $sk->makeStubLinkObj( $title,
 4097+ $replacePairs[$searchkey] = $sk->makeStubLinkObj( $title,
41174098 $this->mLinkHolders['texts'][$key],
41184099 $this->mLinkHolders['queries'][$key] );
41194100 }
41204101 }
 4102+ $replacer = new HashtableReplacer( $replacePairs, 1 );
41214103 wfProfileOut( $fname.'-construct' );
41224104
41234105 # Do the thing
41244106 wfProfileIn( $fname.'-replace' );
4125 -
41264107 $text = preg_replace_callback(
41274108 '/(<!--LINK .*?-->)/',
4128 - "wfOutputReplaceMatches",
 4109+ $replacer->cb(),
41294110 $text);
41304111
41314112 wfProfileOut( $fname.'-replace' );
@@ -4135,15 +4116,16 @@
41364117 if ( !empty( $this->mInterwikiLinkHolders['texts'] ) ) {
41374118 wfProfileIn( $fname.'-interwiki' );
41384119 # Make interwiki link HTML
4139 - $wgOutputReplace = array();
 4120+ $replacePairs = array();
41404121 foreach( $this->mInterwikiLinkHolders['texts'] as $key => $link ) {
41414122 $title = $this->mInterwikiLinkHolders['titles'][$key];
4142 - $wgOutputReplace[$key] = $sk->makeLinkObj( $title, $link );
 4123+ $replacePairs[$key] = $sk->makeLinkObj( $title, $link );
41434124 }
 4125+ $replacer = new HashtableReplacer( $replacePairs, 1 );
41444126
41454127 $text = preg_replace_callback(
41464128 '/<!--IWLINK (.*?)-->/',
4147 - "wfOutputReplaceMatches",
 4129+ $replacer->cb(),
41484130 $text );
41494131 wfProfileOut( $fname.'-interwiki' );
41504132 }
@@ -4196,11 +4178,11 @@
41974179 */
41984180 function renderPreTag( $text, $attribs ) {
41994181 // Backwards-compatibility hack
4200 - $content = preg_replace( '!<nowiki>(.*?)</nowiki>!is', '\\1', $text );
 4182+ $content = StringUtils::delimiterReplace( '<nowiki>', '</nowiki>', '$1', $text, 'i' );
42014183
42024184 $attribs = Sanitizer::validateTagAttributes( $attribs, 'pre' );
42034185 return wfOpenElement( 'pre', $attribs ) .
4204 - wfEscapeHTMLTagsOnly( $content ) .
 4186+ Xml::escapeTagsOnly( $content ) .
42054187 '</pre>';
42064188 }
42074189
@@ -4343,7 +4325,7 @@
43444326 # make sure there are no placeholders in thumbnail attributes
43454327 # that are later expanded to html- so expand them now and
43464328 # remove the tags
4347 - $alt = $this->unstrip($alt, $this->mStripState);
 4329+ $alt = $this->mStripState->unstripBoth( $alt );
43484330 $alt = Sanitizer::stripAllTags( $alt );
43494331
43504332 # Linker does the rest
@@ -4370,15 +4352,10 @@
43714353 */
43724354 function attributeStripCallback( &$text, $args ) {
43734355 $text = $this->replaceVariables( $text, $args );
4374 - $text = $this->unstripForHTML( $text );
 4356+ $text = $this->mStripState->unstripBoth( $text );
43754357 return $text;
43764358 }
43774359
4378 - function unstripForHTML( $text ) {
4379 - $text = $this->unstrip( $text, $this->mStripState );
4380 - $text = $this->unstripNoWiki( $text, $this->mStripState );
4381 - return $text;
4382 - }
43834360 /**#@-*/
43844361
43854362 /**#@+
@@ -4414,14 +4391,14 @@
44154392 private function extractSections( $text, $section, $mode, $newtext='' ) {
44164393 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
44174394 # comments to be stripped as well)
4418 - $striparray = array();
 4395+ $stripState = new StripState;
44194396
44204397 $oldOutputType = $this->mOutputType;
44214398 $oldOptions = $this->mOptions;
44224399 $this->mOptions = new ParserOptions();
44234400 $this->setOutputType( OT_WIKI );
44244401
4425 - $striptext = $this->strip( $text, $striparray, true );
 4402+ $striptext = $this->strip( $text, $stripState, true );
44264403
44274404 $this->setOutputType( $oldOutputType );
44284405 $this->mOptions = $oldOptions;
@@ -4528,9 +4505,7 @@
45294506 }
45304507 }
45314508 # reinsert stripped tags
4532 - $rv = $this->unstrip( $rv, $striparray );
4533 - $rv = $this->unstripNoWiki( $rv, $striparray );
4534 - $rv = trim( $rv );
 4509+ $rv = trim( $stripState->unstripBoth( $rv ) );
45354510 return $rv;
45364511 }
45374512
@@ -4553,6 +4528,23 @@
45544529 return $this->extractSections( $oldtext, $section, "replace", $text );
45554530 }
45564531
 4532+ /**
 4533+ * Get the timestamp associated with the current revision, adjusted for
 4534+ * the user's current timestamp
 4535+ */
 4536+ function getRevisionTimestamp() {
 4537+ if ( is_null( $this->mRevisionTimestamp ) ) {
 4538+ wfProfileIn( __METHOD__ );
 4539+ global $wgContLang;
 4540+ $dbr =& wfGetDB( DB_SLAVE );
 4541+ $timestamp = $dbr->selectField( 'revision', 'rev_timestamp',
 4542+ array( 'rev_id' => $id ), __METHOD__ );
 4543+ $this->mRevisionTimestamp = $wgContLang->userAdjust( $timestamp );
 4544+
 4545+ wfProfileOut( __METHOD__ );
 4546+ }
 4547+ return $this->mRevisionTimestamp;
 4548+ }
45574549 }
45584550
45594551 /**
@@ -4787,152 +4779,47 @@
47884780 }
47894781 }
47904782
4791 -/**
4792 - * Callback function used by Parser::replaceLinkHolders()
4793 - * to substitute link placeholders.
4794 - */
4795 -function &wfOutputReplaceMatches( $matches ) {
4796 - global $wgOutputReplace;
4797 - return $wgOutputReplace[$matches[1]];
4798 -}
 4783+class OnlyIncludeReplacer {
 4784+ var $output = '';
47994785
4800 -/**
4801 - * Return the total number of articles
4802 - */
4803 -function wfNumberOfArticles() {
4804 - global $wgNumberOfArticles;
4805 -
4806 - wfLoadSiteStats();
4807 - return $wgNumberOfArticles;
 4786+ function replace( $matches ) {
 4787+ if ( substr( $matches[1], -1 ) == "\n" ) {
 4788+ $this->output .= substr( $matches[1], 0, -1 );
 4789+ } else {
 4790+ $this->output .= $matches[1];
 4791+ }
 4792+ }
48084793 }
48094794
4810 -/**
4811 - * Return the number of files
4812 - */
4813 -function wfNumberOfFiles() {
4814 - $fname = 'wfNumberOfFiles';
 4795+class StripState {
 4796+ var $general, $nowiki;
48154797
4816 - wfProfileIn( $fname );
4817 - $dbr =& wfGetDB( DB_SLAVE );
4818 - $numImages = $dbr->selectField('site_stats', 'ss_images', array(), $fname );
4819 - wfProfileOut( $fname );
 4798+ function __construct() {
 4799+ $this->general = new ReplacementArray;
 4800+ $this->nowiki = new ReplacementArray;
 4801+ }
48204802
4821 - return $numImages;
4822 -}
4823 -
4824 -/**
4825 - * Return the number of user accounts
4826 - * @return integer
4827 - */
4828 -function wfNumberOfUsers() {
4829 - wfProfileIn( 'wfNumberOfUsers' );
4830 - $dbr =& wfGetDB( DB_SLAVE );
4831 - $count = $dbr->selectField( 'site_stats', 'ss_users', array(), 'wfNumberOfUsers' );
4832 - wfProfileOut( 'wfNumberOfUsers' );
4833 - return (int)$count;
4834 -}
4835 -
4836 -/**
4837 - * Return the total number of pages
4838 - * @return integer
4839 - */
4840 -function wfNumberOfPages() {
4841 - wfProfileIn( 'wfNumberOfPages' );
4842 - $dbr =& wfGetDB( DB_SLAVE );
4843 - $count = $dbr->selectField( 'site_stats', 'ss_total_pages', array(), 'wfNumberOfPages' );
4844 - wfProfileOut( 'wfNumberOfPages' );
4845 - return (int)$count;
4846 -}
4847 -
4848 -/**
4849 - * Return the total number of admins
4850 - *
4851 - * @return integer
4852 - */
4853 -function wfNumberOfAdmins() {
4854 - static $admins = -1;
4855 - wfProfileIn( 'wfNumberOfAdmins' );
4856 - if( $admins == -1 ) {
4857 - $dbr =& wfGetDB( DB_SLAVE );
4858 - $admins = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), 'wfNumberOfAdmins' );
 4803+ function unstripGeneral( $text ) {
 4804+ wfProfileIn( __METHOD__ );
 4805+ $text = $this->general->replace( $text );
 4806+ wfProfileOut( __METHOD__ );
 4807+ return $text;
48594808 }
4860 - wfProfileOut( 'wfNumberOfAdmins' );
4861 - return (int)$admins;
4862 -}
48634809
4864 -/**
4865 - * Count the number of pages in a particular namespace
4866 - *
4867 - * @param $ns Namespace
4868 - * @return integer
4869 - */
4870 -function wfPagesInNs( $ns ) {
4871 - static $pageCount = array();
4872 - wfProfileIn( 'wfPagesInNs' );
4873 - if( !isset( $pageCount[$ns] ) ) {
4874 - $dbr =& wfGetDB( DB_SLAVE );
4875 - $pageCount[$ns] = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => $ns ), 'wfPagesInNs' );
 4810+ function unstripNoWiki( $text ) {
 4811+ wfProfileIn( __METHOD__ );
 4812+ $text = $this->nowiki->replace( $text );
 4813+ wfProfileOut( __METHOD__ );
 4814+ return $text;
48764815 }
4877 - wfProfileOut( 'wfPagesInNs' );
4878 - return (int)$pageCount[$ns];
4879 -}
48804816
4881 -/**
4882 - * Get various statistics from the database
4883 - * @private
4884 - */
4885 -function wfLoadSiteStats() {
4886 - global $wgNumberOfArticles, $wgTotalViews, $wgTotalEdits;
4887 - $fname = 'wfLoadSiteStats';
4888 -
4889 - if ( -1 != $wgNumberOfArticles ) return;
4890 - $dbr =& wfGetDB( DB_SLAVE );
4891 - $s = $dbr->selectRow( 'site_stats',
4892 - array( 'ss_total_views', 'ss_total_edits', 'ss_good_articles' ),
4893 - array( 'ss_row_id' => 1 ), $fname
4894 - );
4895 -
4896 - if ( $s === false ) {
4897 - return;
4898 - } else {
4899 - $wgTotalViews = $s->ss_total_views;
4900 - $wgTotalEdits = $s->ss_total_edits;
4901 - $wgNumberOfArticles = $s->ss_good_articles;
 4817+ function unstripBoth( $text ) {
 4818+ wfProfileIn( __METHOD__ );
 4819+ $text = $this->general->replace( $text );
 4820+ $text = $this->nowiki->replace( $text );
 4821+ wfProfileOut( __METHOD__ );
 4822+ return $text;
49024823 }
49034824 }
49044825
4905 -/**
4906 - * Get revision timestamp from the database considering timecorrection
4907 - *
4908 - * @param $id Int: page revision id
4909 - * @return integer
4910 - */
4911 -function wfRevisionTimestamp( $id ) {
4912 - global $wgContLang;
4913 - $fname = 'wfRevisionTimestamp';
4914 -
4915 - wfProfileIn( $fname );
4916 - $dbr =& wfGetDB( DB_SLAVE );
4917 - $timestamp = $dbr->selectField( 'revision', 'rev_timestamp',
4918 - array( 'rev_id' => $id ), __METHOD__ );
4919 - $timestamp = $wgContLang->userAdjust( $timestamp );
4920 - wfProfileOut( $fname );
4921 -
4922 - return $timestamp;
4923 -}
4924 -
4925 -/**
4926 - * Escape html tags
4927 - * Basically replacing " > and < with HTML entities ( &quot;, &gt;, &lt;)
4928 - *
4929 - * @param $in String: text that might contain HTML tags.
4930 - * @return string Escaped string
4931 - */
4932 -function wfEscapeHTMLTagsOnly( $in ) {
4933 - return str_replace(
4934 - array( '"', '>', '<' ),
4935 - array( '&quot;', '&gt;', '&lt;' ),
4936 - $in );
4937 -}
4938 -
49394826 ?>
Index: trunk/phase3/includes/CoreParserFunctions.php
@@ -126,21 +126,21 @@
127127
128128 function statisticsFunction( $func, $raw = null ) {
129129 if ( self::isRaw( $raw ) ) {
130 - return call_user_func( $func );
 130+ return call_user_func( array( 'SiteStats', $func ) );
131131 } else {
132132 global $wgContLang;
133 - return $wgContLang->formatNum( call_user_func( $func ) );
 133+ return $wgContLang->formatNum( call_user_func( array( 'SiteStats', $func ) ) );
134134 }
135135 }
136136
137 - function numberofpages( $parser, $raw = null ) { return self::statisticsFunction( 'wfNumberOfPages', $raw ); }
138 - function numberofusers( $parser, $raw = null ) { return self::statisticsFunction( 'wfNumberOfUsers', $raw ); }
139 - function numberofarticles( $parser, $raw = null ) { return self::statisticsFunction( 'wfNumberOfArticles', $raw ); }
140 - function numberoffiles( $parser, $raw = null ) { return self::statisticsFunction( 'wfNumberOfFiles', $raw ); }
141 - function numberofadmins( $parser, $raw = null ) { return self::statisticsFunction( 'wfNumberOfAdmins', $raw ); }
 137+ function numberofpages( $parser, $raw = null ) { return self::statisticsFunction( 'pages', $raw ); }
 138+ function numberofusers( $parser, $raw = null ) { return self::statisticsFunction( 'users', $raw ); }
 139+ function numberofarticles( $parser, $raw = null ) { return self::statisticsFunction( 'articles', $raw ); }
 140+ function numberoffiles( $parser, $raw = null ) { return self::statisticsFunction( 'images', $raw ); }
 141+ function numberofadmins( $parser, $raw = null ) { return self::statisticsFunction( 'admins', $raw ); }
142142
143143 function pagesinnamespace( $parser, $namespace = 0, $raw = null ) {
144 - $count = wfPagesInNs( intval( $namespace ) );
 144+ $count = SiteStats::pagesInNs( intval( $namespace ) );
145145 if ( self::isRaw( $raw ) ) {
146146 global $wgContLang;
147147 return $wgContLang->formatNum( $count );
Index: trunk/phase3/includes/BagOStuff.php
@@ -492,11 +492,14 @@
493493 class APCBagOStuff extends BagOStuff {
494494 function get($key) {
495495 $val = apc_fetch($key);
 496+ if ( is_string( $val ) ) {
 497+ $val = unserialize( $val );
 498+ }
496499 return $val;
497500 }
498501
499502 function set($key, $value, $exptime=0) {
500 - apc_store($key, $value, $exptime);
 503+ apc_store($key, serialize($value), $exptime);
501504 return true;
502505 }
503506
Index: trunk/phase3/includes/Image.php
@@ -1462,7 +1462,7 @@
14631463 array( 'img_name' => $this->title->getDBkey() ),
14641464 __METHOD__
14651465 );
1466 - if ( 0 == wfNumRows( $this->historyRes ) ) {
 1466+ if ( 0 == $dbr->numRows( $this->historyRes ) ) {
14671467 return FALSE;
14681468 }
14691469 } else if ( $this->historyLine == 1 ) {
Index: trunk/phase3/includes/SiteStats.php
@@ -0,0 +1,168 @@
 2+<?php
 3+
 4+/**
 5+ * Static accessor class for site_stats and related things
 6+ * @package MediaWiki
 7+ */
 8+class SiteStats {
 9+ static $row, $loaded = false;
 10+ static $admins;
 11+ static $pageCount = array();
 12+
 13+ static function recache() {
 14+ self::load( true );
 15+ }
 16+
 17+ static function load( $recache = false ) {
 18+ if ( self::$loaded && !$recache ) {
 19+ return;
 20+ }
 21+
 22+ $dbr =& wfGetDB( DB_SLAVE );
 23+ self::$row = $dbr->selectRow( 'site_stats', '*', false, __METHOD__ );
 24+
 25+ # This code is somewhat schema-agnostic, because I'm changing it in a minor release -- TS
 26+ if ( !isset( self::$row->ss_total_pages ) && self::$row->ss_total_pages == -1 ) {
 27+ # Update schema
 28+ $u = new SiteStatsUpdate( 0, 0, 0 );
 29+ $u->doUpdate();
 30+ self::$row = $dbr->selectRow( 'site_stats', '*', false, $fname );
 31+ }
 32+ }
 33+
 34+ static function views() {
 35+ self::load();
 36+ return self::$row->ss_total_views;
 37+ }
 38+
 39+ static function edits() {
 40+ self::load();
 41+ return self::$row->ss_total_edits;
 42+ }
 43+
 44+ static function articles() {
 45+ self::load();
 46+ return self::$row->ss_good_articles;
 47+ }
 48+
 49+ static function pages() {
 50+ self::load();
 51+ return self::$row->ss_total_pages;
 52+ }
 53+
 54+ static function users() {
 55+ self::load();
 56+ return self::$row->ss_users;
 57+ }
 58+
 59+ static function images() {
 60+ self::load();
 61+ return self::$row->ss_images;
 62+ }
 63+
 64+ static function admins() {
 65+ if ( !isset( self::$admins ) ) {
 66+ $dbr =& wfGetDB( DB_SLAVE );
 67+ self::$admins = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), __METHOD__ );
 68+ }
 69+ return self::$admins;
 70+ }
 71+
 72+ static function pagesInNs( $ns ) {
 73+ wfProfileIn( __METHOD__ );
 74+ if( !isset( self::$pageCount[$ns] ) ) {
 75+ $dbr =& wfGetDB( DB_SLAVE );
 76+ $pageCount[$ns] = (int)$dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => $ns ), __METHOD__ );
 77+ }
 78+ wfProfileOut( __METHOD__ );
 79+ return $pageCount[$ns];
 80+ }
 81+
 82+}
 83+
 84+
 85+/**
 86+ *
 87+ * @package MediaWiki
 88+ */
 89+class SiteStatsUpdate {
 90+
 91+ var $mViews, $mEdits, $mGood, $mPages, $mUsers;
 92+
 93+ function SiteStatsUpdate( $views, $edits, $good, $pages = 0, $users = 0 ) {
 94+ $this->mViews = $views;
 95+ $this->mEdits = $edits;
 96+ $this->mGood = $good;
 97+ $this->mPages = $pages;
 98+ $this->mUsers = $users;
 99+ }
 100+
 101+ function appendUpdate( &$sql, $field, $delta ) {
 102+ if ( $delta ) {
 103+ if ( $sql ) {
 104+ $sql .= ',';
 105+ }
 106+ if ( $delta < 0 ) {
 107+ $sql .= "$field=$field-1";
 108+ } else {
 109+ $sql .= "$field=$field+1";
 110+ }
 111+ }
 112+ }
 113+
 114+ function doUpdate() {
 115+ $fname = 'SiteStatsUpdate::doUpdate';
 116+ $dbw =& wfGetDB( DB_MASTER );
 117+
 118+ # First retrieve the row just to find out which schema we're in
 119+ $row = $dbw->selectRow( 'site_stats', '*', false, $fname );
 120+
 121+ $updates = '';
 122+
 123+ $this->appendUpdate( $updates, 'ss_total_views', $this->mViews );
 124+ $this->appendUpdate( $updates, 'ss_total_edits', $this->mEdits );
 125+ $this->appendUpdate( $updates, 'ss_good_articles', $this->mGood );
 126+
 127+ if ( isset( $row->ss_total_pages ) ) {
 128+ # Update schema if required
 129+ if ( $row->ss_total_pages == -1 && !$this->mViews ) {
 130+ $dbr =& wfGetDB( DB_SLAVE, array( 'SpecialStatistics', 'vslow') );
 131+ extract( $dbr->tableNames( 'page', 'user' ) );
 132+
 133+ $sql = "SELECT COUNT(page_namespace) AS total FROM $page";
 134+ $res = $dbr->query( $sql, $fname );
 135+ $pageRow = $dbr->fetchObject( $res );
 136+ $pages = $pageRow->total + $this->mPages;
 137+
 138+ $sql = "SELECT COUNT(user_id) AS total FROM $user";
 139+ $res = $dbr->query( $sql, $fname );
 140+ $userRow = $dbr->fetchObject( $res );
 141+ $users = $userRow->total + $this->mUsers;
 142+
 143+ if ( $updates ) {
 144+ $updates .= ',';
 145+ }
 146+ $updates .= "ss_total_pages=$pages, ss_users=$users";
 147+ } else {
 148+ $this->appendUpdate( $updates, 'ss_total_pages', $this->mPages );
 149+ $this->appendUpdate( $updates, 'ss_users', $this->mUsers );
 150+ }
 151+ }
 152+ if ( $updates ) {
 153+ $site_stats = $dbw->tableName( 'site_stats' );
 154+ $sql = $dbw->limitResultForUpdate("UPDATE $site_stats SET $updates", 1);
 155+ $dbw->begin();
 156+ $dbw->query( $sql, $fname );
 157+ $dbw->commit();
 158+ }
 159+
 160+ /*
 161+ global $wgDBname, $wgTitle;
 162+ if ( $this->mGood && $wgDBname == 'enwiki' ) {
 163+ $good = $dbw->selectField( 'site_stats', 'ss_good_articles', '', $fname );
 164+ error_log( $good . ' ' . $wgTitle->getPrefixedDBkey() . "\n", 3, '/home/wikipedia/logs/million.log' );
 165+ }
 166+ */
 167+ }
 168+}
 169+?>
Property changes on: trunk/phase3/includes/SiteStats.php
___________________________________________________________________
Added: svn:eol-style
1170 + native
Added: svn:keywords
2171 + Author Date Id Revision
Index: trunk/phase3/includes/Block.php
@@ -338,7 +338,7 @@
339339 call_user_func( $callback, $block, $tag );
340340 }
341341 }
342 - wfFreeResult( $res );
 342+ $db->freeResult( $res );
343343 return $num_rows;
344344 }
345345
Index: trunk/phase3/includes/Xml.php
@@ -297,5 +297,19 @@
298298 '</html>';
299299 return Xml::isWellFormed( $html );
300300 }
 301+
 302+ /**
 303+ * Escape html tags
 304+ * Basically replacing " > and < with HTML entities ( &quot;, &gt;, &lt;)
 305+ *
 306+ * @param $in String: text that might contain HTML tags.
 307+ * @return string Escaped string
 308+ */
 309+ function escapeTagsOnly( $in ) {
 310+ return str_replace(
 311+ array( '"', '>', '<' ),
 312+ array( '&quot;', '&gt;', '&lt;' ),
 313+ $in );
 314+ }
301315 }
302316 ?>
Index: trunk/phase3/includes/SpecialWatchlist.php
@@ -381,8 +381,8 @@
382382 }
383383
384384 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
385 - $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" .wfStrencode($obj->page_title). "' AND wl_namespace='{$obj->page_namespace}'" ;
386 - $res3 = $dbr->query( $sql3, DB_READ, $fname );
 385+ $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" .$dbr->strencode($obj->page_title). "' AND wl_namespace='{$obj->page_namespace}'" ;
 386+ $res3 = $dbr->query( $sql3, $fname );
387387 $x = $dbr->fetchObject( $res3 );
388388 $rc->numberofWatchingusers = $x->n;
389389 } else {
Index: trunk/phase3/includes/DatabaseFunctions.php
@@ -1,9 +1,8 @@
22 <?php
33 /**
4 - * Backwards compatibility wrapper for Database.php
 4+ * Legacy database functions, for compatibility with pre-1.3 code
 5+ * NOTE: this file is no longer loaded by default.
56 *
6 - * Note: $wgDatabase has ceased to exist. Destroy all references.
7 - *
87 * @package MediaWiki
98 */
109
@@ -44,15 +43,6 @@
4544 return $ret;
4645 }
4746
48 -/*
49 - * @todo document function
50 - */
51 -function &wfGetDB( $db = DB_LAST, $groups = array() ) {
52 - global $wgLoadBalancer;
53 - $ret =& $wgLoadBalancer->getConnection( $db, true, $groups );
54 - return $ret;
55 -}
56 -
5747 /**
5848 * Turns on (false) or off (true) the automatic generation and sending
5949 * of a "we're sorry, but there has been a database error" page on
Index: trunk/phase3/includes/Sanitizer.php
@@ -603,7 +603,8 @@
604604 $stripped = Sanitizer::decodeCharReferences( $value );
605605
606606 // Remove any comments; IE gets token splitting wrong
607 - $stripped = preg_replace( '!/\\*.*?\\*/!S', ' ', $stripped );
 607+ $stripped = StringUtils::delimiterReplace( '/\*', '\*/', ' ', $stripped );
 608+
608609 $value = $stripped;
609610
610611 // ... and continue checks
@@ -1178,7 +1179,7 @@
11791180 */
11801181 static function stripAllTags( $text ) {
11811182 # Actual <tags>
1182 - $text = preg_replace( '/ < .*? > /x', '', $text );
 1183+ $text = StringUtils::delimiterReplace( '<', '>', '', $text );
11831184
11841185 # Normalize &entities and whitespace
11851186 $text = Sanitizer::normalizeAttributeValue( $text );
Index: trunk/extensions/Cache404/extensions/Cache404.php
@@ -32,6 +32,7 @@
3333 require_once("Skin.php");
3434 require_once("skins/MonoBook.php");
3535 require_once("SkinPHPTal.php");
 36+ require_once("DatabaseFunctions.php");
3637
3738 define("CACHE404_VERSION", "0.6");
3839
Index: trunk/extensions/ShowProcesslist/ShowProcesslist_body.php
@@ -14,11 +14,12 @@
1515 return;
1616 }
1717
18 - $res = wfQuery( 'SHOW FULL PROCESSLIST' , DB_READ );
 18+ $dbr =& wfGetDB( DB_SLAVE );
 19+ $res = $dbr->query( 'SHOW FULL PROCESSLIST' );
1920 $output = array();
2021 $output = '<table border="1" cellspacing="0">'."\n";
2122 $output .= '<tr><th>Id</th><th>User</th><th>Host</th><th>db</th><th>Command</th><th>Time</th><th>State</th><th>Info</th>'."\n";
22 - while ( $row = wfFetchObject($res) ) {
 23+ while ( $row = $dbr->fetchObject($res) ) {
2324 $output .= '<tr>';
2425 $fields = get_object_vars($row);
2526 foreach ($fields as $value ) {
Index: trunk/extensions/StableVersion/StableVersion.php
@@ -346,15 +346,26 @@
347347
348348
349349 function fixNoWiki( &$state ) {
350 - if( !is_array( $state ) ) {
 350+ if ( is_object( $state ) ) {
 351+ # MW 1.9 version
 352+ $array = $state->nowiki->getArray();
 353+ } elseif is_array( $state ) {
 354+ $array = $state['nowiki'];
 355+ } else {
351356 return;
352357 }
353 -
 358+
354359 # Surround nowiki content with <nowiki> again
355 - for( $content = end( $state['nowiki'] ); $content !== false; $content = prev( $state['nowiki'] ) ) {
356 - $key = key( $state['nowiki'] );
357 - $state['nowiki'][$key] = "<nowiki>" . $content . "</nowiki>";
 360+ for( $content = end( $array ); $content !== false; $content = prev( $array ) ) {
 361+ $key = key( $array );
 362+ $array[$key] = "<nowiki>" . $content . "</nowiki>";
358363 }
 364+
 365+ if ( is_object( $state ) ) {
 366+ $state->nowiki->setArray( $array );
 367+ } else {
 368+ $state['nowiki'] = $array;
 369+ }
359370 }
360371
361372 /**
Index: trunk/extensions/experimental/SpecialValidate.php
@@ -23,6 +23,9 @@
2424 * @subpackage SpecialPage
2525 */
2626
 27+# Need legacy database functions
 28+require_once("DatabaseFunctions.php");
 29+
2730 /**
2831 *
2932 * @package MediaWiki
Index: trunk/extensions/MakeDBError/MakeDBError_body.php
@@ -16,7 +16,8 @@
1717 $db =& wfGetDB( 1234 );
1818 $wgOut->addHTML("<pre>" . var_export( $db, true ) . "</pre>" );
1919 } else {
20 - wfQuery( "test", DB_READ );
 20+ $db =& wfGetDB( DB_SLAVE );
 21+ $db->query( "test" );
2122 }
2223 }
2324 }
Index: trunk/extensions/FindSpam/FindSpam_body.php
@@ -41,7 +41,7 @@
4242 $s = '';
4343
4444 foreach ( $wgLocalDatabases as $db ) {
45 - $sql = "SELECT rc_namespace,rc_title,rc_timestamp,rc_user_text,rc_last_oldid FROM $db.recentchanges WHERE rc_ip='" . wfStrencode( $ip ) .
 45+ $sql = "SELECT rc_namespace,rc_title,rc_timestamp,rc_user_text,rc_last_oldid FROM $db.recentchanges WHERE rc_ip='" . $dbr->strencode( $ip ) .
4646 "' AND rc_this_oldid=0";
4747 $res = $dbr->query( $sql, "findspam.php" );
4848 list( $site, $lang ) = $wgConf->siteFromDB( $db );

Follow-up revisions

RevisionCommit summaryAuthorDate
r17880Code housekeeping stuff (and barring any stuff-ups on my behalf, there should...nickj08:25, 23 November 2006