* @access public
*/
function getNsText() {
- global $wgContLang;
+ global $wgContLang, $wgCanonicalNamespaceNames;
+
+ if ( '' != $this->mInterwiki ) {
+ // This probably shouldn't even happen. ohh man, oh yuck.
+ // But for interwiki transclusion it sometimes does.
+ // Shit. Shit shit shit.
+ //
+ // Use the canonical namespaces if possible to try to
+ // resolve a foreign namespace.
+ if( isset( $wgCanonicalNamespaceNames[$this->mNamespace] ) ) {
+ return $wgCanonicalNamespaceNames[$this->mNamespace];
+ }
+ }
return $wgContLang->getNsText( $this->mNamespace );
}
/**
} else {
$baseUrl = $this->getInterwikiLink( $this->mInterwiki );
- $namespace = $wgContLang->getNsText( $this->mNamespace );
+ $namespace = wfUrlencode( $this->getNsText() );
if ( '' != $namespace ) {
# Can this actually happen? Interwikis shouldn't be parsed.
+ # Yes! It can in interwiki transclusion. But... it probably shouldn't.
$namespace .= ':';
}
$url = str_replace( '$1', $namespace . $this->mUrlform, $baseUrl );
* @return bool
*/
function isSemiProtected( $action = 'edit' ) {
- $restrictions = $this->getRestrictions( $action );
- # We do a full compare because this could be an array
- foreach( $restrictions as $restriction ) {
- if( strtolower( $restriction ) != 'autoconfirmed' ) {
- return( false );
+ if( $this->exists() ) {
+ $restrictions = $this->getRestrictions( $action );
+ if( count( $restrictions ) > 0 ) {
+ foreach( $restrictions as $restriction ) {
+ if( strtolower( $restriction ) != 'autoconfirmed' )
+ return false;
+ }
+ } else {
+ # Not protected
+ return false;
}
+ return true;
+ } else {
+ # If it doesn't exist, it can't be protected
+ return false;
}
- return( true );
}
/**
* @access public
*/
function loadRestrictions( $res ) {
+ $this->mRestrictions['edit'] = array();
+ $this->mRestrictions['move'] = array();
+
+ if( !$res ) {
+ # No restrictions (page_restrictions blank)
+ $this->mRestrictionsLoaded = true;
+ return;
+ }
+
foreach( explode( ':', trim( $res ) ) as $restrict ) {
$temp = explode( '=', trim( $restrict ) );
if(count($temp) == 1) {
/**
* Accessor/initialisation for mRestrictions
+ *
+ * @access public
* @param string $action action that permission needs to be checked for
* @return array the array of groups allowed to edit this article
- * @access public
*/
- function getRestrictions($action) {
- $id = $this->getArticleID();
- if ( 0 == $id ) { return array(); }
-
- if ( ! $this->mRestrictionsLoaded ) {
- $dbr =& wfGetDB( DB_SLAVE );
- $res = $dbr->selectField( 'page', 'page_restrictions', 'page_id='.$id );
- $this->loadRestrictions( $res );
- }
- if( isset( $this->mRestrictions[$action] ) ) {
- return $this->mRestrictions[$action];
+ function getRestrictions( $action ) {
+ if( $this->exists() ) {
+ if( !$this->mRestrictionsLoaded ) {
+ $dbr =& wfGetDB( DB_SLAVE );
+ $res = $dbr->selectField( 'page', 'page_restrictions', array( 'page_id' => $this->getArticleId() ) );
+ $this->loadRestrictions( $res );
+ }
+ return isset( $this->mRestrictions[$action] )
+ ? $this->mRestrictions[$action]
+ : array();
+ } else {
+ return array();
}
- return array();
}
/**
* @private
*/
/* private */ function prefix( $name ) {
- global $wgContLang;
-
$p = '';
if ( '' != $this->mInterwiki ) {
$p = $this->mInterwiki . ':';
}
if ( 0 != $this->mNamespace ) {
- $p .= $wgContLang->getNsText( $this->mNamespace ) . ':';
+ $p .= $this->getNsText() . ':';
}
return $p . $name;
}