/* static */ function newFromID( $id ) {
$fname = 'Title::newFromID';
$dbr =& wfGetDB( DB_SLAVE );
- $row = $dbr->getArray( 'cur', array( 'cur_namespace', 'cur_title' ),
+ $row = $dbr->selectRow( 'cur', array( 'cur_namespace', 'cur_title' ),
array( 'cur_id' => $id ), $fname );
if ( $row !== false ) {
$title = Title::makeTitle( $row->cur_namespace, $row->cur_title );
$fname = 'Title::nameOf';
$dbr =& wfGetDB( DB_SLAVE );
- $s = $dbr->getArray( 'cur', array( 'cur_namespace','cur_title' ), array( 'cur_id' => $id ), $fname );
+ $s = $dbr->selectRow( 'cur', array( 'cur_namespace','cur_title' ), array( 'cur_id' => $id ), $fname );
if ( $s === false ) { return NULL; }
$n = Title::makeName( $s->cur_namespace, $s->cur_title );
}
}
- /**
- * @deprecated
- */
- function getURL() {
- die( 'Call to obsolete obsolete function Title::getURL()' );
- }
-
/**
* Get a URL with no fragment or server name
* @param string $query an optional query string; if not specified,
if ( $query == '-' ) {
$query = '';
}
- if ( $wgScript != '' ) {
- $url = "{$wgScript}?title={$dbkey}&{$query}";
- } else {
- # Top level wiki
- $url = "/{$dbkey}?{$query}";
- }
+ $url = "{$wgScript}?title={$dbkey}&{$query}";
}
return $url;
}
*/
function userCanEdit() {
global $wgUser;
- if ( -1 == $this->mNamespace ) { return false; }
- if ( NS_MEDIAWIKI == $this->mNamespace && !$wgUser->isSysop() ) { return false; }
- # if ( 0 == $this->getArticleID() ) { return false; }
- if ( $this->mDbkeyform == '_' ) { return false; }
+ if( NS_SPECIAL == $this->mNamespace ) {
+ return false;
+ }
+ if( NS_MEDIAWIKI == $this->mNamespace &&
+ !$wgUser->isAllowed('editinterface') ) {
+ return false;
+ }
+ if( $this->mDbkeyform == '_' ) {
+ # FIXME: Is this necessary? Shouldn't be allowed anyway...
+ return false;
+ }
+
# protect global styles and js
if ( NS_MEDIAWIKI == $this->mNamespace
- && preg_match("/\\.(css|js)$/", $this->mTextform )
- && !$wgUser->isSysop() )
- { return false; }
- //if ( $this->isCssJsSubpage() and !$this->userCanEditCssJsSubpage() ) { return false; }
+ && preg_match("/\\.(css|js)$/", $this->mTextform )
+ && !$wgUser->isAllowed('editinterface') ) {
+ return false;
+ }
+
# protect css/js subpages of user pages
# XXX: this might be better using restrictions
# XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working
- if( Namespace::getUser() == $this->mNamespace
- and preg_match("/\\.(css|js)$/", $this->mTextform )
- and !$wgUser->isSysop()
- and !preg_match('/^'.preg_quote($wgUser->getName(), '/').'/', $this->mTextform) )
- { return false; }
- $ur = $wgUser->getRights();
- foreach ( $this->getRestrictions() as $r ) {
- if ( '' != $r && ( ! in_array( $r, $ur ) ) ) {
+ if( NS_USER == $this->mNamespace
+ && preg_match("/\\.(css|js)$/", $this->mTextform )
+ && !$wgUser->isAllowed('editinterface')
+ && !preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) ) {
+ return false;
+ }
+
+ foreach( $this->getRestrictions() as $right ) {
+ if( '' != $right && !$wgUser->isAllowed( $right ) ) {
return false;
}
}
*/
function userCanRead() {
global $wgUser;
- global $wgWhitelistRead;
- if( 0 != $wgUser->getID() ) return true;
- if( !is_array( $wgWhitelistRead ) ) return true;
-
- $name = $this->getPrefixedText();
- if( in_array( $name, $wgWhitelistRead ) ) return true;
-
- # Compatibility with old settings
- if( $this->getNamespace() == NS_MAIN ) {
- if( in_array( ':' . $name, $wgWhitelistRead ) ) return true;
+ if( $wgUser->isAllowed('read') ) {
+ return true;
+ } else {
+ global $wgWhitelistRead;
+
+ /** If anon users can create an account,
+ they need to reach the login page first! */
+ if( $wgUser->isAllowed( 'createaccount' )
+ && $this->mId == NS_SPECIAL
+ && $this->getText() == 'Userlogin' ) {
+ return true;
+ }
+
+ /** some pages are explicitly allowed */
+ $name = $this->getPrefixedText();
+ if( in_array( $name, $wgWhitelistRead ) ) {
+ return true;
+ }
+
+ # Compatibility with old settings
+ if( $this->getNamespace() == NS_MAIN ) {
+ if( in_array( ':' . $name, $wgWhitelistRead ) ) {
+ return true;
+ }
+ }
}
return false;
}
*/
function userCanEditCssJsSubpage() {
global $wgUser;
- return ( $wgUser->isSysop() or preg_match('/^'.preg_quote($wgUser->getName()).'/', $this->mTextform) );
+ return ( $wgUser->isAllowed('editinterface') or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) );
}
/**
if ( ! $this->mRestrictionsLoaded ) {
$dbr =& wfGetDB( DB_SLAVE );
- $res = $dbr->getField( 'cur', 'cur_restrictions', 'cur_id='.$id );
+ $res = $dbr->selectField( 'cur', 'cur_restrictions', 'cur_id='.$id );
$this->mRestrictions = explode( ',', trim( $res ) );
$this->mRestrictionsLoaded = true;
}
function isDeleted() {
$fname = 'Title::isDeleted';
$dbr =& wfGetDB( DB_SLAVE );
- $n = $dbr->getField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),
+ $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),
'ar_title' => $this->getDBkey() ), $fname );
return (int)$n;
}
function invalidateCache() {
$now = wfTimestampNow();
$dbw =& wfGetDB( DB_MASTER );
- $success = $dbw->updateArray( 'cur',
+ $success = $dbw->update( 'cur',
array( /* SET */
'cur_touched' => $dbw->timestamp()
), array( /* WHERE */
if ( $imgpre === false ) {
$imgpre = ':' . $wgContLang->getNsText( Namespace::getImage() ) . ':';
# % is needed as well
- $rxTc = '/[^' . Title::legalChars() . ']/';
+ $rxTc = '/[^' . Title::legalChars() . ']|%[0-9A-Fa-f]{2}/';
}
$this->mInterwiki = $this->mFragment = '';
$links = $dbw->tableName( 'links' );
# Change the name of the target page:
- $dbw->updateArray( 'cur',
+ $dbw->update( 'cur',
/* SET */ array(
'cur_touched' => $dbw->timestamp($now),
'cur_namespace' => $nt->getNamespace(),
# by definition if we've got here it's rather uninteresting.
$redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
- $dbw->updateArray( 'cur',
+ $dbw->update( 'cur',
/* SET */ array(
'cur_touched' => $dbw->timestamp($now),
'cur_timestamp' => $dbw->timestamp($now),
# Fix the redundant names for the past revisions of the target page.
# The redirect should have no old revisions.
- $dbw->updateArray(
+ $dbw->update(
/* table */ 'old',
/* SET */ array(
'old_namespace' => $nt->getNamespace(),
# Now, we record the link from the redirect to the new title.
# It should have no other outgoing links...
$dbw->delete( 'links', array( 'l_from' => $newid ) );
- $dbw->insertArray( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ) );
+ $dbw->insert( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ) );
# Clear linkscc
LinkCache::linksccClearLinksTo( $oldid );
$rand = wfRandom();
# Rename cur entry
- $dbw->updateArray( 'cur',
+ $dbw->update( 'cur',
/* SET */ array(
'cur_touched' => $now,
'cur_namespace' => $nt->getNamespace(),
$wgLinkCache->clearLink( $nt->getPrefixedDBkey() );
# Insert redirect
- $dbw->insertArray( 'cur', array(
+ $dbw->insert( 'cur', array(
'cur_id' => $dbw->nextSequenceValue('cur_cur_id_seq'),
'cur_namespace' => $this->getNamespace(),
'cur_title' => $this->getDBkey(),
$wgLinkCache->clearLink( $this->getPrefixedDBkey() );
# Rename old entries
- $dbw->updateArray(
+ $dbw->update(
/* table */ 'old',
/* SET */ array(
'old_namespace' => $nt->getNamespace(),
Article::onArticleCreate( $nt );
# Any text links to the old title must be reassigned to the redirect
- $dbw->updateArray( 'links', array( 'l_to' => $newid ), array( 'l_to' => $oldid ), $fname );
+ $dbw->update( 'links', array( 'l_to' => $newid ), array( 'l_to' => $oldid ), $fname );
LinkCache::linksccClearLinksTo( $oldid );
# Record the just-created redirect's linking to the page
- $dbw->insertArray( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ), $fname );
+ $dbw->insert( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ), $fname );
# Non-existent target may have had broken links to it; these must
# now be removed and made into good links.
# Is it a redirect?
$id = $nt->getArticleID();
- $obj = $dbw->getArray( 'cur', array( 'cur_is_redirect','cur_text' ),
+ $obj = $dbw->selectRow( 'cur', array( 'cur_is_redirect','cur_text' ),
array( 'cur_id' => $id ), $fname, 'FOR UPDATE' );
if ( !$obj || 0 == $obj->cur_is_redirect ) {
}
# Does the article have a history?
- $row = $dbw->getArray( 'old', array( 'old_id' ),
+ $row = $dbw->selectRow( 'old', array( 'old_id' ),
array(
'old_namespace' => $nt->getNamespace(),
'old_title' => $nt->getDBkey()
$won = wfInvertTimestamp( $now );
$seqVal = $dbw->nextSequenceValue( 'cur_cur_id_seq' );
- $dbw->insertArray( 'cur', array(
+ $dbw->insert( 'cur', array(
'cur_id' => $seqVal,
'cur_namespace' => $this->getNamespace(),
'cur_title' => $this->getDBkey(),
# Link table
if ( $dest->getArticleID() ) {
- $dbw->insertArray( 'links',
+ $dbw->insert( 'links',
array(
'l_to' => $dest->getArticleID(),
'l_from' => $newid
), $fname
);
} else {
- $dbw->insertArray( 'brokenlinks',
+ $dbw->insert( 'brokenlinks',
array(
'bl_to' => $dest->getPrefixedDBkey(),
'bl_from' => $newid
$sk =& $wgUser->getSkin();
$parents = array();
$dbr =& wfGetDB( DB_SLAVE );
- $cur = $dbr->tableName( 'cur' );
$categorylinks = $dbr->tableName( 'categorylinks' );
# NEW SQL
- $sql = "SELECT * FROM categorylinks"
+ $sql = "SELECT * FROM $categorylinks"
." WHERE cl_from='$titlekey'"
." AND cl_from <> '0'"
." ORDER BY cl_sortkey";
}
/**
- * Go through all parent categories of this Title
+ * Get a tree of parent categories
+ * @param array $children an array with the children in the keys, to check for circular refs
* @return array
* @access public
*/
- function getCategorieBrowser() {
+ function getParentCategoryTree( $children = array() ) {
$parents = $this->getParentCategories();
if($parents != '') {
foreach($parents as $parent => $current)
{
- $nt = Title::newFromText($parent);
- $stack[$parent] = $nt->getCategorieBrowser();
+ if ( array_key_exists( $parent, $children ) ) {
+ # Circular reference
+ $stack[$parent] = array();
+ } else {
+ $nt = Title::newFromText($parent);
+ $stack[$parent] = $nt->getParentCategoryTree( $children + array($parent => 1) );
+ }
}
return $stack;
} else {