includes/namespaces/default.php
changeset 963 b572ce1114f1
parent 953 323c4cd1aa37
child 970 d894086f38cc
equal deleted inserted replaced
962:ceeecb160aec 963:b572ce1114f1
   322         $this->error_404();
   322         $this->error_404();
   323         $output->footer();
   323         $output->footer();
   324       }
   324       }
   325     }
   325     }
   326   }
   326   }
       
   327   
       
   328   /**
       
   329    * Get a redirect, if there is one.
       
   330    * @return mixed Array: Page ID and namespace, associative; bool: false (no redirect)
       
   331    */
       
   332   
       
   333   public function get_redirect()
       
   334   {
       
   335     $text = $this->fetch_text();
       
   336     if ( preg_match('/^#redirect \[\[([^\]]+?)\]\]/i', $text, $match ) )
       
   337     {
       
   338       list($page_id, $namespace) = RenderMan::strToPageID($match[1]);
       
   339       return array(
       
   340           'page_id' => $page_id,
       
   341           'namespace' => $namespace
       
   342         );
       
   343     }
       
   344     return false;
       
   345   }
   327    
   346    
   328   /**
   347   /**
   329    * The "real" send-the-page function. The reason for this is so other namespaces can re-use the code
   348    * The "real" send-the-page function. The reason for this is so other namespaces can re-use the code
   330    * to fetch the page from the DB while being able to install their own wrappers.
   349    * to fetch the page from the DB while being able to install their own wrappers.
   331    */
   350    */
   340     
   359     
   341     profiler_log("Namespace [$this->namespace, $this->page_id]: pulled text from DB");
   360     profiler_log("Namespace [$this->namespace, $this->page_id]: pulled text from DB");
   342     
   361     
   343     $text = preg_replace('/([\s]*)__NOBREADCRUMBS__([\s]*)/', '', $text);
   362     $text = preg_replace('/([\s]*)__NOBREADCRUMBS__([\s]*)/', '', $text);
   344     $text = preg_replace('/([\s]*)__NOTOC__([\s]*)/', '', $text);
   363     $text = preg_replace('/([\s]*)__NOTOC__([\s]*)/', '', $text);
   345     
   364     $text = preg_replace('/^#redirect \[\[.+?\]\]\s*/i', '', $text);
   346     $redir_enabled = false;
       
   347     if ( preg_match('/^#redirect \[\[([^\]]+?)\]\]/i', $text, $match ) )
       
   348     {
       
   349       $redir_enabled = true;
       
   350       
       
   351       $oldtarget = RenderMan::strToPageID($match[1]);
       
   352       $oldtarget[0] = sanitize_page_id($oldtarget[0]);
       
   353       
       
   354       $url = makeUrlNS($oldtarget[1], $oldtarget[0], false, true);
       
   355       $page_data = $paths->get_cdata($oldtarget[0], $oldtarget[1]);
       
   356       $title = ( isset($page_data['name']) ) ? $page_data['name'] : $paths->nslist[$oldtarget[1]] . htmlspecialchars( str_replace('_', ' ', dirtify_page_id( $oldtarget[0] ) ) );
       
   357       if ( !isset($page_data['name']) )
       
   358       {
       
   359         $cls = 'class="wikilink-nonexistent"';
       
   360       }
       
   361       else
       
   362       {
       
   363         $cls = '';
       
   364       }
       
   365       $a = '<a ' . $cls . ' href="' . $url . '">' . $title . '</a>';
       
   366       $redir_html = '<br /><div class="mdg-infobox">
       
   367               <table border="0" width="100%" cellspacing="0" cellpadding="0">
       
   368                 <tr>
       
   369                   <td valign="top">
       
   370                     <img alt="Cute wet-floor icon" src="'.scriptPath.'/images/redirector.png" />
       
   371                   </td>
       
   372                   <td valign="top" style="padding-left: 10px;">
       
   373                     ' . $lang->get('page_msg_this_is_a_redirector', array( 'redirect_target' => $a )) . '
       
   374                   </td>
       
   375                 </tr>
       
   376               </table>
       
   377             </div>
       
   378             <br />
       
   379             <hr style="margin-left: 1em; width: 200px;" />';
       
   380       $text = str_replace($match[0], '', $text);
       
   381       $text = trim($text);
       
   382     }
       
   383     
   365     
   384     if ( $send_headers )
   366     if ( $send_headers )
   385     {
   367     {
   386       $output->set_title($this->title);
   368       $output->set_title($this->title);
   387       $output->header();
   369       $output->header();
   429       $db->free_result();
   411       $db->free_result();
   430     }
   412     }
   431     else
   413     else
   432     {
   414     {
   433       $page_format = $this->cdata['page_format'];
   415       $page_format = $this->cdata['page_format'];
   434     }
       
   435     
       
   436     if ( $redir_enabled )
       
   437     {
       
   438       echo $redir_html;
       
   439     }
   416     }
   440     
   417     
   441     $code = $plugins->setHook('pageprocess_render_head');
   418     $code = $plugins->setHook('pageprocess_render_head');
   442     foreach ( $code as $cmd )
   419     foreach ( $code as $cmd )
   443     {
   420     {