*/
static private $titleCache=array();
static private $interwikiCache=array();
-
-
+
+
/**
* All member variables should be considered private
* Please use the accessor functions
$this->mLatestID = false;
$this->mOldRestrictions = false;
$this->mLength = -1;
- $this->mRedirect = null;
+ $this->mRedirect = NULL;
}
/**
}
/**
- * Make an array of titles from an array of IDs
+ * Make an array of titles from an array of IDs
*/
public static function newFromIDs( $ids ) {
if ( !count( $ids ) ) {
}
return $titles;
}
-
+
/**
* Make a Title object from a DB row
* @param Row $row (needs at least page_title,page_namespace)
*/
public static function newFromRow( $row ) {
$t = self::makeTitle( $row->page_namespace, $row->page_title );
- $t->mArticleID = isset($row->page_id) ? $row->page_id : -1;
- $t->mLength = isset($row->page_len) ? $row->page_len : -1;
- $t->mRedirect = isset($row->page_is_redirect) ? (bool)$row->page_is_redirect : null;
- $t->mLatest = isset($row->page_latest) ? $row->page_latest : 0;
-
+
+ $t->mArticleID = isset($row->page_id) ? intval($row->page_id) : -1;
+ $t->mLength = isset($row->page_len) ? intval($row->page_len) : -1;
+ $t->mRedirect = isset($row->page_is_redirect) ? (bool)$row->page_is_redirect : NULL;
+ $t->mLatestID = isset($row->page_latest) ? $row->page_latest : false;
+
return $t;
}
return $s->iw_url;
}
-
+
/**
* Fetch interwiki prefix data from local cache in constant database
*
$url = "{$wgScript}?title={$dbkey}&{$query}";
}
}
-
+
// FIXME: this causes breakage in various places when we
// actually expected a local URL and end up with dupe prefixes.
if ($wgRequest->getVal('action') == 'render') {
return true;
# Check regular protection levels
- foreach( $wgRestrictionTypes as $type ){
+ foreach( $wgRestrictionTypes as $type ){
if( $action == $type || $action == '' ) {
$r = $this->getRestrictions( $type );
foreach( $wgRestrictionLevels as $level ) {
$intended = $user->mBlock->mAddress;
- $errors[] = array ( ($block->mAuto ? 'autoblockedtext' : 'blockedtext'), $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp );
+ $errors[] = array( ($block->mAuto ? 'autoblockedtext' : 'blockedtext'), $link, $reason, $ip, $name,
+ $blockid, $blockExpiry, $intended, $blockTimestamp );
}
return $errors;
// Use getUserPermissionsErrors instead
if ( !wfRunHooks( 'userCan', array( &$this, &$user, $action, &$result ) ) ) {
+ wfProfileOut( __METHOD__ );
return $result ? array() : array( array( 'badaccess-group0' ) );
}
if( NS_SPECIAL == $this->mNamespace ) {
$errors[] = array('ns-specialprotected');
}
-
+
if ( $this->isNamespaceProtected() ) {
$ns = $this->getNamespace() == NS_MAIN
? wfMsg( 'nstab-main' )
: $this->getNsText();
- $errors[] = (NS_MEDIAWIKI == $this->mNamespace
- ? array('protectedinterface')
+ $errors[] = (NS_MEDIAWIKI == $this->mNamespace
+ ? array('protectedinterface')
: array( 'namespaceprotected', $ns ) );
}
&& !preg_match('/^'.preg_quote($user->getName(), '/').'\//', $this->mTextform) ) {
$errors[] = array('customcssjsprotected');
}
-
+
if ( $doExpensiveQueries && !$this->isCssJsSubpage() ) {
# We /could/ use the protection level on the source page, but it's fairly ugly
# as we have to establish a precedence hierarchy for pages included by multiple
}
}
}
-
+
foreach( $this->getRestrictions($action) as $right ) {
// Backwards compatibility, rewrite sysop -> protect
if ( $right == 'sysop' ) {
}
}
- if ($action == 'create') {
+ if ($action == 'create') {
$title_protection = $this->getTitleProtection();
if (is_array($title_protection)) {
}
$dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( 'protected_titles', '*',
+ $res = $dbr->select( 'protected_titles', '*',
array ('pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey()) );
if ($row = $dbr->fetchRow( $res )) {
public function deleteTitleProtection() {
$dbw = wfGetDB( DB_MASTER );
- $dbw->delete( 'protected_titles',
+ $dbw->delete( 'protected_titles',
array ('pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey()), __METHOD__ );
}
} else {
global $wgWhitelistRead;
- /**
+ /**
* Always grant access to the login page.
* Even anons need to be able to log in.
*/
public function isTalkPage() {
return MWNamespace::isTalk( $this->getNamespace() );
}
-
- /**
- * Is this an article that is a redirect page?
- * @return bool
- */
- public function isRedirect() {
- if( $this->mRedirect !== null )
- return $this->mRedirect;
- # Zero for special pages
- if( $this->mArticleID <= 0 )
- return 0;
-
- $dbr = wfGetDB( DB_SLAVE );
- $redir = $dbr->selectField( 'page', 'page_is_redirect',
- array( 'page_id' => $this->mArticleID ),
- __METHOD__ );
-
- $this->mRedirect = $redir ? true : false;
-
- return $this->mRedirect;
- }
-
- /**
- * What is the length of this page (-1 for special pages)?
- * @return bool
- */
- public function getLength() {
- if( $this->mLength != -1 || $this->mArticleID == 0 )
- return $this->mLength;
- # Zero for special pages
- if( $this->mArticleID <= 0 )
- return -1;
-
- $dbr = wfGetDB( DB_SLAVE );
- $len = $dbr->selectField( 'page', 'page_len',
- array( 'page_id' => $this->mArticleID ),
- __METHOD__ );
- $this->mLength = intval($len);
-
- return $this->mLength;
- }
/**
* Is this a subpage?
*/
public function isSubpage() {
global $wgNamespacesWithSubpages;
-
+
if( isset( $wgNamespacesWithSubpages[ $this->mNamespace ] ) ) {
return ( strpos( $this->getText(), '/' ) !== false && $wgNamespacesWithSubpages[ $this->mNamespace ] == true );
} else {
return false;
}
}
-
+
/**
* Could this page contain custom CSS or JavaScript, based
* on the title?
$sources = $get_pages ? array() : false;
$now = wfTimestampNow();
$purgeExpired = false;
-
+
while( $row = $dbr->fetchObject( $res ) ) {
$expiry = Block::decodeExpiry( $row->pr_expiry );
if( $expiry > $now ) {
while ($row = $dbr->fetchObject( $res ) ) {
# Cycle through all the restrictions.
-
+
// Don't take care of restrictions types that aren't in $wgRestrictionTypes
if( !in_array( $row->pr_type, $wgRestrictionTypes ) )
continue;
* @return int the ID
*/
public function getArticleID( $flags = 0 ) {
- $linkCache =& LinkCache::singleton();
+ $linkCache = LinkCache::singleton();
if ( $flags & GAID_FOR_UPDATE ) {
$oldUpdate = $linkCache->forUpdate( true );
$this->mArticleID = $linkCache->addLinkObj( $this );
return $this->mArticleID;
}
+ /**
+ * Is this an article that is a redirect page?
+ * Uses link cache, adding it if necessary
+ * @param int $flags a bit field; may be GAID_FOR_UPDATE to select for update
+ * @return bool
+ */
+ public function isRedirect( $flags = 0 ) {
+ if( !is_null($this->mRedirect) )
+ return $this->mRedirect;
+ # Zero for special pages.
+ # Also, calling getArticleID() loads the field from cache!
+ if( !$this->getArticleID($flags) || $this->getNamespace() == NS_SPECIAL ) {
+ return false;
+ }
+ $linkCache = LinkCache::singleton();
+ $this->mRedirect = (bool)$linkCache->getGoodLinkFieldObj( $this, 'redirect' );
+
+ return $this->mRedirect;
+ }
+
+ /**
+ * What is the length of this page?
+ * Uses link cache, adding it if necessary
+ * @param int $flags a bit field; may be GAID_FOR_UPDATE to select for update
+ * @return bool
+ */
+ public function getLength( $flags = 0 ) {
+ if( $this->mLength != -1 )
+ return $this->mLength;
+ # Zero for special pages.
+ # Also, calling getArticleID() loads the field from cache!
+ if( !$this->getArticleID($flags) || $this->getNamespace() == NS_SPECIAL ) {
+ return 0;
+ }
+ $linkCache = LinkCache::singleton();
+ $this->mLength = intval( $linkCache->getGoodLinkFieldObj( $this, 'length' ) );
+
+ return $this->mLength;
+ }
+
public function getLatestRevID() {
if ($this->mLatestID !== false)
return $this->mLatestID;
* @param int $newid the new Article ID
*/
public function resetArticleID( $newid ) {
- $linkCache =& LinkCache::singleton();
+ $linkCache = LinkCache::singleton();
$linkCache->clearBadLink( $this->getPrefixedDBkey() );
if ( 0 == $newid ) { $this->mArticleID = -1; }
$this->mInterwiki = $this->mFragment = '';
$this->mNamespace = $this->mDefaultNamespace; # Usually NS_MAIN
-
+
$dbkey = $this->mDbkeyform;
# Strip Unicode bidi override characters.
# override chars get included in list displays.
$dbkey = str_replace( "\xE2\x80\x8E", '', $dbkey ); // 200E LEFT-TO-RIGHT MARK
$dbkey = str_replace( "\xE2\x80\x8F", '', $dbkey ); // 200F RIGHT-TO-LEFT MARK
-
+
# Clean up whitespace
#
$dbkey = preg_replace( '/[ _]+/', '_', $dbkey );
{
return false;
}
-
+
/**
* Magic tilde sequences? Nu-uh!
*/
* Limit the size of titles to 255 bytes.
* This is typically the size of the underlying database field.
* We make an exception for special pages, which don't need to be stored
- * in the database, and may edge over 255 bytes due to subpage syntax
+ * in the database, and may edge over 255 bytes due to subpage syntax
* for long titles, e.g. [[Special:Block/Long name]]
*/
if ( ( $this->mNamespace != NS_SPECIAL && strlen( $dbkey ) > 255 ) ||
- strlen( $dbkey ) > 512 )
+ strlen( $dbkey ) > 512 )
{
return false;
}
return false;
}
// Allow IPv6 usernames to start with '::' by canonicalizing IPv6 titles.
- // IP names are not allowed for accounts, and can only be referring to
- // edits from the IP. Given '::' abbreviations and caps/lowercaps,
- // there are numerous ways to present the same IP. Having sp:contribs scan
- // them all is silly and having some show the edits and others not is
+ // IP names are not allowed for accounts, and can only be referring to
+ // edits from the IP. Given '::' abbreviations and caps/lowercaps,
+ // there are numerous ways to present the same IP. Having sp:contribs scan
+ // them all is silly and having some show the edits and others not is
// inconsistent. Same for talk/userpages. Keep them normalized instead.
- $dbkey = ($this->mNamespace == NS_USER || $this->mNamespace == NS_USER_TALK) ?
+ $dbkey = ($this->mNamespace == NS_USER || $this->mNamespace == NS_USER_TALK) ?
IP::sanitizeIP( $dbkey ) : $dbkey;
// Any remaining initial :s are illegal.
if ( $dbkey !== '' && ':' == $dbkey{0} ) {
return false;
}
-
+
# Fill fields
$this->mDbkeyform = $dbkey;
$this->mUrlform = wfUrlencode( $dbkey );
/**
* Set the fragment for this title
* This is kind of bad, since except for this rarely-used function, Title objects
- * are immutable. The reason this is here is because it's better than setting the
+ * are immutable. The reason this is here is because it's better than setting the
* members directly, which is what Linker::formatComment was doing previously.
*
* @param string $fragment text
* @return array the Title objects linking here
*/
public function getLinksTo( $options = '', $table = 'pagelinks', $prefix = 'pl' ) {
- $linkCache =& LinkCache::singleton();
+ $linkCache = LinkCache::singleton();
if ( $options ) {
$db = wfGetDB( DB_MASTER );
if ( $db->numRows( $res ) ) {
while ( $row = $db->fetchObject( $res ) ) {
if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
- $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redir );
+ $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect );
$retVal[] = $titleObj;
}
}
$newarticle = new Article( $nt );
$wgMessageCache->replace( $nt->getDBkey(), $newarticle->getContent() );
}
-
+
global $wgUser;
wfRunHooks( 'TitleMoveComplete', array( &$this, &$nt, &$wgUser, $pageid, $redirid ) );
return true;
} else {
$this->resetArticleID( 0 );
}
-
+
# Log the move
$log = new LogPage( 'move' );
$log->addEntry( 'move_redir', $this, $reason, array( 1 => $nt->getPrefixedText() ) );
# Return true if there was no history
return $row === false;
}
-
+
/**
* Can this title be added to a user's watchlist?
*
/**
* Get the number of revisions between the given revision IDs.
+ * Used for diffs and other things that really need it.
*
* @param integer $old Revision ID.
* @param integer $new Revision ID.
return $dbr->selectField( 'revision', 'count(*)',
'rev_page = ' . intval( $this->getArticleId() ) .
' AND rev_id > ' . intval( $old ) .
- ' AND rev_id < ' . intval( $new ) );
+ ' AND rev_id < ' . intval( $new ),
+ __METHOD__,
+ array( 'USE INDEX' => 'PRIMARY' ) );
}
/**
&& $this->getNamespace() == $title->getNamespace()
&& $this->getDBkey() === $title->getDBkey();
}
-
+
/**
* Return a string representation of this title
*
/**
* Update page_touched timestamps and send squid purge messages for
- * pages linking to this title. May be sent to the job queue depending
+ * pages linking to this title. May be sent to the job queue depending
* on the number of links. Typically called on create and delete.
*/
public function touchLinks() {
public function getTouched() {
$dbr = wfGetDB( DB_SLAVE );
$touched = $dbr->selectField( 'page', 'page_touched',
- array(
+ array(
'page_namespace' => $this->getNamespace(),
'page_title' => $this->getDBkey()
), __METHOD__
}
/**
- * If the Title refers to a special page alias which is not the local default,
+ * If the Title refers to a special page alias which is not the local default,
* returns a new Title which points to the local default. Otherwise, returns $this.
*/
public function fixSpecialName() {
public function isContentPage() {
return MWNamespace::isContent( $this->getNamespace() );
}
-
+
+ public function getRedirectsHere() {
+ $redirs = array();
+ $dbr = wfGetDB( DB_SLAVE );
+ list($page,$redirect) = $dbr->tableNamesN( 'page', 'redirect' );
+ $result = $dbr->query( "SELECT page_title, page_namespace FROM $page JOIN $redirect ON page_id = rd_from WHERE rd_title = "
+ . $dbr->addQuotes( $this->getDBKey() ) . " AND rd_namespace = " . $this->getNamespace(), __METHOD__ );
+ while( $row = $dbr->fetchObject( $result ) ) {
+ $redirs[] = self::newFromRow( $row );
+ }
+ return $redirs;
+ }
}