/**@{{
* @private
*/
- protected $mContext; // !< RequestContext
+
+ /**
+ * @var RequestContext
+ */
+ protected $mContext;
var $mContent; // !<
var $mContentLoaded = false; // !<
var $mCounter = -1; // !< Not loaded
var $mDataLoaded = false; // !<
- var $mForUpdate = false; // !<
- var $mGoodAdjustment = 0; // !<
var $mIsRedirect = false; // !<
var $mLatest = false; // !<
var $mOldId; // !<
- var $mPreparedEdit = false; // !< Title object if set
- var $mRedirectedFrom = null; // !< Title object if set
- var $mRedirectTarget = null; // !< Title object if set
+ var $mPreparedEdit = false;
+
+ /**
+ * @var Title
+ */
+ var $mRedirectedFrom = null;
+
+ /**
+ * @var Title
+ */
+ var $mRedirectTarget = null;
+
+ /**
+ * @var mixed: boolean false or URL string
+ */
var $mRedirectUrl = false; // !<
var $mRevIdFetched = 0; // !<
- var $mLastRevision = null; // !< Latest revision if set
- var $mRevision = null; // !< Loaded revision object if set
+
+ /**
+ * @var Revision
+ */
+ var $mLastRevision = null;
+
+ /**
+ * @var Revision
+ */
+ var $mRevision = null;
+
var $mTimestamp = ''; // !<
var $mTitle; // !< Title object
- var $mTotalAdjustment = 0; // !<
var $mTouched = '19700101000000'; // !<
- var $mParserOptions; // !< ParserOptions object
- var $mParserOutput; // !< ParserCache object if set
+
+ /**
+ * @var ParserOptions: ParserOptions object for $wgUser articles
+ */
+ var $mParserOptions;
+
+ /**
+ * @var ParserOutput
+ */
+ var $mParserOutput;
+
/**@}}*/
/**
* Constructor and clear the article
- * @param $title Reference to a Title object.
+ * @param $title Title Reference to a Title object.
* @param $oldId Integer revision ID, null to fetch from request, zero for current
*/
public function __construct( Title $title, $oldId = null ) {
- // FIXME: does the reference play any role here?
+ // @todo FIXME: Does the reference play any role here?
$this->mTitle =& $title;
$this->mOldId = $oldId;
}
+ /**
+ * Create an Article object of the appropriate class for the given page.
+ *
+ * @param $title Title
+ * @param $context RequestContext
+ * @return Article object
+ */
+ public static function newFromTitle( $title, RequestContext $context ) {
+ if ( NS_MEDIA == $title->getNamespace() ) {
+ // FIXME: where should this go?
+ $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
+ }
+
+ $article = null;
+ wfRunHooks( 'ArticleFromTitle', array( &$title, &$article ) );
+ if ( $article ) {
+ $article->setContext( $context );
+ return $article;
+ }
+
+ switch( $title->getNamespace() ) {
+ case NS_FILE:
+ $page = new ImagePage( $title );
+ break;
+ case NS_CATEGORY:
+ $page = new CategoryPage( $title );
+ break;
+ default:
+ $page = new Article( $title );
+ }
+ $page->setContext( $context );
+ return $page;
+ }
+
/**
* Constructor from an page id
* @param $id Int article ID to load
*/
public static function newFromID( $id ) {
$t = Title::newFromID( $id );
- # FIXME: doesn't inherit right
+ # @todo FIXME: Doesn't inherit right
return $t == null ? null : new self( $t );
# return $t == null ? null : new static( $t ); // PHP 5.3
}
*
* The target will be fetched from the redirect table if possible.
* If this page doesn't have an entry there, call insertRedirect()
- * @return mixed Title object, or null if this page is not a redirect
+ * @return Title|mixed object, or null if this page is not a redirect
*/
public function getRedirectTarget() {
if ( !$this->mTitle->isRedirect() ) {
/**
* Clear the object
- * FIXME: shouldn't this be public?
+ * @todo FIXME: Shouldn't this be public?
* @private
*/
public function clear() {
$this->mRedirectTarget = null; # Title object if set
$this->mLastRevision = null; # Latest revision
$this->mTimestamp = '';
- $this->mGoodAdjustment = $this->mTotalAdjustment = 0;
$this->mTouched = '19700101000000';
- $this->mForUpdate = false;
$this->mIsRedirect = false;
$this->mRevIdFetched = 0;
$this->mRedirectUrl = false;
return $text;
}
- /**
- * 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.
- *
- * @param $text String: text to look in
- * @param $section Integer: section number
- * @return string text of the requested section
- * @deprecated
- */
- public function getSection( $text, $section ) {
- global $wgParser;
- return $wgParser->getSection( $text, $section );
- }
-
/**
* Get the text that needs to be saved in order to undo all revisions
* between $undo and $undoafter. Revisions must belong to the same page,
* @return mixed string on success, false on failure
*/
public function getUndoText( Revision $undo, Revision $undoafter = null ) {
- $currentRev = Revision::newFromTitle( $this->mTitle );
- if ( !$currentRev ) {
+ $cur_text = $this->getRawText();
+ if ( $cur_text === false ) {
return false; // no page
}
$undo_text = $undo->getText();
$undoafter_text = $undoafter->getText();
- $cur_text = $currentRev->getText();
if ( $cur_text == $undo_text ) {
# No use doing a merge if it's just a straight revert.
/**
* Fetch a page record with the given conditions
- * @param $dbr Database object
+ * @param $dbr DatabaseBase object
* @param $conditions Array
* @return mixed Database result resource, or false on failure
*/
* Fetch a page record matching the Title object's namespace and title
* using a sanitized title string
*
- * @param $dbr Database object
+ * @param $dbr DatabaseBase object
* @param $title Title object
* @return mixed Database result resource, or false on failure
*/
/**
* Fetch a page record matching the requested ID
*
- * @param $dbr Database
+ * @param $dbr DatabaseBase
* @param $id Integer
* @return mixed Database result resource, or false on failure
*/
* Set the general counter, title etc data loaded from
* some source.
*
- * @param $data Database row object or "fromdb"
+ * @param $data Object|String $res->fetchObject() object or the string "fromdb" to reload
*/
public function loadPageData( $data = 'fromdb' ) {
if ( $data === 'fromdb' ) {
}
}
- // FIXME: Horrible, horrible! This content-loading interface just plain sucks.
+ // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
// We should instead work with the Revision object when we need it...
$this->mContent = $revision->getText( Revision::FOR_THIS_USER ); // Loads if user is allowed
}
/**
- * 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
+ * No-op
+ * @deprecated since 1.18
*/
- public function forUpdate( $x = null ) {
+ public function forUpdate() {
wfDeprecated( __METHOD__ );
- return wfSetVar( $this->mForUpdate, $x );
}
/**
* Determine whether a page would be suitable for being counted as an
* article in the site_stats table based on the title & its content
*
- * @param $text String: text to analyze
- * @return bool
+ * @param $editInfo Object or false: object returned by prepareTextForEdit(),
+ * if false, the current database state will be used
+ * @return Boolean
*/
- public function isCountable( $text ) {
- global $wgUseCommaCount;
+ public function isCountable( $editInfo = false ) {
+ global $wgArticleCountMethod;
- $token = $wgUseCommaCount ? ',' : '[[';
+ if ( !$this->mTitle->isContentPage() ) {
+ return false;
+ }
+
+ $text = $editInfo ? $editInfo->pst : false;
- return $this->mTitle->isContentPage() && !$this->isRedirect( $text ) && in_string( $token, $text );
+ if ( $this->isRedirect( $text ) ) {
+ return false;
+ }
+
+ switch ( $wgArticleCountMethod ) {
+ case 'any':
+ return true;
+ case 'comma':
+ if ( $text === false ) {
+ $text = $this->getRawText();
+ }
+ return strpos( $text, ',' ) !== false;
+ case 'link':
+ if ( $editInfo ) {
+ // ParserOutput::getLinks() is a 2D array of page links, so
+ // to be really correct we would need to recurse in the array
+ // but the main array should only have items in it if there are
+ // links.
+ return (bool)count( $editInfo->output->getLinks() );
+ } else {
+ return (bool)wfGetDB( DB_SLAVE )->selectField( 'pagelinks', 1,
+ array( 'pl_from' => $this->getId() ), __METHOD__ );
+ }
+ }
}
/**
/**
* 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
+ * @return UserArrayFromResult
*/
public function getContributors() {
- # FIXME: this is expensive; cache this info somewhere.
+ # @todo FIXME: This is expensive; cache this info somewhere.
$dbr = wfGetDB( DB_SLAVE );
- $userTable = $dbr->tableName( 'user' );
+
+ if ( $dbr->implicitGroupby() ) {
+ $realNameField = 'user_real_name';
+ } else {
+ $realNameField = 'FIRST(user_real_name) AS user_real_name';
+ }
$tables = array( 'revision', 'user' );
$fields = array(
- "$userTable.*",
+ 'rev_user as user_id',
'rev_user_text AS user_name',
+ $realNameField,
'MAX(rev_timestamp) AS timestamp',
);
'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 );
}
if ( $wgOut->isPrintable() ) {
$parserOptions->setIsPrintable( true );
$parserOptions->setEditSection( false );
- } else if ( $wgUseETag && !$this->mTitle->quickUserCan( 'edit' ) ) {
+ } elseif ( $wgUseETag && !$this->mTitle->quickUserCan( 'edit' ) ) {
$parserOptions->setEditSection( false );
}
return;
# Try file cache
- } else if ( $wgUseFileCache && $this->tryFileCache() ) {
+ } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
wfDebug( __METHOD__ . ": done file cache\n" );
# tell wgOut that output is taken care of
$wgOut->disable();
* @return boolean
*/
public function showRedirectedFromHeader() {
- global $wgOut, $wgUser, $wgRequest, $wgRedirectSources;
+ global $wgOut, $wgRequest, $wgRedirectSources;
$rdfrom = $wgRequest->getVal( 'rdfrom' );
// This is an internally redirected page view.
// We'll need a backlink to the source page for navigation.
if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
- $redir = $wgUser->getSkin()->link(
+ $redir = Linker::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 = $wgUser->getSkin()->makeExternalLink( $rdfrom, $rdfrom );
+ $redir = Linker::makeExternalLink( $rdfrom, $rdfrom );
$s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
$wgOut->setSubtitle( $s );
return;
}
- $sk = $wgUser->getSkin();
$token = $wgUser->editToken( $rcid );
$wgOut->preventClickjacking();
"<div class='patrollink'>" .
wfMsgHtml(
'markaspatrolledlink',
- $sk->link(
+ Linker::link(
$this->mTitle,
wfMsgHtml( 'markaspatrolledtext' ),
array(),
if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
$wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
- array( 'userpage-userdoesnotexist-view', $rootPart ) );
- } else if ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
+ array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
+ } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
LogEventsList::showLogExtract(
$wgOut,
'block',
return false;
// If the user needs to confirm that they want to see it...
- } else if ( $wgRequest->getInt( 'unhide' ) != 1 ) {
+ } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
# Give explanation and add a link to view the revision...
$oldid = intval( $this->getOldID() );
$link = $this->mTitle->getFullUrl( "oldid={$oldid}&unhide=1" );
* @return string containing HMTL with redirect link
*/
public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
- global $wgOut, $wgContLang, $wgStylePath, $wgUser;
+ global $wgOut, $wgContLang, $wgStylePath;
if ( !is_array( $target ) ) {
$target = array( $target );
$wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
}
- $sk = $wgUser->getSkin();
// the loop prepends the arrow image before the link, so the first case needs to be outside
$title = array_shift( $target );
if ( $forceKnown ) {
- $link = $sk->linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
+ $link = Linker::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
} else {
- $link = $sk->link( $title, htmlspecialchars( $title->getFullText() ) );
+ $link = Linker::link( $title, htmlspecialchars( $title->getFullText() ) );
}
$nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
foreach ( $target as $rt ) {
$link .= Html::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
if ( $forceKnown ) {
- $link .= $sk->linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
+ $link .= Linker::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
} else {
- $link .= $sk->link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
+ $link .= Linker::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
}
}
/**
* Removes trackback record for current article from trackbacks table
+ * @deprecated since 1.19
*/
public function deletetrackback() {
- global $wgRequest, $wgOut;
-
- if ( !$wgOut->getUser()->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
- $wgOut->addWikiMsg( 'sessionfailure' );
-
- return;
- }
-
- $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgOut->getUser() );
-
- if ( count( $permission_errors ) ) {
- $wgOut->showPermissionsErrorPage( $permission_errors );
-
- return;
- }
-
- $db = wfGetDB( DB_MASTER );
- $db->delete( 'trackbacks', array( 'tb_id' => $wgRequest->getInt( 'tbid' ) ) );
-
- $wgOut->addWikiMsg( 'trackbackdeleteok' );
- $this->mTitle->invalidateCache();
+ return Action::factory( 'deletetrackback', $this )->show();
}
/**
}
}
+ /**
+ * Mark this particular edit/page as patrolled
+ * @deprecated since 1.19
+ */
+ public function markpatrolled() {
+ Action::factory( 'markpatrolled', $this )->show();
+ }
+
+ /**
+ * User-interface handler for the "watch" action.
+ * Requires Request to pass a token as of 1.19.
+ * @deprecated since 1.18
+ */
+ public function watch() {
+ 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;
+ return WatchAction::doWatch( $this->mTitle, $wgUser );
+ }
+
+ /**
+ * User interface handler for the "unwatch" action.
+ * Requires Request to pass a token as of 1.19.
+ * @deprecated since 1.18
+ */
+ public function unwatch() {
+ Action::factory( 'unwatch', $this )->show();
+ }
+
+ /**
+ * Stop watching a page
+ * @return bool true on successful unwatch
+ * @deprecated since 1.18
+ */
+ public function doUnwatch() {
+ global $wgUser;
+ return WatchAction::doUnwatch( $this->mTitle, $wgUser );
+ }
+
+ /**
+ * action=protect handler
+ */
+ public function protect() {
+ $form = new ProtectionForm( $this );
+ $form->execute();
+ }
+
+ /**
+ * action=unprotect handler (alias)
+ */
+ public function unprotect() {
+ $this->protect();
+ }
+
+ /**
+ * Info about this page
+ * Called for ?action=info when $wgAllowPageInfo is on.
+ */
+ public function info() {
+ Action::factory( 'info', $this )->show();
+ }
+
/**
* Insert a new empty page record for this article.
* This *must* be followed up by creating a revision
* or else the record will be left in a funky state.
* Best if all done inside a transaction.
*
- * @param $dbw Database
+ * @param $dbw DatabaseBase
* @return int The newly created page_id key, or false if the title already existed
* @private
*/
* on.
* @param $lastRevIsRedirect Boolean: if given, will optimize adding and
* removing rows in redirect table.
- * @param $setNewFlag Boolean: Set to true if a page flag should be set
- * Needed when $lastRevision has to be set to sth. !=0
* @return bool true on success, false on failure
* @private
*/
- public function updateRevisionOn( &$dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null, $setNewFlag = false ) {
+ public function updateRevisionOn( &$dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null ) {
wfProfileIn( __METHOD__ );
$text = $revision->getText();
$conditions['page_latest'] = $lastRevision;
}
- if ( !$setNewFlag ) {
- $setNewFlag = ( $lastRevision === 0 );
- }
-
$dbw->update( 'page',
array( /* SET */
'page_latest' => $revision->getId(),
'page_touched' => $dbw->timestamp(),
- 'page_is_new' => $setNewFlag,
+ 'page_is_new' => ( $lastRevision === 0 ) ? 1 : 0,
'page_is_redirect' => $rt !== null ? 1 : 0,
'page_len' => strlen( $text ),
),
/**
* Add row to the redirect table if this is a redirect, remove otherwise.
*
- * @param $dbw Database
+ * @param $dbw DatabaseBase
* @param $redirectTitle Title object pointing to the redirect target,
* or NULL if this is not a redirect
* @param $lastRevIsRedirect If given, will optimize adding and
$changed = ( strcmp( $text, $oldtext ) != 0 );
if ( $changed ) {
- $this->mGoodAdjustment = (int)$this->isCountable( $text )
- - (int)$this->isCountable( $oldtext );
- $this->mTotalAdjustment = 0;
-
if ( !$this->mLatest ) {
# Article gone missing
wfDebug( __METHOD__ . ": EDIT_UPDATE specified but article doesn't exist\n" );
# Create new article
$status->value['new'] = true;
- # Set statistics members
- # We work out if it's countable after PST to avoid counter drift
- # when articles are created with {{subst:}}
- $this->mGoodAdjustment = (int)$this->isCountable( $text );
- $this->mTotalAdjustment = 1;
-
$dbw->begin();
# Add the page record; stake our claim on this title!
$revisionId = $revision->insertOn( $dbw );
$this->mTitle->resetArticleID( $newid );
- # Update the LinkCache. Resetting the Title ArticleID means it will rely on having that already cached (FIXME?)
+ # Update the LinkCache. Resetting the Title ArticleID means it will rely on having that already cached
+ # @todo FIXME?
LinkCache::singleton()->addGoodLinkObj( $newid, $this->mTitle, strlen( $text ), (bool)Title::newFromRedirect( $text ), $revisionId );
# Update the page record with revision data
$dbw->commit();
# Update links, etc.
- $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, true, $user );
+ $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, true, $user, true );
# Clear caches
Article::onArticleCreate( $this->mTitle );
* Output a redirect back to the article.
* This is typically used after an edit.
*
+ * @deprecated in 1.19; call $wgOut->redirect() directly
* @param $noRedir Boolean: add redirect=no
* @param $sectionAnchor String: section to redirect to, including "#"
* @param $extraQuery String: extra query params
*/
public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
+ wfDeprecated( __METHOD__ );
global $wgOut;
if ( $noRedir ) {
$wgOut->redirect( $this->mTitle->getFullURL( $query ) . $sectionAnchor );
}
- /**
- * Mark this particular edit/page as patrolled
- */
- public function markpatrolled() {
- 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 ( !$wgOut->getUser()->matchEditToken( $wgRequest->getVal( 'token' ), $rcid ) ) {
- $wgOut->showErrorPage( 'sessionfailure-title', 'sessionfailure' );
- return;
- }
-
- $rc = RecentChange::newFromId( $rcid );
-
- if ( is_null( $rc ) ) {
- $wgOut->showErrorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
- return;
- }
-
- # It would be nice to see where the user had actually come from, but for now just guess
- $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges';
- $return = SpecialPage::getTitleFor( $returnto );
-
- $errors = $rc->doMarkPatrolled();
-
- if ( in_array( array( 'rcpatroldisabled' ), $errors ) ) {
- $wgOut->showErrorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
-
- return;
- }
-
- if ( in_array( array( 'hookaborted' ), $errors ) ) {
- // The hook itself has handled any output
- return;
- }
-
- if ( in_array( array( 'markedaspatrollederror-noautopatrol' ), $errors ) ) {
- $wgOut->setPageTitle( wfMsg( 'markedaspatrollederror' ) );
- $wgOut->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
- $wgOut->returnToMain( false, $return );
-
- return;
- }
-
- if ( !empty( $errors ) ) {
- $wgOut->showPermissionsErrorPage( $errors );
-
- return;
- }
-
- # Inform the user
- $wgOut->setPageTitle( wfMsg( 'markedaspatrolled' ) );
- $wgOut->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
- $wgOut->returnToMain( false, $return );
- }
-
- /**
- * User-interface handler for the "watch" action
- * @deprecated since 1.18
- */
- public function watch() {
- 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() {
- return Action::factory( 'watch', $this )->execute();
- }
-
- /**
- * User interface handler for the "unwatch" action.
- * @deprecated since 1.18
- */
- public function unwatch() {
- Action::factory( 'unwatch', $this )->show();
- }
-
- /**
- * Stop watching a page
- * @return bool true on successful unwatch
- * @deprecated since 1.18
- */
- public function doUnwatch() {
- return Action::factory( 'unwatch', $this )->execute();
- }
-
- /**
- * action=protect handler
- */
- public function protect() {
- $form = new ProtectionForm( $this );
- $form->execute();
- }
-
- /**
- * action=unprotect handler (alias)
- */
- public function unprotect() {
- $this->protect();
- }
-
/**
* Update the article's restriction field, and leave a log entry.
*
// Take this opportunity to purge out expired restrictions
Title::purgeExpiredRestrictions();
- # FIXME: Same limitations as described in ProtectionForm.php (line 37);
+ # @todo FIXME: Same limitations as described in ProtectionForm.php (line 37);
# we expect a single selection, but the schema allows otherwise.
$current = array();
$updated = Article::flattenRestrictions( $limit );
}
- /*
+ /**
* UI entry point for page deletion
*/
public function delete() {
Html::rawElement(
'div',
array( 'class' => 'error mw-error-cannotdelete' ),
- wfMsgExt( 'cannotdelete', array( 'parse' ), $this->mTitle->getPrefixedText() )
+ wfMsgExt( 'cannotdelete', array( 'parse' ),
+ wfEscapeWikiText( $this->mTitle->getPrefixedText() ) )
)
);
$wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
if ( $hasHistory && !$confirm ) {
global $wgLang;
- $skin = $wgOut->getSkin();
$revisions = $this->estimateRevisionCount();
- //FIXME: lego
+ // @todo FIXME: i18n issue/patchwork message
$wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
- wfMsgHtml( 'word-separator' ) . $skin->link( $this->mTitle,
+ wfMsgHtml( 'word-separator' ) . Linker::link( $this->mTitle,
wfMsgHtml( 'history' ),
array( 'rel' => 'archives' ),
array( 'action' => 'history' ) ) .
/**
* Output deletion confirmation dialog
- * FIXME: Move to another file?
+ * @todo FIXME: Move to another file?
* @param $reason String: prefilled reason
*/
public function confirmDelete( $reason ) {
wfDebug( "Article::confirmDelete\n" );
- $deleteBackLink = $wgOut->getSkin()->linkKnown( $this->mTitle );
+ $deleteBackLink = Linker::linkKnown( $this->mTitle );
$wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $deleteBackLink ) );
$wgOut->setRobotPolicy( 'noindex,nofollow' );
$wgOut->addWikiMsg( 'confirmdeletetext' );
Xml::closeElement( 'form' );
if ( $wgOut->getUser()->isAllowed( 'editinterface' ) ) {
- $skin = $wgOut->getSkin();
$title = Title::makeTitle( NS_MEDIAWIKI, 'Deletereason-dropdown' );
- $link = $skin->link(
+ $link = Linker::link(
$title,
wfMsgHtml( 'delete-edit-reasonlist' ),
array(),
$loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
- $wgOut->addWikiMsg( 'deletedtext', $deleted, $loglink );
+ $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
$wgOut->returnToMain( false );
} else {
if ( $error == '' ) {
Html::rawElement(
'div',
array( 'class' => 'error mw-error-cannotdelete' ),
- wfMsgExt( 'cannotdelete', array( 'parse' ), $this->mTitle->getPrefixedText() )
+ wfMsgExt( 'cannotdelete', array( 'parse' ),
+ wfEscapeWikiText( $this->mTitle->getPrefixedText() ) )
)
);
return false;
}
- $u = new SiteStatsUpdate( 0, 1, - (int)$this->isCountable( $this->getRawText() ), -1 );
+ $u = new SiteStatsUpdate( 0, 1, - (int)$this->isCountable(), -1 );
array_push( $wgDeferredUpdateList, $u );
// Bitfields to further suppress the content
$dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
$dbw->delete( 'externallinks', array( 'el_from' => $id ) );
$dbw->delete( 'langlinks', array( 'll_from' => $id ) );
+ $dbw->delete( 'iwlinks', array( 'iwl_from' => $id ) );
$dbw->delete( 'redirect', array( 'rd_from' => $id ) );
}
if ( $s === false ) {
# No one else ever edited this page
return array( array( 'cantrollback' ) );
- } else if ( $s->rev_deleted & Revision::DELETED_TEXT || $s->rev_deleted & Revision::DELETED_USER ) {
+ } elseif ( $s->rev_deleted & Revision::DELETED_TEXT || $s->rev_deleted & Revision::DELETED_USER ) {
# Only admins can see this text
return array( array( 'notvisiblerev' ) );
}
if ( $current->getComment() != '' ) {
$wgOut->addWikiMsgArray( 'editcomment', array(
- $wgUser->getSkin()->formatComment( $current->getComment() ) ), array( 'replaceafter' ) );
+ Linker::formatComment( $current->getComment() ) ), array( 'replaceafter' ) );
}
}
if ( $current->getUserText() === '' ) {
$old = wfMsg( 'rev-deleted-user' );
} else {
- $old = $wgUser->getSkin()->userLink( $current->getUser(), $current->getUserText() )
- . $wgUser->getSkin()->userToolLinks( $current->getUser(), $current->getUserText() );
+ $old = Linker::userLink( $current->getUser(), $current->getUserText() )
+ . Linker::userToolLinks( $current->getUser(), $current->getUserText() );
}
- $new = $wgUser->getSkin()->userLink( $target->getUser(), $target->getUserText() )
- . $wgUser->getSkin()->userToolLinks( $target->getUser(), $target->getUserText() );
+ $new = Linker::userLink( $target->getUser(), $target->getUserText() )
+ . Linker::userToolLinks( $target->getUser(), $target->getUserText() );
$wgOut->addHTML( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) );
$wgOut->returnToMain( false, $this->mTitle );
$edit->revid = $revid;
$edit->newText = $text;
$edit->pst = $this->preSaveTransform( $text, $user, $popts );
- $edit->popts = $this->getParserOptions();
+ $edit->popts = $this->getParserOptions( true );
$edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $edit->popts, true, true, $revid );
$edit->oldText = $this->getRawText();
* @param $newid Integer: rev_id value of the new revision
* @param $changed Boolean: Whether or not the content actually changed
* @param $user User object: User doing the edit
+ * @param $created Boolean: Whether the edit created the page
*/
- public function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true, User $user = null ) {
+ public function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid,
+ $changed = true, User $user = null, $created = false )
+ {
global $wgDeferredUpdateList, $wgUser, $wgEnableParserCache;
wfProfileIn( __METHOD__ );
return;
}
- $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment, $this->mTotalAdjustment );
- array_push( $wgDeferredUpdateList, $u );
- $u = new SearchUpdate( $id, $title, $text );
- array_push( $wgDeferredUpdateList, $u );
+ if ( !$changed ) {
+ $good = 0;
+ $total = 0;
+ } elseif ( $created ) {
+ $good = (int)$this->isCountable( $editInfo );
+ $total = 1;
+ } else {
+ $good = (int)$this->isCountable( $editInfo ) - (int)$this->isCountable();
+ $total = 0;
+ }
+
+ $wgDeferredUpdateList[] = new SiteStatsUpdate( 0, 1, $good, $total );
+ $wgDeferredUpdateList[] = new SearchUpdate( $id, $title, $text );
# If this is another user's talk page, update newtalk
# Don't do this if $changed = false otherwise some idiot can null-edit a
* anymore.
*/
public function createUpdates( $rev ) {
- $this->mGoodAdjustment = $this->isCountable( $rev->getText() );
- $this->mTotalAdjustment = 1;
$this->editUpdates( $rev->getText(), $rev->getComment(),
- $rev->isMinor(), wfTimestamp(), $rev->getId(), true );
+ $rev->isMinor(), wfTimestamp(), $rev->getId(), true, null, true );
}
/**
}
$revision = Revision::newFromId( $oldid );
+ $timestamp = $revision->getTimestamp();
$current = ( $oldid == $this->mLatest );
- $td = $wgLang->timeanddate( $this->mTimestamp, true );
- $tddate = $wgLang->date( $this->mTimestamp, true );
- $tdtime = $wgLang->time( $this->mTimestamp, true );
- $sk = $wgUser->getSkin();
+ $td = $wgLang->timeanddate( $timestamp, true );
+ $tddate = $wgLang->date( $timestamp, true );
+ $tdtime = $wgLang->time( $timestamp, true );
+
$lnk = $current
? wfMsgHtml( 'currentrevisionlink' )
- : $sk->link(
+ : Linker::link(
$this->mTitle,
wfMsgHtml( 'currentrevisionlink' ),
array(),
);
$curdiff = $current
? wfMsgHtml( 'diff' )
- : $sk->link(
+ : Linker::link(
$this->mTitle,
wfMsgHtml( 'diff' ),
array(),
);
$prev = $this->mTitle->getPreviousRevisionID( $oldid ) ;
$prevlink = $prev
- ? $sk->link(
+ ? Linker::link(
$this->mTitle,
wfMsgHtml( 'previousrevision' ),
array(),
)
: wfMsgHtml( 'previousrevision' );
$prevdiff = $prev
- ? $sk->link(
+ ? Linker::link(
$this->mTitle,
wfMsgHtml( 'diff' ),
array(),
: wfMsgHtml( 'diff' );
$nextlink = $current
? wfMsgHtml( 'nextrevision' )
- : $sk->link(
+ : Linker::link(
$this->mTitle,
wfMsgHtml( 'nextrevision' ),
array(),
);
$nextdiff = $current
? wfMsgHtml( 'diff' )
- : $sk->link(
+ : Linker::link(
$this->mTitle,
wfMsgHtml( 'diff' ),
array(),
$canHide = $wgUser->isAllowed( 'deleterevision' );
if ( $canHide || ( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
if ( !$revision->userCan( Revision::DELETED_RESTRICTED ) ) {
- $cdel = $sk->revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
+ $cdel = Linker::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
} else {
$query = array(
'type' => 'revision',
'target' => $this->mTitle->getPrefixedDbkey(),
'ids' => $oldid
);
- $cdel = $sk->revDeleteLink( $query, $revision->isDeleted( File::DELETED_RESTRICTED ), $canHide );
+ $cdel = Linker::revDeleteLink( $query, $revision->isDeleted( File::DELETED_RESTRICTED ), $canHide );
}
$cdel .= ' ';
}
# Show user links if allowed to see them. If hidden, then show them only if requested...
- $userlinks = $sk->revUserTools( $revision, !$unhide );
+ $userlinks = Linker::revUserTools( $revision, !$unhide );
$infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
? 'revision-info-current'
/**
* Clears caches when article is deleted
+ *
+ * @param $title Title
*/
public static function onArticleDelete( $title ) {
# Update existence markers on article/talk tabs...
$wgOut->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
}
- /**
- * Info about this page
- * Called for ?action=info when $wgAllowPageInfo is on.
- */
- public function info() {
- global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
-
- if ( !$wgAllowPageInfo ) {
- $wgOut->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
- return;
- }
-
- $page = $this->mTitle->getSubjectPage();
-
- $wgOut->setPagetitle( $page->getPrefixedText() );
- $wgOut->setPageTitleActionText( wfMsg( 'info_short' ) );
- $wgOut->setSubtitle( wfMsgHtml( 'infosubtitle' ) );
-
- if ( !$this->mTitle->exists() ) {
- $wgOut->addHTML( '<div class="noarticletext">' );
- if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
- // This doesn't quite make sense; the user is asking for
- // information about the _page_, not the message... -- RC
- $wgOut->addHTML( htmlspecialchars( $this->mTitle->getDefaultMessageText() ) );
- } else {
- $msg = $wgUser->isLoggedIn()
- ? 'noarticletext'
- : 'noarticletextanon';
- $wgOut->addHTML( wfMsgExt( $msg, 'parse' ) );
- }
-
- $wgOut->addHTML( '</div>' );
- } else {
- $dbr = wfGetDB( DB_SLAVE );
- $wl_clause = array(
- 'wl_title' => $page->getDBkey(),
- 'wl_namespace' => $page->getNamespace() );
- $numwatchers = $dbr->selectField(
- 'watchlist',
- 'COUNT(*)',
- $wl_clause,
- __METHOD__ );
-
- $pageInfo = $this->pageCountInfo( $page );
- $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
-
-
- //FIXME: unescaped messages
- $wgOut->addHTML( "<ul><li>" . wfMsg( "numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
- $wgOut->addHTML( "<li>" . wfMsg( 'numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>' );
-
- if ( $talkInfo ) {
- $wgOut->addHTML( '<li>' . wfMsg( "numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>' );
- }
-
- $wgOut->addHTML( '<li>' . wfMsg( "numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
-
- if ( $talkInfo ) {
- $wgOut->addHTML( '<li>' . wfMsg( 'numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
- }
-
- $wgOut->addHTML( '</ul>' );
- }
- }
-
- /**
- * Return the total number of edits and number of unique editors
- * on a given page. If page does not exist, returns false.
- *
- * @param $title Title object
- * @return mixed array or boolean false
- */
- public function pageCountInfo( $title ) {
- $id = $title->getArticleId();
-
- if ( $id == 0 ) {
- return false;
- }
-
- $dbr = wfGetDB( DB_SLAVE );
- $rev_clause = array( 'rev_page' => $id );
- $edits = $dbr->selectField(
- 'revision',
- 'COUNT(rev_page)',
- $rev_clause,
- __METHOD__
- );
- $authors = $dbr->selectField(
- 'revision',
- 'COUNT(DISTINCT rev_user_text)',
- $rev_clause,
- __METHOD__
- );
-
- return array( 'edits' => $edits, 'authors' => $authors );
- }
-
/**
* Return a list of templates used by this article.
* Uses the templatelinks table
/**
* Get parser options suitable for rendering the primary article wikitext
+ * @param $canonical boolean Determines that the generated options must not depend on user preferences (see bug 14404)
* @return mixed ParserOptions object or boolean false
*/
- public function getParserOptions() {
- global $wgUser;
-
- if ( !$this->mParserOptions ) {
- $this->mParserOptions = new ParserOptions( $wgUser );
- $this->mParserOptions->setTidy( true );
- $this->mParserOptions->enableLimitReport();
+ 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;
}
-
- // Clone to allow modifications of the return value without affecting
- // the cache
+ // Clone to allow modifications of the return value without affecting cache
return clone $this->mParserOptions;
}
+ /**
+ * Get parser options suitable for rendering the primary article wikitext
+ * @param User $user
+ * @return ParserOptions
+ */
+ public function makeParserOptions( User $user ) {
+ $options = ParserOptions::newFromUser( $user );
+ $options->enableLimitReport(); // show inclusion/loop reports
+ $options->setTidy( true ); // fix bad HTML
+ return $options;
+ }
+
/**
* Updates cascading protections
*
- * @param $parserOutput mixed ParserOptions object, or boolean false
+ * @param $parserOutput ParserOutput object, or boolean false
**/
protected function doCascadeProtectionUpdates( $parserOutput ) {
if ( !$this->isCurrent() || wfReadOnly() || !$this->mTitle->areRestrictionsCascading() ) {
}
class PoolWorkArticleView extends PoolCounterWork {
+
+ /**
+ * @var Article
+ */
private $mArticle;
function __construct( $article, $key, $useParserCache, $parserOptions ) {
return $this->mArticle->tryDirtyCache();
}
+ /**
+ * @param $status Status
+ */
function error( $status ) {
global $wgOut;