From 4ac09fcc22769f0e59320f4575b37147c01befc9 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Tue, 23 Mar 2004 10:11:24 +0000 Subject: [PATCH] getContentWithoutUsingSoManyDamnGlobals(), allowing deletion in MediaWiki namespace --- includes/Article.php | 84 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 6 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 07ee977fe6..a57b0407ad 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -208,6 +208,84 @@ class Article { wfFreeResult( $res ); } $this->mContentLoaded = true; + return $this->mContent; + } + + # Gets the article text without using so many damn globals + # Returns false on error + function getContentWithoutUsingSoManyDamnGlobals( $oldid = 0, $noredir = false ) { + global $wgMwRedir; + + if ( $this->mContentLoaded ) { + return $this->mContent; + } + $this->mContent = false; + + $fname = "Article::loadContent"; + + if ( ! $oldid ) { # Retrieve current version + $id = $this->getID(); + if ( 0 == $id ) { + return false; + } + + $sql = "SELECT " . + "cur_text,cur_timestamp,cur_user,cur_counter,cur_restrictions,cur_touched " . + "FROM cur WHERE cur_id={$id}"; + $res = wfQuery( $sql, DB_READ, $fname ); + if ( 0 == wfNumRows( $res ) ) { + return false; + } + + $s = wfFetchObject( $res ); + # If we got a redirect, follow it (unless we've been told + # not to by either the function parameter or the query + if ( !$noredir && $wgMwRedir->matchStart( $s->cur_text ) ) { + if ( preg_match( "/\\[\\[([^\\]\\|]+)[\\]\\|]/", + $s->cur_text, $m ) ) { + $rt = Title::newFromText( $m[1] ); + if( $rt && $rt->getInterwiki() == "" && $rt->getNamespace() != Namespace::getSpecial() ) { + $rid = $rt->getArticleID(); + if ( 0 != $rid ) { + $sql = "SELECT cur_text,cur_timestamp,cur_user," . + "cur_counter,cur_restrictions,cur_touched FROM cur WHERE cur_id={$rid}"; + $res = wfQuery( $sql, DB_READ, $fname ); + + if ( 0 != wfNumRows( $res ) ) { + $this->mRedirectedFrom = $this->mTitle->getPrefixedText(); + $this->mTitle = $rt; + $s = wfFetchObject( $res ); + } + } + } + } + } + + $this->mContent = $s->cur_text; + $this->mUser = $s->cur_user; + $this->mCounter = $s->cur_counter; + $this->mTimestamp = $s->cur_timestamp; + $this->mTouched = $s->cur_touched; + $this->mTitle->mRestrictions = explode( ",", trim( $s->cur_restrictions ) ); + $this->mTitle->mRestrictionsLoaded = true; + wfFreeResult( $res ); + } else { # oldid set, retrieve historical version + $sql = "SELECT old_text,old_timestamp,old_user,old_flags FROM old " . + "WHERE old_id={$oldid}"; + $res = wfQuery( $sql, DB_READ, $fname ); + if ( 0 == wfNumRows( $res ) ) { + return false; + } + + $s = wfFetchObject( $res ); + $this->mContent = Article::getRevisionText( $s ); + $this->mUser = $s->old_user; + $this->mCounter = 0; + $this->mTimestamp = $s->old_timestamp; + wfFreeResult( $res ); + } + $this->mContentLoaded = true; + return $this->mContent; } function getID() { @@ -675,12 +753,6 @@ class Article { return; } - # Can't delete MediaWiki namespace - if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { - $wgOut->fatalError( wfMsg( "cannotdelete" ) ); - return; - } - # Better double-check that it hasn't been deleted yet! $wgOut->setPagetitle( wfMsg( "confirmdelete" ) ); if ( ( "" == trim( $this->mTitle->getText() ) ) -- 2.20.1