plugins/SpecialPageFuncs.php
changeset 761 82560fba0fd1
parent 722 4ea698929756
child 801 eb8b23f11744
equal deleted inserted replaced
760:60c132a5bc8e 761:82560fba0fd1
   260     
   260     
   261   echo '</form>';
   261   echo '</form>';
   262   
   262   
   263   echo '<script type="text/javascript">addOnloadHook(cpGenPreviewUrl); addOnloadHook(function(){load_component(\'expander\')});</script>';
   263   echo '<script type="text/javascript">addOnloadHook(cpGenPreviewUrl); addOnloadHook(function(){load_component(\'expander\')});</script>';
   264   
   264   
   265   $template->footer();
       
   266 }
       
   267 
       
   268 function page_Special_CreatePage_Old()
       
   269 {
       
   270   global $db, $session, $paths, $template, $plugins; // Common objects
       
   271   global $lang;
       
   272   
       
   273   if ( isset($_POST['do']) )
       
   274   {
       
   275     $p = $_POST['pagename'];
       
   276     $k = array_keys($paths->nslist);
       
   277     for ( $i = 0; $i < sizeof( $paths->nslist ); $i++ )
       
   278     {
       
   279       $ln = strlen( $paths->nslist[$k[$i]] );
       
   280       if ( substr($p, 0, $ln) == $paths->nslist[$k[$i]] )
       
   281       {
       
   282         $namespace = $k[$i];
       
   283       }
       
   284     }
       
   285     if ( $namespace == 'Special' || ( $namespace == 'System' && $session->user_level < USER_LEVEL_ADMIN ) || $namespace == 'Admin')
       
   286     {
       
   287       $template->header();
       
   288       
       
   289       echo '<h3>' . $lang->get('pagetools_create_err_title') . '</h3>
       
   290              <p>' . $lang->get('pagetools_create_err_name_invalid', array('page_name' => htmlspecialchars($p))) . '</p>';
       
   291       
       
   292       $template->footer();
       
   293       $db->close();
       
   294       
       
   295       exit;
       
   296     }
       
   297     $name = $db->escape(str_replace('_', ' ', $p));
       
   298     $urlname = str_replace(' ', '_', $p);
       
   299     $namespace = $_POST['namespace'];
       
   300     if ( $namespace == 'Special' || ( $namespace == 'System' && $session->user_level < USER_LEVEL_ADMIN ) || $namespace == 'Admin')
       
   301     {
       
   302       $template->header();
       
   303       
       
   304       echo '<h3>' . $lang->get('pagetools_create_err_title') . '</h3>
       
   305              <p>' . $lang->get('pagetools_create_err_name_invalid', array('page_name' => htmlspecialchars($paths->nslist[$namespace].$p))) . '</p>';
       
   306       
       
   307       $template->footer();
       
   308       $db->close();
       
   309       
       
   310       exit;
       
   311     }
       
   312     $code = $plugins->setHook('page_create_request');
       
   313     foreach ( $code as $cmd )
       
   314     {
       
   315       eval($cmd);
       
   316     }
       
   317     if ( substr($urlname, 0, 8) == 'Project:' )
       
   318     {
       
   319       $template->header();
       
   320       
       
   321       echo '<h3>' . $lang->get('pagetools_create_err_title') . '</h3>
       
   322              <p>' . $lang->get('pagetools_create_err_project_shortcut', array('page_name' => htmlspecialchars($p))) . '</p>';
       
   323       
       
   324       $template->footer();
       
   325       $db->close();
       
   326       
       
   327       exit;
       
   328     }
       
   329     
       
   330     $tn = $paths->nslist[$_POST['namespace']] . $urlname;
       
   331     if ( isset($paths->pages[$tn]) )
       
   332     {
       
   333       die_friendly($lang->get('pagetools_create_err_title'), '<p>' . $lang->get('pagetools_create_err_already_exist') . '</p>');
       
   334     }
       
   335     
       
   336     if ( $paths->nslist[$namespace] == substr($urlname, 0, strlen($paths->nslist[$namespace]) ) )
       
   337     {
       
   338       $urlname = substr($urlname, strlen($paths->nslist[$namespace]), strlen($urlname));
       
   339     }
       
   340     
       
   341     $k = array_keys( $paths->nslist );
       
   342     if(!in_array($_POST['namespace'], $k))
       
   343     {
       
   344       $db->_die('An SQL injection attempt was caught at '.dirname(__FILE__).':'.__LINE__.'.');
       
   345     }
       
   346     
       
   347     $ips = array(
       
   348       'ip' => array(),
       
   349       'u' => array()
       
   350       );
       
   351     $ips = $db->escape(serialize($ips));
       
   352     
       
   353     $urlname = sanitize_page_id($urlname);
       
   354     $urlname = $db->escape($urlname);
       
   355     
       
   356     $perms = $session->fetch_page_acl($urlname, $namespace);
       
   357     if ( !$perms->get_permissions('create_page') )
       
   358       die_friendly($lang->get('pagetools_create_err_title'), '<p>An access control rule is preventing you from creating pages.</p>');
       
   359     
       
   360     $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace) VALUES('.time().', \''.enano_date('d M Y h:i a').'\', \'page\', \'create\', \''.$session->username.'\', \''.$urlname.'\', \''.$_POST['namespace'].'\');');
       
   361     if ( !$q )
       
   362     {
       
   363       $db->_die('The page log could not be updated.');
       
   364     }
       
   365     
       
   366     $q = $db->sql_query('INSERT INTO '.table_prefix.'pages(name,urlname,namespace,delvote_ips) VALUES(\''.$name.'\', \''.$urlname.'\', \''.$_POST['namespace'].'\',\'' . $ips . '\');');
       
   367     if ( !$q )
       
   368     {
       
   369       $db->_die('The page entry could not be inserted.');
       
   370     }
       
   371     $q = $db->sql_query('INSERT INTO '.table_prefix.'page_text(page_id,namespace,page_text) VALUES(\''.$urlname.'\', \''.$_POST['namespace'].'\', \''.'\');');
       
   372     if ( !$q )
       
   373     {
       
   374       $db->_die('The page text entry could not be inserted.');
       
   375     }
       
   376     
       
   377     header('Location: '.makeUrlNS($_POST['namespace'], sanitize_page_id($p)) . '#do:edit');
       
   378     exit;
       
   379   }
       
   380   $template->header();
       
   381   /*
       
   382   if ( !$session->get_permissions('create_page') )
       
   383   {
       
   384     echo 'Wiki mode is disabled, only admins can create pages.';
       
   385     
       
   386     $template->footer();
       
   387     $db->close();
       
   388     
       
   389     exit;
       
   390   }
       
   391   */
       
   392   echo '<p>' . $lang->get('pagetools_create_blurb') . '</p>';
       
   393   ?>
       
   394   <form action="" method="post">
       
   395     <p>
       
   396       <select name="namespace">
       
   397         <?php
       
   398         $k = array_keys($paths->nslist);
       
   399         for ( $i = 0; $i < sizeof($k); $i++ )
       
   400         {
       
   401           if ( $paths->nslist[$k[$i]] == '' )
       
   402           {
       
   403             $s = $lang->get('pagetools_create_namespace_none');
       
   404           }
       
   405           else
       
   406           {
       
   407             $s = $paths->nslist[$k[$i]];
       
   408           }
       
   409           if ( ( $k[$i] != 'System' || $session->user_level >= USER_LEVEL_ADMIN ) && $k[$i] != 'Admin' && $k[$i] != 'Special')
       
   410           {
       
   411             echo '<option value="'.$k[$i].'">'.$s.'</option>';
       
   412           }
       
   413         }
       
   414         ?>
       
   415       </select> <input type="text" name="pagename" /></p>
       
   416       <p><input type="submit" name="do" value="<?php echo $lang->get('pagetools_create_btn_create'); ?>" /></p>
       
   417   </form>
       
   418   <?php
       
   419   $template->footer();
   265   $template->footer();
   420 }
   266 }
   421 
   267 
   422 function PagelistingFormatter($id, $row)
   268 function PagelistingFormatter($id, $row)
   423 {
   269 {