- } elseif ( $preload === '' ) {
- return '';
- } else {
- $preloadTitle = Title::newFromText( $preload );
- if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
- $rev = Revision::newFromTitle($preloadTitle);
- if ( is_object( $rev ) ) {
- $text = $rev->getText();
- // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
- // its own mini-parser! -ævar
- $text = preg_replace( '~</?includeonly>~', '', $text );
- return $text;
- } else
- return '';
- }
- }
- }
-
- /**
- * This is the function that extracts metadata from the article body on the first view.
- * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
- * and set $wgMetadataWhitelist to the *full* title of the template whitelist
- */
- function extractMetaDataFromArticle () {
- global $wgUseMetadataEdit, $wgMetadataWhitelist, $wgContLang;
- $this->mMetaData = '';
- if ( !$wgUseMetadataEdit ) return;
- if ( $wgMetadataWhitelist == '' ) return;
- $s = '';
- $t = $this->getContent();
-
- # MISSING : <nowiki> filtering
-
- # Categories and language links
- $t = explode ( "\n" , $t );
- $catlow = strtolower ( $wgContLang->getNsText( NS_CATEGORY ) );
- $cat = $ll = array();
- foreach ( $t AS $key => $x ) {
- $y = trim ( strtolower ( $x ) );
- while ( substr ( $y , 0 , 2 ) == '[[' ) {
- $y = explode ( ']]' , trim ( $x ) );
- $first = array_shift ( $y );
- $first = explode ( ':' , $first );
- $ns = array_shift ( $first );
- $ns = trim ( str_replace ( '[' , '' , $ns ) );
- if ( $wgContLang->getLanguageName( $ns ) || strtolower ( $ns ) == $catlow ) {
- $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]';
- if ( strtolower ( $ns ) == $catlow ) $cat[] = $add;
- else $ll[] = $add;
- $x = implode ( ']]' , $y );
- $t[$key] = $x;
- $y = trim ( strtolower ( $x ) );
- } else {
- $x = implode ( ']]' , $y );
- $y = trim ( strtolower ( $x ) );
- }
- }
- }
- if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n";
- if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n";
- $t = implode ( "\n" , $t );
-
- # Load whitelist
- $sat = array () ; # stand-alone-templates; must be lowercase
- $wl_title = Title::newFromText ( $wgMetadataWhitelist );
- $wl_article = new Article ( $wl_title );
- $wl = explode ( "\n" , $wl_article->getContent() );
- foreach ( $wl AS $x ) {
- $isentry = false;
- $x = trim ( $x );
- while ( substr ( $x , 0 , 1 ) == '*' ) {
- $isentry = true;
- $x = trim ( substr ( $x , 1 ) );
- }
- if ( $isentry ) {
- $sat[] = strtolower ( $x );
- }
-
- }
-
- # Templates, but only some
- $t = explode ( '{{' , $t );
- $tl = array () ;
- foreach ( $t AS $key => $x ) {
- $y = explode ( '}}' , $x , 2 );
- if ( count ( $y ) == 2 ) {
- $z = $y[0];
- $z = explode ( '|' , $z );
- $tn = array_shift ( $z );
- if ( in_array ( strtolower ( $tn ) , $sat ) ) {
- $tl[] = '{{' . $y[0] . '}}';
- $t[$key] = $y[1];
- $y = explode ( '}}' , $y[1] , 2 );
+ } elseif ( $preload !== '' ) {
+ $title = Title::newFromText( $preload );
+ # Check for existence to avoid getting MediaWiki:Noarticletext
+ if ( isset( $title ) && $title->exists() && $title->userCanRead() ) {
+ $article = new Article( $title );
+
+ if ( $article->isRedirect() ) {
+ $title = Title::newFromRedirectRecurse( $article->getContent() );
+ # Redirects to missing titles are displayed, to hidden pages are followed
+ # Copying observed behaviour from ?action=view
+ if ( $title->exists() ) {
+ if ($title->userCanRead() ) {
+ $article = new Article( $title );
+ } else {
+ return "";
+ }
+ }