includes/pageprocess.php
changeset 963 b572ce1114f1
parent 953 323c4cd1aa37
child 1027 98c052fc3337
equal deleted inserted replaced
962:ceeecb160aec 963:b572ce1114f1
   102    */
   102    */
   103   
   103   
   104   var $allow_redir = true;
   104   var $allow_redir = true;
   105   
   105   
   106   /**
   106   /**
       
   107    * Holds any error message from redirection code. Defaults to false (no error).
       
   108    * @var mixed
       
   109    */
       
   110    
       
   111   var $redir_error = false;
       
   112   
       
   113   /**
   107    * If this is set to true, this will call the header and footer funcs on $template when render() is called.
   114    * If this is set to true, this will call the header and footer funcs on $template when render() is called.
   108    * @var bool
   115    * @var bool
   109    */
   116    */
   110   
   117   
   111   var $send_headers = false;
   118   var $send_headers = false;
   173    */
   180    */
   174   
   181   
   175   function send( $do_stats = false )
   182   function send( $do_stats = false )
   176   {
   183   {
   177     global $db, $session, $paths, $template, $plugins; // Common objects
   184     global $db, $session, $paths, $template, $plugins; // Common objects
   178     global $lang;
   185     global $lang, $output;
   179     
   186     
   180     profiler_log('PageProcessor: send() called');
   187     profiler_log('PageProcessor: send() called');
   181     
   188     
   182     if ( !$this->perms->get_permissions('read') )
   189     if ( !$this->perms->get_permissions('read') )
   183     {
   190     {
   275       require_once(ENANO_ROOT.'/includes/stats.php');
   282       require_once(ENANO_ROOT.'/includes/stats.php');
   276       doStats($this->page_id, $this->namespace);
   283       doStats($this->page_id, $this->namespace);
   277     }
   284     }
   278     
   285     
   279     // We are all done. Ship off the page.
   286     // We are all done. Ship off the page.
       
   287     
       
   288     if ( !$this->allow_redir )
       
   289     {
       
   290       if ( method_exists($this->ns, 'get_redirect') )
       
   291       {
       
   292         if ( $result = $this->ns->get_redirect() )
       
   293           display_redirect_notice($result['page_id'], $result['namespace']);
       
   294       }
       
   295     }
       
   296     else
       
   297     {
       
   298       $this->process_redirects();
       
   299       
       
   300       if ( count($this->redirect_stack) > 0 )
       
   301       {
       
   302         $stack = array_reverse($this->redirect_stack);
       
   303         foreach ( $stack as $stackel )
       
   304         {
       
   305           $url = makeUrlNS($stackel['old_namespace'], $stackel['old_page_id'], 'redirect=no', true);
       
   306           $page_data = $this->ns->get_cdata();
       
   307           $title = $stackel['old_title'];
       
   308           $a = '<a href="' . $url . '">' . htmlspecialchars($title) . '</a>';
       
   309           $output->add_after_header('<small>' . $lang->get('page_msg_redirected_from', array('from' => $a)) . '<br /></small>');
       
   310         }
       
   311         $template->set_page($this);
       
   312       }
       
   313       
       
   314       if ( $this->redir_error )
       
   315       {
       
   316         $output->add_after_header('<div class="usermessage"><b>' . $this->redir_error . '</b></div>');
       
   317         $result = $this->ns->get_redirect();
       
   318         display_redirect_notice($result['page_id'], $result['namespace']);
       
   319       }
       
   320     }
   280     
   321     
   281     $this->ns->send();
   322     $this->ns->send();
   282   }
   323   }
   283   
   324   
   284   /**
   325   /**
   940   {
   981   {
   941     global $db, $session, $paths, $template, $plugins; // Common objects
   982     global $db, $session, $paths, $template, $plugins; // Common objects
   942     
   983     
   943     $page_id_cleaned = sanitize_page_id($page_id);
   984     $page_id_cleaned = sanitize_page_id($page_id);
   944     
   985     
   945     $this->page_id = $page_id_cleaned;
       
   946     $this->namespace = $namespace;
       
   947     $this->revision_id = $revision_id;
   986     $this->revision_id = $revision_id;
   948     $this->page_id_unclean = dirtify_page_id($page_id);
   987     $this->page_id_unclean = dirtify_page_id($page_id);
   949     
   988     
       
   989     // resolve namespace
       
   990     $this->ns = namespace_factory($page_id, $namespace, $this->revision_id);
       
   991     $this->page_id =& $this->ns->page_id;
       
   992     $this->namespace =& $this->ns->namespace;
       
   993     
   950     $this->perms = $session->fetch_page_acl( $page_id, $namespace );
   994     $this->perms = $session->fetch_page_acl( $page_id, $namespace );
   951     
       
   952     // resolve namespace
       
   953     $this->ns = namespace_factory($this->page_id, $this->namespace, $this->revision_id);
       
   954     
   995     
   955     $this->page_exists = $this->ns->exists();
   996     $this->page_exists = $this->ns->exists();
   956     $this->title = get_page_title_ns($this->page_id, $this->namespace);
   997     $this->title = get_page_title_ns($this->page_id, $this->namespace);
   957     
   998     
   958     profiler_log("PageProcessor [{$this->namespace}:{$this->page_id}]: Ran _setup()");
   999     profiler_log("PageProcessor [{$this->namespace}:{$this->page_id}]: Ran _setup()");
   959   }
  1000   }
   960   
  1001   
   961   /**
  1002   /**
   962    * Renders it all in one go, and echoes it out. This assumes that the text is in the DB.
  1003    * Processes any redirects.
   963    * @access private
  1004    * @access private
   964    */
  1005    */
   965   
  1006   
   966   function render($incl_inner_headers = true, $_errormsg = false)
  1007   function process_redirects()
   967   {
  1008   {
   968     global $db, $session, $paths, $template, $plugins; // Common objects
  1009     global $db, $session, $paths, $template, $plugins; // Common objects
   969     global $output, $lang;
  1010     global $output, $lang;
   970     
  1011     
   971     if ( count($this->redirect_stack) > 0 )
  1012     $this->redirect_stack = array();
   972     {
  1013     
   973       $stack = array_reverse($this->redirect_stack);
  1014     if ( !method_exists($this->ns, 'get_redirect') )
   974       foreach ( $stack as $oldtarget )
  1015       return true;
   975       {
  1016     
   976         $url = makeUrlNS($oldtarget[1], $oldtarget[0], 'redirect=no', true);
  1017     if ( !$this->allow_redir )
   977         $page_data = $this->ns->get_cdata();
  1018       return true;
   978         $title = ( isset($page_data['name']) ) ? $page_data['name'] : $paths->nslist[$oldtarget[1]] . htmlspecialchars( str_replace('_', ' ', dirtify_page_id( $oldtarget[0] ) ) );
  1019     
   979         $a = '<a href="' . $url . '">' . $title . '</a>';
  1020     $redirect_count = 0;
   980         $output->add_after_header('<small>' . $lang->get('page_msg_redirected_from', array('from' => $a)) . '<br /></small>');
  1021     
   981       }
  1022     while ( $result = $this->ns->get_redirect() )
   982     }
  1023     {
   983     $this->ns->send($incl_inner_headers, $_errormsg);
  1024       if ( $result['namespace'] == 'Special' || $result['namespace'] == 'Admin' )
   984   }
  1025       {
   985   
  1026         // Can't redirect to special/admin page
       
  1027         $this->redir_error = $lang->get('page_err_redirect_to_special');
       
  1028         break;
       
  1029       }
       
  1030       if ( $redirect_count == 3 )
       
  1031       {
       
  1032         // max of 3 internal redirects exceeded
       
  1033         $this->redir_error = $lang->get('page_err_redirects_exceeded');
       
  1034         break;
       
  1035       }
       
  1036       
       
  1037       $loop = false;
       
  1038       foreach ( $this->redirect_stack as $stackel )
       
  1039       {
       
  1040         if ( $result['page_id'] == $stackel['old_page_id'] && $result['namespace'] == $stackel['old_namespace'] )
       
  1041         {
       
  1042           $loop = true;
       
  1043           break;
       
  1044         }
       
  1045       }
       
  1046       
       
  1047       if ( $loop )
       
  1048       {
       
  1049         // redirect loop
       
  1050         $this->redir_error = $lang->get('page_err_redirect_infinite_loop');
       
  1051         break;
       
  1052       }
       
  1053       $new_ns = namespace_factory($result['page_id'], $result['namespace']);
       
  1054       if ( !$new_ns->exists() )
       
  1055       {
       
  1056         // new page doesn't exist
       
  1057         $this->redir_error = $lang->get('page_err_redirect_to_nonexistent');
       
  1058         break;
       
  1059       }
       
  1060       
       
  1061       // build stack entry
       
  1062       $stackel = array(
       
  1063           'page_id' => $result['page_id'],
       
  1064           'namespace' => $result['namespace'],
       
  1065           'old_page_id' => $this->page_id,
       
  1066           'old_namespace' => $this->namespace,
       
  1067           'old_title' => $this->ns->title
       
  1068         );
       
  1069       
       
  1070       // replace everything (perform the actual redirect)
       
  1071       $this->ns = $new_ns;
       
  1072       
       
  1073       $this->page_id =& $this->ns->page_id;
       
  1074       $this->namespace =& $this->ns->namespace;
       
  1075       
       
  1076       $this->redirect_stack[] = $stackel;
       
  1077       
       
  1078       $redirect_count++;
       
  1079     }
       
  1080   }
       
  1081     
   986   /**
  1082   /**
   987    * Sends the page header, dependent on, of course, whether we're supposed to.
  1083    * Sends the page header, dependent on, of course, whether we're supposed to.
   988    */
  1084    */
   989   
  1085   
   990   function header()
  1086   function header()
  1030    * @param string Page ID to redirect to
  1126    * @param string Page ID to redirect to
  1031    * @param string Namespace to redirect to
  1127    * @param string Namespace to redirect to
  1032    * @access private
  1128    * @access private
  1033    */
  1129    */
  1034   
  1130   
       
  1131   /*
  1035   function _handle_redirect($page_id, $namespace)
  1132   function _handle_redirect($page_id, $namespace)
  1036   {
  1133   {
  1037     global $db, $session, $paths, $template, $plugins; // Common objects
  1134     global $db, $session, $paths, $template, $plugins; // Common objects
  1038     global $lang;
  1135     global $lang;
  1039     $arr_pid = array($this->page_id, $this->namespace);
  1136     $arr_pid = array($this->page_id, $this->namespace);
  1040     if ( $namespace == 'Special' || $namespace == 'Admin' )
  1137     if ( $namespace == 'Special' || $namespace == 'Admin' )
  1041     {
  1138     {
  1042       return $lang->get('page_err_redirect_to_special');
  1139       return ;
  1043     }
  1140     }
  1044     $looped = false;
  1141     $looped = false;
  1045     foreach ( $this->redirect_stack as $page )
  1142     foreach ( $this->redirect_stack as $page )
  1046     {
  1143     {
  1047       if ( $page[0] == $arr_pid[0] && $page[1] == $arr_pid[1] )
  1144       if ( $page[0] == $arr_pid[0] && $page[1] == $arr_pid[1] )
  1050         break;
  1147         break;
  1051       }
  1148       }
  1052     }
  1149     }
  1053     if ( $looped )
  1150     if ( $looped )
  1054     {
  1151     {
  1055       return $lang->get('page_err_redirect_infinite_loop');
  1152       return ;
  1056     }
  1153     }
  1057     $page_id_key = $paths->nslist[ $namespace ] . sanitize_page_id($page_id);
  1154     $page_id_key = $paths->nslist[ $namespace ] . sanitize_page_id($page_id);
  1058     if ( !isPage($page_id_key) )
  1155     if ( !isPage($page_id_key) )
  1059     {
  1156     {
  1060       return $lang->get('page_err_redirect_to_nonexistent');
  1157       return $lang->get('page_err_redirect_to_nonexistent');
  1066     $this->text_cache = '';
  1163     $this->text_cache = '';
  1067     $this->_setup($page_id, $namespace, 0);
  1164     $this->_setup($page_id, $namespace, 0);
  1068     $this->send();
  1165     $this->send();
  1069     return true;
  1166     return true;
  1070   }
  1167   }
       
  1168   */
  1071   
  1169   
  1072   /**
  1170   /**
  1073    * Send the error message to the user that the access to this page is denied.
  1171    * Send the error message to the user that the access to this page is denied.
  1074    * @access private
  1172    * @access private
  1075    */
  1173    */