Permalink
Browse files

initial import

  • Loading branch information...
0 parents commit 7e1cfe3e4b4b69d247437ebeb138321d7a1787cc @samdark committed Feb 21, 2012
Showing with 2,488 additions and 0 deletions.
  1. +18 −0 .gitignore
  2. +1 −0 app/.htaccess
  3. +18 −0 app/components/Controller.php
  4. +33 −0 app/components/UserIdentity.php
  5. +17 −0 app/components/VarDumper.php
  6. +13 −0 app/config/console.php
  7. +15 −0 app/config/db.php
  8. +74 −0 app/config/main.php
  9. +17 −0 app/config/test.php
  10. +53 −0 app/controllers/SiteController.php
  11. +77 −0 app/models/LoginForm.php
  12. +67 −0 app/modules/wiki/WikiModule.php
  13. +38 −0 app/modules/wiki/assets/wiki.css
  14. +19 −0 app/modules/wiki/components/TextDiff.php
  15. +41 −0 app/modules/wiki/components/markup/AbstractMarkup.php
  16. +21 −0 app/modules/wiki/components/markup/MarkdownMarkup.php
  17. +364 −0 app/modules/wiki/controllers/DefaultController.php
  18. +56 −0 app/modules/wiki/migrations/m120213_183419_init.php
  19. +79 −0 app/modules/wiki/models/WikiLink.php
  20. +147 −0 app/modules/wiki/models/WikiPage.php
  21. +76 −0 app/modules/wiki/models/WikiPageRevision.php
  22. +9 −0 app/modules/wiki/views/default/diff.php
  23. +13 −0 app/modules/wiki/views/default/edit.php
  24. +17 −0 app/modules/wiki/views/default/history.php
  25. +2 −0 app/modules/wiki/views/default/no_page.php
  26. +8 −0 app/modules/wiki/views/default/page_index.php
  27. +15 −0 app/modules/wiki/views/default/view.php
  28. +25 −0 app/tests/WebTestCase.php
  29. +10 −0 app/tests/bootstrap.php
  30. +47 −0 app/tests/functional/SiteTest.php
  31. +13 −0 app/tests/phpunit.xml
  32. +57 −0 app/views/layouts/main.php
  33. +12 −0 app/views/site/error.php
  34. +49 −0 app/views/site/login.php
  35. +4 −0 app/yiic
  36. +16 −0 app/yiic.bat
  37. +7 −0 app/yiic.php
  38. +7 −0 changelog.md
  39. +25 −0 license.md
  40. +95 −0 readme.md
  41. +48 −0 todo.md
  42. +10 −0 www/.htaccess
  43. BIN www/css/bg.gif
  44. +160 −0 www/css/form.css
  45. +36 −0 www/css/ie.css
  46. +229 −0 www/css/main.css
  47. +29 −0 www/css/print.css
  48. +238 −0 www/css/screen.css
  49. +15 −0 www/index-test.php
  50. +12 −0 www/index.php
  51. +36 −0 www/install.php
