/** * Our hook which is processed whenever a Category Page is viewed. When * this happens, we hijack the normal mediawiki flow and create an instance * of our CategoryViewer(PonyDocsCategoryPageHandler) which has a special * addPage method which adds the H1 of the article content, instead of the * title itself. * * @param CategoryArticle $categoryArticle a reference to the * CategoryArticle which fired off the event. * @return boolean We return false to make mediawiki stop processing the * normal flow. */ static function onCategoryPageView(&$categoryArticle) { global $wgOut, $wgRequest; $from = $wgRequest->getVal('from'); $until = $wgRequest->getVal('until'); $cacheKey = "category-" . $categoryArticle->getTitle() . "-{$from}-{$until}"; $res = null; $cache = PonyDocsCache::getInstance(); // See if this exists in our cache $res = $cache->get($cacheKey); if ($res == null) { // Either cache is disabled, or cached entry does not exist $categoryViewer = new PonyDocsCategoryPageHandler($categoryArticle->getTitle(), $from, $until); $res = $categoryViewer->getHTML(); // Store in our cache $cache->put($cacheKey, $res, CATEGORY_CACHE_TTL); } $wgOut->addHTML($res); return false; // We don't want to continue processing the "normal" mediawiki path, so return false here. }
public function actionDeleteLogoFile($id) { $id = (int)$id; // check that you have access to this note $file = CategoryArticle::model()->findByPk($id); if(!empty($file)){ // Delete file $filename = $file->logotip; $imagePath = $file->getFileFolder() . $filename; if(file_exists($imagePath)) { unlink($imagePath); //delete file } $file->logotip = ''; $file->logotip_realname = ''; $file->saveNode(array('logotip','logotip_realname')); echo "[]"; Yii::app()->end(); } echo 'error'; Yii::app()->end(); }
public function checkIfAvailable($attr) { $labels = $this->attributeLabels(); $check = CategoryArticle::model()->countByAttributes(array( $attr=>$this->$attr, ), 't.id != :id', array(':id'=>(int)$this->id)); if($check>0) $this->addError($attr, $labels[$attr].' '.Yii::t('site', 'is occupied')); }
public function applyCategoriesWithSub($categories, $select = 't.*') { $cat = array(); if($categories instanceof CategoryArticle){ $cat[] = $categories->id; $category = CategoryArticle::model()->findByPk($categories->id); $descendants = $category->descendants()->findAll(); if(!empty($descendants)){ foreach($descendants as $c){ if(is_object($c)){ $cat[] = $c->id; } else { $cat[] = $c; } } } $categories = $cat; } $criteria = new CDbCriteria; if($select) $criteria->select = $select; $criteria->join = 'LEFT JOIN "article_category" "categorization" ON ("categorization"."article"="t"."id")'; $criteria->addInCondition('categorization.category', $categories); $this->getDbCriteria()->mergeWith($criteria); return $this; }
public function _loadModel($url) { // Find category $model = CategoryArticle::model() ->withUrl($url) ->find(); if (!$model) throw new CHttpException(404, 'Категория не найдена.'); return $model; }