# Note: edit user interface and cache support functions have been
# moved to separate EditPage and CacheManager classes.
+/* CHECK MERGE @@@
+ TEST THIS @@@
+
+ * s/\$wgTitle/\$this->mTitle/ performed, many replacements
+ * mTitle variable added to class
+*/
+
include_once( "CacheManager.php" );
class Article {
/* private */ var $mUser, $mTimestamp, $mUserText;
/* private */ var $mCounter, $mComment, $mCountAdjustment;
/* private */ var $mMinorEdit, $mRedirectedFrom;
- /* private */ var $mTouched, $mFileCache;
+ /* private */ var $mTouched, $mFileCache, $mTitle;
function Article( &$title ) {
$this->mTitle =& $title;
}
# Note that getContent/loadContent may follow redirects if
- # not told otherwise, and so may cause a change to wgTitle.
+ # not told otherwise, and so may cause a change to mTitle.
function getContent( $noredir = false )
{
global $action,$section,$count; # From query string
- wfProfileIn( "Article::getContent" );
+ $fname = "Article::getContent";
+ wfProfileIn( $fname );
if ( 0 == $this->getID() ) {
if ( "edit" == $action ) {
+ wfProfileOut( $fname );
return ""; # was "newarticletext", now moved above the box)
}
- wfProfileOut();
+ wfProfileOut( $fname );
return wfMsg( "noarticletext" );
} else {
$this->loadContent( $noredir );
- wfProfileOut();
if(
# check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
$action=="view"
)
{
+ wfProfileOut( $fname );
return $this->mContent . "\n" .wfMsg("anontalkpagetext"); }
else {
if($action=="edit") {
if($section!="") {
- if($section=="new") { return ""; }
+ if($section=="new") {
+ wfProfileOut( $fname );
+ return "";
+ }
$secs=preg_split("/(^=+.*?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)/mi",
$this->mContent, -1,
PREG_SPLIT_DELIM_CAPTURE);
if($section==0) {
+ wfProfileOut( $fname );
return trim($secs[0]);
} else {
+ wfProfileOut( $fname );
return trim($secs[$section*2-1] . $secs[$section*2]);
}
}
}
+ wfProfileOut( $fname );
return $this->mContent;
}
}
# fails we'll have something telling us what we intended.
$t = $this->mTitle->getPrefixedText();
- if ( $oldid ) { $t .= ",oldid={$oldid}"; }
- if ( $redirect ) { $t .= ",redirect={$redirect}"; }
- $this->mContent = str_replace( "$1", $t, wfMsg( "missingarticle" ) );
+ if ( isset( $oldid ) ) {
+ $oldid = IntVal( $oldid );
+ $t .= ",oldid={$oldid}";
+ }
+ if ( isset( $redirect ) ) {
+ $redirect = ($redirect == "no") ? "no" : "yes";
+ $t .= ",redirect={$redirect}";
+ }
+ $this->mContent = wfMsg( "missingarticle", $t );
if ( ! $oldid ) { # Retrieve current version
$id = $this->getID();
$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 ) &&
$rid = $rt->getArticleID();
if ( 0 != $rid ) {
$sql = "SELECT cur_text,cur_timestamp,cur_user," .
- "cur_counter,cur_touched FROM cur WHERE cur_id={$rid}";
+ "cur_counter,cur_restrictions,cur_touched FROM cur WHERE cur_id={$rid}";
$res = wfQuery( $sql, DB_READ, $fname );
if ( 0 != wfNumRows( $res ) ) {
}
}
}
+
$this->mContent = $s->cur_text;
$this->mUser = $s->cur_user;
$this->mCounter = $s->cur_counter;
$this->mContentLoaded = true;
}
- function getID() { return $this->mTitle->getArticleID(); }
+ function getID() {
+ if( $this->mTitle ) {
+ return $this->mTitle->getArticleID();
+ } else {
+ return 0;
+ }
+ }
function getCount()
{
{
global $wgUser, $wgOut, $wgLang;
global $oldid, $diff; # From query
- global $wgLinkCache;
- wfProfileIn( "Article::view" );
+ global $wgLinkCache, $IP;
+ $fname = "Article::view";
+ wfProfileIn( $fname );
$wgOut->setArticleFlag( true );
$wgOut->setRobotpolicy( "index,follow" );
$wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
$de = new DifferenceEngine( $oldid, $diff );
$de->showDiffPage();
- wfProfileOut();
+ wfProfileOut( $fname );
return;
}
- $text = $this->getContent(); # May change wgTitle!
+
+ if ( !isset( $oldid ) ) {
+ if( $this->checkTouched() ) {
+ $wgOut->checkLastModified( $this->mTouched );
+ $this->tryFileCache();
+ }
+ }
+
+ $text = $this->getContent(); # May change mTitle
$wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
$wgOut->setHTMLTitle( $this->mTitle->getPrefixedText() .
" - " . wfMsg( "wikititlesuffix" ) );
$sk = $wgUser->getSkin();
$redir = $sk->makeKnownLink( $this->mRedirectedFrom, "",
"redirect=no" );
- $s = str_replace( "$1", $redir, wfMsg( "redirectedfrom" ) );
+ $s = wfMsg( "redirectedfrom", $redir );
$wgOut->setSubtitle( $s );
}
- $wgOut->checkLastModified( $this->mTouched );
- $this->tryFileCache();
$wgLinkCache->preFill( $this->mTitle );
$wgOut->addWikiText( $text );
$this->viewUpdates();
- wfProfileOut();
+ wfProfileOut( $fname );
}
# Theoretically we could defer these whole insert and update
/* private */ function insertNewArticle( $text, $summary, $isminor, $watchthis )
{
global $wgOut, $wgUser, $wgLinkCache, $wgMwRedir;
+ global $wgEnablePersistentLC;
+
$fname = "Article::insertNewArticle";
+ $this->mCountAdjustment = $this->isCountable( $text );
+
$ns = $this->mTitle->getNamespace();
$ttl = $this->mTitle->getDBkey();
$text = $this->preSaveTransform( $text );
$newid = wfInsertId();
$this->mTitle->resetArticleID( $newid );
+ if ( $wgEnablePersistentLC ) {
+ // Purge related entries in links cache on new page, to heal broken links
+ $ptitle = wfStrencode( $ttl );
+ wfQuery("DELETE linkscc FROM linkscc,brokenlinks ".
+ "WHERE lcc_pageid=bl_from AND bl_to='{$ptitle}'", DB_WRITE);
+ }
+
$sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time," .
"rc_namespace,rc_title,rc_new,rc_minor,rc_cur_id,rc_user," .
"rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid,rc_bot) VALUES (" .
}
}
+ # The talk page isn't in the regular link tables, so we need to update manually:
+ $talkns = $ns ^ 1; # talk -> normal; normal -> talk
+ $sql = "UPDATE cur set cur_touched='$now' WHERE cur_namespace=$talkns AND cur_title='" . wfStrencode( $ttl ) . "'";
+ wfQuery( $sql, DB_WRITE );
+
$this->showArticle( $text, wfMsg( "newarticle" ) );
}
- function updateArticle( $text, $summary, $minor, $watchthis, $section="" )
+ function updateArticle( $text, $summary, $minor, $watchthis, $section = "")
{
global $wgOut, $wgUser, $wgLinkCache;
global $wgDBtransactions, $wgMwRedir;
$sql = "UPDATE recentchanges SET rc_cur_time='{$now}' " .
"WHERE rc_cur_id=" . $this->getID();
wfQuery( $sql, DB_WRITE, $fname );
+
+ global $wgEnablePersistentLC;
+ if ( $wgEnablePersistentLC ) {
+ // Purge link cache for this page
+ $pageid=$this->getID();
+ wfQuery("DELETE FROM linkscc WHERE lcc_pageid='{$pageid}'", DB_WRITE);
+ }
}
+
if( $wgDBtransactions ) {
$sql = "COMMIT";
wfQuery( $sql, DB_WRITE );
# If page hasn't changed, client can cache this
$wgOut->checkLastModified( $this->getTimestamp() );
- wfProfileIn( "Article::history" );
+ $fname = "Article::history";
+ wfProfileIn( $fname );
$wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
$wgOut->setSubtitle( wfMsg( "revhistory" ) );
if( $this->mTitle->getArticleID() == 0 ) {
$wgOut->addHTML( wfMsg( "nohistory" ) );
- wfProfileOut();
+ wfProfileOut( $fname );
return;
}
$revs = wfNumRows( $res );
if( $this->mTitle->getArticleID() == 0 ) {
$wgOut->addHTML( wfMsg( "nohistory" ) );
- wfProfileOut();
+ wfProfileOut( $fname );
return;
}
$s .= $sk->endHistoryList();
$s .= $numbar;
$wgOut->addHTML( $s );
- wfProfileOut();
+ wfProfileOut( $fname );
}
function protect( $limit = "sysop" )
"cur_restrictions='{$limit}' WHERE cur_id={$id}";
wfQuery( $sql, DB_WRITE, "Article::protect" );
+ $log = new LogPage( wfMsg( "protectlogpage" ), wfMsg( "protectlogtext" ) );
+ if ( $limit === "" ) {
+ $log->addEntry( wfMsg( "unprotectedarticle", $this->mTitle->getPrefixedText() ), "" );
+ } else {
+ $log->addEntry( wfMsg( "protectedarticle", $this->mTitle->getPrefixedText() ), "" );
+ }
$wgOut->redirect( wfLocalUrl( $this->mTitle->getPrefixedURL() ) );
}
global $wgUser, $wgOut;
global $wpConfirm, $wpReason, $image, $oldimage;
- # Anybody can delete old revisions of images; only sysops
- # can delete articles and current images
-
- if ( ( ! $oldimage ) && ( ! $wgUser->isSysop() ) ) {
+ # This code desperately needs to be totally rewritten
+
+ if ( ( ! $wgUser->isSysop() ) ) {
$wgOut->sysopRequired();
return;
}
return;
}
+ if ( $_POST["wpConfirm"] ) {
+ $this->doDelete();
+ return;
+ }
+
# determine whether this page has earlier revisions
# and insert a warning if it does
# we select the text because it might be useful below
- $sql="SELECT old_text FROM old WHERE old_namespace=0 and old_title='" . wfStrencode($this->mTitle->getPrefixedDBkey())."' ORDER BY inverse_timestamp LIMIT 1";
- $res=wfQuery($sql, DB_READ, $fname);
+ $ns = $this->mTitle->getNamespace();
+ $title = $this->mTitle->getDBkey();
+ $etitle = wfStrencode( $title );
+ $sql = "SELECT old_text FROM old WHERE old_namespace=$ns and old_title='$etitle' ORDER BY inverse_timestamp LIMIT 1";
+ $res = wfQuery( $sql, DB_READ, $fname );
if( ($old=wfFetchObject($res)) && !$wpConfirm ) {
$skin=$wgUser->getSkin();
$wgOut->addHTML("<B>".wfMsg("historywarning"));
$wgOut->addHTML( $skin->historyLink() ."</B><P>");
}
- $sql="SELECT cur_text FROM cur WHERE cur_namespace=0 and cur_title='" . wfStrencode($this->mTitle->getPrefixedDBkey())."'";
+ $sql="SELECT cur_text FROM cur WHERE cur_namespace=$ns and cur_title='$etitle'";
$res=wfQuery($sql, DB_READ, $fname);
if( ($s=wfFetchObject($res))) {
function confirmDelete( $par = "" )
{
global $wgOut;
+ global $wpReason;
+
+ wfDebug( "Article::confirmDelete\n" );
$sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
$wgOut->setSubtitle( wfMsg( "deletesub", $sub ) );
<form id=\"deleteconfirm\" method=\"post\" action=\"{$formaction}\">
<table border=0><tr><td align=right>
{$delcom}:</td><td align=left>
-<input type=text size=60 name=\"wpReason\" value=\"{$wpReason}\">
+<input type=text size=60 name=\"wpReason\" value=\"" . htmlspecialchars( $wpReason ) . "\">
</td></tr><tr><td> </td></tr>
<tr><td align=right>
<input type=checkbox name=\"wpConfirm\" value='1' id=\"wpConfirm\">
global $wgOut, $wgUser, $wgLang;
global $wpReason;
$fname = "Article::doDelete";
+ wfDebug( "$fname\n" );
$this->doDeleteArticle( $this->mTitle );
$deleted = $this->mTitle->getPrefixedText();
Namespace::getWikipedia() ) .
":" . wfMsg( "dellogpage" ), wfMsg( "deletionlog" ) );
- $text = str_replace( "$1" , $deleted, wfMsg( "deletedtext" ) );
- $text = str_replace( "$2", $loglink, $text );
+ $text = wfMsg( "deletedtext", $deleted, $loglink );
$wgOut->addHTML( "<p>" . $text );
$wgOut->returnToMain( false );
function doDeleteArticle( $title )
{
- global $wgUser, $wgOut, $wgLang, $wpReason, $wgDeferredUpdateList;
+ global $wgUser, $wgOut, $wgLang, $wpReason, $wgDeferredUpdateList,
+ $wgEnablePersistentLC;
$fname = "Article::doDeleteArticle";
+ wfDebug( "$fname\n" );
+
$ns = $title->getNamespace();
$t = wfStrencode( $title->getDBkey() );
$id = $title->getArticleID();
$sql = "DELETE FROM recentchanges WHERE rc_namespace={$ns} AND " .
"rc_title='{$t}'";
- wfQuery( $sql, DB_WRITE, $fname );
+ wfQuery( $sql, DB_WRITE, $fname );
# Finally, clean up the link tables
if ( 0 != $id ) {
+
$t = wfStrencode( $title->getPrefixedDBkey() );
+
+ if ( $wgEnablePersistentLC ) {
+ // Purge related entries in links cache on delete,
+ wfQuery("DELETE linkscc FROM linkscc,links ".
+ "WHERE lcc_title=links.l_from AND l_to={$id}", DB_WRITE);
+ wfQuery("DELETE FROM linkscc WHERE lcc_title='{$t}'", DB_WRITE);
+ }
+
$sql = "SELECT l_from FROM links WHERE l_to={$id}";
$res = wfQuery( $sql, DB_READ, $fname );
$sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
- $now = wfTimestampNow();
+ $now = wfTimestampNow();
$sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
$first = true;
$log = new LogPage( wfMsg( "dellogpage" ), wfMsg( "dellogpagetext" ) );
$art = $title->getPrefixedText();
$wpReason = wfCleanQueryVar( $wpReason );
- $log->addEntry( str_replace( "$1", $art, wfMsg( "deletedarticle" ) ), $wpReason );
+ $log->addEntry( wfMsg( "deletedarticle", $art ), $wpReason );
# Clear the cached article id so the interface doesn't act like we exist
$this->mTitle->resetArticleID( 0 );
$s = wfFetchObject( $res );
# Save it!
- $newcomment = str_replace( "$1", $s->old_user_text, wfMsg( "revertpage" ) );
+ $newcomment = wfMsg( "revertpage", $s->old_user_text );
$wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
$wgOut->setRobotpolicy( "noindex,nofollow" );
$wgOut->addHTML( "<h2>" . $newcomment . "</h2>\n<hr>\n" );
$this->updateArticle( $s->old_text, $newcomment, 1, $this->mTitle->userIsWatching() );
+ global $wgEnablePersistentLC;
+ if ( $wgEnablePersistentLC ) {
+ wfQuery("DELETE FROM linkscc WHERE lcc_pageid='{$pid}'", DB_WRITE);
+ }
+
$wgOut->returnToMain( false );
}
/* private */ function viewUpdates()
{
global $wgDeferredUpdateList;
-
+
if ( 0 != $this->getID() ) {
- $u = new ViewCountUpdate( $this->getID() );
- array_push( $wgDeferredUpdateList, $u );
- $u = new SiteStatsUpdate( 1, 0, 0 );
- array_push( $wgDeferredUpdateList, $u );
-
+ global $wgDisableCounters;
+ if( !$wgDisableCounters ) {
+ $u = new ViewCountUpdate( $this->getID() );
+ array_push( $wgDeferredUpdateList, $u );
+ $u = new SiteStatsUpdate( 1, 0, 0 );
+ array_push( $wgDeferredUpdateList, $u );
+ }
$u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(),
$this->mTitle->getDBkey() );
array_push( $wgDeferredUpdateList, $u );
$this->mTitle->getDBkey() );
array_push( $wgDeferredUpdateList, $u );
- if ( $this->getNamespace == NS_MEDIAWIKI ) {
- $key = "$wgDBname:MediaWiki:title:" . $this->mTitle->getDBkey();
- $wgMemc->delete( $key );
+ if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
+ $messageCache = $wgMemc->get( "$wgDBname:messages" );
+ if (!$messageCache) {
+ $messageCache = wfLoadAllMessages();
+ }
+ $messageCache[$title] = $text;
+ $wgMemc->set( "$wgDBname:messages", $messageCache, 86400 );
}
}
}
global $wgLang, $wgOut;
$td = $wgLang->timeanddate( $this->mTimestamp, true );
- $r = str_replace( "$1", "{$td}", wfMsg( "revisionasof" ) );
+ $r = wfMsg( "revisionasof", $td );
$wgOut->setSubtitle( "({$r})" );
}
#
$tc = "[&;%\\-,.\\(\\)' _0-9A-Za-z\\/:\\x80-\\xff]";
$np = "[&;%\\-,.' _0-9A-Za-z\\/:\\x80-\\xff]"; # No parens
+ $namespacechar = '[ _0-9A-Za-z\x80-\xff]'; # Namespaces can use non-ascii!
$conpat = "/^({$np}+) \\(({$tc}+)\\)$/";
$p1 = "/\[\[({$np}+) \\(({$np}+)\\)\\|]]/"; # [[page (context)|]]
$p2 = "/\[\[\\|({$tc}+)]]/"; # [[|page]]
- $p3 = "/\[\[([A-Za-z _]+):({$np}+)\\|]]/"; # [[namespace:page|]]
- $p4 = "/\[\[([A-Aa-z _]+):({$np}+) \\(({$np}+)\\)\\|]]/";
+ $p3 = "/\[\[($namespacechar+):({$np}+)\\|]]/"; # [[namespace:page|]]
+ $p4 = "/\[\[($namespacechar+):({$np}+) \\(({$np}+)\\)\\|]]/";
# [[ns:page (cont)|]]
$context = "";
$t = $this->mTitle->getText();
# {{SUBST:xxx}} variables
#
$mw =& MagicWord::get( MAG_SUBST );
- $text = $mw->substituteCallback( $text, "replaceMsgVar" );
+ $text = $mw->substituteCallback( $text, "wfReplaceSubstVar" );
return $text;
}
/* Caching functions */
function tryFileCache() {
+ static $called = false;
+ if( $called ) {
+ wfDebug( " tryFileCache() -- called twice!?\n" );
+ return;
+ }
+ $called = true;
if($this->isFileCacheable()) {
$touched = $this->mTouched;
if( strpos( $this->mContent, "{{" ) !== false ) {
}
$cache = new CacheManager( $this->mTitle );
if($cache->isFileCacheGood( $touched )) {
+ global $wgOut;
wfDebug( " tryFileCache() - about to load\n" );
$cache->loadFromFileCache();
+ $wgOut->reportTime(); # For profiling
exit;
} else {
wfDebug( " tryFileCache() - starting buffer\n" );
and (!isset($redirect))
and (!isset($printable))
and (!$this->mRedirectedFrom);
-
}
+ function checkTouched() {
+ $id = $this->getID();
+ $sql = "SELECT cur_touched,cur_is_redirect FROM cur WHERE cur_id=$id";
+ $res = wfQuery( $sql, DB_READ, "Article::checkTouched" );
+ if( $s = wfFetchObject( $res ) ) {
+ $this->mTouched = $s->cur_touched;
+ return !$s->cur_is_redirect;
+ } else {
+ return false;
+ }
+ }
+}
+function wfReplaceSubstVar( $matches ) {
+ return wfMsg( $matches[1] );
}
?>