/**
* Get the DB key with the initial letter case as specified by the user
+ * @deprecated since 1.33; please use Title::getDBKey() instead
*
* @return string DB key
*/
/**
* Get the page's content model id, see the CONTENT_MODEL_XXX constants.
*
+ * @todo Deprecate this in favor of SlotRecord::getModel()
+ *
* @param int $flags A bit field; may be Title::GAID_FOR_UPDATE to select for update
* @return string Content model id
*/
$p = $this->mInterwiki . ':';
}
- if ( 0 != $this->mNamespace ) {
+ if ( $this->mNamespace != 0 ) {
$nsText = $this->getNsText();
if ( $nsText === false ) {
}
$useReplica = ( $rigor !== 'secure' );
- $block = $user->getBlock( $useReplica );
-
- // The block may explicitly allow an action (like "read" or "upload").
- if ( $block && $block->prevents( $action ) === false ) {
- return $errors;
- }
-
- // Determine if the user is blocked from this action on this page.
- try {
+ if ( ( $action == 'edit' || $action == 'create' )
+ && !$user->isBlockedFrom( $this, $useReplica )
+ ) {
+ // Don't block the user from editing their own talk page unless they've been
+ // explicitly blocked from that too.
+ } elseif ( $user->isBlocked() && $user->getBlock()->prevents( $action ) !== false ) {
// @todo FIXME: Pass the relevant context into this function.
- $action = Action::factory( $action, WikiPage::factory( $this ), RequestContext::getMain() );
- } catch ( Exception $e ) {
- $action = null;
- }
-
- // If no action object is returned, assume that the action requires unblock
- // which is the default.
- if ( !$action || $action->requiresUnblock() ) {
- if ( $user->isBlockedFrom( $this, $useReplica ) ) {
- // @todo FIXME: Pass the relevant context into this function.
- $errors[] = $block
- ? $block->getPermissionsError( RequestContext::getMain() )
- : [ 'badaccess-group0' ];
- }
+ $errors[] = $user->getBlock()->getPermissionsError( RequestContext::getMain() );
}
return $errors;
}
$errors = [];
- while ( count( $checks ) > 0 &&
- !( $short && count( $errors ) > 0 ) ) {
- $method = array_shift( $checks );
+ foreach ( $checks as $method ) {
$errors = $this->$method( $action, $user, $errors, $rigor, $short );
+
+ if ( $short && $errors !== [] ) {
+ break;
+ }
}
return $errors;
* indicating who can move or edit the page from the page table, (pre 1.10) rows.
* Edit and move sections are separated by a colon
* Example: "edit=autoconfirmed,sysop:move=sysop"
+ * @param bool $readLatest When true, skip replicas and read from the master DB.
*/
- public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
- $dbr = wfGetDB( DB_REPLICA );
+ public function loadRestrictionsFromRows(
+ $rows, $oldFashionedRestrictions = null, $readLatest = false
+ ) {
+ $whichDb = $readLatest ? DB_MASTER : DB_REPLICA;
+ $dbr = wfGetDB( $whichDb );
$restrictionTypes = $this->getRestrictionTypes();
* indicating who can move or edit the page from the page table, (pre 1.10) rows.
* Edit and move sections are separated by a colon
* Example: "edit=autoconfirmed,sysop:move=sysop"
+ * @param bool $readLatest When true, skip replicas and read from the master DB.
*/
- public function loadRestrictions( $oldFashionedRestrictions = null ) {
- if ( $this->mRestrictionsLoaded ) {
+ public function loadRestrictions( $oldFashionedRestrictions = null, $readLatest = false ) {
+ if ( $this->mRestrictionsLoaded && !$readLatest ) {
return;
}
$fname = __METHOD__;
$rows = $cache->getWithSetCallback(
// Page protections always leave a new null revision
- $cache->makeKey( 'page-restrictions', $id, $this->getLatestRevID() ),
+ $cache->makeKey( 'page-restrictions', $id, $this->getLatestRevID(), $readLatest ),
$cache::TTL_DAY,
- function ( $curValue, &$ttl, array &$setOpts ) use ( $fname ) {
- $dbr = wfGetDB( DB_REPLICA );
+ function ( $curValue, &$ttl, array &$setOpts ) use ( $fname, $readLatest ) {
+ $whichDb = $readLatest ? DB_MASTER : DB_REPLICA;
+ $dbr = wfGetDB( $whichDb );
$setOpts += Database::getCacheSetOptions( $dbr );
}
);
- $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions );
+ $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions, $readLatest );
} else {
$title_protection = $this->getTitleProtectionInternal();
$this->mArticleID = $linkCache->addLinkObj( $this );
$linkCache->forUpdate( $oldUpdate );
} else {
- if ( -1 == $this->mArticleID ) {
+ if ( $this->mArticleID == -1 ) {
$this->mArticleID = $linkCache->addLinkObj( $this );
}
}
if ( MWNamespace::hasSubpages( $this->mNamespace ) ) {
// Optional notice for page itself and any parent page
- $parts = explode( '/', $this->mDbkeyform );
$editnotice_base = $editnotice_ns;
- while ( count( $parts ) > 0 ) {
- $editnotice_base .= '-' . array_shift( $parts );
+ foreach ( explode( '/', $this->mDbkeyform ) as $part ) {
+ $editnotice_base .= '-' . $part;
$msg = wfMessage( $editnotice_base );
if ( $msg->exists() ) {
$html = $msg->parseAsBlock();