2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-06-09 16:14:41 +00:00
|
|
|
# $Id$
|
|
|
|
|
#
|
2003-04-14 23:10:40 +00:00
|
|
|
# Class representing a Wikipedia article and history.
|
|
|
|
|
# See design.doc for an overview.
|
|
|
|
|
|
2003-08-02 20:43:11 +00:00
|
|
|
# Note: edit user interface and cache support functions have been
|
|
|
|
|
# moved to separate EditPage and CacheManager classes.
|
|
|
|
|
|
2004-07-20 20:48:19 +00:00
|
|
|
require_once ( 'CacheManager.php' );
|
|
|
|
|
include_once ( 'SpecialValidate.php' ) ;
|
2003-08-08 03:08:06 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
$wgArticleCurContentFields = false;
|
|
|
|
|
$wgArticleOldContentFields = false;
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
class Article {
|
|
|
|
|
/* private */ var $mContent, $mContentLoaded;
|
|
|
|
|
/* private */ var $mUser, $mTimestamp, $mUserText;
|
|
|
|
|
/* private */ var $mCounter, $mComment, $mCountAdjustment;
|
|
|
|
|
/* private */ var $mMinorEdit, $mRedirectedFrom;
|
2003-11-09 11:45:12 +00:00
|
|
|
/* private */ var $mTouched, $mFileCache, $mTitle;
|
2004-01-17 05:49:39 +00:00
|
|
|
/* private */ var $mId, $mTable;
|
2004-08-20 14:59:49 +00:00
|
|
|
/* private */ var $mForUpdate;
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-09-01 08:30:14 +00:00
|
|
|
function Article( &$title ) {
|
|
|
|
|
$this->mTitle =& $title;
|
|
|
|
|
$this->clear();
|
|
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
/* private */ function clear() {
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->mContentLoaded = false;
|
2004-01-17 05:49:39 +00:00
|
|
|
$this->mCurID = $this->mUser = $this->mCounter = -1; # Not loaded
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->mRedirectedFrom = $this->mUserText =
|
2004-06-08 19:51:10 +00:00
|
|
|
$this->mTimestamp = $this->mComment = $this->mFileCache = '';
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->mCountAdjustment = 0;
|
2004-06-08 19:51:10 +00:00
|
|
|
$this->mTouched = '19700101000000';
|
2004-08-20 14:59:49 +00:00
|
|
|
$this->mForUpdate = false;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-06-15 15:05:56 +00:00
|
|
|
# Get revision text associated with an old or archive row
|
|
|
|
|
# $row is usually an object from wfFetchRow(), both the flags and the text field must be included
|
2004-06-08 19:51:10 +00:00
|
|
|
/* static */ function getRevisionText( $row, $prefix = 'old_' ) {
|
2004-06-15 15:05:56 +00:00
|
|
|
# Get data
|
|
|
|
|
$textField = $prefix . 'text';
|
|
|
|
|
$flagsField = $prefix . 'flags';
|
|
|
|
|
|
|
|
|
|
if ( isset( $row->$flagsField ) ) {
|
2004-08-22 17:24:50 +00:00
|
|
|
$flags = explode( ',', $row->$flagsField );
|
2004-06-15 15:05:56 +00:00
|
|
|
} else {
|
|
|
|
|
$flags = array();
|
2004-01-03 12:32:32 +00:00
|
|
|
}
|
2004-06-15 15:05:56 +00:00
|
|
|
|
|
|
|
|
if ( isset( $row->$textField ) ) {
|
|
|
|
|
$text = $row->$textField;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
2004-01-03 12:32:32 +00:00
|
|
|
}
|
2004-06-15 15:05:56 +00:00
|
|
|
|
|
|
|
|
if ( in_array( 'link', $flags ) ) {
|
|
|
|
|
# Handle link type
|
|
|
|
|
$text = Article::followLink( $text );
|
|
|
|
|
} elseif ( in_array( 'gzip', $flags ) ) {
|
|
|
|
|
# Deal with optional compression of archived pages.
|
|
|
|
|
# This can be done periodically via maintenance/compressOld.php, and
|
|
|
|
|
# as pages are saved if $wgCompressRevisions is set.
|
|
|
|
|
return gzinflate( $text );
|
|
|
|
|
}
|
|
|
|
|
return $text;
|
2004-01-03 12:32:32 +00:00
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-01-04 03:35:00 +00:00
|
|
|
/* static */ function compressRevisionText( &$text ) {
|
|
|
|
|
global $wgCompressRevisions;
|
|
|
|
|
if( !$wgCompressRevisions ) {
|
2004-06-08 19:51:10 +00:00
|
|
|
return '';
|
2004-01-04 03:35:00 +00:00
|
|
|
}
|
2004-06-08 19:51:10 +00:00
|
|
|
if( !function_exists( 'gzdeflate' ) ) {
|
2004-01-04 03:35:00 +00:00
|
|
|
wfDebug( "Article::compressRevisionText() -- no zlib support, not compressing\n" );
|
2004-06-08 19:51:10 +00:00
|
|
|
return '';
|
2004-01-04 03:35:00 +00:00
|
|
|
}
|
|
|
|
|
$text = gzdeflate( $text );
|
2004-06-08 19:51:10 +00:00
|
|
|
return 'gzip';
|
2004-01-04 03:35:00 +00:00
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-06-15 15:05:56 +00:00
|
|
|
# Returns the text associated with a "link" type old table row
|
|
|
|
|
/* static */ function followLink( $link ) {
|
|
|
|
|
# Split the link into fields and values
|
|
|
|
|
$lines = explode( '\n', $link );
|
|
|
|
|
$hash = '';
|
|
|
|
|
$locations = array();
|
|
|
|
|
foreach ( $lines as $line ) {
|
|
|
|
|
# Comments
|
|
|
|
|
if ( $line{0} == '#' ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
# Field/value pairs
|
|
|
|
|
if ( preg_match( '/^(.*?)\s*:\s*(.*)$/', $line, $matches ) ) {
|
|
|
|
|
$field = strtolower($matches[1]);
|
|
|
|
|
$value = $matches[2];
|
|
|
|
|
if ( $field == 'hash' ) {
|
|
|
|
|
$hash = $value;
|
|
|
|
|
} elseif ( $field == 'location' ) {
|
|
|
|
|
$locations[] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $hash === '' ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Look in each specified location for the text
|
|
|
|
|
$text = false;
|
|
|
|
|
foreach ( $locations as $location ) {
|
|
|
|
|
$text = Article::fetchFromLocation( $location, $hash );
|
|
|
|
|
if ( $text !== false ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */ function fetchFromLocation( $location, $hash ) {
|
2004-06-26 04:46:08 +00:00
|
|
|
global $wgLoadBalancer;
|
2004-06-15 15:05:56 +00:00
|
|
|
$fname = 'fetchFromLocation';
|
|
|
|
|
wfProfileIn( $fname );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-06-15 15:05:56 +00:00
|
|
|
$p = strpos( $location, ':' );
|
|
|
|
|
if ( $p === false ) {
|
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$type = substr( $location, 0, $p );
|
|
|
|
|
$text = false;
|
|
|
|
|
switch ( $type ) {
|
|
|
|
|
case 'mysql':
|
|
|
|
|
# MySQL locations are specified by mysql://<machineID>/<dbname>/<tblname>/<index>
|
|
|
|
|
# Machine ID 0 is the current connection
|
2004-07-08 14:53:54 +00:00
|
|
|
if ( preg_match( '/^mysql:\/\/(\d+)\/([A-Za-z_]+)\/([A-Za-z_]+)\/([A-Za-z_]+)$/',
|
2004-06-15 15:05:56 +00:00
|
|
|
$location, $matches ) ) {
|
|
|
|
|
$machineID = $matches[1];
|
|
|
|
|
$dbName = $matches[2];
|
|
|
|
|
$tblName = $matches[3];
|
|
|
|
|
$index = $matches[4];
|
|
|
|
|
if ( $machineID == 0 ) {
|
|
|
|
|
# Current connection
|
2004-08-20 14:59:49 +00:00
|
|
|
$db =& $this->getDB();
|
2004-06-15 15:05:56 +00:00
|
|
|
} else {
|
|
|
|
|
# Alternate connection
|
|
|
|
|
$db =& $wgLoadBalancer->getConnection( $machineID );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-06-15 15:05:56 +00:00
|
|
|
if ( array_key_exists( $machineId, $wgKnownMysqlServers ) ) {
|
|
|
|
|
# Try to open, return false on failure
|
|
|
|
|
$params = $wgKnownDBServers[$machineId];
|
2004-07-08 14:53:54 +00:00
|
|
|
$db = Database::newFromParams( $params['server'], $params['user'], $params['password'],
|
2004-07-24 07:24:04 +00:00
|
|
|
$dbName, 1, DBO_IGNORE );
|
2004-06-15 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( $db->isOpen() ) {
|
2004-07-10 03:09:26 +00:00
|
|
|
$index = $db->strencode( $index );
|
2004-08-20 14:59:49 +00:00
|
|
|
$res = $db->query( "SELECT blob_data FROM $dbName.$tblName " .
|
|
|
|
|
"WHERE blob_index='$index' " . $this->getSelectOptions(), $fname );
|
2004-06-15 15:05:56 +00:00
|
|
|
$row = $db->fetchObject( $res );
|
|
|
|
|
$text = $row->text_data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'file':
|
|
|
|
|
# File locations are of the form file://<filename>, relative to the current directory
|
|
|
|
|
if ( preg_match( '/^file:\/\/(.*)$', $location, $matches ) )
|
|
|
|
|
$filename = strstr( $location, 'file://' );
|
|
|
|
|
$text = @file_get_contents( $matches[1] );
|
|
|
|
|
}
|
|
|
|
|
if ( $text !== false ) {
|
|
|
|
|
# Got text, now we need to interpret it
|
|
|
|
|
# The first line contains information about how to do this
|
|
|
|
|
$p = strpos( $text, '\n' );
|
|
|
|
|
$type = substr( $text, 0, $p );
|
|
|
|
|
$text = substr( $text, $p + 1 );
|
|
|
|
|
switch ( $type ) {
|
|
|
|
|
case 'plain':
|
|
|
|
|
break;
|
|
|
|
|
case 'gzip':
|
|
|
|
|
$text = gzinflate( $text );
|
|
|
|
|
break;
|
|
|
|
|
case 'object':
|
|
|
|
|
$object = unserialize( $text );
|
|
|
|
|
$text = $object->getItem( $hash );
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$text = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
return $text;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
# Note that getContent/loadContent may follow redirects if
|
2003-11-09 11:45:12 +00:00
|
|
|
# not told otherwise, and so may cause a change to mTitle.
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-01-17 05:49:39 +00:00
|
|
|
# Return the text of this revision
|
2004-08-12 14:27:38 +00:00
|
|
|
function getContent( $noredir ) {
|
2004-05-13 14:17:44 +00:00
|
|
|
global $wgRequest;
|
2004-03-29 14:48:07 +00:00
|
|
|
|
|
|
|
|
# Get variables from query string :P
|
|
|
|
|
$action = $wgRequest->getText( 'action', 'view' );
|
|
|
|
|
$section = $wgRequest->getText( 'section' );
|
2004-05-13 14:17:44 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
$fname = 'Article::getContent';
|
2004-05-13 14:17:44 +00:00
|
|
|
wfProfileIn( $fname );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
if ( 0 == $this->getID() ) {
|
2004-06-08 19:51:10 +00:00
|
|
|
if ( 'edit' == $action ) {
|
2003-10-16 13:30:45 +00:00
|
|
|
wfProfileOut( $fname );
|
2004-06-08 19:51:10 +00:00
|
|
|
return ''; # was "newarticletext", now moved above the box)
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2003-10-16 13:30:45 +00:00
|
|
|
wfProfileOut( $fname );
|
2004-06-08 19:51:10 +00:00
|
|
|
return wfMsg( 'noarticletext' );
|
2004-05-13 14:17:44 +00:00
|
|
|
} else {
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->loadContent( $noredir );
|
2004-08-07 03:50:46 +00:00
|
|
|
# check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
|
|
|
|
|
if ( $this->mTitle->getNamespace() == NS_USER_TALK &&
|
|
|
|
|
preg_match('/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/',$this->mTitle->getText()) &&
|
|
|
|
|
$action=='view'
|
|
|
|
|
) {
|
2004-05-13 14:17:44 +00:00
|
|
|
wfProfileOut( $fname );
|
2004-08-09 05:38:11 +00:00
|
|
|
return $this->mContent . "\n" .wfMsg('anontalkpagetext');
|
2004-08-07 03:50:46 +00:00
|
|
|
} else {
|
2004-06-08 19:51:10 +00:00
|
|
|
if($action=='edit') {
|
|
|
|
|
if($section!='') {
|
|
|
|
|
if($section=='new') {
|
2004-05-13 14:17:44 +00:00
|
|
|
wfProfileOut( $fname );
|
2004-06-08 19:51:10 +00:00
|
|
|
return '';
|
2004-05-13 14:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
|
|
|
|
|
# comments to be stripped as well)
|
2004-05-13 17:25:34 +00:00
|
|
|
$rv=$this->getSection($this->mContent,$section);
|
2004-05-13 14:17:44 +00:00
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
return $rv;
|
|
|
|
|
}
|
2004-05-13 12:20:59 +00:00
|
|
|
}
|
2004-05-13 14:17:44 +00:00
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
return $this->mContent;
|
2004-05-13 12:20:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-05-13 17:25:34 +00:00
|
|
|
# This function returns the text of a section, specified by a number ($section).
|
2004-08-21 08:50:49 +00:00
|
|
|
# A section is text under a heading like == Heading == or <h1>Heading</h1>, or
|
2004-05-13 17:25:34 +00:00
|
|
|
# the first section before any such heading (section 0).
|
|
|
|
|
#
|
|
|
|
|
# If a section contains subsections, these are also returned.
|
|
|
|
|
#
|
2004-08-12 14:27:38 +00:00
|
|
|
function getSection($text,$section) {
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-05-13 17:25:34 +00:00
|
|
|
# strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
|
|
|
|
|
# comments to be stripped as well)
|
|
|
|
|
$striparray=array();
|
|
|
|
|
$parser=new Parser();
|
|
|
|
|
$parser->mOutputType=OT_WIKI;
|
|
|
|
|
$striptext=$parser->strip($text, $striparray, true);
|
|
|
|
|
|
|
|
|
|
# now that we can be sure that no pseudo-sections are in the source,
|
|
|
|
|
# split it up by section
|
|
|
|
|
$secs =
|
|
|
|
|
preg_split(
|
2004-06-08 19:51:10 +00:00
|
|
|
'/(^=+.*?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)/mi',
|
2004-05-13 17:25:34 +00:00
|
|
|
$striptext, -1,
|
|
|
|
|
PREG_SPLIT_DELIM_CAPTURE);
|
|
|
|
|
if($section==0) {
|
|
|
|
|
$rv=$secs[0];
|
|
|
|
|
} else {
|
|
|
|
|
$headline=$secs[$section*2-1];
|
2004-06-08 19:51:10 +00:00
|
|
|
preg_match( '/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$headline,$matches);
|
2004-05-13 17:25:34 +00:00
|
|
|
$hlevel=$matches[1];
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-05-13 17:25:34 +00:00
|
|
|
# translate wiki heading into level
|
2004-06-08 19:51:10 +00:00
|
|
|
if(strpos($hlevel,'=')!==false) {
|
2004-07-08 14:53:54 +00:00
|
|
|
$hlevel=strlen($hlevel);
|
2004-05-13 17:25:34 +00:00
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-05-13 17:25:34 +00:00
|
|
|
$rv=$headline. $secs[$section*2];
|
|
|
|
|
$count=$section+1;
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-05-13 17:25:34 +00:00
|
|
|
$break=false;
|
|
|
|
|
while(!empty($secs[$count*2-1]) && !$break) {
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-05-13 17:25:34 +00:00
|
|
|
$subheadline=$secs[$count*2-1];
|
2004-06-08 19:51:10 +00:00
|
|
|
preg_match( '/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$subheadline,$matches);
|
2004-05-13 17:25:34 +00:00
|
|
|
$subhlevel=$matches[1];
|
2004-06-08 19:51:10 +00:00
|
|
|
if(strpos($subhlevel,'=')!==false) {
|
2004-07-08 14:53:54 +00:00
|
|
|
$subhlevel=strlen($subhlevel);
|
2004-05-13 17:25:34 +00:00
|
|
|
}
|
|
|
|
|
if($subhlevel > $hlevel) {
|
|
|
|
|
$rv.=$subheadline.$secs[$count*2];
|
|
|
|
|
}
|
|
|
|
|
if($subhlevel <= $hlevel) {
|
|
|
|
|
$break=true;
|
|
|
|
|
}
|
|
|
|
|
$count++;
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-05-13 17:25:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
# reinsert stripped tags
|
|
|
|
|
$rv=$parser->unstrip($rv,$striparray);
|
2004-06-02 12:29:15 +00:00
|
|
|
$rv=$parser->unstripNoWiki($rv,$striparray);
|
2004-05-13 17:25:34 +00:00
|
|
|
$rv=trim($rv);
|
|
|
|
|
return $rv;
|
|
|
|
|
|
|
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-07-10 09:06:24 +00:00
|
|
|
# Return an array of the columns of the "cur"-table
|
2004-07-10 03:09:26 +00:00
|
|
|
function &getCurContentFields() {
|
|
|
|
|
global $wgArticleCurContentFields;
|
|
|
|
|
if ( !$wgArticleCurContentFields ) {
|
|
|
|
|
$wgArticleCurContentFields = array( 'cur_text','cur_timestamp','cur_user', 'cur_user_text',
|
|
|
|
|
'cur_comment','cur_counter','cur_restrictions','cur_touched' );
|
|
|
|
|
}
|
|
|
|
|
return $wgArticleCurContentFields;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-10 09:06:24 +00:00
|
|
|
# Return an array of the columns of the "old"-table
|
2004-07-10 03:09:26 +00:00
|
|
|
function &getOldContentFields() {
|
|
|
|
|
global $wgArticleOldContentFields;
|
|
|
|
|
if ( !$wgArticleOldContentFields ) {
|
2004-08-09 05:38:11 +00:00
|
|
|
$wgArticleOldContentFields = array( 'old_namespace','old_title','old_text','old_timestamp',
|
2004-07-10 03:09:26 +00:00
|
|
|
'old_user','old_user_text','old_comment','old_flags' );
|
|
|
|
|
}
|
|
|
|
|
return $wgArticleOldContentFields;
|
|
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-01-17 05:49:39 +00:00
|
|
|
# Load the revision (including cur_text) into this object
|
2004-08-12 14:27:38 +00:00
|
|
|
function loadContent( $noredir = false ) {
|
2004-07-10 03:09:26 +00:00
|
|
|
global $wgOut, $wgMwRedir, $wgRequest;
|
2004-04-28 04:50:35 +00:00
|
|
|
|
2004-08-20 14:59:49 +00:00
|
|
|
$dbr =& $this->getDB();
|
2004-03-29 14:48:07 +00:00
|
|
|
# Query variables :P
|
|
|
|
|
$oldid = $wgRequest->getVal( 'oldid' );
|
|
|
|
|
$redirect = $wgRequest->getVal( 'redirect' );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
if ( $this->mContentLoaded ) return;
|
2004-06-08 19:51:10 +00:00
|
|
|
$fname = 'Article::loadContent';
|
2004-07-08 14:53:54 +00:00
|
|
|
|
|
|
|
|
# Pre-fill content with error message so that if something
|
2004-04-28 04:50:35 +00:00
|
|
|
# fails we'll have something telling us what we intended.
|
2004-03-21 06:58:12 +00:00
|
|
|
|
2004-07-08 14:53:54 +00:00
|
|
|
$t = $this->mTitle->getPrefixedText();
|
|
|
|
|
if ( isset( $oldid ) ) {
|
|
|
|
|
$oldid = IntVal( $oldid );
|
2004-08-22 17:24:50 +00:00
|
|
|
$t .= ',oldid='.$oldid;
|
2004-07-08 14:53:54 +00:00
|
|
|
}
|
|
|
|
|
if ( isset( $redirect ) ) {
|
|
|
|
|
$redirect = ($redirect == 'no') ? 'no' : 'yes';
|
2004-08-22 17:24:50 +00:00
|
|
|
$t .= ',redirect='.$redirect;
|
2004-07-08 14:53:54 +00:00
|
|
|
}
|
2004-06-08 19:51:10 +00:00
|
|
|
$this->mContent = wfMsg( 'missingarticle', $t );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
if ( ! $oldid ) { # Retrieve current version
|
|
|
|
|
$id = $this->getID();
|
|
|
|
|
if ( 0 == $id ) return;
|
|
|
|
|
|
2004-08-20 14:59:49 +00:00
|
|
|
$s = $dbr->selectRow( 'cur', $this->getCurContentFields(), array( 'cur_id' => $id ), $fname,
|
|
|
|
|
$this->getSelectOptions() );
|
2004-08-09 05:38:11 +00:00
|
|
|
if ( $s === false ) {
|
2004-07-08 14:53:54 +00:00
|
|
|
return;
|
2003-11-02 13:57:24 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
# If we got a redirect, follow it (unless we've been told
|
|
|
|
|
# not to by either the function parameter or the query
|
2004-08-07 03:50:46 +00:00
|
|
|
if ( ( 'no' != $redirect ) && ( false == $noredir ) ) {
|
|
|
|
|
$rt = Title::newFromRedirect( $s->cur_text );
|
2004-08-22 17:24:50 +00:00
|
|
|
# process if title object is valid and not special:userlogout
|
2004-08-16 04:42:48 +00:00
|
|
|
if ( $rt && ! ( $rt->getNamespace() == NS_SPECIAL && $rt->getText() == 'Userlogout' ) ) {
|
2004-08-07 03:50:46 +00:00
|
|
|
# Gotta hand redirects to special pages differently:
|
|
|
|
|
# Fill the HTTP response "Location" header and ignore
|
|
|
|
|
# the rest of the page we're on.
|
|
|
|
|
|
|
|
|
|
if ( $rt->getInterwiki() != '' ) {
|
|
|
|
|
$wgOut->redirect( $rt->getFullURL() ) ;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( $rt->getNamespace() == NS_SPECIAL ) {
|
|
|
|
|
$wgOut->redirect( $rt->getFullURL() );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$rid = $rt->getArticleID();
|
|
|
|
|
if ( 0 != $rid ) {
|
2004-08-20 14:59:49 +00:00
|
|
|
$redirRow = $dbr->selectRow( 'cur', $this->getCurContentFields(),
|
|
|
|
|
array( 'cur_id' => $rid ), $fname, $this->getSelectOptions() );
|
2004-08-07 03:50:46 +00:00
|
|
|
|
|
|
|
|
if ( $redirRow !== false ) {
|
|
|
|
|
$this->mRedirectedFrom = $this->mTitle->getPrefixedText();
|
|
|
|
|
$this->mTitle = $rt;
|
|
|
|
|
$s = $redirRow;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-11-02 13:57:24 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->mContent = $s->cur_text;
|
|
|
|
|
$this->mUser = $s->cur_user;
|
2004-05-30 22:02:28 +00:00
|
|
|
$this->mUserText = $s->cur_user_text;
|
|
|
|
|
$this->mComment = $s->cur_comment;
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->mCounter = $s->cur_counter;
|
2004-08-20 12:47:46 +00:00
|
|
|
$this->mTimestamp = wfTimestamp(TS_MW,$s->cur_timestamp);
|
|
|
|
|
$this->mTouched = wfTimestamp(TS_MW,$s->cur_touched);
|
2004-06-08 19:51:10 +00:00
|
|
|
$this->mTitle->mRestrictions = explode( ',', trim( $s->cur_restrictions ) );
|
2003-09-01 08:30:14 +00:00
|
|
|
$this->mTitle->mRestrictionsLoaded = true;
|
2003-04-14 23:10:40 +00:00
|
|
|
} else { # oldid set, retrieve historical version
|
2004-08-20 14:59:49 +00:00
|
|
|
$s = $dbr->getArray( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ),
|
|
|
|
|
$fname, $this->getSelectOptions() );
|
2004-07-10 03:09:26 +00:00
|
|
|
if ( $s === false ) {
|
2004-05-11 09:47:41 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-05-11 09:47:41 +00:00
|
|
|
if( $this->mTitle->getNamespace() != $s->old_namespace ||
|
|
|
|
|
$this->mTitle->getDBkey() != $s->old_title ) {
|
|
|
|
|
$oldTitle = Title::makeTitle( $s->old_namesapce, $s->old_title );
|
|
|
|
|
$this->mTitle = $oldTitle;
|
|
|
|
|
$wgTitle = $oldTitle;
|
|
|
|
|
}
|
2004-01-03 12:32:32 +00:00
|
|
|
$this->mContent = Article::getRevisionText( $s );
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->mUser = $s->old_user;
|
2004-05-30 22:02:28 +00:00
|
|
|
$this->mUserText = $s->old_user_text;
|
|
|
|
|
$this->mComment = $s->old_comment;
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->mCounter = 0;
|
2004-08-20 12:47:46 +00:00
|
|
|
$this->mTimestamp = wfTimestamp(TS_MW,$s->old_timestamp);
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
$this->mContentLoaded = true;
|
2004-03-23 10:11:24 +00:00
|
|
|
return $this->mContent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Gets the article text without using so many damn globals
|
|
|
|
|
# Returns false on error
|
|
|
|
|
function getContentWithoutUsingSoManyDamnGlobals( $oldid = 0, $noredir = false ) {
|
2004-07-10 03:09:26 +00:00
|
|
|
global $wgMwRedir;
|
2004-03-23 10:11:24 +00:00
|
|
|
|
|
|
|
|
if ( $this->mContentLoaded ) {
|
|
|
|
|
return $this->mContent;
|
|
|
|
|
}
|
|
|
|
|
$this->mContent = false;
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
$fname = 'Article::getContentWithout';
|
2004-08-20 14:59:49 +00:00
|
|
|
$dbr =& $this->getDB();
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-03-23 10:11:24 +00:00
|
|
|
if ( ! $oldid ) { # Retrieve current version
|
|
|
|
|
$id = $this->getID();
|
|
|
|
|
if ( 0 == $id ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-20 14:59:49 +00:00
|
|
|
$s = $dbr->selectRow( 'cur', $this->getCurContentFields(), array( 'cur_id' => $id ),
|
|
|
|
|
$fname, $this->getSelectOptions() );
|
2004-08-09 05:38:11 +00:00
|
|
|
if ( $s === false ) {
|
2004-07-08 14:53:54 +00:00
|
|
|
return false;
|
2004-03-23 10:11:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# If we got a redirect, follow it (unless we've been told
|
|
|
|
|
# not to by either the function parameter or the query
|
2004-08-07 03:50:46 +00:00
|
|
|
if ( !$noredir ) {
|
|
|
|
|
$rt = Title::newFromRedirect( $s->cur_text );
|
|
|
|
|
if( $rt && $rt->getInterwiki() == '' && $rt->getNamespace() != NS_SPECIAL ) {
|
|
|
|
|
$rid = $rt->getArticleID();
|
|
|
|
|
if ( 0 != $rid ) {
|
2004-08-20 14:59:49 +00:00
|
|
|
$redirRow = $dbr->selectRow( 'cur', $this->getCurContentFields(),
|
|
|
|
|
array( 'cur_id' => $rid ), $fname, $this->getSelectOptions() );
|
2004-08-07 03:50:46 +00:00
|
|
|
|
|
|
|
|
if ( $redirRow !== false ) {
|
|
|
|
|
$this->mRedirectedFrom = $this->mTitle->getPrefixedText();
|
|
|
|
|
$this->mTitle = $rt;
|
|
|
|
|
$s = $redirRow;
|
2004-03-23 10:11:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->mContent = $s->cur_text;
|
|
|
|
|
$this->mUser = $s->cur_user;
|
2004-07-10 03:09:26 +00:00
|
|
|
$this->mUserText = $s->cur_user_text;
|
|
|
|
|
$this->mComment = $s->cur_comment;
|
2004-03-23 10:11:24 +00:00
|
|
|
$this->mCounter = $s->cur_counter;
|
2004-08-20 12:47:46 +00:00
|
|
|
$this->mTimestamp = wfTimestamp(TS_MW,$s->cur_timestamp);
|
|
|
|
|
$this->mTouched = wfTimestamp(TS_MW,$s->cur_touched);
|
2004-08-22 17:24:50 +00:00
|
|
|
$this->mTitle->mRestrictions = explode( ',', trim( $s->cur_restrictions ) );
|
2004-03-23 10:11:24 +00:00
|
|
|
$this->mTitle->mRestrictionsLoaded = true;
|
|
|
|
|
} else { # oldid set, retrieve historical version
|
2004-08-20 14:59:49 +00:00
|
|
|
$s = $dbr->selectRow( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ),
|
|
|
|
|
$fname, $this->getSelectOptions() );
|
2004-08-09 05:38:11 +00:00
|
|
|
if ( $s === false ) {
|
2004-07-08 14:53:54 +00:00
|
|
|
return false;
|
2004-03-23 10:11:24 +00:00
|
|
|
}
|
|
|
|
|
$this->mContent = Article::getRevisionText( $s );
|
|
|
|
|
$this->mUser = $s->old_user;
|
2004-07-10 03:09:26 +00:00
|
|
|
$this->mUserText = $s->old_user_text;
|
|
|
|
|
$this->mComment = $s->old_comment;
|
2004-03-23 10:11:24 +00:00
|
|
|
$this->mCounter = 0;
|
2004-08-20 12:47:46 +00:00
|
|
|
$this->mTimestamp = wfTimestamp(TS_MW,$s->old_timestamp);
|
2004-03-23 10:11:24 +00:00
|
|
|
}
|
|
|
|
|
$this->mContentLoaded = true;
|
|
|
|
|
return $this->mContent;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-08-20 14:59:49 +00:00
|
|
|
# Read/write accessor to select FOR UPDATE
|
|
|
|
|
function forUpdate( $x = NULL ) {
|
|
|
|
|
return wfSetVar( $this->mForUpdate, $x );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Get the database which should be used for reads
|
|
|
|
|
function &getDB() {
|
|
|
|
|
if ( $this->mForUpdate ) {
|
|
|
|
|
return wfGetDB( DB_MASTER );
|
|
|
|
|
} else {
|
|
|
|
|
return wfGetDB( DB_SLAVE );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Get options for all SELECT statements
|
|
|
|
|
# Can pass an option array, to which the class-wide options will be appended
|
|
|
|
|
function getSelectOptions( $options = '' ) {
|
|
|
|
|
if ( $this->mForUpdate ) {
|
|
|
|
|
if ( $options ) {
|
|
|
|
|
$options[] = 'FOR UPDATE';
|
|
|
|
|
} else {
|
|
|
|
|
$options = 'FOR UPDATE';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $options;
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-24 10:24:04 +00:00
|
|
|
function getID() {
|
|
|
|
|
if( $this->mTitle ) {
|
|
|
|
|
return $this->mTitle->getArticleID();
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
function getCount() {
|
2003-04-14 23:10:40 +00:00
|
|
|
if ( -1 == $this->mCounter ) {
|
|
|
|
|
$id = $this->getID();
|
2004-08-20 14:59:49 +00:00
|
|
|
$dbr =& $this->getDB();
|
2004-08-22 17:24:50 +00:00
|
|
|
$this->mCounter = $dbr->selectField( 'cur', 'cur_counter', 'cur_id='.$id,
|
2004-08-20 14:59:49 +00:00
|
|
|
'Article::getCount', $this->getSelectOptions() );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
return $this->mCounter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Would the given text make this article a "good" article (i.e.,
|
|
|
|
|
# suitable for including in the article count)?
|
2004-08-12 14:27:38 +00:00
|
|
|
function isCountable( $text ) {
|
2003-09-01 08:30:14 +00:00
|
|
|
global $wgUseCommaCount, $wgMwRedir;
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-09-01 08:30:14 +00:00
|
|
|
if ( 0 != $this->mTitle->getNamespace() ) { return 0; }
|
2003-08-31 09:46:37 +00:00
|
|
|
if ( $wgMwRedir->matchStart( $text ) ) { return 0; }
|
2004-06-08 19:51:10 +00:00
|
|
|
$token = ($wgUseCommaCount ? ',' : '[[' );
|
2003-04-14 23:10:40 +00:00
|
|
|
if ( false === strstr( $text, $token ) ) { return 0; }
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-17 05:49:39 +00:00
|
|
|
# Loads everything from cur except cur_text
|
2003-04-14 23:10:40 +00:00
|
|
|
# This isn't necessary for all uses, so it's only done if needed.
|
2004-08-12 14:27:38 +00:00
|
|
|
/* private */ function loadLastEdit() {
|
2003-04-14 23:10:40 +00:00
|
|
|
global $wgOut;
|
|
|
|
|
if ( -1 != $this->mUser ) return;
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
$fname = 'Article::loadLastEdit';
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-08-20 14:59:49 +00:00
|
|
|
$dbr =& $this->getDB();
|
2004-08-09 05:38:11 +00:00
|
|
|
$s = $dbr->getArray( 'cur',
|
2004-07-10 03:09:26 +00:00
|
|
|
array( 'cur_user','cur_user_text','cur_timestamp', 'cur_comment','cur_minor_edit' ),
|
2004-08-20 14:59:49 +00:00
|
|
|
array( 'cur_id' => $this->getID() ), $fname, $this->getSelectOptions() );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
if ( $s !== false ) {
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->mUser = $s->cur_user;
|
|
|
|
|
$this->mUserText = $s->cur_user_text;
|
2004-08-20 12:47:46 +00:00
|
|
|
$this->mTimestamp = wfTimestamp(TS_MW,$s->cur_timestamp);
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->mComment = $s->cur_comment;
|
|
|
|
|
$this->mMinorEdit = $s->cur_minor_edit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
function getTimestamp() {
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->loadLastEdit();
|
|
|
|
|
return $this->mTimestamp;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
function getUser() {
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->loadLastEdit();
|
|
|
|
|
return $this->mUser;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
function getUserText() {
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->loadLastEdit();
|
|
|
|
|
return $this->mUserText;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
function getComment() {
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->loadLastEdit();
|
|
|
|
|
return $this->mComment;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
function getMinorEdit() {
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->loadLastEdit();
|
|
|
|
|
return $this->mMinorEdit;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
function getContributors($limit = 0, $offset = 0) {
|
|
|
|
|
$fname = 'Article::getContributors';
|
2004-04-29 01:58:20 +00:00
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
# XXX: this is expensive; cache this info somewhere.
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
$title = $this->mTitle;
|
|
|
|
|
$contribs = array();
|
2004-08-20 14:59:49 +00:00
|
|
|
$dbr =& $this->getDB();
|
2004-07-10 03:09:26 +00:00
|
|
|
$oldTable = $dbr->tableName( 'old' );
|
|
|
|
|
$userTable = $dbr->tableName( 'user' );
|
|
|
|
|
$encDBkey = $dbr->strencode( $title->getDBkey() );
|
|
|
|
|
$ns = $title->getNamespace();
|
|
|
|
|
$user = $this->getUser();
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT old_user, old_user_text, user_real_name, MAX(old_timestamp) as timestamp
|
2004-08-09 05:38:11 +00:00
|
|
|
FROM $oldTable LEFT JOIN $userTable ON old_user = user_id
|
2004-07-10 03:09:26 +00:00
|
|
|
WHERE old_namespace = $user
|
|
|
|
|
AND old_title = $encDBkey
|
|
|
|
|
AND old_user != $user
|
2004-08-09 05:38:11 +00:00
|
|
|
GROUP BY old_user
|
2004-07-10 03:09:26 +00:00
|
|
|
ORDER BY timestamp DESC";
|
2004-04-29 01:58:20 +00:00
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
|
2004-08-20 14:59:49 +00:00
|
|
|
$sql .= ' '. $this->getSelectOptions();
|
2004-04-29 01:58:20 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
$res = $dbr->query($sql, $fname);
|
2004-08-20 14:59:49 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
while ( $line = $dbr->fetchObject( $res ) ) {
|
2004-08-12 14:27:38 +00:00
|
|
|
$contribs[] = array($line->old_user, $line->old_user_text, $line->user_real_name);
|
|
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbr->freeResult($res);
|
2004-08-12 14:27:38 +00:00
|
|
|
return $contribs;
|
2004-04-23 21:01:29 +00:00
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
# This is the default action of the script: just view the page of
|
|
|
|
|
# the given title.
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
function view() {
|
2004-08-09 05:38:11 +00:00
|
|
|
global $wgUser, $wgOut, $wgLang, $wgRequest, $wgMwRedir, $wgOnlySysopsCanPatrol;
|
2004-08-09 23:30:02 +00:00
|
|
|
global $wgLinkCache, $IP, $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol;
|
2004-08-09 05:38:11 +00:00
|
|
|
$sk = $wgUser->getSkin();
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
$fname = 'Article::view';
|
2003-10-16 13:30:45 +00:00
|
|
|
wfProfileIn( $fname );
|
2004-08-09 05:38:11 +00:00
|
|
|
# Get variables from query string
|
2004-03-29 14:48:07 +00:00
|
|
|
$oldid = $wgRequest->getVal( 'oldid' );
|
|
|
|
|
$diff = $wgRequest->getVal( 'diff' );
|
2004-08-09 05:38:11 +00:00
|
|
|
$rcid = $wgRequest->getVal( 'rcid' );
|
2004-03-29 14:48:07 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
$wgOut->setArticleFlag( true );
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->setRobotpolicy( 'index,follow' );
|
2003-04-14 23:10:40 +00:00
|
|
|
# If we got diff and oldid in the query, we want to see a
|
|
|
|
|
# diff page instead of the article.
|
|
|
|
|
|
2004-05-13 14:17:44 +00:00
|
|
|
if ( !is_null( $diff ) ) {
|
2004-08-21 09:32:34 +00:00
|
|
|
require_once( 'DifferenceEngine.php' );
|
2003-09-01 08:30:14 +00:00
|
|
|
$wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
|
2004-08-09 05:38:11 +00:00
|
|
|
$de = new DifferenceEngine( intval($oldid), intval($diff), intval($rcid) );
|
2003-04-14 23:10:40 +00:00
|
|
|
$de->showDiffPage();
|
2003-10-16 13:30:45 +00:00
|
|
|
wfProfileOut( $fname );
|
2004-08-03 04:52:19 +00:00
|
|
|
if( $diff == 0 ) {
|
|
|
|
|
# Run view updates for current revision only
|
|
|
|
|
$this->viewUpdates();
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2004-07-22 00:05:52 +00:00
|
|
|
if ( empty( $oldid ) && $this->checkTouched() ) {
|
2003-12-11 20:16:34 +00:00
|
|
|
if( $wgOut->checkLastModified( $this->mTouched ) ){
|
|
|
|
|
return;
|
|
|
|
|
} else if ( $this->tryFileCache() ) {
|
|
|
|
|
# tell wgOut that output is taken care of
|
|
|
|
|
$wgOut->disable();
|
2003-12-13 21:32:32 +00:00
|
|
|
$this->viewUpdates();
|
2003-12-11 20:16:34 +00:00
|
|
|
return;
|
2003-11-09 11:45:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
2004-06-04 10:40:44 +00:00
|
|
|
# Should the parser cache be used?
|
2004-06-08 19:51:10 +00:00
|
|
|
if ( $wgEnableParserCache && intval($wgUser->getOption( 'stubthreshold' )) == 0 && empty( $oldid ) ) {
|
2004-06-04 10:40:44 +00:00
|
|
|
$pcache = true;
|
|
|
|
|
} else {
|
|
|
|
|
$pcache = false;
|
2004-05-11 09:47:41 +00:00
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-06-04 10:40:44 +00:00
|
|
|
$outputDone = false;
|
|
|
|
|
if ( $pcache ) {
|
|
|
|
|
if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
|
|
|
|
|
$outputDone = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( !$outputDone ) {
|
|
|
|
|
$text = $this->getContent( false ); # May change mTitle by following a redirect
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-06-04 10:40:44 +00:00
|
|
|
# Another whitelist check in case oldid or redirects are altering the title
|
|
|
|
|
if ( !$this->mTitle->userCanRead() ) {
|
|
|
|
|
$wgOut->loginToUse();
|
|
|
|
|
$wgOut->output();
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-06-04 10:40:44 +00:00
|
|
|
# We're looking at an old revision
|
2003-12-11 20:16:34 +00:00
|
|
|
|
2004-06-04 10:40:44 +00:00
|
|
|
if ( !empty( $oldid ) ) {
|
|
|
|
|
$this->setOldSubtitle();
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->setRobotpolicy( 'noindex,follow' );
|
2004-06-04 10:40:44 +00:00
|
|
|
}
|
2004-06-08 19:51:10 +00:00
|
|
|
if ( '' != $this->mRedirectedFrom ) {
|
2004-06-04 10:40:44 +00:00
|
|
|
$sk = $wgUser->getSkin();
|
2004-06-08 19:51:10 +00:00
|
|
|
$redir = $sk->makeKnownLink( $this->mRedirectedFrom, '',
|
|
|
|
|
'redirect=no' );
|
|
|
|
|
$s = wfMsg( 'redirectedfrom', $redir );
|
2004-06-04 10:40:44 +00:00
|
|
|
$wgOut->setSubtitle( $s );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
|
|
|
|
# Can't cache redirects
|
2004-06-04 10:40:44 +00:00
|
|
|
$pcache = false;
|
|
|
|
|
}
|
2004-04-29 23:13:19 +00:00
|
|
|
|
2004-06-04 10:40:44 +00:00
|
|
|
# wrap user css and user js in pre and don't parse
|
|
|
|
|
# XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
|
2004-07-08 14:53:54 +00:00
|
|
|
if (
|
2004-08-07 03:50:46 +00:00
|
|
|
$this->mTitle->getNamespace() == NS_USER &&
|
2004-06-08 19:51:10 +00:00
|
|
|
preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle->getDBkey())
|
2004-06-04 10:40:44 +00:00
|
|
|
) {
|
2004-06-09 13:04:52 +00:00
|
|
|
$wgOut->addWikiText( wfMsg('clearyourcache'));
|
2004-06-04 10:40:44 +00:00
|
|
|
$wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent)."\n</pre>" );
|
2004-08-07 03:50:46 +00:00
|
|
|
} else if ( $rt = Title::newFromRedirect( $text ) ) {
|
|
|
|
|
# Display redirect
|
2004-08-22 17:24:50 +00:00
|
|
|
$imageUrl = $wgStylePath.'/images/redirect.png';
|
2004-08-07 03:50:46 +00:00
|
|
|
$targetUrl = $rt->escapeLocalURL();
|
|
|
|
|
$titleText = htmlspecialchars( $rt->getPrefixedText() );
|
|
|
|
|
$link = $sk->makeLinkObj( $rt );
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgOut->addHTML( '<img valign="center" src="'.$imageUrl.'">' .
|
|
|
|
|
'<span class="redirectText">'.$link.'</span>' );
|
2004-06-04 10:40:44 +00:00
|
|
|
} else if ( $pcache ) {
|
2004-08-07 03:50:46 +00:00
|
|
|
# Display content and save to parser cache
|
2004-08-21 14:56:07 +00:00
|
|
|
$wgOut->addPrimaryWikiText( $text, $this );
|
2004-06-04 10:40:44 +00:00
|
|
|
} else {
|
2004-08-07 03:50:46 +00:00
|
|
|
# Display content, don't attempt to save to parser cache
|
2004-06-04 10:40:44 +00:00
|
|
|
$wgOut->addWikiText( $text );
|
|
|
|
|
}
|
2004-02-27 02:24:14 +00:00
|
|
|
}
|
2004-06-04 12:49:16 +00:00
|
|
|
$wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
|
2004-08-09 05:38:11 +00:00
|
|
|
# If we have been passed an &rcid= parameter, we want to give the user a
|
|
|
|
|
# chance to mark this new article as patrolled.
|
2004-08-09 23:30:02 +00:00
|
|
|
if ( $wgUseRCPatrol && !is_null ( $rcid ) && $rcid != 0 && $wgUser->getID() != 0 &&
|
2004-08-09 05:38:11 +00:00
|
|
|
( $wgUser->isSysop() || !$wgOnlySysopsCanPatrol ) )
|
|
|
|
|
{
|
|
|
|
|
$wgOut->addHTML( wfMsg ( 'markaspatrolledlink',
|
|
|
|
|
$sk->makeKnownLinkObj ( $this->mTitle, wfMsg ( 'markaspatrolledtext' ),
|
2004-08-22 17:24:50 +00:00
|
|
|
'action=markpatrolled&rcid='.$rcid )
|
2004-08-09 05:38:11 +00:00
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-14 13:34:57 +00:00
|
|
|
# Put link titles into the link cache
|
2004-08-21 14:56:07 +00:00
|
|
|
$wgOut->transformBuffer();
|
2004-08-20 14:59:49 +00:00
|
|
|
|
2004-03-20 13:27:08 +00:00
|
|
|
# Add link titles as META keywords
|
|
|
|
|
$wgOut->addMetaTags() ;
|
2004-08-20 14:59:49 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->viewUpdates();
|
2003-10-16 13:30:45 +00:00
|
|
|
wfProfileOut( $fname );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Theoretically we could defer these whole insert and update
|
|
|
|
|
# functions for after display, but that's taking a big leap
|
|
|
|
|
# of faith, and we want to be able to report database
|
|
|
|
|
# errors at some point.
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
/* private */ function insertNewArticle( $text, $summary, $isminor, $watchthis ) {
|
2004-07-24 07:24:04 +00:00
|
|
|
global $wgOut, $wgUser, $wgMwRedir;
|
2004-07-10 03:09:26 +00:00
|
|
|
global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
$fname = 'Article::insertNewArticle';
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2003-11-27 02:04:02 +00:00
|
|
|
$this->mCountAdjustment = $this->isCountable( $text );
|
|
|
|
|
|
2003-09-01 08:30:14 +00:00
|
|
|
$ns = $this->mTitle->getNamespace();
|
|
|
|
|
$ttl = $this->mTitle->getDBkey();
|
2003-04-14 23:10:40 +00:00
|
|
|
$text = $this->preSaveTransform( $text );
|
2003-08-31 09:46:37 +00:00
|
|
|
if ( $wgMwRedir->matchStart( $text ) ) { $redir = 1; }
|
2003-04-14 23:10:40 +00:00
|
|
|
else { $redir = 0; }
|
|
|
|
|
|
|
|
|
|
$now = wfTimestampNow();
|
|
|
|
|
$won = wfInvertTimestamp( $now );
|
2003-06-03 21:27:06 +00:00
|
|
|
wfSeedRandom();
|
2004-06-08 19:51:10 +00:00
|
|
|
$rand = number_format( mt_rand() / mt_getrandmax(), 12, '.', '' );
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-08-09 05:38:11 +00:00
|
|
|
$cur_id = $dbw->nextSequenceValue( 'cur_cur_id_seq' );
|
2004-06-11 14:48:31 +00:00
|
|
|
|
2004-01-24 16:12:23 +00:00
|
|
|
$isminor = ( $isminor && $wgUser->getID() ) ? 1 : 0;
|
2004-07-10 03:09:26 +00:00
|
|
|
|
|
|
|
|
$dbw->insertArray( 'cur', array(
|
|
|
|
|
'cur_id' => $cur_id,
|
|
|
|
|
'cur_namespace' => $ns,
|
|
|
|
|
'cur_title' => $ttl,
|
|
|
|
|
'cur_text' => $text,
|
|
|
|
|
'cur_comment' => $summary,
|
|
|
|
|
'cur_user' => $wgUser->getID(),
|
2004-08-19 12:59:57 +00:00
|
|
|
'cur_timestamp' => $dbw->timestamp($now),
|
2004-07-10 03:09:26 +00:00
|
|
|
'cur_minor_edit' => $isminor,
|
|
|
|
|
'cur_counter' => 0,
|
|
|
|
|
'cur_restrictions' => '',
|
|
|
|
|
'cur_user_text' => $wgUser->getName(),
|
|
|
|
|
'cur_is_redirect' => $redir,
|
|
|
|
|
'cur_is_new' => 1,
|
|
|
|
|
'cur_random' => $rand,
|
2004-08-19 12:59:57 +00:00
|
|
|
'cur_touched' => $dbw->timestamp($now),
|
2004-07-10 03:09:26 +00:00
|
|
|
'inverse_timestamp' => $won,
|
|
|
|
|
), $fname );
|
|
|
|
|
|
|
|
|
|
$newid = $dbw->insertId();
|
2003-09-01 08:30:14 +00:00
|
|
|
$this->mTitle->resetArticleID( $newid );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-01-31 16:59:08 +00:00
|
|
|
Article::onArticleCreate( $this->mTitle );
|
2004-01-17 05:49:39 +00:00
|
|
|
RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
|
|
|
|
if ($watchthis) {
|
|
|
|
|
if(!$this->mTitle->userIsWatching()) $this->watch();
|
2003-04-14 23:10:40 +00:00
|
|
|
} else {
|
2003-09-01 08:30:14 +00:00
|
|
|
if ( $this->mTitle->userIsWatching() ) {
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->unwatch();
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-11-12 13:07:08 +00:00
|
|
|
# The talk page isn't in the regular link tables, so we need to update manually:
|
|
|
|
|
$talkns = $ns ^ 1; # talk -> normal; normal -> talk
|
2004-08-19 12:59:57 +00:00
|
|
|
$dbw->updateArray( 'cur', array('cur_touched' => $dbw->timestamp($now) ),
|
|
|
|
|
array( 'cur_namespace' => $talkns, 'cur_title' => $ttl ), $fname );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-02-02 01:40:03 +00:00
|
|
|
# standard deferred updates
|
|
|
|
|
$this->editUpdates( $text );
|
2004-03-20 15:03:26 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
$this->showArticle( $text, wfMsg( 'newarticle' ) );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2003-08-24 12:09:20 +00:00
|
|
|
|
2004-03-14 22:28:52 +00:00
|
|
|
/* Side effects: loads last edit */
|
2004-08-12 14:27:38 +00:00
|
|
|
function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '') {
|
2003-08-24 12:09:20 +00:00
|
|
|
$this->loadLastEdit();
|
2004-07-08 14:53:54 +00:00
|
|
|
$oldtext = $this->getContent( true );
|
2004-06-08 19:51:10 +00:00
|
|
|
if ($section != '') {
|
|
|
|
|
if($section=='new') {
|
2003-07-29 15:26:53 +00:00
|
|
|
if($summary) $subject="== {$summary} ==\n\n";
|
|
|
|
|
$text=$oldtext."\n\n".$subject.$text;
|
2003-07-21 07:36:52 +00:00
|
|
|
} else {
|
2004-04-28 04:50:35 +00:00
|
|
|
|
|
|
|
|
# strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
|
|
|
|
|
# comments to be stripped as well)
|
|
|
|
|
$striparray=array();
|
|
|
|
|
$parser=new Parser();
|
|
|
|
|
$parser->mOutputType=OT_WIKI;
|
|
|
|
|
$oldtext=$parser->strip($oldtext, $striparray, true);
|
|
|
|
|
|
|
|
|
|
# now that we can be sure that no pseudo-sections are in the source,
|
|
|
|
|
# split it up
|
2004-05-13 17:25:34 +00:00
|
|
|
# Unfortunately we can't simply do a preg_replace because that might
|
|
|
|
|
# replace the wrong section, so we have to use the section counter instead
|
2004-06-08 19:51:10 +00:00
|
|
|
$secs=preg_split('/(^=+.*?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)/mi',
|
2003-07-21 07:36:52 +00:00
|
|
|
$oldtext,-1,PREG_SPLIT_DELIM_CAPTURE);
|
|
|
|
|
$secs[$section*2]=$text."\n\n"; // replace with edited
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-05-13 17:25:34 +00:00
|
|
|
# section 0 is top (intro) section
|
2004-07-08 14:53:54 +00:00
|
|
|
if($section!=0) {
|
|
|
|
|
|
2004-05-13 17:25:34 +00:00
|
|
|
# headline of old section - we need to go through this section
|
|
|
|
|
# to determine if there are any subsections that now need to
|
|
|
|
|
# be erased, as the mother section has been replaced with
|
|
|
|
|
# the text of all subsections.
|
|
|
|
|
$headline=$secs[$section*2-1];
|
2004-06-08 19:51:10 +00:00
|
|
|
preg_match( '/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$headline,$matches);
|
2004-05-13 17:25:34 +00:00
|
|
|
$hlevel=$matches[1];
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-05-13 17:25:34 +00:00
|
|
|
# determine headline level for wikimarkup headings
|
2004-06-08 19:51:10 +00:00
|
|
|
if(strpos($hlevel,'=')!==false) {
|
2004-07-08 14:53:54 +00:00
|
|
|
$hlevel=strlen($hlevel);
|
2004-05-13 17:25:34 +00:00
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
$secs[$section*2-1]=''; // erase old headline
|
2004-05-13 17:25:34 +00:00
|
|
|
$count=$section+1;
|
|
|
|
|
$break=false;
|
|
|
|
|
while(!empty($secs[$count*2-1]) && !$break) {
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-05-13 17:25:34 +00:00
|
|
|
$subheadline=$secs[$count*2-1];
|
|
|
|
|
preg_match(
|
2004-06-08 19:51:10 +00:00
|
|
|
'/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$subheadline,$matches);
|
2004-05-13 17:25:34 +00:00
|
|
|
$subhlevel=$matches[1];
|
2004-06-08 19:51:10 +00:00
|
|
|
if(strpos($subhlevel,'=')!==false) {
|
2004-07-08 14:53:54 +00:00
|
|
|
$subhlevel=strlen($subhlevel);
|
2004-05-13 17:25:34 +00:00
|
|
|
}
|
|
|
|
|
if($subhlevel > $hlevel) {
|
|
|
|
|
// erase old subsections
|
2004-06-08 19:51:10 +00:00
|
|
|
$secs[$count*2-1]='';
|
|
|
|
|
$secs[$count*2]='';
|
2004-05-13 17:25:34 +00:00
|
|
|
}
|
|
|
|
|
if($subhlevel <= $hlevel) {
|
|
|
|
|
$break=true;
|
|
|
|
|
}
|
|
|
|
|
$count++;
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-05-13 17:25:34 +00:00
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-05-13 17:25:34 +00:00
|
|
|
}
|
2004-06-08 19:51:10 +00:00
|
|
|
$text=join('',$secs);
|
2004-04-28 04:50:35 +00:00
|
|
|
# reinsert the stuff that we stripped out earlier
|
2004-07-08 14:53:54 +00:00
|
|
|
$text=$parser->unstrip($text,$striparray);
|
|
|
|
|
$text=$parser->unstripNoWiki($text,$striparray);
|
2003-07-21 07:36:52 +00:00
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-06-30 00:19:35 +00:00
|
|
|
}
|
2004-03-14 22:28:52 +00:00
|
|
|
return $text;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
|
2004-07-24 07:24:04 +00:00
|
|
|
global $wgOut, $wgUser;
|
2004-03-14 22:28:52 +00:00
|
|
|
global $wgDBtransactions, $wgMwRedir;
|
|
|
|
|
global $wgUseSquid, $wgInternalServer;
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
$fname = 'Article::updateArticle';
|
2004-07-10 03:09:26 +00:00
|
|
|
$good = true;
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
if ( $this->mMinorEdit ) { $me1 = 1; } else { $me1 = 0; }
|
2004-07-08 14:53:54 +00:00
|
|
|
if ( $minor && $wgUser->getID() ) { $me2 = 1; } else { $me2 = 0; }
|
2004-06-08 19:51:10 +00:00
|
|
|
if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ')[^\\n]+)/i', $text, $m ) ) {
|
2003-04-14 23:10:40 +00:00
|
|
|
$redir = 1;
|
|
|
|
|
$text = $m[1] . "\n"; # Remove all content but redirect
|
|
|
|
|
}
|
|
|
|
|
else { $redir = 0; }
|
|
|
|
|
|
|
|
|
|
$text = $this->preSaveTransform( $text );
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
# Update article, but only if changed.
|
|
|
|
|
|
2004-08-09 05:38:11 +00:00
|
|
|
# It's important that we either rollback or complete, otherwise an attacker could
|
|
|
|
|
# overwrite cur entries by sending precisely timed user aborts. Random bored users
|
2004-07-10 03:09:26 +00:00
|
|
|
# could conceivably have the same effect, especially if cur is locked for long periods.
|
2003-04-14 23:10:40 +00:00
|
|
|
if( $wgDBtransactions ) {
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbw->query( 'BEGIN', $fname );
|
|
|
|
|
} else {
|
|
|
|
|
$userAbort = ignore_user_abort( true );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
$oldtext = $this->getContent( true );
|
|
|
|
|
|
|
|
|
|
if ( 0 != strcmp( $text, $oldtext ) ) {
|
|
|
|
|
$this->mCountAdjustment = $this->isCountable( $text )
|
|
|
|
|
- $this->isCountable( $oldtext );
|
2003-08-17 11:58:33 +00:00
|
|
|
$now = wfTimestampNow();
|
|
|
|
|
$won = wfInvertTimestamp( $now );
|
|
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
# First update the cur row
|
2004-08-09 05:38:11 +00:00
|
|
|
$dbw->updateArray( 'cur',
|
|
|
|
|
array( /* SET */
|
2004-07-10 03:09:26 +00:00
|
|
|
'cur_text' => $text,
|
|
|
|
|
'cur_comment' => $summary,
|
2004-08-09 05:38:11 +00:00
|
|
|
'cur_minor_edit' => $me2,
|
2004-07-10 03:09:26 +00:00
|
|
|
'cur_user' => $wgUser->getID(),
|
2004-08-20 12:47:46 +00:00
|
|
|
'cur_timestamp' => $dbw->timestamp($now),
|
2004-07-10 03:09:26 +00:00
|
|
|
'cur_user_text' => $wgUser->getName(),
|
2004-08-09 05:38:11 +00:00
|
|
|
'cur_is_redirect' => $redir,
|
2004-07-10 03:09:26 +00:00
|
|
|
'cur_is_new' => 0,
|
2004-08-20 12:47:46 +00:00
|
|
|
'cur_touched' => $dbw->timestamp($now),
|
2004-07-10 03:09:26 +00:00
|
|
|
'inverse_timestamp' => $won
|
|
|
|
|
), array( /* WHERE */
|
2004-08-09 05:38:11 +00:00
|
|
|
'cur_id' => $this->getID(),
|
2004-08-20 12:47:46 +00:00
|
|
|
'cur_timestamp' => $dbw->timestamp($this->getTimestamp())
|
2004-08-09 05:38:11 +00:00
|
|
|
), $fname
|
2004-07-10 03:09:26 +00:00
|
|
|
);
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
if( $dbw->affectedRows() == 0 ) {
|
|
|
|
|
/* Belated edit conflict! Run away!! */
|
|
|
|
|
$good = false;
|
2004-06-11 14:48:31 +00:00
|
|
|
} else {
|
2004-07-10 03:09:26 +00:00
|
|
|
# Now insert the previous revision into old
|
|
|
|
|
|
|
|
|
|
# This overwrites $oldtext if revision compression is on
|
|
|
|
|
$flags = Article::compressRevisionText( $oldtext );
|
2004-08-09 05:38:11 +00:00
|
|
|
|
|
|
|
|
$dbw->insertArray( 'old',
|
2004-07-10 03:09:26 +00:00
|
|
|
array(
|
|
|
|
|
'old_id' => $dbw->nextSequenceValue( 'old_old_id_seq' ),
|
|
|
|
|
'old_namespace' => $this->mTitle->getNamespace(),
|
|
|
|
|
'old_title' => $this->mTitle->getDBkey(),
|
|
|
|
|
'old_text' => $oldtext,
|
|
|
|
|
'old_comment' => $this->getComment(),
|
|
|
|
|
'old_user' => $this->getUser(),
|
|
|
|
|
'old_user_text' => $this->getUserText(),
|
2004-08-20 12:47:46 +00:00
|
|
|
'old_timestamp' => $dbw->timestamp($this->getTimestamp()),
|
2004-07-10 03:09:26 +00:00
|
|
|
'old_minor_edit' => $me1,
|
|
|
|
|
'inverse_timestamp' => wfInvertTimestamp( $this->getTimestamp() ),
|
|
|
|
|
'old_flags' => $flags,
|
2004-08-09 05:38:11 +00:00
|
|
|
), $fname
|
2004-07-10 03:09:26 +00:00
|
|
|
);
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
$oldid = $dbw->insertId();
|
|
|
|
|
|
|
|
|
|
$bot = (int)($wgUser->isBot() || $forceBot);
|
2004-08-09 05:38:11 +00:00
|
|
|
RecentChange::notifyEdit( $now, $this->mTitle, $me2, $wgUser, $summary,
|
2004-07-10 03:09:26 +00:00
|
|
|
$oldid, $this->getTimestamp(), $bot );
|
|
|
|
|
Article::onArticleEdit( $this->mTitle );
|
2004-06-11 14:48:31 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2003-11-28 09:42:13 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
if( $wgDBtransactions ) {
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbw->query( 'COMMIT', $fname );
|
|
|
|
|
} else {
|
|
|
|
|
ignore_user_abort( $userAbort );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
if ( $good ) {
|
2004-07-08 14:53:54 +00:00
|
|
|
if ($watchthis) {
|
|
|
|
|
if (!$this->mTitle->userIsWatching()) $this->watch();
|
2003-04-14 23:10:40 +00:00
|
|
|
} else {
|
2003-09-01 08:30:14 +00:00
|
|
|
if ( $this->mTitle->userIsWatching() ) {
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->unwatch();
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-02-02 01:40:03 +00:00
|
|
|
# standard deferred updates
|
|
|
|
|
$this->editUpdates( $text );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
|
|
|
|
|
2004-03-20 15:03:26 +00:00
|
|
|
$urls = array();
|
|
|
|
|
# Template namespace
|
|
|
|
|
# Purge all articles linking here
|
|
|
|
|
if ( $this->mTitle->getNamespace() == NS_TEMPLATE) {
|
|
|
|
|
$titles = $this->mTitle->getLinksTo();
|
|
|
|
|
Title::touchArray( $titles );
|
|
|
|
|
if ( $wgUseSquid ) {
|
2004-07-10 03:09:26 +00:00
|
|
|
foreach ( $titles as $title ) {
|
|
|
|
|
$urls[] = $title->getInternalURL();
|
|
|
|
|
}
|
2004-03-20 15:03:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-03-20 15:03:26 +00:00
|
|
|
# Squid updates
|
2004-02-02 01:40:03 +00:00
|
|
|
if ( $wgUseSquid ) {
|
2004-03-20 15:03:26 +00:00
|
|
|
$urls = array_merge( $urls, $this->mTitle->getSquidURLs() );
|
|
|
|
|
$u = new SquidUpdate( $urls );
|
|
|
|
|
$u->doUpdate();
|
2004-02-02 01:40:03 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
$this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor );
|
2004-07-10 03:09:26 +00:00
|
|
|
}
|
|
|
|
|
return $good;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# After we've either updated or inserted the article, update
|
|
|
|
|
# the link tables and redirect to the new page.
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
function showArticle( $text, $subtitle , $sectionanchor = '' ) {
|
2004-01-03 02:46:35 +00:00
|
|
|
global $wgOut, $wgUser, $wgLinkCache;
|
2003-08-31 09:46:37 +00:00
|
|
|
global $wgMwRedir;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
$wgLinkCache = new LinkCache();
|
2004-07-18 08:48:43 +00:00
|
|
|
# Select for update
|
|
|
|
|
$wgLinkCache->forUpdate( true );
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2003-07-06 11:42:42 +00:00
|
|
|
# Get old version of link table to allow incremental link updates
|
2004-01-03 02:46:35 +00:00
|
|
|
$wgLinkCache->preFill( $this->mTitle );
|
|
|
|
|
$wgLinkCache->clear();
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-08-14 13:34:57 +00:00
|
|
|
# Parse the text and replace links with placeholders
|
2003-08-31 14:30:24 +00:00
|
|
|
$wgOut = new OutputPage();
|
2004-02-27 00:08:19 +00:00
|
|
|
$wgOut->addWikiText( $text );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-08-14 13:34:57 +00:00
|
|
|
# Look up the links in the DB and add them to the link cache
|
2004-08-21 15:14:56 +00:00
|
|
|
$wgOut->transformBuffer( RLH_FOR_UPDATE );
|
2004-08-14 13:34:57 +00:00
|
|
|
|
2003-08-31 09:46:37 +00:00
|
|
|
if( $wgMwRedir->matchStart( $text ) )
|
2004-06-08 19:51:10 +00:00
|
|
|
$r = 'redirect=no';
|
2003-04-14 23:10:40 +00:00
|
|
|
else
|
2004-06-08 19:51:10 +00:00
|
|
|
$r = '';
|
2004-05-14 13:03:57 +00:00
|
|
|
$wgOut->redirect( $this->mTitle->getFullURL( $r ).$sectionanchor );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-07-20 20:48:19 +00:00
|
|
|
# Validate article
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
function validate () {
|
2004-08-16 01:59:53 +00:00
|
|
|
global $wgOut, $wgUseValidation;
|
|
|
|
|
if( $wgUseValidation ) {
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgOut->setPagetitle( wfMsg( 'validate' ) . ': ' . $this->mTitle->getPrefixedText() );
|
2004-08-16 01:59:53 +00:00
|
|
|
$wgOut->setRobotpolicy( 'noindex,follow' );
|
|
|
|
|
if( $this->mTitle->getNamespace() != 0 ) {
|
|
|
|
|
$wgOut->addHTML( wfMsg( 'val_validate_article_namespace_only' ) );
|
|
|
|
|
return;
|
2004-07-31 21:23:14 +00:00
|
|
|
}
|
2004-08-16 01:59:53 +00:00
|
|
|
$v = new Validation;
|
|
|
|
|
$v->validate_form( $this->mTitle->getDBkey() );
|
|
|
|
|
} else {
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
|
2004-08-16 01:59:53 +00:00
|
|
|
}
|
2004-07-20 20:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2004-08-09 05:38:11 +00:00
|
|
|
# Mark this particular edit as patrolled
|
2004-08-12 14:27:38 +00:00
|
|
|
function markpatrolled() {
|
2004-08-14 06:40:14 +00:00
|
|
|
global $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgUseRCPatrol, $wgUser;
|
2004-08-09 05:38:11 +00:00
|
|
|
$wgOut->setRobotpolicy( 'noindex,follow' );
|
2004-08-09 23:30:02 +00:00
|
|
|
|
|
|
|
|
if ( !$wgUseRCPatrol )
|
|
|
|
|
{
|
|
|
|
|
$wgOut->errorpage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( $wgUser->getID() == 0 )
|
|
|
|
|
{
|
|
|
|
|
$wgOut->loginToUse();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( $wgOnlySysopsCanPatrol && !$wgUser->isSysop() )
|
2004-08-09 05:38:11 +00:00
|
|
|
{
|
|
|
|
|
$wgOut->sysopRequired();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$rcid = $wgRequest->getVal( 'rcid' );
|
|
|
|
|
if ( !is_null ( $rcid ) )
|
|
|
|
|
{
|
|
|
|
|
RecentChange::markPatrolled( $rcid );
|
|
|
|
|
$wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
|
|
|
|
|
$wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
|
|
|
|
|
$wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-08-09 05:38:11 +00:00
|
|
|
|
|
|
|
|
# Add this page to my watchlist
|
2004-08-12 14:27:38 +00:00
|
|
|
|
|
|
|
|
function watch( $add = true ) {
|
2003-09-01 08:30:14 +00:00
|
|
|
global $wgUser, $wgOut, $wgLang;
|
2003-04-14 23:10:40 +00:00
|
|
|
global $wgDeferredUpdateList;
|
|
|
|
|
|
|
|
|
|
if ( 0 == $wgUser->getID() ) {
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->errorpage( 'watchnologin', 'watchnologintext' );
|
2003-04-14 23:10:40 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( wfReadOnly() ) {
|
|
|
|
|
$wgOut->readOnlyPage();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-09-01 09:59:53 +00:00
|
|
|
if( $add )
|
|
|
|
|
$wgUser->addWatch( $this->mTitle );
|
|
|
|
|
else
|
|
|
|
|
$wgUser->removeWatch( $this->mTitle );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->setPagetitle( wfMsg( $add ? 'addedwatch' : 'removedwatch' ) );
|
|
|
|
|
$wgOut->setRobotpolicy( 'noindex,follow' );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
$sk = $wgUser->getSkin() ;
|
2004-04-09 08:27:00 +00:00
|
|
|
$link = $this->mTitle->getPrefixedText();
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
if($add)
|
2004-06-08 19:51:10 +00:00
|
|
|
$text = wfMsg( 'addedwatchtext', $link );
|
2003-09-01 09:59:53 +00:00
|
|
|
else
|
2004-06-08 19:51:10 +00:00
|
|
|
$text = wfMsg( 'removedwatchtext', $link );
|
2004-04-09 08:27:00 +00:00
|
|
|
$wgOut->addWikiText( $text );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
$up = new UserUpdate();
|
|
|
|
|
array_push( $wgDeferredUpdateList, $up );
|
|
|
|
|
|
2004-08-06 05:51:09 +00:00
|
|
|
$wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
function unwatch() {
|
2003-09-01 09:59:53 +00:00
|
|
|
$this->watch( false );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
# protect a page
|
|
|
|
|
|
|
|
|
|
function protect( $limit = 'sysop' ) {
|
2004-04-21 16:17:49 +00:00
|
|
|
global $wgUser, $wgOut, $wgRequest;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
if ( ! $wgUser->isSysop() ) {
|
|
|
|
|
$wgOut->sysopRequired();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( wfReadOnly() ) {
|
|
|
|
|
$wgOut->readOnlyPage();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-09-01 08:30:14 +00:00
|
|
|
$id = $this->mTitle->getArticleID();
|
2003-04-14 23:10:40 +00:00
|
|
|
if ( 0 == $id ) {
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->fatalError( wfMsg( 'badarticleerror' ) );
|
2003-04-14 23:10:40 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2004-04-21 16:17:49 +00:00
|
|
|
|
|
|
|
|
$confirm = $wgRequest->getBool( 'wpConfirmProtect' ) && $wgRequest->wasPosted();
|
|
|
|
|
$reason = $wgRequest->getText( 'wpReasonProtect' );
|
|
|
|
|
|
|
|
|
|
if ( $confirm ) {
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
2004-08-09 05:38:11 +00:00
|
|
|
$dbw->updateArray( 'cur',
|
2004-07-10 03:09:26 +00:00
|
|
|
array( /* SET */
|
2004-08-20 12:47:46 +00:00
|
|
|
'cur_touched' => $dbw->timestamp(),
|
2004-07-10 03:09:26 +00:00
|
|
|
'cur_restrictions' => (string)$limit
|
|
|
|
|
), array( /* WHERE */
|
2004-08-09 05:38:11 +00:00
|
|
|
'cur_id' => $id
|
|
|
|
|
), 'Article::protect'
|
2004-07-10 03:09:26 +00:00
|
|
|
);
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-07-08 14:53:54 +00:00
|
|
|
$log = new LogPage( wfMsg( 'protectlogpage' ), wfMsg( 'protectlogtext' ) );
|
2004-08-22 17:24:50 +00:00
|
|
|
if ( $limit === '' ) {
|
2004-07-08 14:53:54 +00:00
|
|
|
$log->addEntry( wfMsg( 'unprotectedarticle', $this->mTitle->getPrefixedText() ), $reason );
|
|
|
|
|
} else {
|
|
|
|
|
$log->addEntry( wfMsg( 'protectedarticle', $this->mTitle->getPrefixedText() ), $reason );
|
|
|
|
|
}
|
|
|
|
|
$wgOut->redirect( $this->mTitle->getFullURL() );
|
2004-04-21 16:17:49 +00:00
|
|
|
return;
|
|
|
|
|
} else {
|
2004-06-08 19:51:10 +00:00
|
|
|
$reason = htmlspecialchars( wfMsg( 'protectreason' ) );
|
|
|
|
|
return $this->confirmProtect( '', $reason, $limit );
|
2004-04-21 16:17:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
# Output protection confirmation dialog
|
|
|
|
|
|
|
|
|
|
function confirmProtect( $par, $reason, $limit = 'sysop' ) {
|
2004-04-21 16:17:49 +00:00
|
|
|
global $wgOut;
|
|
|
|
|
|
|
|
|
|
wfDebug( "Article::confirmProtect\n" );
|
|
|
|
|
|
|
|
|
|
$sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->setRobotpolicy( 'noindex,nofollow' );
|
2004-04-21 16:17:49 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
$check = '';
|
|
|
|
|
$protcom = '';
|
2004-04-21 16:17:49 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
if ( $limit === '' ) {
|
2004-07-08 14:53:54 +00:00
|
|
|
$wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) );
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->setSubtitle( wfMsg( 'unprotectsub', $sub ) );
|
|
|
|
|
$wgOut->addWikiText( wfMsg( 'confirmunprotecttext' ) );
|
|
|
|
|
$check = htmlspecialchars( wfMsg( 'confirmunprotect' ) );
|
|
|
|
|
$protcom = htmlspecialchars( wfMsg( 'unprotectcomment' ) );
|
|
|
|
|
$formaction = $this->mTitle->escapeLocalURL( 'action=unprotect' . $par );
|
2004-04-21 16:17:49 +00:00
|
|
|
} else {
|
2004-07-08 14:53:54 +00:00
|
|
|
$wgOut->setPageTitle( wfMsg( 'confirmprotect' ) );
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) );
|
|
|
|
|
$wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) );
|
|
|
|
|
$check = htmlspecialchars( wfMsg( 'confirmprotect' ) );
|
|
|
|
|
$protcom = htmlspecialchars( wfMsg( 'protectcomment' ) );
|
|
|
|
|
$formaction = $this->mTitle->escapeLocalURL( 'action=protect' . $par );
|
2004-04-21 16:17:49 +00:00
|
|
|
}
|
|
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
$confirm = htmlspecialchars( wfMsg( 'confirm' ) );
|
2004-04-21 16:17:49 +00:00
|
|
|
|
|
|
|
|
$wgOut->addHTML( "
|
|
|
|
|
<form id='protectconfirm' method='post' action=\"{$formaction}\">
|
|
|
|
|
<table border='0'>
|
|
|
|
|
<tr>
|
|
|
|
|
<td align='right'>
|
|
|
|
|
<label for='wpReasonProtect'>{$protcom}:</label>
|
|
|
|
|
</td>
|
|
|
|
|
<td align='left'>
|
|
|
|
|
<input type='text' size='60' name='wpReasonProtect' id='wpReasonProtect' value=\"" . htmlspecialchars( $reason ) . "\" />
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td align='right'>
|
|
|
|
|
<input type='checkbox' name='wpConfirmProtect' value='1' id='wpConfirmProtect' />
|
|
|
|
|
</td>
|
|
|
|
|
<td>
|
|
|
|
|
<label for='wpConfirmProtect'>{$check}</label>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td> </td>
|
|
|
|
|
<td>
|
|
|
|
|
<input type='submit' name='wpConfirmProtectB' value=\"{$confirm}\" />
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</form>\n" );
|
|
|
|
|
|
|
|
|
|
$wgOut->returnToMain( false );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
function unprotect() {
|
2004-06-08 19:51:10 +00:00
|
|
|
return $this->protect( '' );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-07-08 14:53:54 +00:00
|
|
|
# UI entry point for page deletion
|
2004-08-12 14:27:38 +00:00
|
|
|
|
|
|
|
|
function delete() {
|
2004-07-10 03:09:26 +00:00
|
|
|
global $wgUser, $wgOut, $wgMessageCache, $wgRequest;
|
2004-06-08 19:51:10 +00:00
|
|
|
$fname = 'Article::delete';
|
2004-04-01 12:35:45 +00:00
|
|
|
$confirm = $wgRequest->getBool( 'wpConfirm' ) && $wgRequest->wasPosted();
|
2004-03-29 14:48:07 +00:00
|
|
|
$reason = $wgRequest->getText( 'wpReason' );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-11-09 11:45:12 +00:00
|
|
|
# This code desperately needs to be totally rewritten
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-03-29 14:48:07 +00:00
|
|
|
# Check permissions
|
2003-11-09 11:45:12 +00:00
|
|
|
if ( ( ! $wgUser->isSysop() ) ) {
|
2003-04-14 23:10:40 +00:00
|
|
|
$wgOut->sysopRequired();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( wfReadOnly() ) {
|
|
|
|
|
$wgOut->readOnlyPage();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Better double-check that it hasn't been deleted yet!
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
|
|
|
|
|
if ( ( '' == trim( $this->mTitle->getText() ) )
|
2003-09-01 09:59:53 +00:00
|
|
|
or ( $this->mTitle->getArticleId() == 0 ) ) {
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->fatalError( wfMsg( 'cannotdelete' ) );
|
2003-09-01 09:59:53 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2003-05-23 04:26:51 +00:00
|
|
|
|
2004-03-29 14:48:07 +00:00
|
|
|
if ( $confirm ) {
|
|
|
|
|
$this->doDelete( $reason );
|
2003-11-15 12:38:02 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
# determine whether this page has earlier revisions
|
|
|
|
|
# and insert a warning if it does
|
|
|
|
|
# we select the text because it might be useful below
|
2004-08-20 14:59:49 +00:00
|
|
|
$dbr =& $this->getDB();
|
2003-11-24 08:41:40 +00:00
|
|
|
$ns = $this->mTitle->getNamespace();
|
|
|
|
|
$title = $this->mTitle->getDBkey();
|
2004-08-09 05:38:11 +00:00
|
|
|
$old = $dbr->getArray( 'old',
|
|
|
|
|
array( 'old_text', 'old_flags' ),
|
2004-07-10 03:09:26 +00:00
|
|
|
array(
|
|
|
|
|
'old_namespace' => $ns,
|
|
|
|
|
'old_title' => $title,
|
2004-08-20 14:59:49 +00:00
|
|
|
), $fname, $this->getSelectOptions( array( 'ORDER BY' => 'inverse_timestamp' ) )
|
2004-07-10 03:09:26 +00:00
|
|
|
);
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
if( $old !== false && !$confirm ) {
|
2003-09-01 09:59:53 +00:00
|
|
|
$skin=$wgUser->getSkin();
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->addHTML('<b>'.wfMsg('historywarning'));
|
|
|
|
|
$wgOut->addHTML( $skin->historyLink() .'</b>');
|
2003-09-01 09:59:53 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
# Fetch cur_text
|
2004-08-09 05:38:11 +00:00
|
|
|
$s = $dbr->getArray( 'cur',
|
|
|
|
|
array( 'cur_text' ),
|
|
|
|
|
array(
|
|
|
|
|
'cur_namespace' => $ns,
|
2004-07-10 03:09:26 +00:00
|
|
|
'cur_title' => $title,
|
2004-08-20 14:59:49 +00:00
|
|
|
), $fname, $this->getSelectOptions()
|
2004-07-10 03:09:26 +00:00
|
|
|
);
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
if( $s !== false ) {
|
2003-09-01 09:59:53 +00:00
|
|
|
# if this is a mini-text, we can paste part of it into the deletion reason
|
2003-05-23 04:26:51 +00:00
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
#if this is empty, an earlier revision may contain "useful" text
|
2004-03-20 15:03:26 +00:00
|
|
|
$blanked = false;
|
2004-08-14 19:33:59 +00:00
|
|
|
if($s->cur_text != '') {
|
2003-09-01 09:59:53 +00:00
|
|
|
$text=$s->cur_text;
|
|
|
|
|
} else {
|
|
|
|
|
if($old) {
|
2004-01-03 12:32:32 +00:00
|
|
|
$text = Article::getRevisionText( $old );
|
2004-03-20 15:03:26 +00:00
|
|
|
$blanked = true;
|
2003-05-23 04:26:51 +00:00
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
|
|
|
|
$length=strlen($text);
|
|
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
# this should not happen, since it is not possible to store an empty, new
|
|
|
|
|
# page. Let's insert a standard text in case it does, though
|
2004-07-08 14:53:54 +00:00
|
|
|
if($length == 0 && $reason === '') {
|
2004-06-08 19:51:10 +00:00
|
|
|
$reason = wfMsg('exblank');
|
2004-03-29 14:48:07 +00:00
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
if($length < 500 && $reason === '') {
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
# comment field=255, let's grep the first 150 to have some user
|
|
|
|
|
# space left
|
|
|
|
|
$text=substr($text,0,150);
|
|
|
|
|
# let's strip out newlines and HTML tags
|
2004-06-08 19:51:10 +00:00
|
|
|
$text=preg_replace('/\"/',"'",$text);
|
|
|
|
|
$text=preg_replace('/\</','<',$text);
|
|
|
|
|
$text=preg_replace('/\>/','>',$text);
|
|
|
|
|
$text=preg_replace("/[\n\r]/",'',$text);
|
2003-09-01 09:59:53 +00:00
|
|
|
if(!$blanked) {
|
2004-06-08 19:51:10 +00:00
|
|
|
$reason=wfMsg('excontent'). " '".$text;
|
2003-09-01 09:59:53 +00:00
|
|
|
} else {
|
2004-06-08 19:51:10 +00:00
|
|
|
$reason=wfMsg('exbeforeblank') . " '".$text;
|
2003-05-23 04:26:51 +00:00
|
|
|
}
|
2004-06-08 19:51:10 +00:00
|
|
|
if($length>150) { $reason .= '...'; } # we've only pasted part of the text
|
2004-07-08 14:53:54 +00:00
|
|
|
$reason.="'";
|
2003-05-23 04:26:51 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
return $this->confirmDelete( '', $reason );
|
2003-09-01 09:59:53 +00:00
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-03-29 14:48:07 +00:00
|
|
|
# Output deletion confirmation dialog
|
2004-08-12 14:27:38 +00:00
|
|
|
|
|
|
|
|
function confirmDelete( $par, $reason ) {
|
2003-09-01 09:59:53 +00:00
|
|
|
global $wgOut;
|
2003-11-15 12:38:02 +00:00
|
|
|
|
|
|
|
|
wfDebug( "Article::confirmDelete\n" );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
$sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
|
|
|
|
|
$wgOut->setRobotpolicy( 'noindex,nofollow' );
|
|
|
|
|
$wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
$formaction = $this->mTitle->escapeLocalURL( 'action=delete' . $par );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
$confirm = htmlspecialchars( wfMsg( 'confirm' ) );
|
|
|
|
|
$check = htmlspecialchars( wfMsg( 'confirmcheck' ) );
|
|
|
|
|
$delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
$wgOut->addHTML( "
|
2004-04-03 10:01:08 +00:00
|
|
|
<form id='deleteconfirm' method='post' action=\"{$formaction}\">
|
|
|
|
|
<table border='0'>
|
|
|
|
|
<tr>
|
|
|
|
|
<td align='right'>
|
|
|
|
|
<label for='wpReason'>{$delcom}:</label>
|
|
|
|
|
</td>
|
|
|
|
|
<td align='left'>
|
|
|
|
|
<input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td align='right'>
|
|
|
|
|
<input type='checkbox' name='wpConfirm' value='1' id='wpConfirm' />
|
|
|
|
|
</td>
|
|
|
|
|
<td>
|
|
|
|
|
<label for='wpConfirm'>{$check}</label>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td> </td>
|
|
|
|
|
<td>
|
|
|
|
|
<input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</form>\n" );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
$wgOut->returnToMain( false );
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
|
2004-03-29 14:48:07 +00:00
|
|
|
# Perform a deletion and output success or failure messages
|
2004-08-12 14:27:38 +00:00
|
|
|
|
|
|
|
|
function doDelete( $reason ) {
|
2003-09-01 08:30:14 +00:00
|
|
|
global $wgOut, $wgUser, $wgLang;
|
2004-06-08 19:51:10 +00:00
|
|
|
$fname = 'Article::doDelete';
|
2004-08-22 17:24:50 +00:00
|
|
|
wfDebug( $fname."\n" );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-07-08 14:53:54 +00:00
|
|
|
if ( $this->doDeleteArticle( $reason ) ) {
|
2004-03-20 15:03:26 +00:00
|
|
|
$deleted = $this->mTitle->getPrefixedText();
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
|
|
|
|
|
$wgOut->setRobotpolicy( 'noindex,nofollow' );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-03-20 15:03:26 +00:00
|
|
|
$sk = $wgUser->getSkin();
|
2004-08-07 03:50:46 +00:00
|
|
|
$loglink = $sk->makeKnownLink( $wgLang->getNsText( NS_WIKIPEDIA ) .
|
2004-06-08 19:51:10 +00:00
|
|
|
':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-08-22 17:24:50 +00:00
|
|
|
$text = wfMsg( 'deletedtext', $deleted, $loglink );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->addHTML( '<p>' . $text . "</p>\n" );
|
2004-03-20 15:03:26 +00:00
|
|
|
$wgOut->returnToMain( false );
|
|
|
|
|
} else {
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->fatalError( wfMsg( 'cannotdelete' ) );
|
2004-03-20 15:03:26 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-03-29 14:48:07 +00:00
|
|
|
# Back-end article deletion
|
|
|
|
|
# Deletes the article with database consistency, writes logs, purges caches
|
|
|
|
|
# Returns success
|
2004-08-12 14:27:38 +00:00
|
|
|
function doDeleteArticle( $reason ) {
|
2004-03-29 14:48:07 +00:00
|
|
|
global $wgUser, $wgLang;
|
2004-02-02 01:40:03 +00:00
|
|
|
global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
$fname = 'Article::doDeleteArticle';
|
|
|
|
|
wfDebug( $fname."\n" );
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
2004-03-20 15:03:26 +00:00
|
|
|
$ns = $this->mTitle->getNamespace();
|
2004-07-10 03:09:26 +00:00
|
|
|
$t = $this->mTitle->getDBkey();
|
2004-03-20 15:03:26 +00:00
|
|
|
$id = $this->mTitle->getArticleID();
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-08-14 19:33:59 +00:00
|
|
|
if ( $t == '' || $id == 0 ) {
|
2004-03-20 15:03:26 +00:00
|
|
|
return false;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ) );
|
|
|
|
|
array_push( $wgDeferredUpdateList, $u );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-03-20 15:03:26 +00:00
|
|
|
$linksTo = $this->mTitle->getLinksTo();
|
|
|
|
|
|
2004-02-02 01:40:03 +00:00
|
|
|
# Squid purging
|
|
|
|
|
if ( $wgUseSquid ) {
|
2004-07-08 14:53:54 +00:00
|
|
|
$urls = array(
|
2004-03-09 12:55:54 +00:00
|
|
|
$this->mTitle->getInternalURL(),
|
2004-07-08 14:53:54 +00:00
|
|
|
$this->mTitle->getInternalURL( 'history' )
|
2004-02-02 01:40:03 +00:00
|
|
|
);
|
2004-03-20 15:03:26 +00:00
|
|
|
foreach ( $linksTo as $linkTo ) {
|
|
|
|
|
$urls[] = $linkTo->getInternalURL();
|
2004-02-02 01:40:03 +00:00
|
|
|
}
|
2004-03-20 15:03:26 +00:00
|
|
|
|
|
|
|
|
$u = new SquidUpdate( $urls );
|
2004-02-02 01:40:03 +00:00
|
|
|
array_push( $wgDeferredUpdateList, $u );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-20 15:03:26 +00:00
|
|
|
# Client and file cache invalidation
|
|
|
|
|
Title::touchArray( $linksTo );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
# Move article and history to the "archive" table
|
2004-07-10 03:09:26 +00:00
|
|
|
$archiveTable = $dbw->tableName( 'archive' );
|
|
|
|
|
$oldTable = $dbw->tableName( 'old' );
|
|
|
|
|
$curTable = $dbw->tableName( 'cur' );
|
|
|
|
|
$recentchangesTable = $dbw->tableName( 'recentchanges' );
|
|
|
|
|
$linksTable = $dbw->tableName( 'links' );
|
|
|
|
|
$brokenlinksTable = $dbw->tableName( 'brokenlinks' );
|
2004-08-09 05:38:11 +00:00
|
|
|
|
|
|
|
|
$dbw->insertSelect( 'archive', 'cur',
|
2004-07-10 03:09:26 +00:00
|
|
|
array(
|
|
|
|
|
'ar_namespace' => 'cur_namespace',
|
|
|
|
|
'ar_title' => 'cur_title',
|
|
|
|
|
'ar_text' => 'cur_text',
|
|
|
|
|
'ar_comment' => 'cur_comment',
|
|
|
|
|
'ar_user' => 'cur_user',
|
|
|
|
|
'ar_user_text' => 'cur_user_text',
|
|
|
|
|
'ar_timestamp' => 'cur_timestamp',
|
|
|
|
|
'ar_minor_edit' => 'cur_minor_edit',
|
|
|
|
|
'ar_flags' => 0,
|
|
|
|
|
), array(
|
|
|
|
|
'cur_namespace' => $ns,
|
|
|
|
|
'cur_title' => $t,
|
2004-08-09 05:38:11 +00:00
|
|
|
), $fname
|
2004-07-10 03:09:26 +00:00
|
|
|
);
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbw->insertSelect( 'archive', 'old',
|
|
|
|
|
array(
|
|
|
|
|
'ar_namespace' => 'old_namespace',
|
|
|
|
|
'ar_title' => 'old_title',
|
|
|
|
|
'ar_text' => 'old_text',
|
|
|
|
|
'ar_comment' => 'old_comment',
|
|
|
|
|
'ar_user' => 'old_user',
|
|
|
|
|
'ar_user_text' => 'old_user_text',
|
|
|
|
|
'ar_timestamp' => 'old_timestamp',
|
|
|
|
|
'ar_minor_edit' => 'old_minor_edit',
|
|
|
|
|
'ar_flags' => 'old_flags'
|
|
|
|
|
), array(
|
|
|
|
|
'old_namespace' => $ns,
|
|
|
|
|
'old_title' => $t,
|
|
|
|
|
), $fname
|
|
|
|
|
);
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
# Now that it's safely backed up, delete it
|
|
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbw->delete( 'cur', array( 'cur_namespace' => $ns, 'cur_title' => $t ), $fname );
|
|
|
|
|
$dbw->delete( 'old', array( 'old_namespace' => $ns, 'old_title' => $t ), $fname );
|
|
|
|
|
$dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
# Finally, clean up the link tables
|
2004-07-10 03:09:26 +00:00
|
|
|
$t = $this->mTitle->getPrefixedDBkey();
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-03-20 15:03:26 +00:00
|
|
|
Article::onArticleDelete( $this->mTitle );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
# Insert broken links
|
|
|
|
|
$brokenLinks = array();
|
2004-03-20 15:03:26 +00:00
|
|
|
foreach ( $linksTo as $titleObj ) {
|
|
|
|
|
# Get article ID. Efficient because it was loaded into the cache by getLinksTo().
|
2004-07-08 14:53:54 +00:00
|
|
|
$linkID = $titleObj->getArticleID();
|
2004-07-10 03:09:26 +00:00
|
|
|
$brokenLinks[] = array( 'bl_from' => $linkID, 'bl_to' => $t );
|
|
|
|
|
}
|
2004-07-24 07:24:04 +00:00
|
|
|
$dbw->insert( 'brokenlinks', $brokenLinks, $fname, 'IGNORE' );
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
# Delete live links
|
|
|
|
|
$dbw->delete( 'links', array( 'l_to' => $id ) );
|
|
|
|
|
$dbw->delete( 'links', array( 'l_from' => $id ) );
|
|
|
|
|
$dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
|
|
|
|
|
$dbw->delete( 'brokenlinks', array( 'bl_from' => $id ) );
|
|
|
|
|
$dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
|
|
|
|
|
|
|
|
|
|
# Log the deletion
|
2004-06-08 19:51:10 +00:00
|
|
|
$log = new LogPage( wfMsg( 'dellogpage' ), wfMsg( 'dellogpagetext' ) );
|
2004-03-20 15:03:26 +00:00
|
|
|
$art = $this->mTitle->getPrefixedText();
|
2004-06-08 19:51:10 +00:00
|
|
|
$log->addEntry( wfMsg( 'deletedarticle', $art ), $reason );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
# Clear the cached article id so the interface doesn't act like we exist
|
2003-09-01 08:30:14 +00:00
|
|
|
$this->mTitle->resetArticleID( 0 );
|
|
|
|
|
$this->mTitle->mArticleID = 0;
|
2004-03-20 15:03:26 +00:00
|
|
|
return true;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
function rollback() {
|
2004-07-10 03:09:26 +00:00
|
|
|
global $wgUser, $wgLang, $wgOut, $wgRequest;
|
2004-08-22 17:24:50 +00:00
|
|
|
$fname = 'Article::rollback';
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
if ( ! $wgUser->isSysop() ) {
|
|
|
|
|
$wgOut->sysopRequired();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-12-05 10:55:50 +00:00
|
|
|
if ( wfReadOnly() ) {
|
2004-04-30 08:19:59 +00:00
|
|
|
$wgOut->readOnlyPage( $this->getContent( true ) );
|
2003-12-05 10:55:50 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-01-17 11:16:14 +00:00
|
|
|
# Enhanced rollback, marks edits rc_bot=1
|
2004-03-08 09:09:35 +00:00
|
|
|
$bot = $wgRequest->getBool( 'bot' );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
# Replace all this user's current edits with the next one down
|
2004-07-10 03:09:26 +00:00
|
|
|
$tt = $this->mTitle->getDBKey();
|
2003-09-01 08:30:14 +00:00
|
|
|
$n = $this->mTitle->getNamespace();
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
# Get the last editor, lock table exclusively
|
2004-08-09 05:38:11 +00:00
|
|
|
$s = $dbw->getArray( 'cur',
|
2004-07-10 03:09:26 +00:00
|
|
|
array( 'cur_id','cur_user','cur_user_text','cur_comment' ),
|
|
|
|
|
array( 'cur_title' => $tt, 'cur_namespace' => $n ),
|
|
|
|
|
$fname, 'FOR UPDATE'
|
|
|
|
|
);
|
|
|
|
|
if( $s === false ) {
|
2003-04-14 23:10:40 +00:00
|
|
|
# Something wrong
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->addHTML( wfMsg( 'notanarticle' ) );
|
2003-04-14 23:10:40 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2004-07-10 03:09:26 +00:00
|
|
|
$ut = $dbw->strencode( $s->cur_user_text );
|
2003-04-14 23:10:40 +00:00
|
|
|
$uid = $s->cur_user;
|
|
|
|
|
$pid = $s->cur_id;
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
$from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
|
2003-05-25 07:09:23 +00:00
|
|
|
if( $from != $s->cur_user_text ) {
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->setPageTitle(wfmsg('rollbackfailed'));
|
|
|
|
|
$wgOut->addWikiText( wfMsg( 'alreadyrolled',
|
2003-09-01 08:30:14 +00:00
|
|
|
htmlspecialchars( $this->mTitle->getPrefixedText()),
|
2003-05-25 07:09:23 +00:00
|
|
|
htmlspecialchars( $from ),
|
2003-05-25 07:56:08 +00:00
|
|
|
htmlspecialchars( $s->cur_user_text ) ) );
|
2004-06-08 19:51:10 +00:00
|
|
|
if($s->cur_comment != '') {
|
2003-05-25 07:56:08 +00:00
|
|
|
$wgOut->addHTML(
|
2004-06-08 19:51:10 +00:00
|
|
|
wfMsg('editcomment',
|
2003-05-25 07:56:08 +00:00
|
|
|
htmlspecialchars( $s->cur_comment ) ) );
|
2004-01-17 11:16:14 +00:00
|
|
|
}
|
2003-05-25 07:09:23 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
# Get the last edit not by this guy
|
2004-08-09 05:38:11 +00:00
|
|
|
$s = $dbw->getArray( 'old',
|
2004-07-10 03:09:26 +00:00
|
|
|
array( 'old_text','old_user','old_user_text','old_timestamp','old_flags' ),
|
2004-08-09 05:38:11 +00:00
|
|
|
array(
|
|
|
|
|
'old_namespace' => $n,
|
2004-07-10 03:09:26 +00:00
|
|
|
'old_title' => $tt,
|
|
|
|
|
"old_user <> {$uid} OR old_user_text <> '{$ut}'"
|
|
|
|
|
), $fname, array( 'FOR UPDATE', 'USE INDEX' => 'name_title_timestamp' )
|
|
|
|
|
);
|
|
|
|
|
if( $s === false ) {
|
2003-04-14 23:10:40 +00:00
|
|
|
# Something wrong
|
2004-06-08 19:51:10 +00:00
|
|
|
$wgOut->setPageTitle(wfMsg('rollbackfailed'));
|
|
|
|
|
$wgOut->addHTML( wfMsg( 'cantrollback' ) );
|
2003-04-14 23:10:40 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-12-14 14:29:35 +00:00
|
|
|
if ( $bot ) {
|
|
|
|
|
# Mark all reverted edits as bot
|
2004-08-09 05:38:11 +00:00
|
|
|
$dbw->updateArray( 'recentchanges',
|
|
|
|
|
array( /* SET */
|
|
|
|
|
'rc_bot' => 1
|
2004-07-10 03:09:26 +00:00
|
|
|
), array( /* WHERE */
|
|
|
|
|
'rc_user' => $uid,
|
|
|
|
|
"rc_timestamp > '{$s->old_timestamp}'",
|
2004-08-09 05:38:11 +00:00
|
|
|
), $fname
|
2004-07-10 03:09:26 +00:00
|
|
|
);
|
2003-12-14 14:29:35 +00:00
|
|
|
}
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
# Save it!
|
2004-06-08 19:51:10 +00:00
|
|
|
$newcomment = wfMsg( 'revertpage', $s->old_user_text, $from );
|
|
|
|
|
$wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
|
|
|
|
|
$wgOut->setRobotpolicy( 'noindex,nofollow' );
|
|
|
|
|
$wgOut->addHTML( '<h2>' . $newcomment . "</h2>\n<hr />\n" );
|
2004-03-14 22:28:52 +00:00
|
|
|
$this->updateArticle( Article::getRevisionText( $s ), $newcomment, 1, $this->mTitle->userIsWatching(), $bot );
|
2004-01-05 23:32:39 +00:00
|
|
|
Article::onArticleEdit( $this->mTitle );
|
2003-04-14 23:10:40 +00:00
|
|
|
$wgOut->returnToMain( false );
|
|
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
# Do standard deferred updates after page view
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
/* private */ function viewUpdates() {
|
2003-09-01 08:30:14 +00:00
|
|
|
global $wgDeferredUpdateList;
|
2003-04-14 23:10:40 +00:00
|
|
|
if ( 0 != $this->getID() ) {
|
2003-11-09 11:45:12 +00:00
|
|
|
global $wgDisableCounters;
|
|
|
|
|
if( !$wgDisableCounters ) {
|
2003-12-13 21:32:32 +00:00
|
|
|
Article::incViewCount( $this->getID() );
|
2003-11-09 11:45:12 +00:00
|
|
|
$u = new SiteStatsUpdate( 1, 0, 0 );
|
|
|
|
|
array_push( $wgDeferredUpdateList, $u );
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2004-08-03 04:52:19 +00:00
|
|
|
$u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(),
|
|
|
|
|
$this->mTitle->getDBkey() );
|
|
|
|
|
array_push( $wgDeferredUpdateList, $u );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-01-31 16:59:08 +00:00
|
|
|
# Do standard deferred updates after page edit.
|
|
|
|
|
# Every 1000th edit, prune the recent changes table.
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
/* private */ function editUpdates( $text ) {
|
2004-01-31 16:59:08 +00:00
|
|
|
global $wgDeferredUpdateList, $wgDBname, $wgMemc;
|
|
|
|
|
global $wgMessageCache;
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-01-31 16:59:08 +00:00
|
|
|
wfSeedRandom();
|
|
|
|
|
if ( 0 == mt_rand( 0, 999 ) ) {
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
2004-01-31 16:59:08 +00:00
|
|
|
$cutoff = wfUnix2Timestamp( time() - ( 7 * 86400 ) );
|
|
|
|
|
$sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$cutoff}'";
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbw->query( $sql );
|
2004-01-31 16:59:08 +00:00
|
|
|
}
|
|
|
|
|
$id = $this->getID();
|
|
|
|
|
$title = $this->mTitle->getPrefixedDBkey();
|
|
|
|
|
$shortTitle = $this->mTitle->getDBkey();
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-01-31 16:59:08 +00:00
|
|
|
$adj = $this->mCountAdjustment;
|
|
|
|
|
|
|
|
|
|
if ( 0 != $id ) {
|
|
|
|
|
$u = new LinksUpdate( $id, $title );
|
|
|
|
|
array_push( $wgDeferredUpdateList, $u );
|
|
|
|
|
$u = new SiteStatsUpdate( 0, 1, $adj );
|
|
|
|
|
array_push( $wgDeferredUpdateList, $u );
|
|
|
|
|
$u = new SearchUpdate( $id, $title, $text );
|
|
|
|
|
array_push( $wgDeferredUpdateList, $u );
|
|
|
|
|
|
|
|
|
|
$u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle );
|
|
|
|
|
array_push( $wgDeferredUpdateList, $u );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-01-31 16:59:08 +00:00
|
|
|
if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
|
|
|
|
|
$wgMessageCache->replace( $shortTitle, $text );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
/* private */ function setOldSubtitle() {
|
2003-04-14 23:10:40 +00:00
|
|
|
global $wgLang, $wgOut;
|
|
|
|
|
|
|
|
|
|
$td = $wgLang->timeanddate( $this->mTimestamp, true );
|
2004-06-08 19:51:10 +00:00
|
|
|
$r = wfMsg( 'revisionasof', $td );
|
2003-04-14 23:10:40 +00:00
|
|
|
$wgOut->setSubtitle( "({$r})" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# This function is called right before saving the wikitext,
|
|
|
|
|
# so we can do things like signatures and links-in-context.
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
function preSaveTransform( $text ) {
|
2004-03-06 01:49:16 +00:00
|
|
|
global $wgParser, $wgUser;
|
|
|
|
|
return $wgParser->preSaveTransform( $text, $this->mTitle, $wgUser, ParserOptions::newFromUser( $wgUser ) );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-05-16 13:39:22 +00:00
|
|
|
/* Caching functions */
|
2003-12-11 20:16:34 +00:00
|
|
|
|
2004-03-20 15:03:26 +00:00
|
|
|
# checkLastModified returns true if it has taken care of all
|
2003-12-11 20:16:34 +00:00
|
|
|
# output to the client that is necessary for this request.
|
|
|
|
|
# (that is, it has sent a cached version of the page)
|
2003-08-02 10:13:27 +00:00
|
|
|
function tryFileCache() {
|
2003-11-24 08:41:40 +00:00
|
|
|
static $called = false;
|
|
|
|
|
if( $called ) {
|
|
|
|
|
wfDebug( " tryFileCache() -- called twice!?\n" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$called = true;
|
2003-05-16 13:39:22 +00:00
|
|
|
if($this->isFileCacheable()) {
|
2003-09-05 21:12:24 +00:00
|
|
|
$touched = $this->mTouched;
|
2004-06-08 19:51:10 +00:00
|
|
|
if( $this->mTitle->getPrefixedDBkey() == wfMsg( 'mainpage' ) ) {
|
2003-12-17 09:41:17 +00:00
|
|
|
# Expire the main page quicker
|
2003-09-05 21:12:24 +00:00
|
|
|
$expire = wfUnix2Timestamp( time() - 3600 );
|
|
|
|
|
$touched = max( $expire, $touched );
|
|
|
|
|
}
|
2003-09-01 08:30:14 +00:00
|
|
|
$cache = new CacheManager( $this->mTitle );
|
2003-09-05 21:12:24 +00:00
|
|
|
if($cache->isFileCacheGood( $touched )) {
|
2003-11-09 11:45:12 +00:00
|
|
|
global $wgOut;
|
2003-08-02 10:13:27 +00:00
|
|
|
wfDebug( " tryFileCache() - about to load\n" );
|
|
|
|
|
$cache->loadFromFileCache();
|
2003-12-11 20:16:34 +00:00
|
|
|
return true;
|
2003-05-16 13:39:22 +00:00
|
|
|
} else {
|
2004-07-08 14:53:54 +00:00
|
|
|
wfDebug( " tryFileCache() - starting buffer\n" );
|
2003-08-02 10:13:27 +00:00
|
|
|
ob_start( array(&$cache, 'saveToFileCache' ) );
|
2003-05-16 13:39:22 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
wfDebug( " tryFileCache() - not cacheable\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isFileCacheable() {
|
2004-03-29 14:48:07 +00:00
|
|
|
global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
|
|
|
|
|
extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2003-05-16 13:39:22 +00:00
|
|
|
return $wgUseFileCache
|
|
|
|
|
and (!$wgShowIPinHeader)
|
2003-09-01 19:40:52 +00:00
|
|
|
and ($this->getID() != 0)
|
2003-05-16 13:39:22 +00:00
|
|
|
and ($wgUser->getId() == 0)
|
|
|
|
|
and (!$wgUser->getNewtalk())
|
2004-08-07 03:50:46 +00:00
|
|
|
and ($this->mTitle->getNamespace() != NS_SPECIAL )
|
2004-08-08 09:39:16 +00:00
|
|
|
and (empty( $action ) || $action == 'view')
|
2003-05-16 13:39:22 +00:00
|
|
|
and (!isset($oldid))
|
|
|
|
|
and (!isset($diff))
|
|
|
|
|
and (!isset($redirect))
|
|
|
|
|
and (!isset($printable))
|
|
|
|
|
and (!$this->mRedirectedFrom);
|
|
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-06-04 10:40:44 +00:00
|
|
|
# Loads cur_touched and returns a value indicating if it should be used
|
2003-11-09 11:45:12 +00:00
|
|
|
function checkTouched() {
|
2004-07-18 08:48:43 +00:00
|
|
|
$fname = 'Article::checkTouched';
|
2003-11-09 11:45:12 +00:00
|
|
|
$id = $this->getID();
|
2004-08-20 14:59:49 +00:00
|
|
|
$dbr =& $this->getDB();
|
2004-08-09 05:38:11 +00:00
|
|
|
$s = $dbr->getArray( 'cur', array( 'cur_touched', 'cur_is_redirect' ),
|
2004-08-20 14:59:49 +00:00
|
|
|
array( 'cur_id' => $id ), $fname, $this->getSelectOptions() );
|
2004-07-10 03:09:26 +00:00
|
|
|
if( $s !== false ) {
|
2004-08-20 12:47:46 +00:00
|
|
|
$this->mTouched = wfTimestamp(TS_MW,$s->cur_touched);
|
2003-11-09 11:45:12 +00:00
|
|
|
return !$s->cur_is_redirect;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-05-27 15:24:04 +00:00
|
|
|
|
2004-06-02 13:14:40 +00:00
|
|
|
# Edit an article without doing all that other stuff
|
2004-06-08 19:51:10 +00:00
|
|
|
function quickEdit( $text, $comment = '', $minor = 0 ) {
|
2004-07-10 03:09:26 +00:00
|
|
|
global $wgUser, $wgMwRedir;
|
2004-06-08 19:51:10 +00:00
|
|
|
$fname = 'Article::quickEdit';
|
2004-06-02 13:14:40 +00:00
|
|
|
wfProfileIn( $fname );
|
|
|
|
|
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
2004-06-02 13:14:40 +00:00
|
|
|
$ns = $this->mTitle->getNamespace();
|
2004-06-02 13:58:31 +00:00
|
|
|
$dbkey = $this->mTitle->getDBkey();
|
2004-07-10 03:09:26 +00:00
|
|
|
$encDbKey = $dbw->strencode( $dbkey );
|
2004-06-02 13:14:40 +00:00
|
|
|
$timestamp = wfTimestampNow();
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-06-02 13:14:40 +00:00
|
|
|
# Save to history
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbw->insertSelect( 'old', 'cur',
|
|
|
|
|
array(
|
|
|
|
|
'old_namespace' => 'cur_namespace',
|
|
|
|
|
'old_title' => 'cur_title',
|
|
|
|
|
'old_text' => 'cur_text',
|
|
|
|
|
'old_comment' => 'cur_comment',
|
|
|
|
|
'old_user' => 'cur_user',
|
|
|
|
|
'old_user_text' => 'cur_user_text',
|
|
|
|
|
'old_timestamp' => 'cur_timestamp',
|
|
|
|
|
'inverse_timestamp' => '99999999999999-cur_timestamp',
|
|
|
|
|
), array(
|
|
|
|
|
'cur_namespace' => $ns,
|
|
|
|
|
'cur_title' => $dbkey,
|
2004-08-09 05:38:11 +00:00
|
|
|
), $fname
|
2004-07-10 03:09:26 +00:00
|
|
|
);
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-06-02 13:14:40 +00:00
|
|
|
# Use the affected row count to determine if the article is new
|
2004-07-10 03:09:26 +00:00
|
|
|
$numRows = $dbw->affectedRows();
|
2004-06-02 13:14:40 +00:00
|
|
|
|
|
|
|
|
# Make an array of fields to be inserted
|
|
|
|
|
$fields = array(
|
|
|
|
|
'cur_text' => $text,
|
|
|
|
|
'cur_timestamp' => $timestamp,
|
|
|
|
|
'cur_user' => $wgUser->getID(),
|
|
|
|
|
'cur_user_text' => $wgUser->getName(),
|
|
|
|
|
'inverse_timestamp' => wfInvertTimestamp( $timestamp ),
|
|
|
|
|
'cur_comment' => $comment,
|
|
|
|
|
'cur_is_redirect' => $wgMwRedir->matchStart( $text ) ? 1 : 0,
|
|
|
|
|
'cur_minor_edit' => intval($minor),
|
2004-08-20 12:47:46 +00:00
|
|
|
'cur_touched' => $dbw->timestamp($timestamp),
|
2004-06-02 13:14:40 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ( $numRows ) {
|
|
|
|
|
# Update article
|
|
|
|
|
$fields['cur_is_new'] = 0;
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbw->updateArray( 'cur', $fields, array( 'cur_namespace' => $ns, 'cur_title' => $dbkey ), $fname );
|
2004-06-02 13:14:40 +00:00
|
|
|
} else {
|
|
|
|
|
# Insert new article
|
|
|
|
|
$fields['cur_is_new'] = 1;
|
2004-06-02 13:58:31 +00:00
|
|
|
$fields['cur_namespace'] = $ns;
|
|
|
|
|
$fields['cur_title'] = $dbkey;
|
2004-06-08 19:51:10 +00:00
|
|
|
$fields['cur_random'] = $rand = number_format( mt_rand() / mt_getrandmax(), 12, '.', '' );
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbw->insertArray( 'cur', $fields, $fname );
|
2004-06-02 13:14:40 +00:00
|
|
|
}
|
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
/* static */ function incViewCount( $id ) {
|
2003-12-13 21:32:32 +00:00
|
|
|
$id = intval( $id );
|
2004-01-17 19:59:42 +00:00
|
|
|
global $wgHitcounterUpdateFreq;
|
|
|
|
|
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
2004-07-10 03:09:26 +00:00
|
|
|
$curTable = $dbw->tableName( 'cur' );
|
|
|
|
|
$hitcounterTable = $dbw->tableName( 'hitcounter' );
|
|
|
|
|
$acchitsTable = $dbw->tableName( 'acchits' );
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-07-08 14:53:54 +00:00
|
|
|
if( $wgHitcounterUpdateFreq <= 1 ){ //
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbw->query( "UPDATE $curTable SET cur_counter = cur_counter + 1 WHERE cur_id = $id" );
|
2004-01-17 19:59:42 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2003-12-13 21:32:32 +00:00
|
|
|
|
|
|
|
|
# Not important enough to warrant an error page in case of failure
|
2004-08-09 05:38:11 +00:00
|
|
|
$oldignore = $dbw->ignoreErrors( true );
|
2003-12-13 21:32:32 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
|
2003-12-13 21:32:32 +00:00
|
|
|
|
2004-01-17 19:59:42 +00:00
|
|
|
$checkfreq = intval( $wgHitcounterUpdateFreq/25 + 1 );
|
2004-07-10 03:09:26 +00:00
|
|
|
if( (rand() % $checkfreq != 0) or ($dbw->lastErrno() != 0) ){
|
2003-12-13 21:32:32 +00:00
|
|
|
# Most of the time (or on SQL errors), skip row count check
|
2004-08-05 07:48:20 +00:00
|
|
|
$dbw->ignoreErrors( $oldignore );
|
2003-12-13 21:32:32 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
$res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
|
|
|
|
|
$row = $dbw->fetchObject( $res );
|
2003-12-13 21:32:32 +00:00
|
|
|
$rown = intval( $row->n );
|
2004-07-08 14:53:54 +00:00
|
|
|
if( $rown >= $wgHitcounterUpdateFreq ){
|
2004-06-08 19:51:10 +00:00
|
|
|
wfProfileIn( 'Article::incViewCount-collect' );
|
2003-12-13 21:32:32 +00:00
|
|
|
$old_user_abort = ignore_user_abort( true );
|
|
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbw->query("LOCK TABLES $hitcounterTable WRITE");
|
|
|
|
|
$dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
|
|
|
|
|
"SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
|
|
|
|
|
'GROUP BY hc_id');
|
|
|
|
|
$dbw->query("DELETE FROM $hitcounterTable");
|
|
|
|
|
$dbw->query('UNLOCK TABLES');
|
|
|
|
|
$dbw->query("UPDATE $curTable,$acchitsTable SET cur_counter=cur_counter + hc_n ".
|
|
|
|
|
'WHERE cur_id = hc_id');
|
|
|
|
|
$dbw->query("DROP TABLE $acchitsTable");
|
2003-12-13 21:32:32 +00:00
|
|
|
|
|
|
|
|
ignore_user_abort( $old_user_abort );
|
2004-06-08 19:51:10 +00:00
|
|
|
wfProfileOut( 'Article::incViewCount-collect' );
|
2003-12-13 21:32:32 +00:00
|
|
|
}
|
2004-08-05 07:48:20 +00:00
|
|
|
$dbw->ignoreErrors( $oldignore );
|
2003-12-13 21:32:32 +00:00
|
|
|
}
|
2004-01-05 23:32:39 +00:00
|
|
|
|
|
|
|
|
# The onArticle*() functions are supposed to be a kind of hooks
|
2004-07-08 14:53:54 +00:00
|
|
|
# which should be called whenever any of the specified actions
|
|
|
|
|
# are done.
|
2004-01-05 23:32:39 +00:00
|
|
|
#
|
2004-07-08 14:53:54 +00:00
|
|
|
# This is a good place to put code to clear caches, for instance.
|
2004-01-05 23:32:39 +00:00
|
|
|
|
2004-07-08 14:53:54 +00:00
|
|
|
# This is called on page move and undelete, as well as edit
|
2004-08-12 14:27:38 +00:00
|
|
|
/* static */ function onArticleCreate($title_obj) {
|
2004-06-05 04:44:45 +00:00
|
|
|
global $wgUseSquid, $wgDeferredUpdateList;
|
2004-03-20 15:03:26 +00:00
|
|
|
|
|
|
|
|
$titles = $title_obj->getBrokenLinksTo();
|
2004-07-08 14:53:54 +00:00
|
|
|
|
|
|
|
|
# Purge squid
|
2004-03-20 15:03:26 +00:00
|
|
|
if ( $wgUseSquid ) {
|
|
|
|
|
$urls = $title_obj->getSquidURLs();
|
|
|
|
|
foreach ( $titles as $linkTitle ) {
|
|
|
|
|
$urls[] = $linkTitle->getInternalURL();
|
|
|
|
|
}
|
|
|
|
|
$u = new SquidUpdate( $urls );
|
|
|
|
|
array_push( $wgDeferredUpdateList, $u );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Clear persistent link cache
|
2004-06-05 04:44:45 +00:00
|
|
|
LinkCache::linksccClearBrokenLinksTo( $title_obj->getPrefixedDBkey() );
|
2004-01-05 23:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
/* static */ function onArticleDelete($title_obj) {
|
2004-06-05 04:44:45 +00:00
|
|
|
LinkCache::linksccClearLinksTo( $title_obj->getArticleID() );
|
2004-01-05 23:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
/* static */ function onArticleEdit($title_obj) {
|
2004-06-05 04:44:45 +00:00
|
|
|
LinkCache::linksccClearPage( $title_obj->getArticleID() );
|
2004-01-05 23:32:39 +00:00
|
|
|
}
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
|
2004-07-08 14:53:54 +00:00
|
|
|
# Info about this page
|
|
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
function info() {
|
2004-07-09 11:42:24 +00:00
|
|
|
global $wgUser, $wgTitle, $wgOut, $wgLang, $wgAllowPageInfo;
|
2004-07-18 08:48:43 +00:00
|
|
|
$fname = 'Article::info';
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-07-09 11:42:24 +00:00
|
|
|
if ( !$wgAllowPageInfo ) {
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
|
2004-07-09 11:42:24 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-08-20 14:59:49 +00:00
|
|
|
$dbr =& $this->getDB();
|
2004-07-08 14:53:54 +00:00
|
|
|
|
|
|
|
|
$basenamespace = $wgTitle->getNamespace() & (~1);
|
2004-07-18 08:48:43 +00:00
|
|
|
$cur_clause = array( 'cur_title' => $wgTitle->getDBkey(), 'cur_namespace' => $basenamespace );
|
|
|
|
|
$old_clause = array( 'old_title' => $wgTitle->getDBkey(), 'old_namespace' => $basenamespace );
|
|
|
|
|
$wl_clause = array( 'wl_title' => $wgTitle->getDBkey(), 'wl_namespace' => $basenamespace );
|
2004-07-08 14:53:54 +00:00
|
|
|
$fullTitle = $wgTitle->makeName($basenamespace, $wgTitle->getDBKey());
|
|
|
|
|
$wgOut->setPagetitle( $fullTitle );
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
|
2004-07-08 14:53:54 +00:00
|
|
|
|
|
|
|
|
# first, see if the page exists at all.
|
2004-08-20 14:59:49 +00:00
|
|
|
$exists = $dbr->selectField( 'cur', 'COUNT(*)', $cur_clause, $fname, $this->getSelectOptions() );
|
2004-07-08 14:53:54 +00:00
|
|
|
if ($exists < 1) {
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgOut->addHTML( wfMsg('noarticletext') );
|
2004-07-08 14:53:54 +00:00
|
|
|
} else {
|
2004-08-20 14:59:49 +00:00
|
|
|
$numwatchers = $dbr->selectField( 'watchlist', 'COUNT(*)', $wl_clause, $fname,
|
|
|
|
|
$this->getSelectOptions() );
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $numwatchers) . '</li>' );
|
2004-08-20 14:59:49 +00:00
|
|
|
$old = $dbr->selectField( 'old', 'COUNT(*)', $old_clause, $fname, $this->getSelectOptions() );
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgOut->addHTML( "<li>" . wfMsg('numedits', $old + 1) . '</li>');
|
2004-07-08 14:53:54 +00:00
|
|
|
|
|
|
|
|
# to find number of distinct authors, we need to do some
|
|
|
|
|
# funny stuff because of the cur/old table split:
|
|
|
|
|
# - first, find the name of the 'cur' author
|
|
|
|
|
# - then, find the number of *other* authors in 'old'
|
|
|
|
|
|
|
|
|
|
# find 'cur' author
|
2004-08-20 14:59:49 +00:00
|
|
|
$cur_author = $dbr->selectField( 'cur', 'cur_user_text', $cur_clause, $fname,
|
|
|
|
|
$this->getSelectOptions() );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
|
|
|
|
# find number of 'old' authors excluding 'cur' author
|
2004-08-09 05:38:11 +00:00
|
|
|
$authors = $dbr->selectField( 'old', 'COUNT(DISTINCT old_user_text)',
|
2004-08-20 14:59:49 +00:00
|
|
|
$old_clause + array( 'old_user_text<>' . $dbr->addQuotes( $cur_author ) ), $fname,
|
|
|
|
|
$this->getSelectOptions() ) + 1;
|
2004-07-08 14:53:54 +00:00
|
|
|
|
|
|
|
|
# now for the Talk page ...
|
2004-07-18 08:48:43 +00:00
|
|
|
$cur_clause = array( 'cur_title' => $wgTitle->getDBkey(), 'cur_namespace' => $basenamespace+1 );
|
|
|
|
|
$old_clause = array( 'old_title' => $wgTitle->getDBkey(), 'old_namespace' => $basenamespace+1 );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
|
|
|
|
# does it exist?
|
2004-08-20 14:59:49 +00:00
|
|
|
$exists = $dbr->selectField( 'cur', 'COUNT(*)', $cur_clause, $fname, $this->getSelectOptions() );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
|
|
|
|
# number of edits
|
|
|
|
|
if ($exists > 0) {
|
2004-08-20 14:59:49 +00:00
|
|
|
$old = $dbr->selectField( 'old', 'COUNT(*)', $old_clause, $fname, $this->getSelectOptions() );
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $old + 1) . '</li>');
|
2004-07-08 14:53:54 +00:00
|
|
|
}
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgOut->addHTML( '<li>' . wfMsg("numauthors", $authors) . '</li>' );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
|
|
|
|
# number of authors
|
|
|
|
|
if ($exists > 0) {
|
2004-08-20 14:59:49 +00:00
|
|
|
$cur_author = $dbr->selectField( 'cur', 'cur_user_text', $cur_clause, $fname,
|
|
|
|
|
$this->getSelectOptions() );
|
2004-08-09 05:38:11 +00:00
|
|
|
$authors = $dbr->selectField( 'cur', 'COUNT(DISTINCT old_user_text)',
|
2004-08-20 14:59:49 +00:00
|
|
|
$old_clause + array( 'old_user_text<>' . $dbr->addQuotes( $cur_author ) ),
|
|
|
|
|
$fname, $this->getSelectOptions() );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $authors) . '</li></ul>' );
|
2004-07-08 14:53:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|