2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* File for articles
|
2004-09-03 00:20:26 +00:00
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-08-02 20:43:11 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Need the CacheManager to be loaded
|
|
|
|
|
*/
|
2004-12-19 12:21:29 +00:00
|
|
|
require_once( 'CacheManager.php' );
|
|
|
|
|
require_once( 'Revision.php' );
|
2003-08-08 03:08:06 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
$wgArticleCurContentFields = false;
|
|
|
|
|
$wgArticleOldContentFields = false;
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Class representing a Wikipedia article and history.
|
|
|
|
|
*
|
|
|
|
|
* See design.doc for an overview.
|
|
|
|
|
* Note: edit user interface and cache support functions have been
|
|
|
|
|
* moved to separate EditPage and CacheManager classes.
|
2004-09-03 00:20:26 +00:00
|
|
|
*
|
|
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-04-14 23:10:40 +00:00
|
|
|
class Article {
|
2004-09-02 23:28:24 +00:00
|
|
|
/**#@+
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
var $mContent, $mContentLoaded;
|
|
|
|
|
var $mUser, $mTimestamp, $mUserText;
|
|
|
|
|
var $mCounter, $mComment, $mCountAdjustment;
|
|
|
|
|
var $mMinorEdit, $mRedirectedFrom;
|
|
|
|
|
var $mTouched, $mFileCache, $mTitle;
|
|
|
|
|
var $mId, $mTable;
|
|
|
|
|
var $mForUpdate;
|
2004-12-19 08:00:50 +00:00
|
|
|
var $mOldId;
|
2004-09-02 23:28:24 +00:00
|
|
|
/**#@-*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor and clear the article
|
2004-09-03 00:20:26 +00:00
|
|
|
* @param mixed &$title
|
2004-09-02 23:28:24 +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-12-29 01:07:43 +00:00
|
|
|
/**
|
|
|
|
|
* get the title object of the article
|
|
|
|
|
* @public
|
|
|
|
|
*/
|
|
|
|
|
function getTitle() {
|
|
|
|
|
return $this->mTitle;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Clear the object
|
|
|
|
|
* @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-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Note that getContent/loadContent may follow redirects if
|
|
|
|
|
* not told otherwise, and so may cause a change to mTitle.
|
|
|
|
|
*
|
2004-09-03 00:20:26 +00:00
|
|
|
* @param $noredir
|
|
|
|
|
* @return Return the text of this revision
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
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-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* This function returns the text of a section, specified by a number ($section).
|
|
|
|
|
* A section is text under a heading like == Heading == or <h1>Heading</h1>, or
|
|
|
|
|
* the first section before any such heading (section 0).
|
|
|
|
|
*
|
|
|
|
|
* If a section contains subsections, these are also returned.
|
2004-09-03 00:20:26 +00:00
|
|
|
*
|
|
|
|
|
* @param string $text text to look in
|
|
|
|
|
* @param integer $section section number
|
|
|
|
|
* @return string text of the requested section
|
|
|
|
|
*/
|
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-08-24 18:04:37 +00:00
|
|
|
'/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/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-08-24 18:04:37 +00:00
|
|
|
preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/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-08-24 18:04:37 +00:00
|
|
|
preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/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-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Return an array of the columns of the "cur"-table
|
2004-09-03 00:20:26 +00:00
|
|
|
*/
|
2004-12-19 08:00:50 +00:00
|
|
|
function getContentFields() {
|
|
|
|
|
return $wgArticleContentFields = array(
|
|
|
|
|
'old_text','old_flags',
|
|
|
|
|
'rev_timestamp','rev_user', 'rev_user_text', 'rev_comment','page_counter',
|
|
|
|
|
'page_namespace', 'page_title', 'page_restrictions','page_touched','page_is_redirect' );
|
2004-07-10 03:09:26 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2004-11-13 08:40:34 +00:00
|
|
|
* Return the oldid of the article that is to be shown.
|
|
|
|
|
* For requests with a "direction", this is not the oldid of the
|
|
|
|
|
* query
|
|
|
|
|
*/
|
|
|
|
|
function getOldID() {
|
|
|
|
|
global $wgRequest, $wgOut;
|
|
|
|
|
static $lastid;
|
2004-12-19 08:00:50 +00:00
|
|
|
|
2004-11-13 08:40:34 +00:00
|
|
|
if ( isset( $lastid ) ) {
|
|
|
|
|
return $lastid;
|
|
|
|
|
}
|
2004-12-19 08:00:50 +00:00
|
|
|
# Query variables :P
|
2004-11-13 08:40:34 +00:00
|
|
|
$oldid = $wgRequest->getVal( 'oldid' );
|
2004-07-08 14:53:54 +00:00
|
|
|
if ( isset( $oldid ) ) {
|
|
|
|
|
$oldid = IntVal( $oldid );
|
2004-10-02 21:36:36 +00:00
|
|
|
if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
|
|
|
|
|
$nextid = $this->mTitle->getNextRevisionID( $oldid );
|
2004-12-19 08:00:50 +00:00
|
|
|
if ( $nextid ) {
|
2004-10-02 21:36:36 +00:00
|
|
|
$oldid = $nextid;
|
|
|
|
|
} else {
|
|
|
|
|
$wgOut->redirect( $this->mTitle->getFullURL( 'redirect=no' ) );
|
|
|
|
|
}
|
|
|
|
|
} elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
|
|
|
|
|
$previd = $this->mTitle->getPreviousRevisionID( $oldid );
|
|
|
|
|
if ( $previd ) {
|
|
|
|
|
$oldid = $previd;
|
|
|
|
|
} else {
|
|
|
|
|
# TODO
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-11-13 08:40:34 +00:00
|
|
|
$lastid = $oldid;
|
2004-10-02 21:36:36 +00:00
|
|
|
}
|
2004-11-13 08:40:34 +00:00
|
|
|
return @$oldid; # "@" to be able to return "unset" without PHP complaining
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load the revision (including cur_text) into this object
|
2004-12-19 08:00:50 +00:00
|
|
|
*/
|
2004-11-13 08:40:34 +00:00
|
|
|
function loadContent( $noredir = false ) {
|
|
|
|
|
global $wgOut, $wgRequest;
|
|
|
|
|
|
|
|
|
|
if ( $this->mContentLoaded ) return;
|
|
|
|
|
|
|
|
|
|
# Query variables :P
|
|
|
|
|
$oldid = $this->getOldID();
|
|
|
|
|
$redirect = $wgRequest->getVal( 'redirect' );
|
|
|
|
|
|
|
|
|
|
$fname = 'Article::loadContent';
|
|
|
|
|
|
|
|
|
|
# Pre-fill content with error message so that if something
|
|
|
|
|
# fails we'll have something telling us what we intended.
|
|
|
|
|
|
|
|
|
|
$t = $this->mTitle->getPrefixedText();
|
|
|
|
|
|
2004-12-19 08:00:50 +00:00
|
|
|
$noredir = $noredir || ($wgRequest->getVal( 'redirect' ) == 'no');
|
|
|
|
|
$this->mOldId = $oldid;
|
|
|
|
|
$this->fetchContent( $oldid, $noredir, true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2005-01-11 01:28:18 +00:00
|
|
|
* Get text of an article from database
|
2004-12-19 08:00:50 +00:00
|
|
|
* @param int $oldid 0 for whatever the latest revision is
|
|
|
|
|
* @param bool $noredir Set to true to avoid following redirects
|
|
|
|
|
* @param bool $globalTitle Set to true to change the global $wgTitle object when following redirects or other unexpected title changes
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function fetchContent( $oldid = 0, $noredir = false, $globalTitle = false ) {
|
|
|
|
|
if ( $this->mContentLoaded ) {
|
|
|
|
|
return $this->mContent;
|
|
|
|
|
}
|
|
|
|
|
$dbr =& $this->getDB();
|
|
|
|
|
$fname = 'Article::fetchContent';
|
|
|
|
|
|
|
|
|
|
# Pre-fill content with error message so that if something
|
|
|
|
|
# fails we'll have something telling us what we intended.
|
|
|
|
|
$t = $this->mTitle->getPrefixedText();
|
|
|
|
|
if( $oldid ) {
|
2004-08-22 17:24:50 +00:00
|
|
|
$t .= ',oldid='.$oldid;
|
2004-07-08 14:53:54 +00:00
|
|
|
}
|
2004-12-19 08:00:50 +00:00
|
|
|
if( isset( $redirect ) ) {
|
2004-07-08 14:53:54 +00:00
|
|
|
$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
|
|
|
|
2004-12-19 08:00:50 +00:00
|
|
|
if( !$oldid ) {
|
|
|
|
|
# Retrieve current version
|
2003-04-14 23:10:40 +00:00
|
|
|
$id = $this->getID();
|
2004-12-19 08:00:50 +00:00
|
|
|
if ( 0 == $id ) {
|
|
|
|
|
return false;
|
2003-11-02 13:57:24 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-12-19 08:00:50 +00:00
|
|
|
$s = $dbr->selectRow( array( 'text', 'revision', 'page' ),
|
|
|
|
|
$this->getContentFields(),
|
|
|
|
|
"page_id='$id' AND rev_page=page_id AND rev_id=page_latest AND old_id=rev_id",
|
|
|
|
|
$fname, $this->getSelectOptions() );
|
|
|
|
|
} else {
|
|
|
|
|
# Historical revision
|
|
|
|
|
$s = $dbr->selectRow( array( 'text', 'revision', 'page' ),
|
|
|
|
|
$this->getContentFields(),
|
|
|
|
|
"rev_page=page_id AND rev_id='$oldid' AND old_id=rev_id",
|
|
|
|
|
$fname, $this->getSelectOptions() );
|
|
|
|
|
}
|
|
|
|
|
if ( $s === false ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2004-08-07 03:50:46 +00:00
|
|
|
|
2004-12-19 08:00:50 +00:00
|
|
|
# If we got a redirect, follow it (unless we've been told
|
|
|
|
|
# not to by either the function parameter or the query
|
|
|
|
|
if ( !$oldid && !$noredir ) {
|
2004-12-19 12:21:29 +00:00
|
|
|
$rt = Title::newFromRedirect( Revision::getRevisionText( $s ) );
|
2004-12-19 08:00:50 +00:00
|
|
|
# process if title object is valid and not special:userlogout
|
|
|
|
|
if ( $rt && ! ( $rt->getNamespace() == NS_SPECIAL && $rt->getText() == 'Userlogout' ) ) {
|
|
|
|
|
# Gotta hand redirects to special pages differently:
|
|
|
|
|
# Fill the HTTP response "Location" header and ignore
|
|
|
|
|
# the rest of the page we're on.
|
|
|
|
|
if( $globalTitle ) {
|
|
|
|
|
global $wgOut;
|
2004-08-07 03:50:46 +00:00
|
|
|
if ( $rt->getInterwiki() != '' ) {
|
|
|
|
|
$wgOut->redirect( $rt->getFullURL() ) ;
|
2004-12-19 08:00:50 +00:00
|
|
|
return false;
|
2004-08-07 03:50:46 +00:00
|
|
|
}
|
|
|
|
|
if ( $rt->getNamespace() == NS_SPECIAL ) {
|
|
|
|
|
$wgOut->redirect( $rt->getFullURL() );
|
2004-12-19 08:00:50 +00:00
|
|
|
return false;
|
2004-08-07 03:50:46 +00:00
|
|
|
}
|
2004-12-19 08:00:50 +00:00
|
|
|
}
|
|
|
|
|
$rid = $rt->getArticleID();
|
|
|
|
|
if ( 0 != $rid ) {
|
|
|
|
|
$redirRow = $dbr->selectRow( array( 'text', 'revision', 'page' ),
|
|
|
|
|
$this->getContentFields(),
|
|
|
|
|
"page_id='$rid' AND rev_page=page_id AND rev_id=page_latest AND old_id=rev_id",
|
|
|
|
|
$fname, $this->getSelectOptions() );
|
|
|
|
|
|
|
|
|
|
if ( $redirRow !== false ) {
|
|
|
|
|
$this->mRedirectedFrom = $this->mTitle->getPrefixedText();
|
|
|
|
|
$this->mTitle = $rt;
|
|
|
|
|
$s = $redirRow;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-12-19 08:00:50 +00:00
|
|
|
}
|
2003-11-02 13:57:24 +00:00
|
|
|
|
2004-12-19 08:00:50 +00:00
|
|
|
# if the title's different from expected, update...
|
|
|
|
|
if( $globalTitle &&
|
|
|
|
|
( $this->mTitle->getNamespace() != $s->page_namespace ||
|
|
|
|
|
$this->mTitle->getDBkey() != $s->page_title ) ) {
|
|
|
|
|
$oldTitle = Title::makeTitle( $s->page_namesapce, $s->page_title );
|
|
|
|
|
$this->mTitle = $oldTitle;
|
|
|
|
|
global $wgTitle;
|
|
|
|
|
$wgTitle = $oldTitle;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2004-12-19 08:00:50 +00:00
|
|
|
|
|
|
|
|
# Back to the business at hand...
|
|
|
|
|
$this->mCounter = $s->page_counter;
|
|
|
|
|
$this->mTitle->mRestrictions = explode( ',', trim( $s->page_restrictions ) );
|
|
|
|
|
$this->mTitle->mRestrictionsLoaded = true;
|
|
|
|
|
$this->mTouched = wfTimestamp( TS_MW, $s->page_touched );
|
|
|
|
|
|
2004-12-19 12:21:29 +00:00
|
|
|
$this->mContent = Revision::getRevisionText( $s );
|
2004-12-19 08:00:50 +00:00
|
|
|
|
|
|
|
|
$this->mUser = $s->rev_user;
|
|
|
|
|
$this->mUserText = $s->rev_user_text;
|
|
|
|
|
$this->mComment = $s->rev_comment;
|
|
|
|
|
$this->mTimestamp = wfTimestamp( TS_MW, $s->rev_timestamp );
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->mContentLoaded = true;
|
2004-03-23 10:11:24 +00:00
|
|
|
return $this->mContent;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Gets the article text without using so many damn globals
|
|
|
|
|
* Returns false on error
|
2004-09-03 00:20:26 +00:00
|
|
|
*
|
|
|
|
|
* @param integer $oldid
|
|
|
|
|
*/
|
2004-03-23 10:11:24 +00:00
|
|
|
function getContentWithoutUsingSoManyDamnGlobals( $oldid = 0, $noredir = false ) {
|
2004-12-19 08:00:50 +00:00
|
|
|
return $this->fetchContent( $oldid, $noredir, false );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Read/write accessor to select FOR UPDATE
|
|
|
|
|
*/
|
2004-08-20 14:59:49 +00:00
|
|
|
function forUpdate( $x = NULL ) {
|
|
|
|
|
return wfSetVar( $this->mForUpdate, $x );
|
|
|
|
|
}
|
2004-09-01 02:57:26 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Get the database which should be used for reads
|
|
|
|
|
*/
|
2004-08-20 14:59:49 +00:00
|
|
|
function &getDB() {
|
|
|
|
|
if ( $this->mForUpdate ) {
|
|
|
|
|
return wfGetDB( DB_MASTER );
|
|
|
|
|
} else {
|
|
|
|
|
return wfGetDB( DB_SLAVE );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Get options for all SELECT statements
|
|
|
|
|
* Can pass an option array, to which the class-wide options will be appended
|
|
|
|
|
*/
|
2004-08-20 14:59:49 +00:00
|
|
|
function getSelectOptions( $options = '' ) {
|
|
|
|
|
if ( $this->mForUpdate ) {
|
2005-01-11 00:06:00 +00:00
|
|
|
if ( is_array( $options ) ) {
|
2004-08-20 14:59:49 +00:00
|
|
|
$options[] = 'FOR UPDATE';
|
|
|
|
|
} else {
|
|
|
|
|
$options = 'FOR UPDATE';
|
|
|
|
|
}
|
2004-09-01 02:57:26 +00:00
|
|
|
}
|
2004-08-20 14:59:49 +00:00
|
|
|
return $options;
|
|
|
|
|
}
|
2004-09-01 02:57:26 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Return the Article ID
|
|
|
|
|
*/
|
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-09-11 11:39:24 +00:00
|
|
|
/**
|
|
|
|
|
* Get the view count for this article
|
2004-09-02 23:28:24 +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-12-19 08:00:50 +00:00
|
|
|
$this->mCounter = $dbr->selectField( 'page', 'page_counter', array( 'page_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;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Would the given text make this article a "good" article (i.e.,
|
|
|
|
|
* suitable for including in the article count)?
|
2005-01-28 05:10:05 +00:00
|
|
|
* @param string $text Text to analyze
|
|
|
|
|
* @return integer 1 if it can be counted else 0
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-08-12 14:27:38 +00:00
|
|
|
function isCountable( $text ) {
|
2004-09-11 11:39:24 +00:00
|
|
|
global $wgUseCommaCount;
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2005-01-28 05:10:05 +00:00
|
|
|
if ( NS_MAIN != $this->mTitle->getNamespace() ) { return 0; }
|
2004-09-11 11:39:24 +00:00
|
|
|
if ( $this->isRedirect( $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-09-11 11:39:24 +00:00
|
|
|
/**
|
|
|
|
|
* Tests if the article text represents a redirect
|
|
|
|
|
*/
|
|
|
|
|
function isRedirect( $text = false ) {
|
|
|
|
|
if ( $text === false ) {
|
|
|
|
|
$this->loadContent();
|
|
|
|
|
$titleObj = Title::newFromRedirect( $this->mText );
|
|
|
|
|
} else {
|
|
|
|
|
$titleObj = Title::newFromRedirect( $text );
|
|
|
|
|
}
|
|
|
|
|
return $titleObj !== NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2004-12-19 08:00:50 +00:00
|
|
|
* Loads everything except the text
|
2004-09-02 23:28:24 +00:00
|
|
|
* This isn't necessary for all uses, so it's only done if needed.
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function loadLastEdit() {
|
2003-04-14 23:10:40 +00:00
|
|
|
global $wgOut;
|
2004-12-19 08:00:50 +00:00
|
|
|
|
|
|
|
|
if ( -1 != $this->mUser )
|
|
|
|
|
return;
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2005-02-06 07:28:21 +00:00
|
|
|
# New or non-existent articles have no user information
|
|
|
|
|
$id = $this->getID();
|
|
|
|
|
if ( 0 == $id ) return;
|
|
|
|
|
|
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-12-19 08:00:50 +00:00
|
|
|
$s = $dbr->selectRow( array( 'revision', 'page') ,
|
|
|
|
|
array( 'rev_user','rev_user_text','rev_timestamp', 'rev_comment','rev_minor_edit' ),
|
2005-02-06 07:28:21 +00:00
|
|
|
array( 'page_id' => $id, 'page_latest=rev_id' ), $fname, $this->getSelectOptions() );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
if ( $s !== false ) {
|
2004-12-19 08:00:50 +00:00
|
|
|
$this->mUser = $s->rev_user;
|
|
|
|
|
$this->mUserText = $s->rev_user_text;
|
|
|
|
|
$this->mTimestamp = wfTimestamp(TS_MW,$s->rev_timestamp);
|
|
|
|
|
$this->mComment = $s->rev_comment;
|
|
|
|
|
$this->mMinorEdit = $s->rev_minor_edit;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-12-19 08:00:50 +00:00
|
|
|
$revTable = $dbr->tableName( 'revision' );
|
2004-07-10 03:09:26 +00:00
|
|
|
$userTable = $dbr->tableName( 'user' );
|
2004-09-26 19:49:44 +00:00
|
|
|
$encDBkey = $dbr->addQuotes( $title->getDBkey() );
|
2004-07-10 03:09:26 +00:00
|
|
|
$ns = $title->getNamespace();
|
|
|
|
|
$user = $this->getUser();
|
2005-01-04 23:49:16 +00:00
|
|
|
$pageId = $this->getId();
|
2004-07-10 03:09:26 +00:00
|
|
|
|
2004-12-19 08:00:50 +00:00
|
|
|
$sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
|
|
|
|
|
FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
|
|
|
|
|
WHERE rev_page = $pageId
|
2005-01-05 22:26:32 +00:00
|
|
|
AND rev_user != $user
|
2004-12-19 08:00:50 +00:00
|
|
|
GROUP BY rev_user, rev_user_text, user_real_name
|
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-09-01 02:57:26 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
while ( $line = $dbr->fetchObject( $res ) ) {
|
2004-12-19 08:00:50 +00:00
|
|
|
$contribs[] = array($line->rev_user, $line->rev_user_text, $line->user_real_name);
|
2004-08-12 14:27:38 +00:00
|
|
|
}
|
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
|
|
|
|
2004-09-02 23:28:24 +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-11-13 08:40:34 +00:00
|
|
|
global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgLang;
|
2004-08-09 23:30:02 +00:00
|
|
|
global $wgLinkCache, $IP, $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol;
|
2004-12-18 03:47:11 +00:00
|
|
|
global $wgEnotif;
|
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-11-13 08:40:34 +00:00
|
|
|
$oldid = $this->getOldID();
|
2004-03-29 14:48:07 +00:00
|
|
|
$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-28 23:00:04 +00:00
|
|
|
$de = new DifferenceEngine( $oldid, $diff, $rcid );
|
2003-04-14 23:10:40 +00:00
|
|
|
$de->showDiffPage();
|
2004-08-03 04:52:19 +00:00
|
|
|
if( $diff == 0 ) {
|
|
|
|
|
# Run view updates for current revision only
|
|
|
|
|
$this->viewUpdates();
|
|
|
|
|
}
|
2004-10-23 10:20:38 +00:00
|
|
|
wfProfileOut( $fname );
|
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 ) ){
|
2004-10-23 10:20:38 +00:00
|
|
|
wfProfileOut( $fname );
|
2003-12-11 20:16:34 +00:00
|
|
|
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();
|
2004-10-23 10:20:38 +00:00
|
|
|
wfProfileOut( $fname );
|
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 ) ) {
|
2004-12-19 08:00:50 +00:00
|
|
|
$this->setOldSubtitle( isset($this->mOldId) ? $this->mOldId : $oldid );
|
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-09-05 03:25:58 +00:00
|
|
|
$imageUrl = $wgStylePath.'/common/images/redirect.png';
|
2004-08-07 03:50:46 +00:00
|
|
|
$targetUrl = $rt->escapeLocalURL();
|
|
|
|
|
$titleText = htmlspecialchars( $rt->getPrefixedText() );
|
|
|
|
|
$link = $sk->makeLinkObj( $rt );
|
2004-11-13 08:40:34 +00:00
|
|
|
|
|
|
|
|
$wgOut->addHTML( '<img valign="center" src="'.$imageUrl.'" alt="#REDIRECT" />' .
|
2004-08-22 17:24:50 +00:00
|
|
|
'<span class="redirectText">'.$link.'</span>' );
|
2004-11-13 08:40:34 +00:00
|
|
|
|
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-10-24 19:14:48 +00:00
|
|
|
( $wgUser->isAllowed('patrol') || !$wgOnlySysopsCanPatrol ) )
|
2004-08-09 05:38:11 +00:00
|
|
|
{
|
|
|
|
|
$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-09-01 02:57:26 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->viewUpdates();
|
2003-10-16 13:30:45 +00:00
|
|
|
wfProfileOut( $fname );
|
2004-12-18 03:47:11 +00:00
|
|
|
|
2004-12-18 07:16:11 +00:00
|
|
|
$wgUser->clearNotification( $this->mTitle );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +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.
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function insertNewArticle( $text, $summary, $isminor, $watchthis ) {
|
2004-09-11 11:39:24 +00:00
|
|
|
global $wgOut, $wgUser;
|
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 );
|
2004-09-11 11:39:24 +00:00
|
|
|
if ( $this->isRedirect( $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-10-11 19:17:34 +00:00
|
|
|
$rand = wfRandom();
|
2004-12-19 08:00:50 +00:00
|
|
|
$isminor = ( $isminor && $wgUser->getID() ) ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
$mungedText = $text;
|
2004-12-19 12:21:29 +00:00
|
|
|
$flags = Revision::compressRevisionText( $mungedText );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-12-19 08:00:50 +00:00
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
2004-06-11 14:48:31 +00:00
|
|
|
|
2004-12-19 08:00:50 +00:00
|
|
|
$old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
|
|
|
|
|
$dbw->insert( 'text', array(
|
|
|
|
|
'old_id' => $old_id,
|
|
|
|
|
'old_text' => $mungedText,
|
|
|
|
|
'old_flags' => $flags,
|
|
|
|
|
), $fname );
|
|
|
|
|
$revisionId = $dbw->insertId();
|
|
|
|
|
|
|
|
|
|
$page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
|
|
|
|
|
$dbw->insert( 'page', array(
|
|
|
|
|
'page_id' => $page_id,
|
|
|
|
|
'page_namespace' => $ns,
|
|
|
|
|
'page_title' => $ttl,
|
|
|
|
|
'page_counter' => 0,
|
|
|
|
|
'page_restrictions' => '',
|
|
|
|
|
'page_is_redirect' => $redir,
|
|
|
|
|
'page_is_new' => 1,
|
|
|
|
|
'page_random' => $rand,
|
|
|
|
|
'page_touched' => $dbw->timestamp($now),
|
|
|
|
|
'page_latest' => $revisionId,
|
|
|
|
|
), $fname );
|
|
|
|
|
$newid = $dbw->insertId();
|
2004-07-10 03:09:26 +00:00
|
|
|
|
2004-12-19 08:00:50 +00:00
|
|
|
$dbw->insert( 'revision', array(
|
|
|
|
|
'rev_page' => $newid,
|
|
|
|
|
'rev_id' => $revisionId,
|
|
|
|
|
'rev_comment' => $summary,
|
|
|
|
|
'rev_user' => $wgUser->getID(),
|
|
|
|
|
'rev_timestamp' => $dbw->timestamp($now),
|
|
|
|
|
'rev_minor_edit' => $isminor,
|
|
|
|
|
'rev_user_text' => $wgUser->getName(),
|
2004-07-10 03:09:26 +00:00
|
|
|
'inverse_timestamp' => $won,
|
|
|
|
|
), $fname );
|
|
|
|
|
|
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-12-19 08:00:50 +00:00
|
|
|
$dbw->update( 'page',
|
|
|
|
|
array( 'page_touched' => $dbw->timestamp($now) ),
|
|
|
|
|
array( 'page_namespace' => $talkns,
|
|
|
|
|
'page_title' => $ttl ),
|
|
|
|
|
$fname );
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-02-02 01:40:03 +00:00
|
|
|
# standard deferred updates
|
2004-12-18 03:47:11 +00:00
|
|
|
$this->editUpdates( $text, $summary, $isminor, $now );
|
2004-03-20 15:03:26 +00:00
|
|
|
|
2004-12-18 03:47:11 +00:00
|
|
|
$oldid = 0; # new article
|
|
|
|
|
$this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2004-12-19 08:00:50 +00:00
|
|
|
* Fetch and uncompress the text for a given revision.
|
|
|
|
|
* Can ask by rev_id number or timestamp (set $field)
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-12-19 08:00:50 +00:00
|
|
|
function fetchRevisionText( $revId = null, $field = 'rev_id' ) {
|
|
|
|
|
$fname = 'Article::fetchRevisionText';
|
|
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
|
|
|
|
if( $revId ) {
|
|
|
|
|
$rev = $dbw->addQuotes( $revId );
|
|
|
|
|
} else {
|
|
|
|
|
$rev = 'page_latest';
|
|
|
|
|
}
|
|
|
|
|
$result = $dbw->query(
|
|
|
|
|
sprintf( "SELECT old_text, old_flags
|
|
|
|
|
FROM %s,%s,%s
|
|
|
|
|
WHERE old_id=rev_id AND rev_page=page_id AND page_id=%d
|
|
|
|
|
AND %s=%s",
|
|
|
|
|
$dbw->tableName( 'page' ),
|
|
|
|
|
$dbw->tableName( 'revision' ),
|
|
|
|
|
$dbw->tableName( 'text' ),
|
|
|
|
|
IntVal( $this->mTitle->getArticleId() ),
|
|
|
|
|
$field,
|
|
|
|
|
$rev ),
|
|
|
|
|
$fname );
|
|
|
|
|
$obj = $dbw->fetchObject( $result );
|
|
|
|
|
$dbw->freeResult( $result );
|
2004-12-19 12:21:29 +00:00
|
|
|
$oldtext = Revision::getRevisionText( $obj );
|
2004-12-19 08:00:50 +00:00
|
|
|
return $oldtext;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-19 20:58:10 +00:00
|
|
|
function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
|
2004-09-22 16:20:34 +00:00
|
|
|
$fname = 'Article::getTextOfLastEditWithSectionReplacedOrAdded';
|
2004-12-19 08:00:50 +00:00
|
|
|
if( is_null( $edittime ) ) {
|
|
|
|
|
$oldtext = $this->fetchRevisionText();
|
2004-09-19 20:58:10 +00:00
|
|
|
} else {
|
2004-12-19 08:00:50 +00:00
|
|
|
$oldtext = $this->fetchRevisionText( $edittime, 'rev_timestamp' );
|
2004-09-19 20:58:10 +00:00
|
|
|
}
|
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-08-24 18:04:37 +00:00
|
|
|
$secs=preg_split('/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/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-08-24 18:04:37 +00:00
|
|
|
preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/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-08-24 18:04:37 +00:00
|
|
|
'/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/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-09-02 23:28:24 +00:00
|
|
|
/**
|
2004-09-11 11:39:24 +00:00
|
|
|
* Change an existing article. Puts the previous version back into the old table, updates RC
|
|
|
|
|
* and all necessary caches, mostly via the deferred update array.
|
|
|
|
|
*
|
|
|
|
|
* It is possible to call this function from a command-line script, but note that you should
|
|
|
|
|
* first set $wgUser, and clean up $wgDeferredUpdates after each edit.
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
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-09-11 11:39:24 +00:00
|
|
|
if ( $this->isRedirect( $text ) ) {
|
|
|
|
|
# Remove all content but redirect
|
|
|
|
|
# This could be done by reconstructing the redirect from a title given by
|
|
|
|
|
# Title::newFromRedirect(), but then we wouldn't know which synonym the user
|
|
|
|
|
# wants to see
|
|
|
|
|
if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ')[^\\n]+)/i', $text, $m ) ) {
|
|
|
|
|
$redir = 1;
|
|
|
|
|
$text = $m[1] . "\n";
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
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-12-19 08:00:50 +00:00
|
|
|
$mungedText = $text;
|
2005-02-08 13:41:07 +00:00
|
|
|
$flags = Revision::compressRevisionText( $mungedText );
|
2004-12-19 08:00:50 +00:00
|
|
|
|
|
|
|
|
$lastRevision = $dbw->selectField(
|
|
|
|
|
'page', 'page_latest', array( 'page_id' => $this->getId() ) );
|
|
|
|
|
|
|
|
|
|
# Record the text to the text table
|
|
|
|
|
$old_id = $dbw->nextSequenceValue( 'text_old_id_val' );
|
|
|
|
|
$dbw->insert( 'text',
|
|
|
|
|
array(
|
|
|
|
|
'old_id' => $old_id,
|
|
|
|
|
'old_text' => $mungedText,
|
|
|
|
|
'old_flags' => $flags,
|
|
|
|
|
), $fname
|
|
|
|
|
);
|
|
|
|
|
$revisionId = $dbw->insertId();
|
|
|
|
|
|
|
|
|
|
# Record the edit in revisions
|
|
|
|
|
$dbw->insert( 'revision',
|
|
|
|
|
array(
|
|
|
|
|
'rev_id' => $revisionId,
|
|
|
|
|
'rev_page' => $this->getID(),
|
|
|
|
|
'rev_comment' => $summary,
|
|
|
|
|
'rev_minor_edit' => $me2,
|
|
|
|
|
'rev_user' => $wgUser->getID(),
|
|
|
|
|
'rev_user_text' => $wgUser->getName(),
|
|
|
|
|
'rev_timestamp' => $dbw->timestamp( $now ),
|
2004-07-10 03:09:26 +00:00
|
|
|
'inverse_timestamp' => $won
|
2004-12-19 08:00:50 +00:00
|
|
|
), $fname
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# Update page
|
|
|
|
|
$dbw->update( 'page',
|
|
|
|
|
array( /* SET */
|
|
|
|
|
'page_latest' => $revisionId,
|
|
|
|
|
'page_touched' => $dbw->timestamp( $now ),
|
|
|
|
|
'page_is_new' => 0,
|
|
|
|
|
'page_is_redirect' => $redir,
|
2004-07-10 03:09:26 +00:00
|
|
|
), array( /* WHERE */
|
2004-12-19 08:00:50 +00:00
|
|
|
'page_id' => $this->getID(),
|
|
|
|
|
'page_latest' => $lastRevision, # Paranoia
|
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-12-19 08:00:50 +00:00
|
|
|
# Update recentchanges and purge cache and whatnot
|
2004-07-10 03:09:26 +00:00
|
|
|
$bot = (int)($wgUser->isBot() || $forceBot);
|
2004-08-09 05:38:11 +00:00
|
|
|
RecentChange::notifyEdit( $now, $this->mTitle, $me2, $wgUser, $summary,
|
2004-12-19 08:00:50 +00:00
|
|
|
$lastRevision, $this->getTimestamp(), $bot );
|
2004-07-10 03:09:26 +00:00
|
|
|
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
|
2004-12-18 03:47:11 +00:00
|
|
|
$this->editUpdates( $text, $summary, $minor, $now );
|
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
|
|
|
|
2005-01-22 10:14:23 +00:00
|
|
|
$this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $me2, $now, $summary, $lastRevision );
|
2004-07-10 03:09:26 +00:00
|
|
|
}
|
|
|
|
|
return $good;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* After we've either updated or inserted the article, update
|
|
|
|
|
* the link tables and redirect to the new page.
|
|
|
|
|
*/
|
2004-12-18 03:47:11 +00:00
|
|
|
function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
|
|
|
|
|
global $wgOut, $wgUser, $wgLinkCache, $wgEnotif;
|
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
|
|
|
|
2004-09-11 11:39:24 +00:00
|
|
|
if( $this->isRedirect( $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 );
|
2004-12-18 03:47:11 +00:00
|
|
|
|
|
|
|
|
# this call would better fit into RecentChange::notifyEdit and RecentChange::notifyNew .
|
|
|
|
|
# this will be improved later (to-do)
|
|
|
|
|
|
|
|
|
|
include_once( "UserMailer.php" );
|
|
|
|
|
$wgEnotif = new EmailNotification ();
|
|
|
|
|
$wgEnotif->NotifyOnPageChange( $wgUser->getID(), $this->mTitle->getDBkey(), $this->mTitle->getNamespace(),$now, $summary, $me2, $oldid );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +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;
|
|
|
|
|
}
|
2004-10-24 19:14:48 +00:00
|
|
|
if ( $wgOnlySysopsCanPatrol && !$wgUser->isAllowed('patrol') )
|
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' ) );
|
2004-12-12 05:07:09 +00:00
|
|
|
|
|
|
|
|
$rcTitle = Title::makeTitle( NS_SPECIAL, 'Recentchanges' );
|
|
|
|
|
$wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
|
2004-08-09 05:38:11 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2004-11-30 05:45:56 +00:00
|
|
|
* Add this page to $wgUser's watchlist
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-11-30 05:45:56 +00:00
|
|
|
|
|
|
|
|
function watch() {
|
|
|
|
|
|
2004-09-24 13:14:52 +00:00
|
|
|
global $wgUser, $wgOut;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-30 05:45:56 +00:00
|
|
|
if (wfRunHooks('WatchArticle', $wgUser, $this)) {
|
|
|
|
|
|
|
|
|
|
$wgUser->addWatch( $this->mTitle );
|
|
|
|
|
$wgUser->saveSettings();
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-11-30 05:45:56 +00:00
|
|
|
wfRunHooks('WatchArticleComplete', $wgUser, $this);
|
|
|
|
|
|
|
|
|
|
$wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
|
|
|
|
|
$wgOut->setRobotpolicy( 'noindex,follow' );
|
|
|
|
|
|
|
|
|
|
$link = $this->mTitle->getPrefixedText();
|
2004-06-08 19:51:10 +00:00
|
|
|
$text = wfMsg( 'addedwatchtext', $link );
|
2004-11-30 05:45:56 +00:00
|
|
|
$wgOut->addWikiText( $text );
|
|
|
|
|
}
|
2004-11-29 05:52:26 +00:00
|
|
|
|
2004-08-06 05:51:09 +00:00
|
|
|
$wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2004-11-30 05:45:56 +00:00
|
|
|
* Stop watching a page
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-11-30 05:45:56 +00:00
|
|
|
|
2004-08-12 14:27:38 +00:00
|
|
|
function unwatch() {
|
2004-11-30 05:45:56 +00:00
|
|
|
|
|
|
|
|
global $wgUser, $wgOut;
|
|
|
|
|
|
|
|
|
|
if ( 0 == $wgUser->getID() ) {
|
|
|
|
|
$wgOut->errorpage( 'watchnologin', 'watchnologintext' );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( wfReadOnly() ) {
|
|
|
|
|
$wgOut->readOnlyPage();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (wfRunHooks('UnwatchArticle', $wgUser, $this)) {
|
|
|
|
|
|
|
|
|
|
$wgUser->removeWatch( $this->mTitle );
|
|
|
|
|
$wgUser->saveSettings();
|
|
|
|
|
|
|
|
|
|
wfRunHooks('UnwatchArticleComplete', $wgUser, $this);
|
|
|
|
|
|
|
|
|
|
$wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
|
|
|
|
|
$wgOut->setRobotpolicy( 'noindex,follow' );
|
|
|
|
|
|
|
|
|
|
$link = $this->mTitle->getPrefixedText();
|
|
|
|
|
$text = wfMsg( 'removedwatchtext', $link );
|
|
|
|
|
$wgOut->addWikiText( $text );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* protect a page
|
|
|
|
|
*/
|
2004-08-12 14:27:38 +00:00
|
|
|
function protect( $limit = 'sysop' ) {
|
2004-04-21 16:17:49 +00:00
|
|
|
global $wgUser, $wgOut, $wgRequest;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-10-24 19:14:48 +00:00
|
|
|
if ( ! $wgUser->isAllowed('protect') ) {
|
2003-04-14 23:10:40 +00:00
|
|
|
$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();
|
2004-11-24 12:55:48 +00:00
|
|
|
$moveonly = $wgRequest->getBool( 'wpMoveOnly' );
|
2004-04-21 16:17:49 +00:00
|
|
|
$reason = $wgRequest->getText( 'wpReasonProtect' );
|
|
|
|
|
|
|
|
|
|
if ( $confirm ) {
|
2004-12-19 08:00:50 +00:00
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
|
|
|
|
$dbw->update( 'page',
|
|
|
|
|
array( /* SET */
|
|
|
|
|
'page_touched' => $dbw->timestamp(),
|
|
|
|
|
'page_restrictions' => (string)$limit
|
|
|
|
|
), array( /* WHERE */
|
|
|
|
|
'page_id' => $id
|
|
|
|
|
), 'Article::protect'
|
|
|
|
|
);
|
2004-11-28 00:20:37 +00:00
|
|
|
|
2004-11-24 12:55:48 +00:00
|
|
|
$restrictions = "move=" . $limit;
|
|
|
|
|
if( !$moveonly ) {
|
|
|
|
|
$restrictions .= ":edit=" . $limit;
|
|
|
|
|
}
|
2004-11-28 00:20:37 +00:00
|
|
|
if (wfRunHooks('ArticleProtect', $this, $wgUser, $limit == 'sysop', $reason, $moveonly)) {
|
|
|
|
|
|
|
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
2004-12-28 14:49:42 +00:00
|
|
|
$dbw->update( 'page',
|
2004-11-28 00:20:37 +00:00
|
|
|
array( /* SET */
|
2004-12-28 14:49:42 +00:00
|
|
|
'page_touched' => $dbw->timestamp(),
|
|
|
|
|
'page_restrictions' => $restrictions
|
2004-11-28 00:20:37 +00:00
|
|
|
), array( /* WHERE */
|
2004-12-28 14:49:42 +00:00
|
|
|
'page_id' => $id
|
2004-11-28 00:20:37 +00:00
|
|
|
), 'Article::protect'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
wfRunHooks('ArticleProtectComplete', $this, $wgUser, $limit == 'sysop', $reason, $moveonly);
|
|
|
|
|
|
|
|
|
|
$log = new LogPage( 'protect' );
|
|
|
|
|
if ( $limit === '' ) {
|
2004-08-24 08:11:46 +00:00
|
|
|
$log->addEntry( 'unprotect', $this->mTitle, $reason );
|
2004-11-28 00:20:37 +00:00
|
|
|
} else {
|
2004-08-24 08:11:46 +00:00
|
|
|
$log->addEntry( 'protect', $this->mTitle, $reason );
|
2004-11-28 00:20:37 +00:00
|
|
|
}
|
|
|
|
|
$wgOut->redirect( $this->mTitle->getFullURL() );
|
2004-07-08 14:53:54 +00:00
|
|
|
}
|
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-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Output protection confirmation dialog
|
|
|
|
|
*/
|
2004-08-12 14:27:38 +00:00
|
|
|
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-11-24 12:55:48 +00:00
|
|
|
$moveonly = '';
|
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' ) );
|
2004-11-24 12:55:48 +00:00
|
|
|
$moveonly = htmlspecialchars( wfMsg( 'protectmoveonly' ) );
|
2004-06-08 19:51:10 +00:00
|
|
|
$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>
|
2004-11-24 12:55:48 +00:00
|
|
|
</tr> " );
|
|
|
|
|
if($moveonly != '') {
|
|
|
|
|
$wgOut->AddHTML( "
|
|
|
|
|
<tr>
|
|
|
|
|
<td align='right'>
|
|
|
|
|
<input type='checkbox' name='wpMoveOnly' value='1' id='wpMoveOnly' />
|
|
|
|
|
</td>
|
|
|
|
|
<td>
|
|
|
|
|
<label for='wpMoveOnly'>{$moveonly}</label>
|
|
|
|
|
</td>
|
|
|
|
|
</tr> " );
|
|
|
|
|
}
|
|
|
|
|
$wgOut->addHTML( "
|
2004-04-21 16:17:49 +00:00
|
|
|
<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-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Unprotect the pages
|
|
|
|
|
*/
|
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-09-02 23:28:24 +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
|
2004-10-24 19:14:48 +00:00
|
|
|
if ( ( ! $wgUser->isAllowed('delete') ) ) {
|
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();
|
2005-01-30 19:46:48 +00:00
|
|
|
$revisions = $dbr->select( array( 'page', 'revision' ),
|
|
|
|
|
array( 'rev_id' ),
|
2004-09-26 19:49:44 +00:00
|
|
|
array(
|
2005-01-30 19:46:48 +00:00
|
|
|
'page_namespace' => $ns,
|
|
|
|
|
'page_title' => $title,
|
|
|
|
|
'rev_page = page_id'
|
2004-09-26 19:49:44 +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
|
|
|
|
2005-01-30 19:46:48 +00:00
|
|
|
if( $dbr->numRows( $revisions ) > 1 && !$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
|
2005-01-30 19:46:48 +00:00
|
|
|
$s = $dbr->selectRow( array( 'page', 'text' ),
|
|
|
|
|
array( 'old_text' ),
|
2004-08-09 05:38:11 +00:00
|
|
|
array(
|
2005-01-30 19:46:48 +00:00
|
|
|
'page_namespace' => $ns,
|
|
|
|
|
'page_title' => $title,
|
|
|
|
|
'page_latest = old_id'
|
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;
|
2005-01-30 19:46:48 +00:00
|
|
|
if($s->old_text != '') {
|
|
|
|
|
$text=$s->old_text;
|
2003-09-01 09:59:53 +00:00
|
|
|
} else {
|
2005-01-30 19:46:48 +00:00
|
|
|
if($old) { # TODO
|
2004-12-19 12:21:29 +00:00
|
|
|
$text = Revision::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-09-02 23:28:24 +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-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Perform a deletion and output success or failure messages
|
|
|
|
|
*/
|
2004-08-12 14:27:38 +00:00
|
|
|
function doDelete( $reason ) {
|
2004-09-24 13:14:52 +00:00
|
|
|
global $wgOut, $wgUser, $wgContLang;
|
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-11-28 06:15:22 +00:00
|
|
|
if (wfRunHooks('ArticleDelete', $this, $wgUser, $reason)) {
|
|
|
|
|
if ( $this->doDeleteArticle( $reason ) ) {
|
|
|
|
|
$deleted = $this->mTitle->getPrefixedText();
|
|
|
|
|
|
|
|
|
|
$wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
|
|
|
|
|
$wgOut->setRobotpolicy( 'noindex,nofollow' );
|
|
|
|
|
|
|
|
|
|
$sk = $wgUser->getSkin();
|
|
|
|
|
$loglink = $sk->makeKnownLink( $wgContLang->getNsText( NS_PROJECT ) .
|
|
|
|
|
':' . wfMsgForContent( 'dellogpage' ),
|
|
|
|
|
wfMsg( 'deletionlog' ) );
|
|
|
|
|
|
|
|
|
|
$text = wfMsg( 'deletedtext', $deleted, $loglink );
|
|
|
|
|
|
|
|
|
|
$wgOut->addHTML( '<p>' . $text . "</p>\n" );
|
|
|
|
|
$wgOut->returnToMain( false );
|
|
|
|
|
wfRunHooks('ArticleDeleteComplete', $this, $wgUser, $reason);
|
|
|
|
|
} else {
|
|
|
|
|
$wgOut->fatalError( wfMsg( 'cannotdelete' ) );
|
|
|
|
|
}
|
2004-03-20 15:03:26 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +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-09-24 13:14:52 +00:00
|
|
|
global $wgUser;
|
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-08-09 05:38:11 +00:00
|
|
|
|
2005-01-30 19:46:48 +00:00
|
|
|
$dbw->insertSelect( 'archive', array( 'page','revision', 'text' ),
|
2004-07-10 03:09:26 +00:00
|
|
|
array(
|
2005-01-30 19:46:48 +00:00
|
|
|
'ar_namespace' => 'page_namespace',
|
|
|
|
|
'ar_title' => 'page_title',
|
2004-07-10 03:09:26 +00:00
|
|
|
'ar_text' => 'old_text',
|
2005-01-30 19:46:48 +00:00
|
|
|
'ar_comment' => 'rev_comment',
|
|
|
|
|
'ar_user' => 'rev_user',
|
|
|
|
|
'ar_user_text' => 'rev_user_text',
|
|
|
|
|
'ar_timestamp' => 'rev_timestamp',
|
|
|
|
|
'ar_minor_edit' => 'rev_minor_edit',
|
|
|
|
|
'ar_flags' => 0,
|
2004-07-10 03:09:26 +00:00
|
|
|
), array(
|
2005-01-30 19:46:48 +00:00
|
|
|
'page_namespace' => $ns,
|
|
|
|
|
'page_title' => $t,
|
|
|
|
|
'page_id = rev_page AND old_id = rev_id'
|
2004-07-10 03:09:26 +00:00
|
|
|
), $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
|
|
|
|
|
|
2005-01-30 19:46:48 +00:00
|
|
|
$dbw->deleteJoin( 'text', 'revision', 'old_id', 'rev_id', array( "rev_page = {$id}" ), $fname );
|
|
|
|
|
$dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
|
|
|
|
|
$dbw->delete( 'page', array( 'page_id' => $id ), $fname);
|
|
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
$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-10-24 07:10:33 +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-08-24 08:11:46 +00:00
|
|
|
$log = new LogPage( 'delete' );
|
|
|
|
|
$log->addEntry( 'delete', $this->mTitle, $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-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Revert a modification
|
|
|
|
|
*/
|
2004-08-12 14:27:38 +00:00
|
|
|
function rollback() {
|
2004-09-24 13:14:52 +00:00
|
|
|
global $wgUser, $wgOut, $wgRequest;
|
2004-08-22 17:24:50 +00:00
|
|
|
$fname = 'Article::rollback';
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-10-24 19:14:48 +00:00
|
|
|
if ( ! $wgUser->isAllowed('rollback') ) {
|
2003-04-14 23:10:40 +00:00
|
|
|
$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
|
2005-01-30 19:46:48 +00:00
|
|
|
$s = $dbw->selectRow( array( 'page', 'revision' ),
|
|
|
|
|
array( 'page_id','rev_user','rev_user_text','rev_comment' ),
|
|
|
|
|
array( 'page_title' => $tt, 'page_namespace' => $n ),
|
2004-07-10 03:09:26 +00:00
|
|
|
$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 );
|
2005-01-30 19:46:48 +00:00
|
|
|
$uid = $s->rev_user;
|
|
|
|
|
$pid = $s->page_id;
|
2004-07-08 14:53:54 +00:00
|
|
|
|
2004-06-08 19:51:10 +00:00
|
|
|
$from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
|
2005-01-30 19:46:48 +00:00
|
|
|
if( $from != $s->rev_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 ),
|
2005-01-30 19:46:48 +00:00
|
|
|
htmlspecialchars( $s->rev_user_text ) ) );
|
|
|
|
|
if($s->rev_comment != '') {
|
2003-05-25 07:56:08 +00:00
|
|
|
$wgOut->addHTML(
|
2004-06-08 19:51:10 +00:00
|
|
|
wfMsg('editcomment',
|
2005-01-30 19:46:48 +00:00
|
|
|
htmlspecialchars( $s->rev_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-10-24 07:10:33 +00:00
|
|
|
$s = $dbw->selectRow( '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(
|
2004-09-26 19:49:44 +00:00
|
|
|
'old_namespace' => $n,
|
|
|
|
|
'old_title' => $tt,
|
2004-07-10 03:09:26 +00:00
|
|
|
"old_user <> {$uid} OR old_user_text <> '{$ut}'"
|
2004-09-26 19:49:44 +00:00
|
|
|
), $fname, array( 'FOR UPDATE', 'USE INDEX' => 'name_title_timestamp' )
|
2004-07-10 03:09:26 +00:00
|
|
|
);
|
|
|
|
|
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-10-24 07:10:33 +00:00
|
|
|
$dbw->update( 'recentchanges',
|
2004-08-09 05:38:11 +00:00
|
|
|
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' );
|
2004-10-14 04:50:14 +00:00
|
|
|
$wgOut->addHTML( '<h2>' . htmlspecialchars( $newcomment ) . "</h2>\n<hr />\n" );
|
2004-12-19 12:21:29 +00:00
|
|
|
$this->updateArticle( Revision::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
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Do standard deferred updates after page view
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function viewUpdates() {
|
2003-09-01 08:30:14 +00:00
|
|
|
global $wgDeferredUpdateList;
|
2004-11-29 17:36:13 +00:00
|
|
|
|
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-11-29 17:36:13 +00:00
|
|
|
|
|
|
|
|
# Update newtalk status if user is reading their own
|
|
|
|
|
# talk page
|
|
|
|
|
|
|
|
|
|
global $wgUser;
|
|
|
|
|
if ($this->mTitle->getNamespace() == NS_USER_TALK &&
|
2004-12-18 03:47:11 +00:00
|
|
|
$this->mTitle->getText() == $wgUser->getName()) {
|
|
|
|
|
require_once( 'UserTalkUpdate.php' );
|
|
|
|
|
$u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(), $this->mTitle->getDBkey(), false, false, false );
|
2004-11-29 17:36:13 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Do standard deferred updates after page edit.
|
|
|
|
|
* Every 1000th edit, prune the recent changes table.
|
|
|
|
|
* @private
|
2004-09-03 00:20:26 +00:00
|
|
|
* @param string $text
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-12-18 03:47:11 +00:00
|
|
|
function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange) {
|
2004-01-31 16:59:08 +00:00
|
|
|
global $wgDeferredUpdateList, $wgDBname, $wgMemc;
|
2004-11-29 17:36:13 +00:00
|
|
|
global $wgMessageCache, $wgUser;
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-01-31 16:59:08 +00:00
|
|
|
wfSeedRandom();
|
|
|
|
|
if ( 0 == mt_rand( 0, 999 ) ) {
|
2005-01-19 03:54:43 +00:00
|
|
|
# Periodically flush old entries from the recentchanges table.
|
|
|
|
|
global $wgRCMaxAge;
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
2005-01-19 03:54:43 +00:00
|
|
|
$cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
|
2005-02-06 11:37:16 +00:00
|
|
|
$recentchanges = $dbw->tableName( 'recentchanges' );
|
|
|
|
|
$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 );
|
|
|
|
|
|
2004-12-18 03:47:11 +00:00
|
|
|
# If this is another user's talk page,
|
|
|
|
|
# create a watchlist entry for this page
|
2004-11-29 17:36:13 +00:00
|
|
|
|
|
|
|
|
if ($this->mTitle->getNamespace() == NS_USER_TALK &&
|
2004-12-18 03:47:11 +00:00
|
|
|
$shortTitle != $wgUser->getName()) {
|
|
|
|
|
require_once( 'UserTalkUpdate.php' );
|
|
|
|
|
$u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle, $summary, $minoredit, $timestamp_of_pagechange);
|
2004-11-29 17:36:13 +00:00
|
|
|
}
|
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-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* @todo document this function
|
|
|
|
|
* @private
|
2004-10-02 21:36:36 +00:00
|
|
|
* @param string $oldid Revision ID of this article revision
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-10-02 21:36:36 +00:00
|
|
|
function setOldSubtitle( $oldid=0 ) {
|
2004-09-01 03:01:37 +00:00
|
|
|
global $wgLang, $wgOut, $wgUser;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
$td = $wgLang->timeanddate( $this->mTimestamp, true );
|
2004-09-01 03:01:37 +00:00
|
|
|
$sk = $wgUser->getSkin();
|
2004-09-01 21:53:50 +00:00
|
|
|
$lnk = $sk->makeKnownLinkObj ( $this->mTitle, wfMsg( 'currentrevisionlink' ) );
|
2004-10-02 21:36:36 +00:00
|
|
|
$prevlink = $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid );
|
|
|
|
|
$nextlink = $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
|
|
|
|
|
$r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
|
2004-09-01 03:01:37 +00:00
|
|
|
$wgOut->setSubtitle( $r );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* This function is called right before saving the wikitext,
|
|
|
|
|
* so we can do things like signatures and links-in-context.
|
2004-09-03 00:20:26 +00:00
|
|
|
*
|
|
|
|
|
* @param string $text
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
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-09-03 00:20:26 +00:00
|
|
|
/**
|
|
|
|
|
* checkLastModified returns true if it has taken care of all
|
|
|
|
|
* 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;
|
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" );
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-09-03 00:20:26 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the page can be cached
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2003-05-16 13:39:22 +00:00
|
|
|
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-09-03 00:20:26 +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-12-19 08:00:50 +00:00
|
|
|
$s = $dbr->selectRow( 'page', array( 'page_touched', 'page_is_redirect' ),
|
|
|
|
|
array( 'page_id' => $id ), $fname, $this->getSelectOptions() );
|
2004-07-10 03:09:26 +00:00
|
|
|
if( $s !== false ) {
|
2004-12-19 08:00:50 +00:00
|
|
|
$this->mTouched = wfTimestamp( TS_MW, $s->page_touched );
|
|
|
|
|
return !$s->page_is_redirect;
|
2003-11-09 11:45:12 +00:00
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-05-27 15:24:04 +00:00
|
|
|
|
2004-09-03 00:20:26 +00:00
|
|
|
/**
|
|
|
|
|
* Edit an article without doing all that other stuff
|
|
|
|
|
*
|
|
|
|
|
* @param string $text text submitted
|
|
|
|
|
* @param string $comment comment submitted
|
|
|
|
|
* @param integer $minor whereas it's a minor modification
|
|
|
|
|
*/
|
2004-06-08 19:51:10 +00:00
|
|
|
function quickEdit( $text, $comment = '', $minor = 0 ) {
|
2004-09-11 11:39:24 +00:00
|
|
|
global $wgUser;
|
2004-06-08 19:51:10 +00:00
|
|
|
$fname = 'Article::quickEdit';
|
2004-12-19 08:00:50 +00:00
|
|
|
|
|
|
|
|
#wfDebugDieBacktrace( "$fname called." );
|
|
|
|
|
|
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 );
|
2005-02-09 13:27:31 +00:00
|
|
|
$timestamp = $dbw->timestamp();
|
2004-12-19 08:00:50 +00:00
|
|
|
# insert new text
|
|
|
|
|
$dbw->insert( 'text', array(
|
|
|
|
|
'old_text' => $text,
|
|
|
|
|
'old_flags' => "" ), $fname );
|
|
|
|
|
$text_id = $dbw->insertID();
|
|
|
|
|
|
|
|
|
|
# update page
|
|
|
|
|
$dbw->update( 'page', array(
|
|
|
|
|
'page_is_new' => 0,
|
|
|
|
|
'page_touched' => $timestamp,
|
|
|
|
|
'page_is_redirect' => $this->isRedirect( $text ) ? 1 : 0,
|
|
|
|
|
'page_latest' => $text_id ),
|
|
|
|
|
array( 'page_namespace' => $ns, 'page_title' => $dbkey ), $fname );
|
|
|
|
|
# Retrieve page ID
|
|
|
|
|
$page_id = $dbw->selectField( 'page', 'page_id', array( 'page_namespace' => $ns, 'page_title' => $dbkey ), $fname );
|
|
|
|
|
|
|
|
|
|
# update revision
|
|
|
|
|
$dbw->insert( 'revision', array(
|
|
|
|
|
'rev_id' => $text_id,
|
|
|
|
|
'rev_page' => $page_id,
|
|
|
|
|
'rev_comment' => $comment,
|
|
|
|
|
'rev_user' => $wgUser->getID(),
|
|
|
|
|
'rev_user_text' => $wgUser->getName(),
|
|
|
|
|
'rev_timestamp' => $timestamp,
|
|
|
|
|
'inverse_timestamp' => wfInvertTimestamp( $timestamp ),
|
|
|
|
|
'rev_minor_edit' => intval($minor) ),
|
|
|
|
|
$fname );
|
2004-06-02 13:14:40 +00:00
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-03 00:20:26 +00:00
|
|
|
/**
|
|
|
|
|
* Used to increment the view counter
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @param integer $id article id
|
|
|
|
|
*/
|
|
|
|
|
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-12-19 08:00:50 +00:00
|
|
|
$pageTable = $dbw->tableName( 'page' );
|
2004-07-10 03:09:26 +00:00
|
|
|
$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-12-19 08:00:50 +00:00
|
|
|
$dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_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
|
|
|
|
2004-09-03 00:20:26 +00:00
|
|
|
/**#@+
|
2004-09-02 23:28:24 +00:00
|
|
|
* The onArticle*() functions are supposed to be a kind of hooks
|
|
|
|
|
* which should be called whenever any of the specified actions
|
|
|
|
|
* are done.
|
|
|
|
|
*
|
|
|
|
|
* This is a good place to put code to clear caches, for instance.
|
|
|
|
|
*
|
|
|
|
|
* This is called on page move and undelete, as well as edit
|
|
|
|
|
* @static
|
|
|
|
|
* @param $title_obj a title object
|
|
|
|
|
*/
|
2004-09-03 00:20:26 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
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-09-02 23:28:24 +00:00
|
|
|
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-09-02 23:28:24 +00:00
|
|
|
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-09-03 00:20:26 +00:00
|
|
|
/**#@-*/
|
2004-08-12 14:27:38 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Info about this page
|
|
|
|
|
*/
|
2004-08-12 14:27:38 +00:00
|
|
|
function info() {
|
2004-09-24 13:14:52 +00:00
|
|
|
global $wgUser, $wgTitle, $wgOut, $wgAllowPageInfo;
|
2004-07-18 08:48:43 +00:00
|
|
|
$fname = 'Article::info';
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2005-01-30 19:46:48 +00:00
|
|
|
wfDebugDieBacktrace( 'This function is apparently not called by any other PHP file and might be obsolete.' );
|
|
|
|
|
|
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 );
|
2004-09-26 19:49:44 +00:00
|
|
|
$old_clause = array( 'old_title' => $wgTitle->getDBkey(), 'old_namespace' => $basenamespace );
|
2004-07-18 08:48:43 +00:00
|
|
|
$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-09-01 02:57:26 +00:00
|
|
|
$numwatchers = $dbr->selectField( 'watchlist', 'COUNT(*)', $wl_clause, $fname,
|
2004-08-20 14:59:49 +00:00
|
|
|
$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-09-01 02:57:26 +00:00
|
|
|
$cur_author = $dbr->selectField( 'cur', 'cur_user_text', $cur_clause, $fname,
|
2004-08-20 14:59:49 +00:00
|
|
|
$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 );
|
2004-09-26 19:49:44 +00:00
|
|
|
$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-09-01 02:57:26 +00:00
|
|
|
$old_clause + array( 'old_user_text<>' . $dbr->addQuotes( $cur_author ) ),
|
2004-08-20 14:59:49 +00:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
2004-12-19 08:00:50 +00:00
|
|
|
/**
|
|
|
|
|
* Check whether an article is a stub
|
|
|
|
|
*
|
|
|
|
|
* @public
|
|
|
|
|
* @param integer $articleID ID of the article that is to be checked
|
|
|
|
|
*/
|
|
|
|
|
function wfArticleIsStub( $articleID ) {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
$fname = 'wfArticleIsStub';
|
|
|
|
|
|
2005-01-30 19:46:48 +00:00
|
|
|
wfDebugDieBacktrace( 'This function seems to be unused. Pending removal.' );
|
|
|
|
|
|
2004-12-19 08:00:50 +00:00
|
|
|
$threshold = $wgUser->getOption('stubthreshold') ;
|
|
|
|
|
if ( $threshold > 0 ) {
|
|
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
|
|
|
|
$s = $dbr->selectRow( array('page', 'text'),
|
|
|
|
|
array( 'LENGTH(old_text) AS len', 'page_namespace', 'page_is_redirect' ),
|
|
|
|
|
array( 'page_id' => $articleID, "page.page_latest=text.old_id" ),
|
|
|
|
|
$fname ) ;
|
2005-01-11 18:18:16 +00:00
|
|
|
if ( $s == false OR $s->page_is_redirect OR $s->page_namespace != NS_MAIN ) {
|
2004-12-19 08:00:50 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$size = $s->len;
|
|
|
|
|
return ( $size < $threshold );
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
?>
|