{"action":"created","comment":{"url":"https://api.github.com/repos/Wikia/app/pulls/comments/31428319","id":31428319,"diff_hunk":"@@ -114,10 +174,268 @@ public function getTemplate() {\n \t}\n \n \t/**\n+\t * Get last parsed template\n+\t *\n+\t * @return mixed\n+\t */\n+\tpublic function getLastTemplate() {\n+\t\tif ( !empty( $this->templates ) ) {\n+\t\t\treturn end( $this->templates );\n+\t\t}\n+\t\treturn null;\n+\t}\n+\n+\t/**\n+\t * Find template (from given list) which is first in the text\n+\t *\n+\t * @param array $templateNames list with allowed templates\n+\t * @return null|string template name\n+\t */\n+\tpublic function findFirstTemplateFromList( Array $templateNames, $text = null ) {\n+\t\t$minPosition = null;\n+\t\t$firstTemplate = null;\n+\n+\t\tif ( !is_null( $text ) ) {\n+\t\t\t$this->text = $text;\n+\t\t}\n+\n+\t\tforeach ( $templateNames as $templateName ) {\n+\t\t\t$templateBegin = \"{{{$templateName}\";\n+\t\t\tif ( ( $position = $this->findTemplatePosition( $templateBegin, 0 ) ) !== false ) {\n+\t\t\t\tif ( $position === 0 ) {\n+\t\t\t\t\treturn $templateName;\n+\t\t\t\t}\n+\n+\t\t\t\tif ( is_null( $minPosition ) || $position < $minPosition ) {\n+\t\t\t\t\t$minPosition = $position;\n+\t\t\t\t\t$firstTemplate = $templateName;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\n+\t\treturn $firstTemplate;\n+\t}\n+\n+\t/**\n+\t * Do some action after template is parsed\n+\t *\n+\t * Actions:\n+\t *\n+\t * - Add first template as flag (@see ACTION_ADD_FIRST_FLAG)\n+\t * - Add all templates as flags (@see ACTION_ADD_ALL_FLAGS)\n+\t * - Remove first template from text (@see ACTION_REMOVE_FIRST_FLAG)\n+\t * - Remove all templates from text (@see ACTION_REMOVE_ALL_FLAGS)\n+\t * - Replace first template by tag (@see ACTION_REPLACE_FIRST_FLAG)\n+\t * - Replace all templates by tag (@see ACTION_REMOVE_ALL_FLAGS)\n+\t *\n+\t * Actions for first template have higher priority\n+\t * For example:\n+\t *\n+\t * If we set \"replace first template\" and \"remove all templates\",\n+\t * first template will be replaced, all others will be removed\n+\t *\n+\t * How to use:\n+\t *\n+\t * if we want: add first template as flag, replace first template and removed all others we need to pass array\n+\t * [\n+\t * \t\tself::ACTION_ADD_FIRST_FLAG,\n+\t * \t\tself::ACTION_REPLACE_FIRST_FLAG,\n+\t * \t\tself::ACTION_REMOVE_ALL_FLAGS\n+\t * ]\n+\t *\n+\t * @return bool\n+\t */\n+\tprivate function doTemplateActions() {\n+\t\tif ( empty( $this->actions ) ) {\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\t$sum = array_sum( $this->actions );\n+\n+\t\t$actionForFirstFlag = ( $sum & ( self::ACTION_REPLACE_FIRST_FLAG | self::ACTION_REMOVE_FIRST_FLAG ) ) && $this->isFirst;\n+\t\t$actionForAllFlags = $sum & ( self::ACTION_REMOVE_ALL_FLAGS | self::ACTION_REPLACE_ALL_FLAGS );\n+\n+\t\tif ( ( $sum & ( self::ACTION_ADD_FIRST_FLAG ) && $this->isFirst )\n+\t\t\t|| ( $sum & self::ACTION_ADD_ALL_FLAGS ) ) {\n+\t\t\t$this->addFlagToPage();\n+\t\t}\n+\n+\t\tif ( $actionForFirstFlag ) {\n+\t\t\tif ( $sum & self::ACTION_REPLACE_FIRST_FLAG ) {\n+\t\t\t\t$this->replaceTemplateByTag();\n+\t\t\t} else {\n+\t\t\t\t$this->removeTemplate();\n+\t\t\t}\n+\t\t} elseif ( $actionForAllFlags ) {\n+\t\t\tif ( $sum & self::ACTION_REPLACE_ALL_FLAGS ) {\n+\t\t\t\t$this->replaceTemplateByTag();\n+\t\t\t} else {\n+\t\t\t\t$this->removeTemplate();\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Add flag to page\n+\t *\n+\t * Parameters:\n+\t * - wiki_id (required)\n+\t * - page_id (required)\n+\t * - flag_type_id (optional)\n+\t *\n+\t * @return bool\n+\t */\n+\tprivate function addFlagToPage() {\n+\t\tif ( !empty( $this->actionParams )\n+\t\t\t&& isset( $this->actionParams['wiki_id'] )\n+\t\t\t&& isset( $this->actionParams['page_id'] )\n+\t\t) {\n+\t\t\t$flagsToPages = $this->prepareParameters();\n+\n+\t\t\tif ( !$flagsToPages ) {\n+\t\t\t\treturn false;\n+\t\t\t}\n+\n+\t\t\t$response = $this->app->sendRequest( 'FlagsApiController',\n+\t\t\t\t'addFlagsToPage',\n+\t\t\t\t$flagsToPages\n+\t\t\t)->getData();\n+\n+\t\t\treturn $response['status'];\n+\t\t}\n+\n+\t\treturn false;\n+\t}\n+\n+\t/**\n+\t * Prepare parameters required to add flag to page\n+\t *\n+\t * @return array|bool\n+\t */\n+\tprivate function prepareParameters() {\n+\t\t$params = [];\n+\n+\t\t$template = $this->getLastTemplate();\n+\n+\t\tif ( !$template ) {\n+\t\t\treturn false;","path":"extensions/wikia/Flags/FlagsExtractor.class.php","position":287,"original_position":287,"commit_id":"7706b24ca12561f274d80ac302b2276ed6a6ace4","original_commit_id":"7706b24ca12561f274d80ac302b2276ed6a6ace4","user":{"login":"lgarczewski","id":2281042,"avatar_url":"https://avatars.githubusercontent.com/u/2281042?v=3","gravatar_id":"","url":"https://api.github.com/users/lgarczewski","html_url":"https://github.com/lgarczewski","followers_url":"https://api.github.com/users/lgarczewski/followers","following_url":"https://api.github.com/users/lgarczewski/following{/other_user}","gists_url":"https://api.github.com/users/lgarczewski/gists{/gist_id}","starred_url":"https://api.github.com/users/lgarczewski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lgarczewski/subscriptions","organizations_url":"https://api.github.com/users/lgarczewski/orgs","repos_url":"https://api.github.com/users/lgarczewski/repos","events_url":"https://api.github.com/users/lgarczewski/events{/privacy}","received_events_url":"https://api.github.com/users/lgarczewski/received_events","type":"User","site_admin":false},"body":"Same here: error logging?","created_at":"2015-06-01T14:11:14Z","updated_at":"2015-06-01T14:11:14Z","html_url":"https://github.com/Wikia/app/pull/7361#discussion_r31428319","pull_request_url":"https://api.github.com/repos/Wikia/app/pulls/7361","_links":{"self":{"href":"https://api.github.com/repos/Wikia/app/pulls/comments/31428319"},"html":{"href":"https://github.com/Wikia/app/pull/7361#discussion_r31428319"},"pull_request":{"href":"https://api.github.com/repos/Wikia/app/pulls/7361"}}},"pull_request":{"url":"https://api.github.com/repos/Wikia/app/pulls/7361","id":36485864,"html_url":"https://github.com/Wikia/app/pull/7361","diff_url":"https://github.com/Wikia/app/pull/7361.diff","patch_url":"https://github.com/Wikia/app/pull/7361.patch","issue_url":"https://api.github.com/repos/Wikia/app/issues/7361","number":7361,"state":"open","locked":false,"title":"CE-1830: Added support for actions like add / replace / remove","user":{"login":"lukaszkonieczny","id":3470655,"avatar_url":"https://avatars.githubusercontent.com/u/3470655?v=3","gravatar_id":"","url":"https://api.github.com/users/lukaszkonieczny","html_url":"https://github.com/lukaszkonieczny","followers_url":"https://api.github.com/users/lukaszkonieczny/followers","following_url":"https://api.github.com/users/lukaszkonieczny/following{/other_user}","gists_url":"https://api.github.com/users/lukaszkonieczny/gists{/gist_id}","starred_url":"https://api.github.com/users/lukaszkonieczny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukaszkonieczny/subscriptions","organizations_url":"https://api.github.com/users/lukaszkonieczny/orgs","repos_url":"https://api.github.com/users/lukaszkonieczny/repos","events_url":"https://api.github.com/users/lukaszkonieczny/events{/privacy}","received_events_url":"https://api.github.com/users/lukaszkonieczny/received_events","type":"User","site_admin":false},"body":"Added options and support for template actions in migration script.","created_at":"2015-05-29T08:57:31Z","updated_at":"2015-06-01T14:11:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fda8761dd95ae770971acd10c9e0e162fef3f169","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Wikia/app/pulls/7361/commits","review_comments_url":"https://api.github.com/repos/Wikia/app/pulls/7361/comments","review_comment_url":"https://api.github.com/repos/Wikia/app/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Wikia/app/issues/7361/comments","statuses_url":"https://api.github.com/repos/Wikia/app/statuses/7706b24ca12561f274d80ac302b2276ed6a6ace4","head":{"label":"Wikia:CE-1830","ref":"CE-1830","sha":"7706b24ca12561f274d80ac302b2276ed6a6ace4","user":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"repo":{"id":5532313,"name":"app","full_name":"Wikia/app","owner":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Wikia/app","description":"Wikia Application Code","fork":false,"url":"https://api.github.com/repos/Wikia/app","forks_url":"https://api.github.com/repos/Wikia/app/forks","keys_url":"https://api.github.com/repos/Wikia/app/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Wikia/app/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Wikia/app/teams","hooks_url":"https://api.github.com/repos/Wikia/app/hooks","issue_events_url":"https://api.github.com/repos/Wikia/app/issues/events{/number}","events_url":"https://api.github.com/repos/Wikia/app/events","assignees_url":"https://api.github.com/repos/Wikia/app/assignees{/user}","branches_url":"https://api.github.com/repos/Wikia/app/branches{/branch}","tags_url":"https://api.github.com/repos/Wikia/app/tags","blobs_url":"https://api.github.com/repos/Wikia/app/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Wikia/app/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Wikia/app/git/refs{/sha}","trees_url":"https://api.github.com/repos/Wikia/app/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Wikia/app/statuses/{sha}","languages_url":"https://api.github.com/repos/Wikia/app/languages","stargazers_url":"https://api.github.com/repos/Wikia/app/stargazers","contributors_url":"https://api.github.com/repos/Wikia/app/contributors","subscribers_url":"https://api.github.com/repos/Wikia/app/subscribers","subscription_url":"https://api.github.com/repos/Wikia/app/subscription","commits_url":"https://api.github.com/repos/Wikia/app/commits{/sha}","git_commits_url":"https://api.github.com/repos/Wikia/app/git/commits{/sha}","comments_url":"https://api.github.com/repos/Wikia/app/comments{/number}","issue_comment_url":"https://api.github.com/repos/Wikia/app/issues/comments{/number}","contents_url":"https://api.github.com/repos/Wikia/app/contents/{+path}","compare_url":"https://api.github.com/repos/Wikia/app/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Wikia/app/merges","archive_url":"https://api.github.com/repos/Wikia/app/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Wikia/app/downloads","issues_url":"https://api.github.com/repos/Wikia/app/issues{/number}","pulls_url":"https://api.github.com/repos/Wikia/app/pulls{/number}","milestones_url":"https://api.github.com/repos/Wikia/app/milestones{/number}","notifications_url":"https://api.github.com/repos/Wikia/app/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Wikia/app/labels{/name}","releases_url":"https://api.github.com/repos/Wikia/app/releases{/id}","created_at":"2012-08-23T20:55:58Z","updated_at":"2015-06-01T12:38:38Z","pushed_at":"2015-06-01T14:04:54Z","git_url":"git://github.com/Wikia/app.git","ssh_url":"git@github.com:Wikia/app.git","clone_url":"https://github.com/Wikia/app.git","svn_url":"https://github.com/Wikia/app","homepage":"http://dev.wikia.com","size":1413189,"stargazers_count":79,"watchers_count":79,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":56,"mirror_url":null,"open_issues_count":69,"forks":56,"open_issues":69,"watchers":79,"default_branch":"dev"}},"base":{"label":"Wikia:dev","ref":"dev","sha":"6f65e25edd236e664f1b918ed842b5d76faf2358","user":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"repo":{"id":5532313,"name":"app","full_name":"Wikia/app","owner":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Wikia/app","description":"Wikia Application Code","fork":false,"url":"https://api.github.com/repos/Wikia/app","forks_url":"https://api.github.com/repos/Wikia/app/forks","keys_url":"https://api.github.com/repos/Wikia/app/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Wikia/app/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Wikia/app/teams","hooks_url":"https://api.github.com/repos/Wikia/app/hooks","issue_events_url":"https://api.github.com/repos/Wikia/app/issues/events{/number}","events_url":"https://api.github.com/repos/Wikia/app/events","assignees_url":"https://api.github.com/repos/Wikia/app/assignees{/user}","branches_url":"https://api.github.com/repos/Wikia/app/branches{/branch}","tags_url":"https://api.github.com/repos/Wikia/app/tags","blobs_url":"https://api.github.com/repos/Wikia/app/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Wikia/app/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Wikia/app/git/refs{/sha}","trees_url":"https://api.github.com/repos/Wikia/app/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Wikia/app/statuses/{sha}","languages_url":"https://api.github.com/repos/Wikia/app/languages","stargazers_url":"https://api.github.com/repos/Wikia/app/stargazers","contributors_url":"https://api.github.com/repos/Wikia/app/contributors","subscribers_url":"https://api.github.com/repos/Wikia/app/subscribers","subscription_url":"https://api.github.com/repos/Wikia/app/subscription","commits_url":"https://api.github.com/repos/Wikia/app/commits{/sha}","git_commits_url":"https://api.github.com/repos/Wikia/app/git/commits{/sha}","comments_url":"https://api.github.com/repos/Wikia/app/comments{/number}","issue_comment_url":"https://api.github.com/repos/Wikia/app/issues/comments{/number}","contents_url":"https://api.github.com/repos/Wikia/app/contents/{+path}","compare_url":"https://api.github.com/repos/Wikia/app/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Wikia/app/merges","archive_url":"https://api.github.com/repos/Wikia/app/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Wikia/app/downloads","issues_url":"https://api.github.com/repos/Wikia/app/issues{/number}","pulls_url":"https://api.github.com/repos/Wikia/app/pulls{/number}","milestones_url":"https://api.github.com/repos/Wikia/app/milestones{/number}","notifications_url":"https://api.github.com/repos/Wikia/app/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Wikia/app/labels{/name}","releases_url":"https://api.github.com/repos/Wikia/app/releases{/id}","created_at":"2012-08-23T20:55:58Z","updated_at":"2015-06-01T12:38:38Z","pushed_at":"2015-06-01T14:04:54Z","git_url":"git://github.com/Wikia/app.git","ssh_url":"git@github.com:Wikia/app.git","clone_url":"https://github.com/Wikia/app.git","svn_url":"https://github.com/Wikia/app","homepage":"http://dev.wikia.com","size":1413189,"stargazers_count":79,"watchers_count":79,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":56,"mirror_url":null,"open_issues_count":69,"forks":56,"open_issues":69,"watchers":79,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/Wikia/app/pulls/7361"},"html":{"href":"https://github.com/Wikia/app/pull/7361"},"issue":{"href":"https://api.github.com/repos/Wikia/app/issues/7361"},"comments":{"href":"https://api.github.com/repos/Wikia/app/issues/7361/comments"},"review_comments":{"href":"https://api.github.com/repos/Wikia/app/pulls/7361/comments"},"review_comment":{"href":"https://api.github.com/repos/Wikia/app/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Wikia/app/pulls/7361/commits"},"statuses":{"href":"https://api.github.com/repos/Wikia/app/statuses/7706b24ca12561f274d80ac302b2276ed6a6ace4"}}}}