/**@{{
* @private
*/
- var $mComment = ''; // !<
+ protected $mContext; // !< RequestContext
+
var $mContent; // !<
var $mContentLoaded = false; // !<
var $mCounter = -1; // !< Not loaded
var $mGoodAdjustment = 0; // !<
var $mIsRedirect = false; // !<
var $mLatest = false; // !<
- var $mMinorEdit; // !<
var $mOldId; // !<
var $mPreparedEdit = false; // !< Title object if set
var $mRedirectedFrom = null; // !< Title object if set
var $mRedirectTarget = null; // !< Title object if set
var $mRedirectUrl = false; // !<
var $mRevIdFetched = 0; // !<
- var $mRevision = null; // !< Revision object if set
+ var $mLastRevision = null; // !< Latest revision if set
+ var $mRevision = null; // !< Loaded revision object if set
var $mTimestamp = ''; // !<
var $mTitle; // !< Title object
var $mTotalAdjustment = 0; // !<
var $mTouched = '19700101000000'; // !<
- var $mUser = -1; // !< Not loaded
- var $mUserText = ''; // !< username from Revision if set
- var $mParserOptions; // !< ParserOptions object for $wgUser articles
+ var $mParserOptions; // !< ParserOptions object
var $mParserOutput; // !< ParserCache object if set
/**@}}*/
*
* @param $text string article content containing redirect info
* @return mixed false, Title of in-wiki target, or string with URL
- * @deprecated @since 1.17
+ * @deprecated since 1.17
*/
public function followRedirectText( $text ) {
// recurse through to only get the final target
$this->mDataLoaded = false;
$this->mContentLoaded = false;
- $this->mUser = $this->mCounter = -1; # Not loaded
+ $this->mCounter = -1; # Not loaded
$this->mRedirectedFrom = null; # Title object if set
$this->mRedirectTarget = null; # Title object if set
- $this->mUserText =
- $this->mTimestamp = $this->mComment = '';
+ $this->mLastRevision = null; # Latest revision
+ $this->mTimestamp = '';
$this->mGoodAdjustment = $this->mTotalAdjustment = 0;
$this->mTouched = '19700101000000';
$this->mForUpdate = false;
wfProfileOut( __METHOD__ );
}
+ /**
+ * Return the list of revision fields that should be selected to create
+ * a new page.
+ */
+ public static function selectFields() {
+ return array(
+ 'page_id',
+ 'page_namespace',
+ 'page_title',
+ 'page_restrictions',
+ 'page_counter',
+ 'page_is_redirect',
+ 'page_is_new',
+ 'page_random',
+ 'page_touched',
+ 'page_latest',
+ 'page_len',
+ );
+ }
+
/**
* Fetch a page record with the given conditions
* @param $dbr Database object
* @return mixed Database result resource, or false on failure
*/
protected function pageData( $dbr, $conditions ) {
- $fields = array(
- 'page_id',
- 'page_namespace',
- 'page_title',
- 'page_restrictions',
- 'page_counter',
- 'page_is_redirect',
- 'page_is_new',
- 'page_random',
- 'page_touched',
- 'page_latest',
- 'page_len',
- );
+ $fields = self::selectFields();
wfRunHooks( 'ArticlePageDataBefore', array( &$this, &$fields ) );
* @param $title Title object
* @return mixed Database result resource, or false on failure
*/
- public function pageDataFromTitle( $dbr, $title ) {
+ protected function pageDataFromTitle( $dbr, $title ) {
return $this->pageData( $dbr, array(
'page_namespace' => $title->getNamespace(),
'page_title' => $title->getDBkey() ) );
*
* @param $dbr Database
* @param $id Integer
+ * @return mixed Database result resource, or false on failure
*/
protected function pageDataFromId( $dbr, $id ) {
return $this->pageData( $dbr, array( 'page_id' => $id ) );
/**
* Read/write accessor to select FOR UPDATE
+ * @FIXME: remove, does nothing
*
* @param $x Mixed: FIXME
* @return mixed value of $x, or value stored in Article::mForUpdate
*/
public function forUpdate( $x = null ) {
+ wfDeprecated();
return wfSetVar( $this->mForUpdate, $x );
}
- /**
- * Get options for all SELECT statements
- *
- * @param $options Array: an optional options array which'll be appended to
- * the default
- * @return Array: options
- */
- protected function getSelectOptions( $options = '' ) {
- if ( $this->mForUpdate ) {
- if ( is_array( $options ) ) {
- $options[] = 'FOR UPDATE';
- } else {
- $options = 'FOR UPDATE';
- }
- }
-
- return $options;
- }
-
/**
* @return int Page ID
*/
$this->mCounter = $dbr->selectField( 'page',
'page_counter',
array( 'page_id' => $id ),
- __METHOD__,
- $this->getSelectOptions()
+ __METHOD__
);
}
}
* This isn't necessary for all uses, so it's only done if needed.
*/
protected function loadLastEdit() {
- if ( -1 != $this->mUser ) {
- return;
+ if ( $this->mLastRevision !== null ) {
+ return; // already loaded
}
# New or non-existent articles have no user information
}
$revision = Revision::loadFromPageId( wfGetDB( DB_MASTER ), $id );
- if ( !is_null( $revision ) ) {
+ if ( $revision ) {
$this->setLastEdit( $revision );
}
}
*/
protected function setLastEdit( Revision $revision ) {
$this->mLastRevision = $revision;
- $this->mUser = $revision->getUser();
- $this->mUserText = $revision->getUserText();
$this->mTimestamp = $revision->getTimestamp();
- $this->mComment = $revision->getComment();
- $this->mMinorEdit = $revision->isMinor();
}
/**
if ( !$this->mTimestamp ) {
$this->loadLastEdit();
}
-
return wfTimestamp( TS_MW, $this->mTimestamp );
}
/**
+ * @param $audience Integer: one of:
+ * Revision::FOR_PUBLIC to be displayed to all users
+ * Revision::FOR_THIS_USER to be displayed to $wgUser
+ * Revision::RAW get the text regardless of permissions
* @return int user ID for the user that made the last article revision
*/
- public function getUser() {
+ public function getUser( $audience = Revision::FOR_PUBLIC ) {
$this->loadLastEdit();
- return $this->mUser;
+ if ( $this->mLastRevision ) {
+ return $this->mLastRevision->getUser( $audience );
+ } else {
+ return -1;
+ }
}
/**
+ * @param $audience Integer: one of:
+ * Revision::FOR_PUBLIC to be displayed to all users
+ * Revision::FOR_THIS_USER to be displayed to $wgUser
+ * Revision::RAW get the text regardless of permissions
* @return string username of the user that made the last article revision
*/
- public function getUserText() {
+ public function getUserText( $audience = Revision::FOR_PUBLIC ) {
$this->loadLastEdit();
- return $this->mUserText;
+ if ( $this->mLastRevision ) {
+ return $this->mLastRevision->getUserText( $audience );
+ } else {
+ return '';
+ }
}
/**
+ * @param $audience Integer: one of:
+ * Revision::FOR_PUBLIC to be displayed to all users
+ * Revision::FOR_THIS_USER to be displayed to $wgUser
+ * Revision::RAW get the text regardless of permissions
* @return string Comment stored for the last article revision
*/
- public function getComment() {
+ public function getComment( $audience = Revision::FOR_PUBLIC ) {
$this->loadLastEdit();
- return $this->mComment;
+ if ( $this->mLastRevision ) {
+ return $this->mLastRevision->getComment( $audience );
+ } else {
+ return '';
+ }
}
/**
*/
public function getMinorEdit() {
$this->loadLastEdit();
- return $this->mMinorEdit;
+ if ( $this->mLastRevision ) {
+ return $this->mLastRevision->isMinor();
+ } else {
+ return false;
+ }
}
/**
}
/**
- * FIXME: this does what?
- * @param $limit Integer: default 0.
- * @param $offset Integer: default 0.
- * @return UserArrayFromResult object with User objects of article contributors for requested range
+ * Get a list of users who have edited this article, not including the user who made
+ * the most recent revision, which you can get from $article->getUser() if you want it
+ * @return UserArray
*/
- public function getContributors( $limit = 0, $offset = 0 ) {
+ public function getContributors() {
# FIXME: this is expensive; cache this info somewhere.
$dbr = wfGetDB( DB_SLAVE );
- $revTable = $dbr->tableName( 'revision' );
$userTable = $dbr->tableName( 'user' );
- $pageId = $this->getId();
+ $tables = array( 'revision', 'user' );
- $user = $this->getUser();
+ $fields = array(
+ "$userTable.*",
+ 'rev_user_text AS user_name',
+ 'MAX(rev_timestamp) AS timestamp',
+ );
+
+ $conds = array( 'rev_page' => $this->getId() );
+ // The user who made the top revision gets credited as "this page was last edited by
+ // John, based on contributions by Tom, Dick and Harry", so don't include them twice.
+ $user = $this->getUser();
if ( $user ) {
- $excludeCond = "AND rev_user != $user";
+ $conds[] = "rev_user != $user";
} else {
- $userText = $dbr->addQuotes( $this->getUserText() );
- $excludeCond = "AND rev_user_text != $userText";
+ $conds[] = "rev_user_text != {$dbr->addQuotes( $this->getUserText() )}";
}
- $deletedBit = $dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER ); // username hidden?
-
- $sql = "SELECT {$userTable}.*, rev_user_text as user_name, MAX(rev_timestamp) as timestamp
- FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
- WHERE rev_page = $pageId
- $excludeCond
- AND $deletedBit = 0
- GROUP BY rev_user, rev_user_text
- ORDER BY timestamp DESC";
-
- if ( $limit > 0 ) {
- $sql = $dbr->limitResult( $sql, $limit, $offset );
- }
+ $conds[] = "{$dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER )} = 0"; // username hidden?
- $sql .= ' ' . $this->getSelectOptions();
- $res = $dbr->query( $sql, __METHOD__ );
+ $jconds = array(
+ 'user' => array( 'LEFT JOIN', 'rev_user = user_id' ),
+ );
+ $options = array(
+ 'GROUP BY' => array( 'rev_user', 'rev_user_text' ),
+ 'ORDER BY' => 'timestamp DESC',
+ );
+
+ $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options, $jconds );
return new UserArrayFromResult( $res );
}
# Get variables from query string
$oldid = $this->getOldID();
+
+ # getOldID may want us to redirect somewhere else
+ if ( $this->mRedirectUrl ) {
+ $wgOut->redirect( $this->mRedirectUrl );
+ wfDebug( __METHOD__ . ": redirecting due to oldid\n" );
+ wfProfileOut( __METHOD__ );
+
+ return;
+ }
+
+ $wgOut->setArticleFlag( true );
+ # Set page title (may be overridden by DISPLAYTITLE)
+ $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
+
+ # If we got diff in the query, we want to see a diff page instead of the article.
+ if ( $wgRequest->getCheck( 'diff' ) ) {
+ wfDebug( __METHOD__ . ": showing diff page\n" );
+ $this->showDiffPage();
+ wfProfileOut( __METHOD__ );
+
+ return;
+ }
+
+ # Allow frames by default
+ $wgOut->allowClickjacking();
+
$parserCache = ParserCache::singleton();
$parserOptions = $this->getParserOptions();
}
}
- # getOldID may want us to redirect somewhere else
- if ( $this->mRedirectUrl ) {
- $wgOut->redirect( $this->mRedirectUrl );
- wfDebug( __METHOD__ . ": redirecting due to oldid\n" );
- wfProfileOut( __METHOD__ );
-
- return;
- }
-
- $wgOut->setArticleFlag( true );
- # Set page title (may be overridden by DISPLAYTITLE)
- $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
-
- # If we got diff in the query, we want to see a diff page instead of the article.
- if ( $wgRequest->getCheck( 'diff' ) ) {
- wfDebug( __METHOD__ . ": showing diff page\n" );
- $this->showDiffPage();
- wfProfileOut( __METHOD__ );
-
- return;
- }
-
- # Allow frames by default
- $wgOut->allowClickjacking();
-
if ( !$wgUseETag && !$this->mTitle->quickUserCan( 'edit' ) ) {
$parserOptions->setEditSection( false );
}
$this->mRevIdFetched = $de->mNewid;
$de->showDiffPage( $diffOnly );
- // Needed to get the page's current revision
- $this->loadPageData();
- if ( $diff == 0 || $diff == $this->mLatest ) {
+ if ( $diff == 0 || $diff == $this->getLatest() ) {
# Run view updates for current revision only
$this->viewUpdates();
}
if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
# Don't index user and user talk pages for blocked users (bug 11443)
if ( !$this->mTitle->isSubpage() ) {
- $block = new Block();
- if ( $block->load( $this->mTitle->getText() ) ) {
+ if ( Block::newFromTarget( null, $this->mTitle->getText() ) instanceof Block ) {
return array(
'index' => 'noindex',
'follow' => 'nofollow'
global $wgOut, $wgUser, $wgRequest, $wgRedirectSources;
$rdfrom = $wgRequest->getVal( 'rdfrom' );
- $sk = $wgUser->getSkin();
if ( isset( $this->mRedirectedFrom ) ) {
// This is an internally redirected page view.
// We'll need a backlink to the source page for navigation.
if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
- $redir = $sk->link(
+ $redir = $wgUser->getSkin()->link(
$this->mRedirectedFrom,
null,
array(),
// This is an externally redirected view, from some other wiki.
// If it was reported from a trusted site, supply a backlink.
if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
- $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
+ $redir = $wgUser->getSkin()->makeExternalLink( $rdfrom, $rdfrom );
$s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
$wgOut->setSubtitle( $s );
if ( !$this->hasViewableContent() ) {
// If there's no backing content, send a 404 Not Found
// for better machine handling of broken links.
- $wgRequest->response()->header( "HTTP/1.x 404 Not Found" );
+ $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
}
$wgOut->addWikiText( $text );
* Builds trackback links for article display if $wgUseTrackbacks is set to true
*/
public function addTrackbacks() {
- global $wgOut, $wgUser;
+ global $wgOut;
$dbr = wfGetDB( DB_SLAVE );
$tbs = $dbr->select( 'trackbacks',
foreach ( $tbs as $o ) {
$rmvtxt = "";
- if ( $wgUser->isAllowed( 'trackback' ) ) {
+ if ( $wgOut->getUser()->isAllowed( 'trackback' ) ) {
$delurl = $this->mTitle->getFullURL( "action=deletetrackback&tbid=" .
- $o->tb_id . "&token=" . urlencode( $wgUser->editToken() ) );
+ $o->tb_id . "&token=" . urlencode( $wgOut->getUser()->editToken() ) );
$rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
}
* Removes trackback record for current article from trackbacks table
*/
public function deletetrackback() {
- global $wgUser, $wgRequest, $wgOut;
+ global $wgRequest, $wgOut;
- if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
+ if ( !$wgOut->getUser()->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
$wgOut->addWikiMsg( 'sessionfailure' );
return;
}
- $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgUser );
+ $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgOut->getUser() );
if ( count( $permission_errors ) ) {
$wgOut->showPermissionsErrorPage( $permission_errors );
* Handle action=purge
*/
public function purge() {
- global $wgUser, $wgRequest, $wgOut;
+ global $wgRequest, $wgOut;
- if ( $wgUser->isAllowed( 'purge' ) || $wgRequest->wasPosted() ) {
+ if ( $wgOut->getUser()->isAllowed( 'purge' ) || $wgRequest->wasPosted() ) {
//FIXME: shouldn't this be in doPurge()?
if ( wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
$this->doPurge();
if ( !$isRedirect && !is_null( $lastRevIsRedirect ) && $lastRevIsRedirect === $isRedirect ) {
return true;
}
-
+
wfProfileIn( __METHOD__ );
if ( $isRedirect ) {
$this->insertRedirectEntry( $redirectTitle );
return $text;
}
- /**
- * @deprecated @since 1.7 use Article::doEdit()
- */
- function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC = false, $comment = false, $bot = false ) {
- wfDeprecated( __METHOD__ );
-
- $flags = EDIT_NEW | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
- ( $isminor ? EDIT_MINOR : 0 ) |
- ( $suppressRC ? EDIT_SUPPRESS_RC : 0 ) |
- ( $bot ? EDIT_FORCE_BOT : 0 );
-
- # If this is a comment, add the summary as headline
- if ( $comment && $summary != "" ) {
- $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $summary ) . "\n\n" . $text;
- }
- $this->doEdit( $text, $summary, $flags );
-
- $dbw = wfGetDB( DB_MASTER );
- if ( $watchthis ) {
- if ( !$this->mTitle->userIsWatching() ) {
- $dbw->begin();
- $this->doWatch();
- $dbw->commit();
- }
- } else {
- if ( $this->mTitle->userIsWatching() ) {
- $dbw->begin();
- $this->doUnwatch();
- $dbw->commit();
- }
- }
- $this->doRedirect( $this->isRedirect( $text ) );
- }
-
- /**
- * @deprecated @since 1.7 use Article::doEdit()
- */
- function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
- wfDeprecated( __METHOD__ );
-
- $flags = EDIT_UPDATE | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
- ( $minor ? EDIT_MINOR : 0 ) |
- ( $forceBot ? EDIT_FORCE_BOT : 0 );
-
- $status = $this->doEdit( $text, $summary, $flags );
-
- if ( !$status->isOK() ) {
- return false;
- }
-
- $dbw = wfGetDB( DB_MASTER );
- if ( $watchthis ) {
- if ( !$this->mTitle->userIsWatching() ) {
- $dbw->begin();
- $this->doWatch();
- $dbw->commit();
- }
- } else {
- if ( $this->mTitle->userIsWatching() ) {
- $dbw->begin();
- $this->doUnwatch();
- $dbw->commit();
- }
- }
-
- $extraQuery = ''; // Give extensions a chance to modify URL query on update
- wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this, &$sectionanchor, &$extraQuery ) );
-
- $this->doRedirect( $this->isRedirect( $text ), $sectionanchor, $extraQuery );
- return true;
- }
-
/**
* Check flags and add EDIT_NEW or EDIT_UPDATE to them as needed.
* @param $flags Int
* Mark this particular edit/page as patrolled
*/
public function markpatrolled() {
- global $wgOut, $wgUser, $wgRequest;
+ global $wgOut, $wgRequest;
$wgOut->setRobotPolicy( 'noindex,nofollow' );
# If we haven't been given an rc_id value, we can't do anything
$rcid = (int) $wgRequest->getVal( 'rcid' );
- if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ), $rcid ) ) {
+ if ( !$wgOut->getUser()->matchEditToken( $wgRequest->getVal( 'token' ), $rcid ) ) {
$wgOut->showErrorPage( 'sessionfailure-title', 'sessionfailure' );
return;
}
/**
* User-interface handler for the "watch" action
+ * @deprecated since 1.18
*/
public function watch() {
- global $wgUser, $wgOut;
-
- if ( $wgUser->isAnon() ) {
- $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
- return;
- }
-
- if ( wfReadOnly() ) {
- $wgOut->readOnlyPage();
- return;
- }
-
- if ( $this->doWatch() ) {
- $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
- $wgOut->setRobotPolicy( 'noindex,nofollow' );
- $wgOut->addWikiMsg( 'addedwatchtext', $this->mTitle->getPrefixedText() );
- }
-
- $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
+ Action::factory( 'watch', $this )->show();
}
/**
* Add this page to $wgUser's watchlist
+ *
+ * This is safe to be called multiple times
+ *
* @return bool true on successful watch operation
+ * @deprecated since 1.18
*/
public function doWatch() {
- global $wgUser;
-
- if ( $wgUser->isAnon() ) {
- return false;
- }
-
- if ( wfRunHooks( 'WatchArticle', array( &$wgUser, &$this ) ) ) {
- $wgUser->addWatch( $this->mTitle );
- return wfRunHooks( 'WatchArticleComplete', array( &$wgUser, &$this ) );
- }
-
- return false;
+ return Action::factory( 'watch', $this )->execute();
}
/**
* User interface handler for the "unwatch" action.
+ * @deprecated since 1.18
*/
public function unwatch() {
- global $wgUser, $wgOut;
-
- if ( $wgUser->isAnon() ) {
- $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
- return;
- }
-
- if ( wfReadOnly() ) {
- $wgOut->readOnlyPage();
- return;
- }
-
- if ( $this->doUnwatch() ) {
- $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
- $wgOut->setRobotPolicy( 'noindex,nofollow' );
- $wgOut->addWikiMsg( 'removedwatchtext', $this->mTitle->getPrefixedText() );
- }
-
- $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
+ Action::factory( 'unwatch', $this )->show();
}
/**
* Stop watching a page
* @return bool true on successful unwatch
+ * @deprecated since 1.18
*/
public function doUnwatch() {
- global $wgUser;
-
- if ( $wgUser->isAnon() ) {
- return false;
- }
-
- if ( wfRunHooks( 'UnwatchArticle', array( &$wgUser, &$this ) ) ) {
- $wgUser->removeWatch( $this->mTitle );
- return wfRunHooks( 'UnwatchArticleComplete', array( &$wgUser, &$this ) );
- }
-
- return false;
+ return Action::factory( 'unwatch', $this )->execute();
}
/**
$protect_description = '';
foreach ( $limit as $action => $restrictions ) {
if ( !isset( $expiry[$action] ) )
- $expiry[$action] = Block::infinity();
+ $expiry[$action] = $dbw->getInfinity();
- $encodedExpiry[$action] = Block::encodeExpiry( $expiry[$action], $dbw );
+ $encodedExpiry[$action] = $dbw->encodeExpiry( $expiry[$action] );
if ( $restrictions != '' ) {
$protect_description .= "[$action=$restrictions] (";
if ( $encodedExpiry[$action] != 'infinity' ) {
* @param &$hasHistory Boolean: whether the page has a history
* @return mixed String containing deletion reason or empty string, or boolean false
* if no revision occurred
+ * @deprecated since 1.18
*/
public function generateReason( &$hasHistory ) {
- global $wgContLang;
-
- $dbw = wfGetDB( DB_MASTER );
- // Get the last revision
- $rev = Revision::newFromTitle( $this->mTitle );
-
- if ( is_null( $rev ) ) {
- return false;
- }
-
- // Get the article's contents
- $contents = $rev->getText();
- $blank = false;
-
- // If the page is blank, use the text from the previous revision,
- // which can only be blank if there's a move/import/protect dummy revision involved
- if ( $contents == '' ) {
- $prev = $rev->getPrevious();
-
- if ( $prev ) {
- $contents = $prev->getText();
- $blank = true;
- }
- }
-
- // Find out if there was only one contributor
- // Only scan the last 20 revisions
- $res = $dbw->select( 'revision', 'rev_user_text',
- array( 'rev_page' => $this->getID(), $dbw->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ),
- __METHOD__,
- array( 'LIMIT' => 20 )
- );
-
- if ( $res === false ) {
- // This page has no revisions, which is very weird
- return false;
- }
-
- $hasHistory = ( $res->numRows() > 1 );
- $row = $dbw->fetchObject( $res );
-
- if ( $row ) { // $row is false if the only contributor is hidden
- $onlyAuthor = $row->rev_user_text;
- // Try to find a second contributor
- foreach ( $res as $row ) {
- if ( $row->rev_user_text != $onlyAuthor ) { // Bug 22999
- $onlyAuthor = false;
- break;
- }
- }
- } else {
- $onlyAuthor = false;
- }
-
- // Generate the summary with a '$1' placeholder
- if ( $blank ) {
- // The current revision is blank and the one before is also
- // blank. It's just not our lucky day
- $reason = wfMsgForContent( 'exbeforeblank', '$1' );
- } else {
- if ( $onlyAuthor ) {
- $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor );
- } else {
- $reason = wfMsgForContent( 'excontent', '$1' );
- }
- }
-
- if ( $reason == '-' ) {
- // Allow these UI messages to be blanked out cleanly
- return '';
- }
-
- // Replace newlines with spaces to prevent uglyness
- $contents = preg_replace( "/[\n\r]/", ' ', $contents );
- // Calculate the maximum amount of chars to get
- // Max content length = max comment length - length of the comment (excl. $1) - '...'
- $maxLength = 255 - ( strlen( $reason ) - 2 ) - 3;
- $contents = $wgContLang->truncate( $contents, $maxLength );
- // Remove possible unfinished links
- $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents );
- // Now replace the '$1' placeholder
- $reason = str_replace( '$1', $contents, $reason );
-
- return $reason;
+ return DeleteAction::getAutoReason( $this );
}
/*
* UI entry point for page deletion
+ * @deprecated since 1.18
*/
public function delete() {
- global $wgUser, $wgOut, $wgRequest;
-
- $confirm = $wgRequest->wasPosted() &&
- $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
-
- $this->DeleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
- $this->DeleteReason = $wgRequest->getText( 'wpReason' );
-
- $reason = $this->DeleteReasonList;
-
- if ( $reason != 'other' && $this->DeleteReason != '' ) {
- // Entry from drop down menu + additional comment
- $reason .= wfMsgForContent( 'colon-separator' ) . $this->DeleteReason;
- } elseif ( $reason == 'other' ) {
- $reason = $this->DeleteReason;
- }
-
- # Flag to hide all contents of the archived revisions
- $suppress = $wgRequest->getVal( 'wpSuppress' ) && $wgUser->isAllowed( 'suppressrevision' );
-
- # This code desperately needs to be totally rewritten
-
- # Read-only check...
- if ( wfReadOnly() ) {
- $wgOut->readOnlyPage();
-
- return;
- }
-
- # Check permissions
- $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgUser );
-
- if ( count( $permission_errors ) > 0 ) {
- $wgOut->showPermissionsErrorPage( $permission_errors );
-
- return;
- }
-
- $wgOut->setPagetitle( wfMsg( 'delete-confirm', $this->mTitle->getPrefixedText() ) );
-
- # Better double-check that it hasn't been deleted yet!
- $dbw = wfGetDB( DB_MASTER );
- $conds = $this->mTitle->pageCond();
- $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__ );
- if ( $latest === false ) {
- $wgOut->showFatalError(
- Html::rawElement(
- 'div',
- array( 'class' => 'error mw-error-cannotdelete' ),
- wfMsgExt( 'cannotdelete', array( 'parse' ), $this->mTitle->getPrefixedText() )
- )
- );
- $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
- LogEventsList::showLogExtract(
- $wgOut,
- 'delete',
- $this->mTitle->getPrefixedText()
- );
-
- return;
- }
-
- # Hack for big sites
- $bigHistory = $this->isBigDeletion();
- if ( $bigHistory && !$this->mTitle->userCan( 'bigdelete' ) ) {
- global $wgLang, $wgDeleteRevisionsLimit;
-
- $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
- array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
-
- return;
- }
-
- if ( $confirm ) {
- $this->doDelete( $reason, $suppress );
-
- if ( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
- $this->doWatch();
- } elseif ( $this->mTitle->userIsWatching() ) {
- $this->doUnwatch();
- }
-
- return;
- }
-
- // Generate deletion reason
- $hasHistory = false;
- if ( !$reason ) {
- $reason = $this->generateReason( $hasHistory );
- }
-
- // If the page has a history, insert a warning
- if ( $hasHistory && !$confirm ) {
- global $wgLang;
-
- $skin = $wgUser->getSkin();
- $revisions = $this->estimateRevisionCount();
- //FIXME: lego
- $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
- wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
- wfMsgHtml( 'word-separator' ) . $skin->link( $this->mTitle,
- wfMsgHtml( 'history' ),
- array( 'rel' => 'archives' ),
- array( 'action' => 'history' ) ) .
- '</strong>'
- );
-
- if ( $bigHistory ) {
- global $wgDeleteRevisionsLimit;
- $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
- array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
- }
- }
-
- return $this->confirmDelete( $reason );
+ return Action::factory( 'delete', $this )->show();
}
/**
* @return bool whether or not the page surpasses $wgDeleteRevisionsLimit revisions
+ * @deprecated since 1.18
*/
public function isBigDeletion() {
global $wgDeleteRevisionsLimit;
-
- if ( $wgDeleteRevisionsLimit ) {
- $revCount = $this->estimateRevisionCount();
-
- return $revCount > $wgDeleteRevisionsLimit;
- }
-
- return false;
+ return $wgDeleteRevisionsLimit && $this->estimateRevisionCount() > $wgDeleteRevisionsLimit;
}
/**
'page_namespace' => $this->mTitle->getNamespace(),
'page_title' => $this->mTitle->getDBkey(),
'rev_page = page_id'
- ), __METHOD__, $this->getSelectOptions( array(
+ ), __METHOD__,
+ array(
'ORDER BY' => 'rev_timestamp DESC',
'LIMIT' => $num
- ) )
+ )
);
if ( !$res ) {
return $authors;
}
- /**
- * Output deletion confirmation dialog
- * FIXME: Move to another file?
- * @param $reason String: prefilled reason
- */
- public function confirmDelete( $reason ) {
- global $wgOut, $wgUser;
-
- wfDebug( "Article::confirmDelete\n" );
-
- $deleteBackLink = $wgUser->getSkin()->linkKnown( $this->mTitle );
- $wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $deleteBackLink ) );
- $wgOut->setRobotPolicy( 'noindex,nofollow' );
- $wgOut->addWikiMsg( 'confirmdeletetext' );
-
- wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
-
- if ( $wgUser->isAllowed( 'suppressrevision' ) ) {
- $suppress = "<tr id=\"wpDeleteSuppressRow\">
- <td></td>
- <td class='mw-input'><strong>" .
- Xml::checkLabel( wfMsg( 'revdelete-suppress' ),
- 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
- "</strong></td>
- </tr>";
- } else {
- $suppress = '';
- }
- $checkWatch = $wgUser->getBoolOption( 'watchdeletion' ) || $this->mTitle->userIsWatching();
-
- $form = Xml::openElement( 'form', array( 'method' => 'post',
- 'action' => $this->mTitle->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
- Xml::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
- Xml::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
- Xml::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
- "<tr id=\"wpDeleteReasonListRow\">
- <td class='mw-label'>" .
- Xml::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
- "</td>
- <td class='mw-input'>" .
- Xml::listDropDown( 'wpDeleteReasonList',
- wfMsgForContent( 'deletereason-dropdown' ),
- wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
- "</td>
- </tr>
- <tr id=\"wpDeleteReasonRow\">
- <td class='mw-label'>" .
- Xml::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
- "</td>
- <td class='mw-input'>" .
- Html::input( 'wpReason', $reason, 'text', array(
- 'size' => '60',
- 'maxlength' => '255',
- 'tabindex' => '2',
- 'id' => 'wpReason',
- 'autofocus'
- ) ) .
- "</td>
- </tr>";
-
- # Disallow watching if user is not logged in
- if ( $wgUser->isLoggedIn() ) {
- $form .= "
- <tr>
- <td></td>
- <td class='mw-input'>" .
- Xml::checkLabel( wfMsg( 'watchthis' ),
- 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
- "</td>
- </tr>";
- }
-
- $form .= "
- $suppress
- <tr>
- <td></td>
- <td class='mw-submit'>" .
- Xml::submitButton( wfMsg( 'deletepage' ),
- array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
- "</td>
- </tr>" .
- Xml::closeElement( 'table' ) .
- Xml::closeElement( 'fieldset' ) .
- Html::hidden( 'wpEditToken', $wgUser->editToken() ) .
- Xml::closeElement( 'form' );
-
- if ( $wgUser->isAllowed( 'editinterface' ) ) {
- $skin = $wgUser->getSkin();
- $title = Title::makeTitle( NS_MEDIAWIKI, 'Deletereason-dropdown' );
- $link = $skin->link(
- $title,
- wfMsgHtml( 'delete-edit-reasonlist' ),
- array(),
- array( 'action' => 'edit' )
- );
- $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
- }
-
- $wgOut->addHTML( $form );
- $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
- LogEventsList::showLogExtract( $wgOut, 'delete',
- $this->mTitle->getPrefixedText()
- );
- }
-
/**
* Perform a deletion and output success or failure messages
+ * @deprecated since 1.18
*/
public function doDelete( $reason, $suppress = false ) {
- global $wgOut, $wgUser;
-
- $id = $this->mTitle->getArticleID( Title::GAID_FOR_UPDATE );
-
- $error = '';
- if ( wfRunHooks( 'ArticleDelete', array( &$this, &$wgUser, &$reason, &$error ) ) ) {
- if ( $this->doDeleteArticle( $reason, $suppress, $id ) ) {
- $deleted = $this->mTitle->getPrefixedText();
-
- $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
- $wgOut->setRobotPolicy( 'noindex,nofollow' );
-
- $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
-
- $wgOut->addWikiMsg( 'deletedtext', $deleted, $loglink );
- $wgOut->returnToMain( false );
- wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$wgUser, $reason, $id ) );
- }
- } else {
- if ( $error == '' ) {
- $wgOut->showFatalError(
- Html::rawElement(
- 'div',
- array( 'class' => 'error mw-error-cannotdelete' ),
- wfMsgExt( 'cannotdelete', array( 'parse' ), $this->mTitle->getPrefixedText() )
- )
- );
-
- $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
-
- LogEventsList::showLogExtract(
- $wgOut,
- 'delete',
- $this->mTitle->getPrefixedText()
- );
- } else {
- $wgOut->showFatalError( $error );
- }
- }
+ return DeleteAction::doDeleteArticle(
+ $this,
+ $this->getContext(),
+ array(
+ 'Suppress' => $suppress !== false,
+ 'Reason' => $reason,
+ ),
+ true
+ );
}
/**
* @param $id int article ID
* @param $commit boolean defaults to true, triggers transaction end
* @return boolean true if successful
+ *
+ * @deprecated since 1.18
*/
- public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true ) {
- global $wgDeferredUpdateList, $wgUseTrackbacks;
-
- wfDebug( __METHOD__ . "\n" );
-
- $dbw = wfGetDB( DB_MASTER );
- $t = $this->mTitle->getDBkey();
- $id = $id ? $id : $this->mTitle->getArticleID( Title::GAID_FOR_UPDATE );
-
- if ( $t === '' || $id == 0 ) {
- return false;
- }
-
- $u = new SiteStatsUpdate( 0, 1, - (int)$this->isCountable( $this->getRawText() ), -1 );
- array_push( $wgDeferredUpdateList, $u );
-
- // Bitfields to further suppress the content
- if ( $suppress ) {
- $bitfield = 0;
- // This should be 15...
- $bitfield |= Revision::DELETED_TEXT;
- $bitfield |= Revision::DELETED_COMMENT;
- $bitfield |= Revision::DELETED_USER;
- $bitfield |= Revision::DELETED_RESTRICTED;
- } else {
- $bitfield = 'rev_deleted';
- }
-
- $dbw->begin();
- // For now, shunt the revision data into the archive table.
- // Text is *not* removed from the text table; bulk storage
- // is left intact to avoid breaking block-compression or
- // immutable storage schemes.
- //
- // For backwards compatibility, note that some older archive
- // table entries will have ar_text and ar_flags fields still.
- //
- // In the future, we may keep revisions and mark them with
- // the rev_deleted field, which is reserved for this purpose.
- $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
+ public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
+ return DeleteAction::doDeleteArticle(
+ $this,
+ $this->getContext(),
array(
- 'ar_namespace' => 'page_namespace',
- 'ar_title' => 'page_title',
- '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_rev_id' => 'rev_id',
- 'ar_text_id' => 'rev_text_id',
- 'ar_text' => '\'\'', // Be explicit to appease
- 'ar_flags' => '\'\'', // MySQL's "strict mode"...
- 'ar_len' => 'rev_len',
- 'ar_page_id' => 'page_id',
- 'ar_deleted' => $bitfield
- ), array(
- 'page_id' => $id,
- 'page_id = rev_page'
- ), __METHOD__
+ 'Suppress' => $suppress !== false,
+ 'Reason' => $reason,
+ ),
+ $commit
);
-
- # Delete restrictions for it
- $dbw->delete( 'page_restrictions', array ( 'pr_page' => $id ), __METHOD__ );
-
- # Now that it's safely backed up, delete it
- $dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__ );
- $ok = ( $dbw->affectedRows() > 0 ); // getArticleId() uses slave, could be laggy
-
- if ( !$ok ) {
- $dbw->rollback();
- return false;
- }
-
- # Fix category table counts
- $cats = array();
- $res = $dbw->select( 'categorylinks', 'cl_to', array( 'cl_from' => $id ), __METHOD__ );
-
- foreach ( $res as $row ) {
- $cats [] = $row->cl_to;
- }
-
- $this->updateCategoryCounts( array(), $cats );
-
- # If using cascading deletes, we can skip some explicit deletes
- if ( !$dbw->cascadingDeletes() ) {
- $dbw->delete( 'revision', array( 'rev_page' => $id ), __METHOD__ );
-
- if ( $wgUseTrackbacks )
- $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), __METHOD__ );
-
- # Delete outgoing links
- $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
- $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
- $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
- $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
- $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
- $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
- $dbw->delete( 'redirect', array( 'rd_from' => $id ) );
- }
-
- # If using cleanup triggers, we can skip some manual deletes
- if ( !$dbw->cleanupTriggers() ) {
- # Clean up recentchanges entries...
- $dbw->delete( 'recentchanges',
- array( 'rc_type != ' . RC_LOG,
- 'rc_namespace' => $this->mTitle->getNamespace(),
- 'rc_title' => $this->mTitle->getDBkey() ),
- __METHOD__ );
- $dbw->delete( 'recentchanges',
- array( 'rc_type != ' . RC_LOG, 'rc_cur_id' => $id ),
- __METHOD__ );
- }
-
- # Clear caches
- Article::onArticleDelete( $this->mTitle );
-
- # Clear the cached article id so the interface doesn't act like we exist
- $this->mTitle->resetArticleID( 0 );
-
- # Log the deletion, if the page was suppressed, log it at Oversight instead
- $logtype = $suppress ? 'suppress' : 'delete';
- $log = new LogPage( $logtype );
-
- # Make sure logging got through
- $log->addEntry( 'delete', $this->mTitle, $reason, array() );
-
- if ( $commit ) {
- $dbw->commit();
- }
-
- return true;
}
/**
$flags |= EDIT_MINOR;
}
- if ( $bot && ( $wgUser->isAllowed( 'markbotedits' ) || $wgUser->isAllowed( 'bot' ) ) ) {
+ if ( $bot && ( $wgUser->isAllowedAny( 'markbotedits', 'bot' ) ) ) {
$flags |= EDIT_FORCE_BOT;
}
$edit->revid = $revid;
$edit->newText = $text;
$edit->pst = $this->preSaveTransform( $text, $user, $popts );
- $edit->popts = $this->getParserOptions( true );
+ $edit->popts = $this->getParserOptions();
$edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $edit->popts, true, true, $revid );
$edit->oldText = $this->getRawText();
$dbw = wfGetDB( DB_MASTER );
$cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
- $recentchanges = $dbw->tableName( 'recentchanges' );
- $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
-
- $dbw->query( $sql );
+ $dbw->delete(
+ 'recentchanges',
+ array( "rc_timestamp < '$cutoff'" ),
+ __METHOD__
+ );
}
}
"\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
$prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
- $wgOut->setSubtitle( $r );
+ $wgOut->addHTML( $r );
}
/**
'watchlist',
'COUNT(*)',
$wl_clause,
- __METHOD__,
- $this->getSelectOptions() );
+ __METHOD__ );
$pageInfo = $this->pageCountInfo( $page );
$talkInfo = $this->pageCountInfo( $page->getTalkPage() );
'revision',
'COUNT(rev_page)',
$rev_clause,
- __METHOD__,
- $this->getSelectOptions()
+ __METHOD__
);
$authors = $dbr->selectField(
'revision',
'COUNT(DISTINCT rev_user_text)',
$rev_clause,
- __METHOD__,
- $this->getSelectOptions()
+ __METHOD__
);
return array( 'edits' => $edits, 'authors' => $authors );
/**
* Get parser options suitable for rendering the primary article wikitext
- * @param $canonical boolean Determines that the generated must not depend on user preferences (see bug 14404)
* @return mixed ParserOptions object or boolean false
*/
- public function getParserOptions( $canonical = false ) {
- global $wgUser, $wgLanguageCode;
-
- if ( !$this->mParserOptions || $canonical ) {
- $user = !$canonical ? $wgUser : new User;
- $parserOptions = new ParserOptions( $user );
- $parserOptions->setTidy( true );
- $parserOptions->enableLimitReport();
-
- if ( $canonical ) {
- $parserOptions->setUserLang( $wgLanguageCode ); # Must be set explicitely
- return $parserOptions;
- }
- $this->mParserOptions = $parserOptions;
+ public function getParserOptions() {
+ global $wgUser;
+
+ if ( !$this->mParserOptions ) {
+ $this->mParserOptions = new ParserOptions( $wgUser );
+ $this->mParserOptions->setTidy( true );
+ $this->mParserOptions->enableLimitReport();
}
// Clone to allow modifications of the return value without affecting
* @since 1.16 (r52326) for LiquidThreads
*
* @param $oldid mixed integer Revision ID or null
- * @return ParserOutput
+ * @return ParserOutput or false if the given revsion ID is not found
*/
public function getParserOutput( $oldid = null ) {
global $wgEnableParserCache, $wgUser;
wfIncrStats( 'pcache_miss_stub' );
}
- $parserOutput = false;
if ( $useParserCache ) {
$parserOutput = ParserCache::singleton()->get( $this, $this->getParserOptions() );
+ if ( $parserOutput !== false ) {
+ return $parserOutput;
+ }
}
- if ( $parserOutput === false ) {
- // Cache miss; parse and output it.
+ // Cache miss; parse and output it.
+ if ( $oldid === null ) {
+ $text = $this->getRawText();
+ } else {
$rev = Revision::newFromTitle( $this->getTitle(), $oldid );
+ if ( $rev === null ) {
+ return false;
+ }
+ $text = $rev->getText();
+ }
+
+ return $this->getOutputFromWikitext( $text, $useParserCache );
+ }
- return $this->getOutputFromWikitext( $rev->getText(), $useParserCache );
+ /**
+ * Sets the context this Article is executed in
+ *
+ * @param $context RequestContext
+ * @since 1.18
+ */
+ public function setContext( $context ) {
+ $this->mContext = $context;
+ }
+
+ /**
+ * Gets the context this Article is executed in
+ *
+ * @return RequestContext
+ * @since 1.18
+ */
+ public function getContext() {
+ if ( $this->mContext instanceof RequestContext ) {
+ return $this->mContext;
} else {
- return $parserOutput;
+ wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
+ return RequestContext::getMain();
}
}