/** * Don't return a 404 for categories in use. * In use defined as: either the actual page exists * or the category currently has members. */ public function hasViewableContent() { if (parent::hasViewableContent()) { return true; } else { $cat = Category::newFromTitle($this->mTitle); // If any of these are not 0, then has members if ($cat->getPageCount() || $cat->getSubcatCount() || $cat->getFileCount()) { return true; } } return false; }
/** * Show the error text for a missing article. For articles in the MediaWiki * namespace, show the default message text. To be called from Article::view(). */ public function showMissingArticle() { global $wgSend404Code; $outputPage = $this->getContext()->getOutput(); // Whether the page is a root user page of an existing user (but not a subpage) $validUserPage = false; # Show info in user (talk) namespace. Does the user exist? Is he blocked? if ($this->getTitle()->getNamespace() == NS_USER || $this->getTitle()->getNamespace() == NS_USER_TALK) { $parts = explode('/', $this->getTitle()->getText()); $rootPart = $parts[0]; $user = User::newFromName($rootPart, false); $ip = User::isIP($rootPart); if (!($user && $user->isLoggedIn()) && !$ip) { # User does not exist $outputPage->wrapWikiMsg("<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>", array('userpage-userdoesnotexist-view', wfEscapeWikiText($rootPart))); } elseif ($user->isBlocked()) { # Show log extract if the user is currently blocked LogEventsList::showLogExtract($outputPage, 'block', $user->getUserPage(), '', array('lim' => 1, 'showIfEmpty' => false, 'msgKey' => array('blocked-notice-logextract', $user->getName()))); $validUserPage = !$this->getTitle()->isSubpage(); } else { $validUserPage = !$this->getTitle()->isSubpage(); } } wfRunHooks('ShowMissingArticle', array($this)); # Show delete and move logs LogEventsList::showLogExtract($outputPage, array('delete', 'move'), $this->getTitle(), '', array('lim' => 10, 'conds' => array("log_action != 'revision'"), 'showIfEmpty' => false, 'msgKey' => array('moveddeleted-notice'))); if (!$this->mPage->hasViewableContent() && $wgSend404Code && !$validUserPage) { // If there's no backing content, send a 404 Not Found // for better machine handling of broken links. $this->getContext()->getRequest()->response()->header("HTTP/1.1 404 Not Found"); } $hookResult = wfRunHooks('BeforeDisplayNoArticleText', array($this)); if (!$hookResult) { return; } # Show error message $oldid = $this->getOldID(); if ($oldid) { $text = wfMessage('missing-revision', $oldid)->plain(); } elseif ($this->getTitle()->getNamespace() === NS_MEDIAWIKI) { // Use the default message text $text = $this->getTitle()->getDefaultMessageText(); } elseif ($this->getTitle()->quickUserCan('create', $this->getContext()->getUser()) && $this->getTitle()->quickUserCan('edit', $this->getContext()->getUser())) { $text = wfMessage('noarticletext')->plain(); } else { $text = wfMessage('noarticletext-nopermission')->plain(); } $text = "<div class='noarticletext'>\n{$text}\n</div>"; $outputPage->addWikiText($text); }
/** * Show the error text for a missing article. For articles in the MediaWiki * namespace, show the default message text. To be called from Article::view(). */ public function showMissingArticle() { global $wgOut, $wgRequest, $wgUser; # Show info in user (talk) namespace. Does the user exist? Is he blocked? if ($this->getTitle()->getNamespace() == NS_USER || $this->getTitle()->getNamespace() == NS_USER_TALK) { $parts = explode('/', $this->getTitle()->getText()); $rootPart = $parts[0]; $user = User::newFromName($rootPart, false); $ip = User::isIP($rootPart); if (!$user->isLoggedIn() && !$ip) { # User does not exist $wgOut->wrapWikiMsg("<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>", array('userpage-userdoesnotexist-view', wfEscapeWikiText($rootPart))); } elseif ($user->isBlocked()) { # Show log extract if the user is currently blocked LogEventsList::showLogExtract($wgOut, 'block', $user->getUserPage()->getPrefixedText(), '', array('lim' => 1, 'showIfEmpty' => false, 'msgKey' => array('blocked-notice-logextract', $user->getName()))); } } wfRunHooks('ShowMissingArticle', array($this)); # Show delete and move logs LogEventsList::showLogExtract($wgOut, array('delete', 'move'), $this->getTitle()->getPrefixedText(), '', array('lim' => 10, 'conds' => array("log_action != 'revision'"), 'showIfEmpty' => false, 'msgKey' => array('moveddeleted-notice'))); # Show error message $oldid = $this->getOldID(); if ($oldid) { $text = wfMsgNoTrans('missing-article', $this->getTitle()->getPrefixedText(), wfMsgNoTrans('missingarticle-rev', $oldid)); } elseif ($this->getTitle()->getNamespace() === NS_MEDIAWIKI) { // Use the default message text $text = $this->getTitle()->getDefaultMessageText(); } else { $createErrors = $this->getTitle()->getUserPermissionsErrors('create', $wgUser); $editErrors = $this->getTitle()->getUserPermissionsErrors('edit', $wgUser); $errors = array_merge($createErrors, $editErrors); if (!count($errors)) { $text = wfMsgNoTrans('noarticletext'); } else { $text = wfMsgNoTrans('noarticletext-nopermission'); } } $text = "<div class='noarticletext'>\n{$text}\n</div>"; if (!$this->mPage->hasViewableContent()) { // If there's no backing content, send a 404 Not Found // for better machine handling of broken links. $wgRequest->response()->header("HTTP/1.1 404 Not Found"); } $wgOut->addWikiText($text); }
/** * @dataProvider provideHasViewableContent * @covers WikiPage::hasViewableContent */ public function testHasViewableContent($title, $viewable, $create = false) { $page = $this->newPage($title); $this->assertEquals($viewable, $page->hasViewableContent()); if ($create) { $this->createPage($page, "some text", CONTENT_MODEL_WIKITEXT); $this->assertTrue($page->hasViewableContent()); $page = new WikiPage($page->getTitle()); $this->assertTrue($page->hasViewableContent()); } }
/** * Show the error text for a missing article. For articles in the MediaWiki * namespace, show the default message text. To be called from Article::view(). */ public function showMissingArticle() { global $wgSend404Code; $outputPage = $this->getContext()->getOutput(); // Whether the page is a root user page of an existing user (but not a subpage) $validUserPage = false; # Show info in user (talk) namespace. Does the user exist? Is he blocked? if ($this->getTitle()->getNamespace() == NS_USER || $this->getTitle()->getNamespace() == NS_USER_TALK) { $parts = explode('/', $this->getTitle()->getText()); $rootPart = $parts[0]; $user = User::newFromName($rootPart, false); $ip = User::isIP($rootPart); if (!($user && $user->isLoggedIn()) && !$ip) { # User does not exist $outputPage->wrapWikiMsg("<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>", array('userpage-userdoesnotexist-view', wfEscapeWikiText($rootPart))); } elseif ($user->isBlocked()) { # Show log extract if the user is currently blocked LogEventsList::showLogExtract($outputPage, 'block', $user->getUserPage(), '', array('lim' => 1, 'showIfEmpty' => false, 'msgKey' => array('blocked-notice-logextract', $user->getName()))); $validUserPage = !$this->getTitle()->isSubpage(); } else { $validUserPage = !$this->getTitle()->isSubpage(); } } wfRunHooks('ShowMissingArticle', array($this)); // Give extensions a chance to hide their (unrelated) log entries $logTypes = array('delete', 'move'); $conds = array("log_action != 'revision'"); wfRunHooks('Article::MissingArticleConditions', array(&$conds, $logTypes)); # Show delete and move logs LogEventsList::showLogExtract($outputPage, $logTypes, $this->getTitle(), '', array('lim' => 10, 'conds' => $conds, 'showIfEmpty' => false, 'msgKey' => array('moveddeleted-notice'))); if (!$this->mPage->hasViewableContent() && $wgSend404Code && !$validUserPage) { // If there's no backing content, send a 404 Not Found // for better machine handling of broken links. $this->getContext()->getRequest()->response()->header("HTTP/1.1 404 Not Found"); } if ($validUserPage) { // Also apply the robot policy for nonexisting user pages (as those aren't served as 404) $policy = $this->getRobotPolicy('view'); $outputPage->setIndexPolicy($policy['index']); $outputPage->setFollowPolicy($policy['follow']); } $hookResult = wfRunHooks('BeforeDisplayNoArticleText', array($this)); if (!$hookResult) { return; } // WIKIHOW - Bebeth added this var to be used below for scustom messages $showHeader = false; # Show error message $oldid = $this->getOldID(); if ($oldid) { $text = wfMessage('missing-revision', $oldid)->plain(); } elseif ($this->getTitle()->getNamespace() === NS_MEDIAWIKI) { // Use the default message text $text = $this->getTitle()->getDefaultMessageText(); } elseif ($this->getTitle()->quickUserCan('create', $this->getContext()->getUser()) && $this->getTitle()->quickUserCan('edit', $this->getContext()->getUser())) { // WIKIHOW - BEBETH changed inside this if condition for // custom messages and params needed for messages if ($this->mTitle->getNamespace() == NS_USER_TALK) { $text = wfMessage('noarticletext_user_talk', $this->getTitle()->getText(), $this->getTitle()->getFullURL() . "?action=edit")->plain(); $showHeader = true; } else { if (MWNamespace::isTalk($this->mTitle->getNamespace())) { $text = wfMessage('noarticletext_talk', $this->getTitle()->getText(), $this->getTitle()->getFullURL() . "?action=edit")->plain(); $showHeader = true; } else { if ($this->mTitle->getNamespace() == NS_USER) { $text = wfMessage('noarticletext_user', $this->getTitle()->getText(), $this->getTitle()->getFullURL() . "?action=edit")->plain(); } else { if ($this->mTitle->getNamespace() == NS_USER_KUDOS) { $text = wfMessage('noarticletext_user_kudos', $this->getTitle()->getText(), $this->getTitle()->getFullURL() . "?action=edit")->plain(); } else { if ($this->mTitle->getNamespace() == NS_MAIN) { $text = wfMessage('noarticletext', $this->getTitle()->getText(), $this->getTitle()->getFullURL() . "?action=edit", urlencode($this->getTitle()->getText()))->plain(); $showHeader = true; } else { $text = wfMessage('noarticletext_standard', $this->getTitle()->getText(), $this->getTitle()->getFullURL() . "?action=edit")->plain(); } } } } } // original lines that were commented out inside this block // $message = $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon'; // $text = wfMessage( $message )->plain(); } else { $text = wfMessage('noarticletext-nopermission')->plain(); } $text = "<div class='noarticletext'>\n{$text}\n</div>"; // WIKIHOW - BEBETH following 3 lines added for styling if ($showHeader) { $text = "<h2>" . wfMessage('noarticlefound')->text() . "</h2>{$text}"; } $outputPage->addWikiText($text); }