@@ -0,0 +1,18 @@
+# phpstorm project files
+.idea
+
+# netbeans project files
+nbproject
+
+# zend studio for eclipse project files
+.buildpath
+.project
+.settings
+
+# windows thumbnail cache
+Thumbs.db
+
+# exclude framework itself
+framework
+app/runtime
+www/assets
@@ -0,0 +1 @@
+deny from all
@@ -0,0 +1,18 @@
+<?php
+/**
+ * Controller is the customized base controller class.
+ * All controller classes for this application should extend from this base class.
+ */
+class Controller extends CController
+{
+ /**
+ * @var array context menu items. This property will be assigned to {@link CMenu::items}.
+ */
+ public $menu=array();
+ /**
+ * @var array the breadcrumbs of the current page. The value of this property will
+ * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
+ * for more details on how to specify this property.
+ */
+ public $breadcrumbs=array();
+}
@@ -0,0 +1,33 @@
+<?php
+
+/**
+ * UserIdentity represents the data needed to identity a user.
+ * It contains the authentication method that checks if the provided
+ * data can identity the user.
+ */
+class UserIdentity extends CUserIdentity
+{
+ /**
+ * Authenticates a user.
+ * The example implementation makes sure if the username and password
+ * are both 'demo'.
+ * In practical applications, this should be changed to authenticate
+ * against some persistent user identity storage (e.g. database).
+ * @return boolean whether authentication succeeds.
+ */
+ public function authenticate()
+ {
+ $users=array(
+ // username => password
+ 'demo'=>'demo',
+ 'admin'=>'admin',
+ );
+ if(!isset($users[$this->username]))
+ $this->errorCode=self::ERROR_USERNAME_INVALID;
+ else if($users[$this->username]!==$this->password)
+ $this->errorCode=self::ERROR_PASSWORD_INVALID;
+ else
+ $this->errorCode=self::ERROR_NONE;
+ return !$this->errorCode;
+ }
+}
@@ -0,0 +1,17 @@
+<?php
+/**
+ * VarDumper
+ */
+class VarDumper extends CVarDumper {
+ /**
+ * Displays a variable.
+ * This method achieves the similar functionality as var_dump and print_r
+ * but is more robust when handling complex objects such as Yii controllers.
+ * @param mixed variable to be dumped
+ * @param integer maximum depth that the dumper should go into the variable. Defaults to 10.
+ * @param boolean whether the result should be syntax-highlighted
+ */
+ public static function dump($var,$depth=10,$highlight=true){
+ echo self::dumpAsString($var,$depth,$highlight);
+ }
+}
@@ -0,0 +1,13 @@
+<?php
+
+// This is the configuration for yiic console application.
+// Any writable CConsoleApplication properties can be configured here.
+return array(
+ 'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
+ 'name'=>'wiki',
+
+ // application components
+ 'components'=>array(
+ 'db'=>require 'db.php',
+ ),
+);
@@ -0,0 +1,15 @@
+<?php
+/**
+ * Database connection settings
+ */
+return array(
+ 'connectionString' => 'mysql:host=localhost;dbname=yii_wiki',
+ 'emulatePrepare' => true,
+ 'username' => 'root',
+ 'password' => '',
+ 'charset' => 'utf8',
+
+ // comment on production
+ 'enableParamLogging' => YII_DEBUG,
+ 'enableProfiling' => YII_DEBUG,
+);
@@ -0,0 +1,74 @@
+<?php
+// uncomment the following to define a path alias
+// Yii::setPathOfAlias('local','path/to/local-folder');
+
+// This is the main Web application configuration. Any writable
+// CWebApplication properties can be configured here.
+return array(
+ 'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
+ 'name'=>'wiki',
+
+ // preloading 'log' component
+ 'preload'=>array('log'),
+
+ // autoloading model and component classes
+ 'import'=>array(
+ 'application.models.*',
+ 'application.components.*',
+ ),
+
+ 'defaultController' => 'wiki/default/index',
+
+ 'modules'=>array(
+ 'wiki',
+ // remove on release
+ 'gii'=>array(
+ 'class'=>'system.gii.GiiModule',
+ 'password'=>false,
+ ),
+ ),
+
+ // application components
+ 'components'=>array(
+ 'user'=>array(
+ // enable cookie-based authentication
+ 'allowAutoLogin'=>true,
+ ),
+ 'urlManager'=>array(
+ 'urlFormat'=>'path',
+ 'showScriptName'=>false,
+ 'rules'=>array(
+ '<controller:\w+>/<id:\d+>'=>'<controller>/view',
+ '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
+ '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
+ ),
+ ),
+ 'db'=>require 'db.php',
+ 'errorHandler'=>array(
+ // use 'site/error' action to display errors
+ 'errorAction'=>'site/error',
+ ),
+ 'log'=>array(
+ 'class'=>'CLogRouter',
+ 'routes'=>array(
+ array(
+ 'class'=>'CFileLogRoute',
+ 'levels'=>'error, warning',
+ ),
+ array(
+ 'class'=>'CProfileLogRoute',
+ ),
+ ),
+ ),
+ 'cache' => array(
+ 'class' => 'CFileCache',
+ ),
+ ),
+
+ // application-level parameters that can be accessed
+ // using Yii::app()->params['paramName']
+ 'params'=>array(
+ // this is used in contact page
+ 'adminEmail'=>'webmaster@example.com',
+ ),
+);
@@ -0,0 +1,17 @@
+<?php
+
+return CMap::mergeArray(
+ require(dirname(__FILE__) . '/main.php'),
+ array(
+ 'components'=>array(
+ 'fixture'=>array(
+ 'class'=>'system.test.CDbFixtureManager',
+ ),
+ /* uncomment the following to provide test database connection
+ 'db'=>array(
+ 'connectionString'=>'DSN for test database',
+ ),
+ */
+ ),
+ )
+);
@@ -0,0 +1,53 @@
+<?php
+
+class SiteController extends Controller
+{
+ /**
+ * This is the action to handle external exceptions.
+ */
+ public function actionError()
+ {
+ if($error=Yii::app()->errorHandler->error)
+ {
+ if(Yii::app()->request->isAjaxRequest)
+ echo $error['message'];
+ else
+ $this->render('error', $error);
+ }
+ }
+
+ /**
+ * Displays the login page
+ */
+ public function actionLogin()
+ {
+ $model=new LoginForm;
+
+ // if it is ajax validation request
+ if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
+ {
+ echo CActiveForm::validate($model);
+ Yii::app()->end();
+ }
+
+ // collect user input data
+ if(isset($_POST['LoginForm']))
+ {
+ $model->attributes=$_POST['LoginForm'];
+ // validate user input and redirect to the previous page if valid
+ if($model->validate() && $model->login())
+ $this->redirect(Yii::app()->user->returnUrl);
+ }
+ // display the login form
+ $this->render('login',array('model'=>$model));
+ }
+
+ /**
+ * Logs out the current user and redirect to homepage.
+ */
+ public function actionLogout()
+ {
+ Yii::app()->user->logout();
+ $this->redirect(Yii::app()->homeUrl);
+ }
+}
@@ -0,0 +1,77 @@
+<?php
+
+/**
+ * LoginForm class.
+ * LoginForm is the data structure for keeping
+ * user login form data. It is used by the 'login' action of 'SiteController'.
+ */
+class LoginForm extends CFormModel
+{
+ public $username;
+ public $password;
+ public $rememberMe;
+
+ private $_identity;
+
+ /**
+ * Declares the validation rules.
+ * The rules state that username and password are required,
+ * and password needs to be authenticated.
+ */
+ public function rules()
+ {
+ return array(
+ // username and password are required
+ array('username, password', 'required'),
+ // rememberMe needs to be a boolean
+ array('rememberMe', 'boolean'),
+ // password needs to be authenticated
+ array('password', 'authenticate'),
+ );
+ }
+
+ /**
+ * Declares attribute labels.
+ */
+ public function attributeLabels()
+ {
+ return array(
+ 'rememberMe'=>'Remember me next time',
+ );
+ }
+
+ /**
+ * Authenticates the password.
+ * This is the 'authenticate' validator as declared in rules().
+ */
+ public function authenticate($attribute,$params)
+ {
+ if(!$this->hasErrors())
+ {
+ $this->_identity=new UserIdentity($this->username,$this->password);
+ if(!$this->_identity->authenticate())
+ $this->addError('password','Incorrect username or password.');
+ }
+ }
+
+ /**
+ * Logs in the user using the given username and password in the model.
+ * @return boolean whether login is successful
+ */
+ public function login()
+ {
+ if($this->_identity===null)
+ {
+ $this->_identity=new UserIdentity($this->username,$this->password);
+ $this->_identity->authenticate();
+ }
+ if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
+ {
+ $duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
+ Yii::app()->user->login($this->_identity,$duration);
+ return true;
+ }
+ else
+ return false;
+ }
+}
Oops, something went wrong.

0 comments on commit 7e1cfe3

Please sign in to comment.