key: $wgDBname:messages
ex: wikidb:messages
stores: an array where the keys are DB keys and the values are messages
- set in: wfMsg()
- cleared by: Article::editUpdates()
+ set in: wfMsg(), Article::editUpdates() both call wfLoadAllMessages()
+ cleared by: nothing
... more to come ...
$t = $this->mTitle->getPrefixedText();
if ( $oldid ) { $t .= ",oldid={$oldid}"; }
if ( $redirect ) { $t .= ",redirect={$redirect}"; }
+
$this->mContent = str_replace( "$1", $t, wfMsg( "missingarticle" ) );
if ( ! $oldid ) { # Retrieve current version
$sql = "SELECT " .
"cur_text,cur_timestamp,cur_user,cur_counter,cur_restrictions,cur_touched " .
"FROM cur WHERE cur_id={$id}";
+ wfDebug( "$sql\n" );
$res = wfQuery( $sql, DB_READ, $fname );
- if ( 0 == wfNumRows( $res ) ) { return; }
+ if ( 0 == wfNumRows( $res ) ) {
+ return;
+ }
$s = wfFetchObject( $res );
-
# If we got a redirect, follow it (unless we've been told
# not to by either the function parameter or the query
if ( ( "no" != $redirect ) && ( false == $noredir ) &&
}
}
}
+
$this->mContent = $s->cur_text;
$this->mUser = $s->cur_user;
$this->mCounter = $s->cur_counter;
array_push( $wgDeferredUpdateList, $u );
if ( $this->getNamespace == NS_MEDIAWIKI ) {
- $wgMemc->delete( "$wgDBname:messages" );
+ $messageCache = $wgMemc->get( "$wgDBname:messages" );
+ if (!$messageCache) {
+ $messageCache = wfLoadAllMessages();
+ }
+ $messageCache[$title] = $text;
+ $wgMemc->set( "$wgDBname:messages" );
}
}
}
# {{SUBST:xxx}} variables
#
$mw =& MagicWord::get( MAG_SUBST );
- $text = $mw->substituteCallback( $text, "replaceMsgVar" );
+ $text = $mw->substituteCallback( $text, "wfReplaceSubstVar" );
return $text;
}
}
+function wfReplaceSubstVar( $matches ) {
+ return wfMsg( $matches[1] );
+}
+
?>
{
global $wgLastDatabaseQuery, $wgOut;
## wfProfileIn( "wfQuery" );
+
+ if ( !is_numeric( $db ) ) {
+ # Someone has tried to call this the old way
+ $wgOut->fatalError( wfMsgNoDB( "wrong_wfQuery_params" ) );
+ }
+
$wgLastDatabaseQuery = $sql;
$conn = wfGetDB();
$ret = mysql_query( $sql, $conn );
$wgReplacementKeys = array( "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9" );
+# Get a message from anywhere
function wfMsg( $key ) {
$args = func_get_args();
if ( count( $args ) ) {
return wfMsgReal( $key, $args, true );
}
+# Get a message from the language file
function wfMsgNoDB( $key ) {
$args = func_get_args();
if ( count( $args ) ) {
return wfMsgReal( $key, $args, false );
}
+# Really get a message
function wfMsgReal( $key, $args, $useDB ) {
global $wgLang, $wgReplacementKeys, $wgMemc, $wgDBname;
global $wgUseDatabaseMessages, $wgUseMemCached, $wgOut;
- global $wgAllMessagesEn;
+ global $wgAllMessagesEn, $wgLanguageCode;
$fname = "wfMsg";
wfProfileIn( $fname );
}
# If there's nothing in memcached, load all the messages from the database
+ # This should only happen on server reset -- ordinary changes should update
+ # memcached in editUpdates()
if ( !$messageCache ) {
# Other threads don't need to load the messages if another thread is doing it.
$wgMemc->set( $memcKey, "loading", time() + 60 );
-
- $sql = "SELECT cur_title,cur_text FROM cur WHERE cur_namespace=" . NS_MEDIAWIKI;
- $res = wfQuery( $sql, DB_READ, $fname );
- for ( $row = wfFetchObject( $res ); $row; $row = wfFetchObject( $res ) ) {
- $messageCache[$row->cur_title] = $row->cur_text;
- }
+ $messageCache = wfLoadAllMessages();
# Save in memcached
$wgMemc->set( $memcKey, $messageCache, time() + 3600 );
+
+
}
if ( is_array( $messageCache ) && array_key_exists( $title, $messageCache ) ) {
$message = $messageCache[$title];
}
}
- # Finally, try the array in $wgLang
+ # Try the array in $wgLang
if ( !$message ) {
$message = $wgLang->getMessage( $key );
}
+
+ # Try the English array
+ if ( !$message && $wgLanguageCode != "en" ) {
+ $message = Language::getMessage( $key );
+ }
# Replace arguments
if( count( $args ) ) {
}
wfProfileOut( $fname );
if ( !$message ) {
- # Failed, message not translated
+ # Failed, message does not exist
return "<$key>";
}
return $message;
return array( $limit, $offset );
}
-# Used in OutputPage::replaceVariables and Article:pstPass2
-function replaceMsgVar( $matches ) {
- return wfMsg( $matches[1] );
-}
-
-function replaceMsgVarNw( $matches ) {
- $text = htmlspecialchars( wfMsg( $matches[1] ) );
+# Escapes the given text so that it may be output using addWikiText()
+# without any linking, formatting, etc. making its way through. This
+# is achieved by substituting certain characters with HTML entities.
+# As required by the callers, <nowiki> is not used. It currently does
+# not filter out characters which have special meaning only at the
+# start of a line, such as "*".
+function wfEscapeWikiText( $text )
+{
+ $text = str_replace(
+ array( '[', "'", 'ISBN ' , '://'),
+ array( '[', ''', 'ISBN ', '://'),
+ htmlspecialchars($text) );
return $text;
}
+# Loads the entire MediaWiki namespace, retuns the array
+function wfLoadAllMessages()
+{
+ $sql = "SELECT cur_title,cur_text FROM cur WHERE cur_namespace=" . NS_MEDIAWIKI;
+ $res = wfQuery( $sql, DB_READ, $fname );
+
+ $messages = array();
+ for ( $row = wfFetchObject( $res ); $row; $row = wfFetchObject( $res ) ) {
+ $messages[$row->cur_title] = $row->cur_text;
+ }
+ wfFreeResult( $res );
+ return $messages;
+}
?>
$case = $this->mCaseSensitive ? "" : "i";
$this->mRegex = "/{$this->mBaseRegex}/{$case}";
$this->mRegexStart = "/^{$this->mBaseRegex}/{$case}";
- $this->mVariableRegex = str_replace( "\\$1", "([A-Za-z0-9]*)", $this->mRegex );
+ $this->mVariableRegex = str_replace( "\\$1", "([A-Za-z0-9_\-]*)", $this->mRegex );
}
function getRegex()
else { # Invalid form; output directly
$s .= "[[" . $line ;
- wfProfileOut( "$fname-loop1" );
continue;
}
if(substr($m[1],0,1)=="/") { # subpage
$fname = "OutputPage::replaceVariables";
wfProfileIn( $fname );
- /* As with sigs, use server's local time --
- ensure this is appropriate for your audience! */
+
+ # Basic variables
+ # See Language.php for the definition of each magic word
+
+ # As with sigs, this uses the server's local time -- ensure
+ # this is appropriate for your audience!
$v = date( "m" );
$mw =& MagicWord::get( MAG_CURRENTMONTH );
$text = $mw->replace( $v, $text );
$text = $mw->replace( $v, $text );
}
- # The callbacks are in GlobalFunctions.php
+ # "Variables" with an additional parameter e.g. {{MSG:wikipedia}}
+ # The callbacks are at the bottom of this file
$mw =& MagicWord::get( MAG_MSG );
- $text = $mw->substituteCallback( $text, "replaceMsgVar" );
+ $text = $mw->substituteCallback( $text, "wfReplaceMsgVar" );
$mw =& MagicWord::get( MAG_MSGNW );
- $text = $mw->substituteCallback( $text, "replaceMsgVarNw" );
+ $text = $mw->substituteCallback( $text, "wfReplaceMsgnwVar" );
wfProfileOut( $fname );
return $text;
}
+ # Cleans up HTML, removes dangerous tags and attributes
/* private */ function removeHTMLtags( $text )
{
$fname = "OutputPage::removeHTMLtags";
}
}
+# Regex callbacks, used in OutputPage::replaceVariables
+
+# Just get rid of the dangerous stuff
+# Necessary because replaceVariables is called after removeHTMLtags,
+# and message text can come from any user
+function wfReplaceMsgVar( $matches ) {
+ global $wgOut;
+ $text = $wgOut->removeHTMLtags( wfMsg( $matches[1] ) );
+ return $text;
+}
+
+# Effective <nowiki></nowiki>
+# Not real <nowiki> because this is called after nowiki sections are processed
+function wfReplaceMsgnwVar( $matches ) {
+ $text = wfEscapeWikiText( wfMsg( $matches[1] ) );
+ return $text;
+}
+
?>
global $wgDebugProfiling;
$bit = array_pop( $this->mWorkStack );
- if ( $wgDebugProfiling ) {
- if ( $functionname == "close" ) {
- wfDebug( "Profile section ended by close(): {$bit[0]}\n" );
- } elseif ( $bit[0] != $functionname ) {
- wfDebug( "Profiling error: in({$bit[0]}), out($functionname)\n" );
+ if ( !$bit ) {
+ wfDebug( "Profiling error, !\$bit: $functionname\n" );
+ } else {
+ if ( $wgDebugProfiling ) {
+ if ( $functionname == "close" ) {
+ wfDebug( "Profile section ended by close(): {$bit[0]}\n" );
+ } elseif ( $bit[0] != $functionname ) {
+ wfDebug( "Profiling error: in({$bit[0]}), out($functionname)\n" );
+ }
}
+ array_push( $bit, microtime() );
+ array_push( $this->mStack, $bit );
}
- array_push( $bit, microtime() );
- array_push( $this->mStack, $bit );
}
function close()
"Debug" => "Debugging information"
);
+#-------------------------------------------------------------------
+# Default messages
+#-------------------------------------------------------------------
+# Allowed characters in keys are: A-Z, a-z, 0-9, underscore (_) and
+# hyphen (-). If you need more characters, you may be able to change
+# the regex in MagicWord::initRegex
+
/* private */ $wgAllMessagesEn = array(
# Bits of text used by many pages:
because it slows the database down to the point that no one can use
the wiki.",
"perfdisabledsub" => "Here's a saved copy from $1:",
+"wrong_wfQuery_params" => "Incorrect parameters to wfQuery",
# Login and logout pages
#
$mw = $mwObj->getSynonym( 0 );
$mw = str_replace( "$1", $key, $mw );
- $message = htmlspecialchars( $message );
+ $message = wfEscapeWikiText( $message );
$navText .=
"<tr><td>
[$wgServer$wgScript?title=MediaWiki:$title&action=edit $key]
print "Rebuilding link tables (pass 1).\n";
$sql = "DROP TABLE IF EXISTS rebuildlinks";
- wfQuery( $sql );
+ wfQuery( $sql, DB_WRITE );
$sql = "CREATE TABLE rebuildlinks (
rl_f_id int(8) unsigned NOT NULL default 0,
rl_f_title varchar(255) binary NOT NULL default '',
rl_to varchar(255) binary NOT NULL default '',
INDEX rl_to (rl_to) ) TYPE=MyISAM";
- wfQuery( $sql );
+ wfQuery( $sql, DB_WRITE );
- $sql = "LOCK TABLES cur READ, rebuildlinks WRITE";
- wfQuery( $sql );
+ $sql = "LOCK TABLES cur READ, rebuildlinks WRITE, interwiki READ";
+ wfQuery( $sql, DB_WRITE );
$sql = "DELETE FROM rebuildlinks";
- wfQuery( $sql );
+ wfQuery( $sql, DB_WRITE );
$sql = "SELECT cur_id,cur_namespace,cur_title,cur_text FROM cur";
- $res = wfQuery( $sql );
+ $res = wfQuery( $sql, DB_WRITE );
$total = wfNumRows( $res );
$tc = Title::legalChars();
if ( 0 != $i ) { $sql .= ","; }
$sql .= "({$id},'{$title}','{$dest}')";
}
- wfQuery( $sql );
+ wfQuery( $sql, DB_WRITE );
}
if ( ( ++$count % 1000 ) == 0 ) {
print "$count of $total articles scanned.\n";
mysql_free_result( $res );
$sql = "UNLOCK TABLES";
- wfQuery( $sql );
+ wfQuery( $sql, DB_WRITE );
}
function rebuildLinkTablesPass2()
$count = 0;
print "Rebuilding link tables (pass 2).\n";
- $sql = "LOCK TABLES cur READ, rebuildlinks READ, " .
+ $sql = "LOCK TABLES cur READ, rebuildlinks READ, interwiki READ, " .
"links WRITE, brokenlinks WRITE, imagelinks WRITE";
- wfQuery( $sql );
+ wfQuery( $sql, DB_WRITE );
$sql = "DELETE FROM links";
- wfQuery( $sql );
+ wfQuery( $sql, DB_WRITE );
$sql = "DELETE FROM brokenlinks";
- wfQuery( $sql );
+ wfQuery( $sql, DB_WRITE );
$sql = "DELETE FROM links";
- wfQuery( $sql );
+ wfQuery( $sql, DB_WRITE );
$ins = $wgLang->getNsText( Namespace::getImage() );
$inslen = strlen($ins)+1;
$sql = "SELECT rl_f_title,rl_to FROM rebuildlinks " .
"WHERE rl_to LIKE '$ins:%'";
- $res = wfQuery( $sql );
+ $res = wfQuery( $sql, DB_WRITE );
$sql = "INSERT INTO imagelinks (il_from,il_to) VALUES ";
$sqlX = "";
if ($sqlX != "") {
$sql .= $sqlX;
wfFreeResult( $res );
- wfQuery( $sql );
+ wfQuery( $sql, DB_WRITE );
}
$sql = "SELECT DISTINCT rl_to FROM rebuildlinks " .
"ORDER BY rl_to";
- $res = wfQuery( $sql );
+ $res = wfQuery( $sql, DB_WRITE );
$count = 0;
$total = wfNumRows( $res );
if ( 0 == $id ) {
$sql = "SELECT rl_f_id FROM rebuildlinks WHERE rl_to='{$to}'";
- $res2 = wfQuery( $sql );
+ $res2 = wfQuery( $sql, DB_WRITE );
$sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
$first = true;
$sql .= "({$from},'{$to}')";
}
wfFreeResult( $res2 );
- if ( ! $first ) { wfQuery( $sql ); }
+ if ( ! $first ) { wfQuery( $sql, DB_WRITE ); }
} else {
$sql = "SELECT rl_f_title FROM rebuildlinks WHERE rl_to='{$to}'";
- $res2 = wfQuery( $sql );
+ $res2 = wfQuery( $sql, DB_WRITE );
$sql = "INSERT INTO links (l_from,l_to) VALUES ";
$first = true;
$sql .= "('{$from}',{$id})";
}
wfFreeResult( $res2 );
- if ( ! $first ) { wfQuery( $sql ); }
+ if ( ! $first ) { wfQuery( $sql, DB_WRITE ); }
}
if ( ( ++$count % 1000 ) == 0 ) {
print "$count of $total titles processed.\n";
wfFreeResult( $res );
$sql = "UNLOCK TABLES";
- wfQuery( $sql );
+ wfQuery( $sql, DB_WRITE );
$sql = "DROP TABLE rebuildlinks";
- wfQuery( $sql );
+ wfQuery( $sql, DB_WRITE );
}
?>