includes/pageprocess.php
changeset 62 9dc4fded30e6
parent 61 e9708657875a
child 73 0a74676a2f2f
equal deleted inserted replaced
61:e9708657875a 62:9dc4fded30e6
    30   
    30   
    31   var $page_id;
    31   var $page_id;
    32   var $namespace;
    32   var $namespace;
    33   
    33   
    34   /**
    34   /**
       
    35    * The title of the page sent to the template parser
       
    36    * @var string
       
    37    */
       
    38   
       
    39   var $title = '';
       
    40   
       
    41   /**
       
    42    * The information about the page(s) we were redirected from
       
    43    * @var array
       
    44    */
       
    45   
       
    46   var $redirect_stack = array();
       
    47   
       
    48   /**
    35    * The revision ID (history entry) to send. If set to 0 (the default) then the most recent revision will be sent.
    49    * The revision ID (history entry) to send. If set to 0 (the default) then the most recent revision will be sent.
    36    * @var int
    50    * @var int
    37    */
    51    */
    38   
    52   
    39   var $revision_id = 0;
    53   var $revision_id = 0;
   229       
   243       
   230       $ob = ob_get_contents();
   244       $ob = ob_get_contents();
   231       
   245       
   232       if ( empty($ob) )
   246       if ( empty($ob) )
   233       {
   247       {
   234         die('ob is empty');
       
   235         $this->err_page_not_existent();
   248         $this->err_page_not_existent();
   236       }
   249       }
   237       else
   250       else
   238       {
   251       {
   239         // Something sent content, so we'll assume the page exist...ed at least according to the plugin
   252         // Something sent content, so we'll assume the page exist...ed at least according to the plugin
   255         $this->err_no_rows();
   268         $this->err_no_rows();
   256         return false;
   269         return false;
   257       }
   270       }
   258       else
   271       else
   259       {
   272       {
   260         $this->render( (!$strict_no_headers) );
   273         $redirect = ( isset($_GET['redirect']) ) ? $_GET['redirect'] : 'YES YOU IDIOT';
       
   274         if ( preg_match('/^#redirect \[\[([^\]]+)\]\]/i', $text, $match) && $redirect != 'no' )
       
   275         {
       
   276           // Redirect page!
       
   277           $page_to = sanitize_page_id($match[1]);
       
   278           $page_id_data = RenderMan::strToPageID($page_to);
       
   279           if ( count($this->redirect_stack) >= 3 )
       
   280           {
       
   281             $this->render( (!$strict_no_headers), '<div class="usermessage"><b>The maximum number of internal redirects has been exceeded.</b></div>' );
       
   282           }
       
   283           else
       
   284           {
       
   285             $result = $this->_handle_redirect($page_id_data[0], $page_id_data[1]);
       
   286             if ( $result !== true )
       
   287             {
       
   288               // There was some error during the redirect process - usually an infinite redirect
       
   289               $this->render( (!$strict_no_headers), '<div class="usermessage"><b>' . $result . '</b></div>' );
       
   290             }
       
   291           }
       
   292         }
       
   293         else
       
   294         {
       
   295           $this->render( (!$strict_no_headers) );
       
   296         }
   261       }
   297       }
   262     }
   298     }
   263   }
   299   }
   264   
   300   
   265   /**
   301   /**
   318         $this->page_exists = true;
   354         $this->page_exists = true;
   319       }
   355       }
   320       
   356       
   321     }
   357     }
   322     
   358     
       
   359     $this->title = get_page_title_ns($this->page_id, $this->namespace);
       
   360     
   323   }
   361   }
   324   
   362   
   325   /**
   363   /**
   326    * Renders it all in one go, and echoes it out. This assumes that the text is in the DB.
   364    * Renders it all in one go, and echoes it out. This assumes that the text is in the DB.
   327    * @access private
   365    * @access private
   328    */
   366    */
   329   
   367   
   330   function render($incl_inner_headers = true)
   368   function render($incl_inner_headers = true, $_errormsg = false)
   331   {
   369   {
       
   370     global $db, $session, $paths, $template, $plugins; // Common objects
       
   371     
   332     $text = $this->fetch_text();
   372     $text = $this->fetch_text();
   333     
   373     
       
   374     $redir_enabled = false;
       
   375     if ( preg_match('/^#redirect \[\[([^\]]+?)\]\]/i', $text, $match ) )
       
   376     {
       
   377       $redir_enabled = true;
       
   378       
       
   379       $oldtarget = RenderMan::strToPageID($match[1]);
       
   380       $oldtarget[0] = sanitize_page_id($oldtarget[0]);
       
   381       
       
   382       $url = makeUrlNS($oldtarget[1], $oldtarget[0], false, true);
       
   383       $page_id_key = $paths->nslist[ $oldtarget[1] ] . $oldtarget[0];
       
   384       $page_data = $paths->pages[$page_id_key];
       
   385       $title = ( isset($page_data['name']) ) ? $page_data['name'] : $paths->nslist[$oldtarget[1]] . htmlspecialchars( str_replace('_', ' ', dirtify_page_id( $oldtarget[0] ) ) );
       
   386       if ( !isset($page_data['name']) )
       
   387       {
       
   388         $cls = 'class="wikilink-nonexistent"';
       
   389       }
       
   390       else
       
   391       {
       
   392         $cls = '';
       
   393       }
       
   394       $a = '<a ' . $cls . ' href="' . $url . '">' . $title . '</a>';
       
   395       $redir_html = '<br /><div class="mdg-infobox">
       
   396               <table border="0" width="100%" cellspacing="0" cellpadding="0">
       
   397                 <tr>
       
   398                   <td valign="top">
       
   399                     <img alt="Cute wet-floor icon" src="'.scriptPath.'/images/redirector.png" />
       
   400                   </td>
       
   401                   <td valign="top" style="padding-left: 10px;">
       
   402                     <b>This page is a <i>redirector</i>.</b><br />
       
   403                     This means that this page will not show its own content by default. Instead it will display the contents of the page it redirects to.<br /><br />
       
   404                     To create a redirect page, make the <i>first characters</i> in the page content <tt>#redirect [[Page_ID]]</tt>. For more information, see the
       
   405                     Enano <a href="http://enanocms.org/Help:Wiki_formatting" onclick="window.open(this.href); return false;">Wiki formatting guide</a>.<br /><br />
       
   406                     This page redirects to ' . $a . '.
       
   407                   </td>
       
   408                 </tr>
       
   409               </table>
       
   410             </div>
       
   411             <br />
       
   412             <hr style="margin-left: 1em; width: 200px;" />';
       
   413       $text = str_replace($match[0], '', $text);
       
   414       $text = trim($text);
       
   415     }
       
   416     
       
   417     $template->tpl_strings['PAGE_NAME'] = htmlspecialchars( $this->title );
       
   418     
   334     $this->header();
   419     $this->header();
       
   420     
       
   421     if ( $_errormsg )
       
   422     {
       
   423       echo $_errormsg;
       
   424     }
       
   425     
   335     if ( $incl_inner_headers )
   426     if ( $incl_inner_headers )
   336     {
   427     {
       
   428       if ( count($this->redirect_stack) > 0 )
       
   429       {
       
   430         $stack = array_reverse($this->redirect_stack);
       
   431         foreach ( $stack as $oldtarget )
       
   432         {
       
   433           $url = makeUrlNS($oldtarget[1], $oldtarget[0], 'redirect=no', true);
       
   434           $page_id_key = $paths->nslist[ $oldtarget[1] ] . $oldtarget[0];
       
   435           $page_data = $paths->pages[$page_id_key];
       
   436           $title = ( isset($page_data['name']) ) ? $page_data['name'] : $paths->nslist[$oldtarget[1]] . htmlspecialchars( str_replace('_', ' ', dirtify_page_id( $oldtarget[0] ) ) );
       
   437           $a = '<a href="' . $url . '">' . $title . '</a>';
       
   438           echo '<small>(Redirected from ' . $a . ')<br /></small>';
       
   439         }
       
   440       }
   337       display_page_headers();
   441       display_page_headers();
   338     }
   442     }
   339     
   443     
   340     if ( $this->revision_id )
   444     if ( $this->revision_id )
   341     {
   445     {
   342       echo '<div class="info-box" style="margin-left: 0; margin-top: 5px;"><b>Notice:</b><br />The page you are viewing was archived on '.date('F d, Y \a\t h:i a', $this->revision_id).'.<br /><a href="'.makeUrlNS($this->namespace, $this->page_id).'" onclick="ajaxReset(); return false;">View current version</a>  |  <a href="'.makeUrlNS($this->namespace, $this->pageid, 'do=rollback&amp;id='.$this->revision_id).'" onclick="ajaxRollback(\''.$this->revision_id.'\')">Restore this version</a></div><br />';
   446       echo '<div class="info-box" style="margin-left: 0; margin-top: 5px;"><b>Notice:</b><br />The page you are viewing was archived on '.date('F d, Y \a\t h:i a', $this->revision_id).'.<br /><a href="'.makeUrlNS($this->namespace, $this->page_id).'" onclick="ajaxReset(); return false;">View current version</a>  |  <a href="'.makeUrlNS($this->namespace, $this->pageid, 'do=rollback&amp;id='.$this->revision_id).'" onclick="ajaxRollback(\''.$this->revision_id.'\')">Restore this version</a></div><br />';
       
   447     }
       
   448     
       
   449     if ( $redir_enabled )
       
   450     {
       
   451       echo $redir_html;
   343     }
   452     }
   344     
   453     
   345     if ( $incl_inner_headers )
   454     if ( $incl_inner_headers )
   346     {
   455     {
   347       $text = '?>' . RenderMan::render($text);
   456       $text = '?>' . RenderMan::render($text);
   810     $this->footer();
   919     $this->footer();
   811     
   920     
   812   }
   921   }
   813   
   922   
   814   /**
   923   /**
       
   924    * Pushes to the redirect stack and resets the instance. This depends on the page ID and namespace already being validated and sanitized, and does not check the size of the redirect stack.
       
   925    * @param string Page ID to redirect to
       
   926    * @param string Namespace to redirect to
       
   927    * @access private
       
   928    */
       
   929   
       
   930   function _handle_redirect($page_id, $namespace)
       
   931   {
       
   932     $arr_pid = array($this->page_id, $this->namespace);
       
   933     if ( $namespace == 'Special' || $namespace == 'Admin' )
       
   934     {
       
   935       return 'This page redirects to a Special or Administration page, which is not allowed.';
       
   936     }
       
   937     if ( in_array($this->redirect_stack, $arr_pid) )
       
   938     {
       
   939       return 'This page infinitely redirects with another page (or another series of pages), and the infinite redirect was trapped.';
       
   940     }
       
   941     $page_id_key = $paths->nslist[ $namespace ] . $page_id;
       
   942     if ( !isset($paths->pages[$page_id_key]) )
       
   943     {
       
   944       return 'This page redirects to another page that doesn\'t exist.';
       
   945     }
       
   946     $this->redirect_stack[] = $arr_pid;
       
   947     
       
   948     
       
   949     // Nuke the text cache to avoid infinite loops, gah...
       
   950     $this->text_cache = '';
       
   951     $this->_setup($page_id, $namespace, 0);
       
   952     $this->send();
       
   953     return true;
       
   954   }
       
   955   
       
   956   /**
   815    * Send the error message to the user that the access to this page is denied.
   957    * Send the error message to the user that the access to this page is denied.
   816    * @access private
   958    * @access private
   817    */
   959    */
   818   
   960   
   819   function err_access_denied()
   961   function err_access_denied()